1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-03-02 03:41:09 +01:00

[PM-5189] Fixing dynamic injection of autofill content scripts based on setting selection

This commit is contained in:
Cesar Gonzalez 2024-04-16 16:31:33 -05:00
parent c15439512b
commit 9bffe6f22c
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
4 changed files with 34 additions and 29 deletions

View File

@ -105,11 +105,7 @@ export class AutofillComponent implements OnInit {
}
async updateAutoFillOverlayVisibility() {
const previousAutoFillOverlayVisibility = await firstValueFrom(
this.autofillSettingsService.inlineMenuVisibility$,
);
await this.autofillSettingsService.setInlineMenuVisibility(this.autoFillOverlayVisibility);
await this.handleUpdatingAutofillOverlayContentScripts(previousAutoFillOverlayVisibility);
await this.requestPrivacyPermission();
}
@ -181,27 +177,6 @@ export class AutofillComponent implements OnInit {
BrowserApi.createNewTab(this.disablePasswordManagerLink);
}
private async handleUpdatingAutofillOverlayContentScripts(
previousAutoFillOverlayVisibility: number,
) {
const autofillOverlayPreviouslyDisabled =
previousAutoFillOverlayVisibility === AutofillOverlayVisibility.Off;
const autofillOverlayCurrentlyDisabled =
this.autoFillOverlayVisibility === AutofillOverlayVisibility.Off;
if (!autofillOverlayPreviouslyDisabled && !autofillOverlayCurrentlyDisabled) {
const tabs = await BrowserApi.tabsQuery({});
tabs.forEach((tab) =>
BrowserApi.tabSendMessageData(tab, "updateAutofillOverlayVisibility", {
autofillOverlayVisibility: this.autoFillOverlayVisibility,
}),
);
return;
}
await this.autofillService.reloadAutofillScripts();
}
async requestPrivacyPermission() {
if (
this.autoFillOverlayVisibility === AutofillOverlayVisibility.Off ||

View File

@ -19,7 +19,7 @@ export type AutofillOverlayContentExtensionMessageHandlers = {
bgUnlockPopoutOpened: () => void;
bgVaultItemRepromptPopoutOpened: () => void;
redirectOverlayFocusOut: ({ message }: AutofillExtensionMessageParam) => void;
updateAutofillOverlayVisibility: ({ message }: AutofillExtensionMessageParam) => void;
updateInlineMenuVisibility: ({ message }: AutofillExtensionMessageParam) => void;
getSubFrameOffsets: ({ message }: AutofillExtensionMessageParam) => Promise<SubFrameOffsetData>;
getSubFrameOffsetsFromWindowMessage: ({ message }: AutofillExtensionMessageParam) => void;
};

View File

@ -48,7 +48,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
bgVaultItemRepromptPopoutOpened: () => this.blurMostRecentOverlayField(true),
redirectOverlayFocusOut: ({ message }) =>
this.redirectOverlayFocusOut(message?.data?.direction),
updateAutofillOverlayVisibility: ({ message }) => this.updateAutofillOverlayVisibility(message),
updateInlineMenuVisibility: ({ message }) => this.updateInlineMenuVisibility(message),
getSubFrameOffsets: ({ message }) => this.getSubFrameOffsets(message),
getSubFrameOffsetsFromWindowMessage: ({ message }) =>
this.getSubFrameOffsetsFromWindowMessage(message),
@ -981,7 +981,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
});
};
private updateAutofillOverlayVisibility({ data }: AutofillExtensionMessage) {
private updateInlineMenuVisibility({ data }: AutofillExtensionMessage) {
if (isNaN(data?.autofillOverlayVisibility)) {
return;
}

View File

@ -1,7 +1,9 @@
import { firstValueFrom } from "rxjs";
import { firstValueFrom, startWith } from "rxjs";
import { pairwise } from "rxjs/operators";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { InlineMenuVisibilitySetting } from "@bitwarden/common/autofill/types";
@ -66,6 +68,11 @@ export default class AutofillService implements AutofillServiceInterface {
async loadAutofillScriptsOnInstall() {
BrowserApi.addListener(chrome.runtime.onConnect, this.handleInjectedScriptPortConnection);
void this.injectAutofillScriptsInAllTabs();
this.autofillSettingsService.inlineMenuVisibility$
.pipe(startWith(undefined), pairwise())
.subscribe(([previousSetting, currentSetting]) =>
this.handleInlineMenuVisibilityChange(previousSetting, currentSetting),
);
}
/**
@ -2066,4 +2073,27 @@ export default class AutofillService implements AutofillServiceInterface {
}
}
}
private async handleInlineMenuVisibilityChange(
previousSetting: InlineMenuVisibilitySetting,
currentSetting: InlineMenuVisibilitySetting,
) {
if (previousSetting === undefined || previousSetting === currentSetting) {
return;
}
const inlineMenuPreviouslyDisabled = previousSetting === AutofillOverlayVisibility.Off;
const inlineMenuCurrentlyDisabled = currentSetting === AutofillOverlayVisibility.Off;
if (!inlineMenuPreviouslyDisabled && !inlineMenuCurrentlyDisabled) {
const tabs = await BrowserApi.tabsQuery({});
tabs.forEach((tab) =>
BrowserApi.tabSendMessageData(tab, "updateInlineMenuVisibility", {
autofillOverlayVisibility: currentSetting,
}),
);
return;
}
await this.reloadAutofillScripts();
}
}