diff --git a/apps/browser/src/autofill/background/abstractions/overlay.background.ts b/apps/browser/src/autofill/background/abstractions/overlay.background.ts index 5e79585306c..6cbaebc6e4e 100644 --- a/apps/browser/src/autofill/background/abstractions/overlay.background.ts +++ b/apps/browser/src/autofill/background/abstractions/overlay.background.ts @@ -94,6 +94,8 @@ export type BackgroundOnMessageHandlerParams = BackgroundMessageParam & Backgrou export type OverlayBackgroundExtensionMessageHandlers = { [key: string]: CallableFunction; + + autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; triggerAutofillOverlayReposition: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; checkIsInlineMenuCiphersPopulated: ({ sender }: BackgroundSenderParam) => void; updateFocusedFieldData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; @@ -144,7 +146,6 @@ export type PortOnMessageHandlerParams = PortMessageParam & PortConnectionParam; export type OverlayContentScriptPortMessageHandlers = { [key: string]: CallableFunction; autofillOverlayElementClosed: ({ message, port }: PortOnMessageHandlerParams) => void; - autofillOverlayAddNewVaultItem: ({ message, port }: PortOnMessageHandlerParams) => void; }; export type InlineMenuButtonPortMessageHandlers = { diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 48f435ae8c4..f076a51ae49 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -77,6 +77,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { private isFieldCurrentlyFilling: boolean = false; private iconsServerUrl: string; private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = { + autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender), triggerAutofillOverlayReposition: ({ sender }) => this.triggerOverlayReposition(sender), checkIsInlineMenuCiphersPopulated: ({ sender }) => this.checkIsInlineMenuCiphersPopulated(sender), @@ -111,7 +112,6 @@ export class OverlayBackground implements OverlayBackgroundInterface { }; private readonly contentScriptPortMessageHandlers: OverlayContentScriptPortMessageHandlers = { autofillOverlayElementClosed: ({ message, port }) => this.overlayElementClosed(message, port), - autofillOverlayAddNewVaultItem: ({ message, port }) => this.addNewVaultItem(message, port), }; private readonly inlineMenuButtonPortMessageHandlers: InlineMenuButtonPortMessageHandlers = { triggerDelayedAutofillInlineMenuClosure: ({ port }) => this.triggerDelayedInlineMenuClosure(), @@ -1020,9 +1020,12 @@ export class OverlayBackground implements OverlayBackgroundInterface { * data captured in the extension message. * * @param login - The login data captured from the extension message - * @param port - The content script port + * @param sender - The sender of the extension message */ - private async addNewVaultItem({ login }: OverlayAddNewItemMessage, port: chrome.runtime.Port) { + private async addNewVaultItem( + { login }: OverlayAddNewItemMessage, + sender: chrome.runtime.MessageSender, + ) { if (!login) { return; } @@ -1046,7 +1049,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { collectionIds: cipherView.collectionIds, }); - await this.openAddEditVaultItemPopout(port.sender.tab, { cipherId: cipherView.id }); + await this.openAddEditVaultItemPopout(sender.tab, { cipherId: cipherView.id }); await BrowserApi.sendMessage("inlineAutofillMenuRefreshAddEditCipher"); } diff --git a/apps/browser/src/autofill/enums/autofill-overlay.enum.ts b/apps/browser/src/autofill/enums/autofill-overlay.enum.ts index c0c958de681..ea9eb0eb40a 100644 --- a/apps/browser/src/autofill/enums/autofill-overlay.enum.ts +++ b/apps/browser/src/autofill/enums/autofill-overlay.enum.ts @@ -3,9 +3,6 @@ export const AutofillOverlayElement = { List: "autofill-inline-menu-list", } as const; -export type AutofillOverlayElementType = - (typeof AutofillOverlayElement)[keyof typeof AutofillOverlayElement]; - export const AutofillOverlayPort = { ContentScript: "autofill-overlay-content-script-port", Button: "autofill-inline-menu-button-port", diff --git a/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts b/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts index e44cc2e3bf8..dbdc7d68936 100644 --- a/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts +++ b/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts @@ -1,7 +1,10 @@ import { AutofillExtensionMessage } from "../../../content/abstractions/autofill-init"; import { AutofillOverlayElement } from "../../../enums/autofill-overlay.enum"; -import { AutofillOverlayContentExtensionMessage } from "../../../services/abstractions/autofill-overlay-content.service"; -import { generateRandomCustomElementName, setElementStyles } from "../../../utils"; +import { + sendExtensionMessage, + generateRandomCustomElementName, + setElementStyles, +} from "../../../utils"; import { InlineMenuExtensionMessageHandlers, AutofillInlineMenuContentService as AutofillInlineMenuContentServiceInterface, @@ -10,6 +13,7 @@ import { AutofillInlineMenuButtonIframe } from "../iframe-content/autofill-inlin import { AutofillInlineMenuListIframe } from "../iframe-content/autofill-inline-menu-list-iframe"; export class AutofillInlineMenuContentService implements AutofillInlineMenuContentServiceInterface { + private readonly sendExtensionMessage = sendExtensionMessage; private readonly generateRandomCustomElementName = generateRandomCustomElementName; private readonly setElementStyles = setElementStyles; private isFirefoxBrowser = @@ -423,10 +427,7 @@ export class AutofillInlineMenuContentService implements AutofillInlineMenuConte * @param command - The command to send through the port. * @param message - The message to send through the port. */ - private sendPortMessage( - command: string, - message: Omit, - ) { + private sendPortMessage(command: string, message: Omit) { this.port.postMessage({ command, ...message }); } 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 a168ebe72c1..79d31536052 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 @@ -1,11 +1,7 @@ import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; -import { - OverlayAddNewItemMessage, - SubFrameOffsetData, -} from "../../background/abstractions/overlay.background"; +import { SubFrameOffsetData } from "../../background/abstractions/overlay.background"; import { AutofillExtensionMessageParam } from "../../content/abstractions/autofill-init"; -import { AutofillOverlayElementType } from "../../enums/autofill-overlay.enum"; import AutofillField from "../../models/autofill-field"; import AutofillPageDetails from "../../models/autofill-page-details"; import { ElementWithOpId, FormFieldElement } from "../../types"; @@ -38,11 +34,6 @@ export type AutofillOverlayContentExtensionMessageHandlers = { destroyAutofillInlineMenuListeners: () => void; }; -export type AutofillOverlayContentExtensionMessage = { - command: string; - overlayElement?: AutofillOverlayElementType; -} & OverlayAddNewItemMessage; - export interface AutofillOverlayContentService { pageDetailsUpdateRequired: boolean; messageHandlers: AutofillOverlayContentExtensionMessageHandlers; 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 aa0d46c9f96..14f533a13f0 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts @@ -31,7 +31,6 @@ import { } from "../utils"; import { - AutofillOverlayContentExtensionMessage, AutofillOverlayContentExtensionMessageHandlers, AutofillOverlayContentService as AutofillOverlayContentServiceInterface, OpenAutofillInlineMenuOptions, @@ -234,7 +233,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ hostname: globalThis.document.location.hostname, }; - this.sendPortMessage("autofillOverlayAddNewVaultItem", { login }); + void this.sendExtensionMessage("autofillOverlayAddNewVaultItem", { login }); } /** @@ -1122,19 +1121,6 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ ); } - /** - * Sends a message through the port to the background script. - * - * @param command - The command to send through the port. - * @param message - The message to send through the port. - */ - private sendPortMessage( - command: string, - message: Omit, - ) { - this.port.postMessage({ command, ...message }); - } - /** * Clears the user interaction event timeout. This is used to ensure that * the overlay is not repositioned while the user is interacting with it.