diff --git a/apps/browser/src/autofill/background/abstractions/overlay.background.ts b/apps/browser/src/autofill/background/abstractions/overlay.background.ts index 947307a7537..2df72e2f4b3 100644 --- a/apps/browser/src/autofill/background/abstractions/overlay.background.ts +++ b/apps/browser/src/autofill/background/abstractions/overlay.background.ts @@ -92,11 +92,17 @@ export type BackgroundOnMessageHandlerParams = BackgroundMessageParam & Backgrou export type OverlayBackgroundExtensionMessageHandlers = { [key: string]: CallableFunction; - openAutofillInlineMenu: () => void; - closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void; autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; + checkIsOverlayLoginCiphersPopulated: ({ sender }: BackgroundSenderParam) => void; + updateFocusedFieldData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; + updateIsFieldCurrentlyFocused: ({ message }: BackgroundMessageParam) => void; + checkIsFieldCurrentlyFocused: () => boolean; + updateIsFieldCurrentlyFilling: ({ message }: BackgroundMessageParam) => void; + checkIsFieldCurrentlyFilling: () => boolean; getAutofillInlineMenuVisibility: () => void; + openAutofillInlineMenu: () => void; + closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; checkAutofillInlineMenuFocused: () => void; focusAutofillInlineMenuList: () => void; updateAutofillInlineMenuPosition: ({ @@ -104,14 +110,8 @@ export type OverlayBackgroundExtensionMessageHandlers = { sender, }: BackgroundOnMessageHandlerParams) => Promise; updateAutofillInlineMenuHidden: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; - updateFocusedFieldData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; - updateIsFieldCurrentlyFocused: ({ message }: BackgroundMessageParam) => void; - checkIsFieldCurrentlyFocused: () => boolean; - updateIsFieldCurrentlyFilling: ({ message }: BackgroundMessageParam) => void; - checkIsFieldCurrentlyFilling: () => boolean; checkIsAutofillInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void; checkIsAutofillInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void; - checkIsOverlayLoginCiphersPopulated: ({ sender }: BackgroundSenderParam) => void; updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void; collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index b0ee30a7662..a0ffc446eec 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -64,28 +64,28 @@ export class OverlayBackground implements OverlayBackgroundInterface { private inlineMenuPageTranslations: Record; private iconsServerUrl: string; private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = { - openAutofillInlineMenu: () => this.openInlineMenu(false), - closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message), autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message), autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender), + checkIsOverlayLoginCiphersPopulated: ({ sender }) => + this.checkIsOverlayLoginCiphersPopulated(sender), + updateFocusedFieldData: ({ message, sender }) => this.setFocusedFieldData(message, sender), + updateIsFieldCurrentlyFocused: ({ message }) => this.updateIsFieldCurrentlyFocused(message), + checkIsFieldCurrentlyFocused: () => this.checkIsFieldCurrentlyFocused(), + updateIsFieldCurrentlyFilling: ({ message }) => this.updateIsFieldCurrentlyFilling(message), + checkIsFieldCurrentlyFilling: () => this.checkIsFieldCurrentlyFilling(), getAutofillInlineMenuVisibility: () => this.getInlineMenuVisibility(), + openAutofillInlineMenu: () => this.openInlineMenu(false), + closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message), checkAutofillInlineMenuFocused: () => this.checkInlineMenuFocused(), focusAutofillInlineMenuList: () => this.focusInlineMenuList(), updateAutofillInlineMenuPosition: ({ message, sender }) => this.updateInlineMenuPosition(message, sender), updateAutofillInlineMenuHidden: ({ message, sender }) => this.updateInlineMenuHidden(message, sender), - updateFocusedFieldData: ({ message, sender }) => this.setFocusedFieldData(message, sender), - updateIsFieldCurrentlyFocused: ({ message }) => this.updateIsFieldCurrentlyFocused(message), - checkIsFieldCurrentlyFocused: () => this.checkIsFieldCurrentlyFocused(), - updateIsFieldCurrentlyFilling: ({ message }) => this.updateIsFieldCurrentlyFilling(message), - checkIsFieldCurrentlyFilling: () => this.checkIsFieldCurrentlyFilling(), checkIsAutofillInlineMenuButtonVisible: ({ sender }) => this.checkIsAutofillInlineMenuButtonVisible(sender), checkIsAutofillInlineMenuListVisible: ({ sender }) => this.checkIsAutofillInlineMenuListVisible(sender), - checkIsOverlayLoginCiphersPopulated: ({ sender }) => - this.checkIsOverlayLoginCiphersPopulated(sender), updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender), rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender), collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender), diff --git a/apps/browser/src/autofill/content/autofill-init.ts b/apps/browser/src/autofill/content/autofill-init.ts index 6d23b7b55ae..d28af1f65fd 100644 --- a/apps/browser/src/autofill/content/autofill-init.ts +++ b/apps/browser/src/autofill/content/autofill-init.ts @@ -40,21 +40,7 @@ class AutofillInit implements AutofillInitInterface { inlineMenuElements?: AutofillInlineMenuContentService, ) { this.autofillOverlayContentService = autofillOverlayContentService; - if (this.autofillOverlayContentService) { - this.extensionMessageHandlers = Object.assign( - this.extensionMessageHandlers, - this.autofillOverlayContentService.extensionMessageHandlers, - ); - } - this.autofillInlineMenuContentService = inlineMenuElements; - if (this.autofillInlineMenuContentService) { - this.extensionMessageHandlers = Object.assign( - this.extensionMessageHandlers, - this.autofillInlineMenuContentService.extensionMessageHandlers, - ); - } - this.domElementVisibilityService = new DomElementVisibilityService( this.autofillInlineMenuContentService, ); @@ -190,7 +176,7 @@ class AutofillInit implements AutofillInitInterface { sendResponse: (response?: any) => void, ): boolean => { const command: string = message.command; - const handler: CallableFunction | undefined = this.extensionMessageHandlers[command]; + const handler: CallableFunction | undefined = this.getExtensionMessageHandler(command); if (!handler) { return; } @@ -204,6 +190,18 @@ class AutofillInit implements AutofillInitInterface { return true; }; + private getExtensionMessageHandler(command: string): CallableFunction | undefined { + if (this.autofillOverlayContentService?.extensionMessageHandlers?.[command]) { + return this.autofillOverlayContentService.extensionMessageHandlers[command]; + } + + if (this.autofillInlineMenuContentService?.extensionMessageHandlers?.[command]) { + return this.autofillInlineMenuContentService.extensionMessageHandlers[command]; + } + + return this.extensionMessageHandlers[command]; + } + /** * Handles destroying the autofill init content script. Removes all * listeners, timeouts, and object instances to prevent memory leaks.