From 3d1104f81ca6a9303f86ebeab4278e753fdd6962 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Fri, 3 May 2024 15:05:52 -0500 Subject: [PATCH] [PM-5189] Reworking project structure to ensure we can better differentiate the inline menu feature from other features --- .../abstractions/overlay.background.ts | 54 +++++++------------ .../background/overlay.background.spec.ts | 2 +- .../autofill/background/overlay.background.ts | 4 +- .../background/tabs.background.spec.ts | 2 +- .../autofill/background/tabs.background.ts | 2 +- .../browser/src/background/main.background.ts | 2 +- 6 files changed, 24 insertions(+), 42 deletions(-) diff --git a/apps/browser/src/autofill/background/abstractions/overlay.background.ts b/apps/browser/src/autofill/background/abstractions/overlay.background.ts index 5c902314cc..947307a753 100644 --- a/apps/browser/src/autofill/background/abstractions/overlay.background.ts +++ b/apps/browser/src/autofill/background/abstractions/overlay.background.ts @@ -6,31 +6,31 @@ import { PageDetail } from "../../services/abstractions/autofill.service"; import { LockedVaultPendingNotificationsData } from "./notification.background"; -type PageDetailsForTab = Record< +export type PageDetailsForTab = Record< chrome.runtime.MessageSender["tab"]["id"], Map >; -type SubFrameOffsetData = { +export type SubFrameOffsetData = { frameId?: number; url?: string; top: number; left: number; } | null; -type SubFrameOffsetsForTab = Record< +export type SubFrameOffsetsForTab = Record< chrome.runtime.MessageSender["tab"]["id"], Map >; -type WebsiteIconData = { +export type WebsiteIconData = { imageEnabled: boolean; image: string; fallbackImage: string; icon: string; }; -type OverlayAddNewItemMessage = { +export type OverlayAddNewItemMessage = { login?: { uri?: string; hostname: string; @@ -39,14 +39,14 @@ type OverlayAddNewItemMessage = { }; }; -type FocusedFieldData = { +export type FocusedFieldData = { focusedFieldStyles: Partial; focusedFieldRects: Partial; tabId?: number; frameId?: number; }; -type OverlayBackgroundExtensionMessage = { +export type OverlayBackgroundExtensionMessage = { command: string; portKey?: string; tab?: chrome.tabs.Tab; @@ -64,14 +64,14 @@ type OverlayBackgroundExtensionMessage = { data?: LockedVaultPendingNotificationsData; } & OverlayAddNewItemMessage; -type OverlayPortMessage = { +export type OverlayPortMessage = { [key: string]: any; command: string; direction?: string; overlayCipherId?: string; }; -type OverlayCipherData = { +export type OverlayCipherData = { id: string; name: string; type: CipherType; @@ -82,15 +82,15 @@ type OverlayCipherData = { card?: string; }; -type BackgroundMessageParam = { +export type BackgroundMessageParam = { message: OverlayBackgroundExtensionMessage; }; -type BackgroundSenderParam = { +export type BackgroundSenderParam = { sender: chrome.runtime.MessageSender; }; -type BackgroundOnMessageHandlerParams = BackgroundMessageParam & BackgroundSenderParam; +export type BackgroundOnMessageHandlerParams = BackgroundMessageParam & BackgroundSenderParam; -type OverlayBackgroundExtensionMessageHandlers = { +export type OverlayBackgroundExtensionMessageHandlers = { [key: string]: CallableFunction; openAutofillInlineMenu: () => void; closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; @@ -120,15 +120,15 @@ type OverlayBackgroundExtensionMessageHandlers = { deletedCipher: () => void; }; -type PortMessageParam = { +export type PortMessageParam = { message: OverlayPortMessage; }; -type PortConnectionParam = { +export type PortConnectionParam = { port: chrome.runtime.Port; }; -type PortOnMessageHandlerParams = PortMessageParam & PortConnectionParam; +export type PortOnMessageHandlerParams = PortMessageParam & PortConnectionParam; -type InlineMenuButtonPortMessageHandlers = { +export type InlineMenuButtonPortMessageHandlers = { [key: string]: CallableFunction; autofillInlineMenuButtonClicked: ({ port }: PortConnectionParam) => void; closeAutofillInlineMenu: ({ port }: PortConnectionParam) => void; @@ -138,7 +138,7 @@ type InlineMenuButtonPortMessageHandlers = { updateAutofillInlineMenuColorScheme: () => void; }; -type InlineMenuListPortMessageHandlers = { +export type InlineMenuListPortMessageHandlers = { [key: string]: CallableFunction; checkAutofillInlineMenuButtonFocused: () => void; forceCloseAutofillInlineMenu: ({ port }: PortConnectionParam) => void; @@ -151,24 +151,8 @@ type InlineMenuListPortMessageHandlers = { updateAutofillInlineMenuListHeight: ({ message, port }: PortOnMessageHandlerParams) => void; }; -interface OverlayBackground { +export interface OverlayBackground { init(): Promise; removePageDetails(tabId: number): void; updateOverlayCiphers(): void; } - -export { - PageDetailsForTab, - SubFrameOffsetData, - SubFrameOffsetsForTab, - WebsiteIconData, - OverlayBackgroundExtensionMessage, - OverlayPortMessage, - FocusedFieldData, - OverlayCipherData, - OverlayAddNewItemMessage, - OverlayBackgroundExtensionMessageHandlers, - InlineMenuButtonPortMessageHandlers, - InlineMenuListPortMessageHandlers, - OverlayBackground, -}; diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 11786f9df3..f117a8a013 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -51,7 +51,7 @@ import { } from "../spec/autofill-mocks"; import { flushPromises, sendMockExtensionMessage, sendPortMessage } from "../spec/testing-utils"; -import OverlayBackground from "./overlay.background"; +import { OverlayBackground } from "./overlay.background"; describe("OverlayBackground", () => { const mockUserId = Utils.newGuid() as UserId; diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 1d9723a5bb..b0ee30a766 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -46,7 +46,7 @@ import { SubFrameOffsetsForTab, } from "./abstractions/overlay.background"; -class OverlayBackground implements OverlayBackgroundInterface { +export class OverlayBackground implements OverlayBackgroundInterface { private readonly openUnlockPopout = openUnlockPopout; private readonly openViewVaultItemPopout = openViewVaultItemPopout; private readonly openAddEditVaultItemPopout = openAddEditVaultItemPopout; @@ -1047,5 +1047,3 @@ class OverlayBackground implements OverlayBackgroundInterface { } }; } - -export default OverlayBackground; diff --git a/apps/browser/src/autofill/background/tabs.background.spec.ts b/apps/browser/src/autofill/background/tabs.background.spec.ts index b95e303f17..e29d6720e1 100644 --- a/apps/browser/src/autofill/background/tabs.background.spec.ts +++ b/apps/browser/src/autofill/background/tabs.background.spec.ts @@ -11,7 +11,7 @@ import { } from "../spec/testing-utils"; import NotificationBackground from "./notification.background"; -import OverlayBackground from "./overlay.background"; +import { OverlayBackground } from "./overlay.background"; import TabsBackground from "./tabs.background"; describe("TabsBackground", () => { diff --git a/apps/browser/src/autofill/background/tabs.background.ts b/apps/browser/src/autofill/background/tabs.background.ts index 53c801ff7b..c1d9fddefe 100644 --- a/apps/browser/src/autofill/background/tabs.background.ts +++ b/apps/browser/src/autofill/background/tabs.background.ts @@ -1,7 +1,7 @@ import MainBackground from "../../background/main.background"; +import { OverlayBackground } from "./abstractions/overlay.background"; import NotificationBackground from "./notification.background"; -import OverlayBackground from "./overlay.background"; export default class TabsBackground { constructor( diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 7cc2739f39..c9da6defbf 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -195,7 +195,7 @@ import { import ContextMenusBackground from "../autofill/background/context-menus.background"; import NotificationBackground from "../autofill/background/notification.background"; -import OverlayBackground from "../autofill/background/overlay.background"; +import { OverlayBackground } from "../autofill/background/overlay.background"; import TabsBackground from "../autofill/background/tabs.background"; import WebRequestBackground from "../autofill/background/web-request.background"; import { CipherContextMenuHandler } from "../autofill/browser/cipher-context-menu-handler";