diff --git a/apps/browser/src/autofill/background/abstractions/overlay.background.ts b/apps/browser/src/autofill/background/abstractions/overlay.background.ts index 8ea643cf60c..ae233de7509 100644 --- a/apps/browser/src/autofill/background/abstractions/overlay.background.ts +++ b/apps/browser/src/autofill/background/abstractions/overlay.background.ts @@ -112,6 +112,7 @@ type OverlayBackgroundExtensionMessageHandlers = { updateIsFieldCurrentlyFilling: ({ message }: BackgroundMessageParam) => void; checkIsInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void; checkIsInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void; + checkIsInlineMenuCiphersPopulated: ({ sender }: BackgroundSenderParam) => void; updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void; }; diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 46803af7d45..bba50cce27b 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -85,6 +85,8 @@ class OverlayBackground implements OverlayBackgroundInterface { (this.isCurrentlyFilling = message.isFieldCurrentlyFilling), checkIsInlineMenuButtonVisible: ({ sender }) => this.checkIsInlineMenuButtonVisible(sender), checkIsInlineMenuListVisible: ({ sender }) => this.checkIsInlineMenuListVisible(sender), + checkIsInlineMenuCiphersPopulated: ({ sender }) => + this.checkIsInlineMenuCiphersPopulated(sender), updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender), rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender), }; @@ -137,6 +139,10 @@ class OverlayBackground implements OverlayBackgroundInterface { ); } + private checkIsInlineMenuCiphersPopulated(sender: chrome.runtime.MessageSender) { + return sender.tab.id === this.focusedFieldData.tabId && this.overlayLoginCiphers.size > 0; + } + updateSubFrameData(message: any, sender: chrome.runtime.MessageSender) { const subFrameOffsetsForTab = this.subFrameOffsetsForTab[sender.tab.id]; if (subFrameOffsetsForTab) { @@ -199,9 +205,6 @@ class OverlayBackground implements OverlayBackgroundInterface { const ciphers = await this.getOverlayCipherData(); this.overlayListPort?.postMessage({ command: "updateOverlayListCiphers", ciphers }); - await BrowserApi.tabSendMessageData(currentTab, "updateIsOverlayCiphersPopulated", { - isOverlayCiphersPopulated: Boolean(ciphers.length), - }); } /** diff --git a/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts b/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts index 21bd964ee42..0256c9b0c19 100644 --- a/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts @@ -20,15 +20,11 @@ export type AutofillOverlayContentExtensionMessageHandlers = { bgVaultItemRepromptPopoutOpened: () => void; redirectOverlayFocusOut: ({ message }: AutofillExtensionMessageParam) => void; updateAutofillOverlayVisibility: ({ message }: AutofillExtensionMessageParam) => void; - updateIsOverlayCiphersPopulated: ({ message }: AutofillExtensionMessageParam) => void; getSubFrameOffsets: ({ message }: AutofillExtensionMessageParam) => Promise; getSubFrameOffsetsFromWindowMessage: ({ message }: AutofillExtensionMessageParam) => void; }; export interface AutofillOverlayContentService { - // isFieldCurrentlyFocused: boolean; - // isCurrentlyFilling: boolean; - isOverlayCiphersPopulated: boolean; pageDetailsUpdateRequired: boolean; autofillOverlayVisibility: number; extensionMessageHandlers: any; @@ -37,11 +33,6 @@ export interface AutofillOverlayContentService { autofillFieldElement: ElementWithOpId, autofillFieldData: AutofillField, ): Promise; - openAutofillOverlay(options: OpenAutofillOverlayOptions): void; - // removeAutofillOverlay(): void; - // removeAutofillOverlayButton(): void; - // removeAutofillOverlayList(): void; - addNewVaultItem(): void; focusMostRecentOverlayField(): void; blurMostRecentOverlayField(isRemovingOverlay?: boolean): void; destroy(): void; diff --git a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts index 27c3033cbd2..7a15f74ced1 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts @@ -23,7 +23,6 @@ import { import { AutoFillConstants } from "./autofill-constants"; class AutofillOverlayContentService implements AutofillOverlayContentServiceInterface { - isOverlayCiphersPopulated = false; pageDetailsUpdateRequired = false; autofillOverlayVisibility: number; private readonly findTabs = tabbable; @@ -47,7 +46,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte bgVaultItemRepromptPopoutOpened: () => this.blurMostRecentOverlayField(true), redirectOverlayFocusOut: ({ message }) => this.redirectOverlayFocusOut(message), updateAutofillOverlayVisibility: ({ message }) => this.updateAutofillOverlayVisibility(message), - updateIsOverlayCiphersPopulated: ({ message }) => this.updateIsOverlayCiphersPopulated(message), getSubFrameOffsets: ({ message }) => this.getSubFrameOffsets(message), getSubFrameOffsetsFromWindowMessage: ({ message }) => this.getSubFrameOffsetsFromWindowMessage(message), @@ -365,14 +363,17 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * * @param formFieldElement - The form field element that triggered the input event. */ - private triggerFormFieldInput(formFieldElement: ElementWithOpId) { + private async triggerFormFieldInput(formFieldElement: ElementWithOpId) { if (!elementIsFillableFormField(formFieldElement)) { return; } this.storeModifiedFormElement(formFieldElement); - if (formFieldElement.value && (this.isOverlayCiphersPopulated || !this.isUserAuthed())) { + if ( + formFieldElement.value && + ((await this.isOverlayCiphersPopulated()) || !this.isUserAuthed()) + ) { void this.sendExtensionMessage("closeAutofillOverlay", { overlayElement: AutofillOverlayElement.List, forceCloseOverlay: true, @@ -475,7 +476,10 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte }); } - if (!formElementHasValue || (!this.isOverlayCiphersPopulated && this.isUserAuthed())) { + if ( + !formElementHasValue || + (!(await this.isOverlayCiphersPopulated()) && this.isUserAuthed()) + ) { void this.sendExtensionMessage("openAutofillOverlay"); return; } @@ -764,9 +768,12 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField); this.updateOverlayElementsPosition(); - setTimeout(() => { + setTimeout(async () => { this.toggleOverlayHidden(false); - if ((this.mostRecentlyFocusedField as HTMLInputElement).value) { + if ( + (this.mostRecentlyFocusedField as HTMLInputElement).value && + ((await this.isOverlayCiphersPopulated()) || !this.isUserAuthed()) + ) { void this.sendExtensionMessage("closeAutofillOverlay", { overlayElement: AutofillOverlayElement.List, forceCloseOverlay: true, @@ -946,8 +953,8 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte this.autofillOverlayVisibility = data.autofillOverlayVisibility; } - private updateIsOverlayCiphersPopulated({ data }: AutofillExtensionMessage) { - this.isOverlayCiphersPopulated = Boolean(data?.isOverlayCiphersPopulated); + private async isOverlayCiphersPopulated() { + return (await this.sendExtensionMessage("checkIsInlineMenuCiphersPopulated")) === true; } /**