1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

[PM-5189] Reworking project structure to ensure we can better differentiate the inline menu feature from other features

This commit is contained in:
Cesar Gonzalez
2024-05-03 15:21:58 -05:00
parent 3d1104f81c
commit 53975e6380
3 changed files with 30 additions and 32 deletions

View File

@@ -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<void>;
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;

View File

@@ -64,28 +64,28 @@ export class OverlayBackground implements OverlayBackgroundInterface {
private inlineMenuPageTranslations: Record<string, string>;
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),

View File

@@ -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.