mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +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:
@@ -92,11 +92,17 @@ export type BackgroundOnMessageHandlerParams = BackgroundMessageParam & Backgrou
|
|||||||
|
|
||||||
export type OverlayBackgroundExtensionMessageHandlers = {
|
export type OverlayBackgroundExtensionMessageHandlers = {
|
||||||
[key: string]: CallableFunction;
|
[key: string]: CallableFunction;
|
||||||
openAutofillInlineMenu: () => void;
|
|
||||||
closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
|
||||||
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
|
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
|
||||||
autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => 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;
|
getAutofillInlineMenuVisibility: () => void;
|
||||||
|
openAutofillInlineMenu: () => void;
|
||||||
|
closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||||
checkAutofillInlineMenuFocused: () => void;
|
checkAutofillInlineMenuFocused: () => void;
|
||||||
focusAutofillInlineMenuList: () => void;
|
focusAutofillInlineMenuList: () => void;
|
||||||
updateAutofillInlineMenuPosition: ({
|
updateAutofillInlineMenuPosition: ({
|
||||||
@@ -104,14 +110,8 @@ export type OverlayBackgroundExtensionMessageHandlers = {
|
|||||||
sender,
|
sender,
|
||||||
}: BackgroundOnMessageHandlerParams) => Promise<void>;
|
}: BackgroundOnMessageHandlerParams) => Promise<void>;
|
||||||
updateAutofillInlineMenuHidden: ({ message, sender }: BackgroundOnMessageHandlerParams) => 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;
|
checkIsAutofillInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void;
|
||||||
checkIsAutofillInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void;
|
checkIsAutofillInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void;
|
||||||
checkIsOverlayLoginCiphersPopulated: ({ sender }: BackgroundSenderParam) => void;
|
|
||||||
updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||||
rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void;
|
rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void;
|
||||||
collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||||
|
|||||||
@@ -64,28 +64,28 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
private inlineMenuPageTranslations: Record<string, string>;
|
private inlineMenuPageTranslations: Record<string, string>;
|
||||||
private iconsServerUrl: string;
|
private iconsServerUrl: string;
|
||||||
private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = {
|
private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = {
|
||||||
openAutofillInlineMenu: () => this.openInlineMenu(false),
|
|
||||||
closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message),
|
|
||||||
autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message),
|
autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message),
|
||||||
autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender),
|
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(),
|
getAutofillInlineMenuVisibility: () => this.getInlineMenuVisibility(),
|
||||||
|
openAutofillInlineMenu: () => this.openInlineMenu(false),
|
||||||
|
closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message),
|
||||||
checkAutofillInlineMenuFocused: () => this.checkInlineMenuFocused(),
|
checkAutofillInlineMenuFocused: () => this.checkInlineMenuFocused(),
|
||||||
focusAutofillInlineMenuList: () => this.focusInlineMenuList(),
|
focusAutofillInlineMenuList: () => this.focusInlineMenuList(),
|
||||||
updateAutofillInlineMenuPosition: ({ message, sender }) =>
|
updateAutofillInlineMenuPosition: ({ message, sender }) =>
|
||||||
this.updateInlineMenuPosition(message, sender),
|
this.updateInlineMenuPosition(message, sender),
|
||||||
updateAutofillInlineMenuHidden: ({ message, sender }) =>
|
updateAutofillInlineMenuHidden: ({ message, sender }) =>
|
||||||
this.updateInlineMenuHidden(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 }) =>
|
checkIsAutofillInlineMenuButtonVisible: ({ sender }) =>
|
||||||
this.checkIsAutofillInlineMenuButtonVisible(sender),
|
this.checkIsAutofillInlineMenuButtonVisible(sender),
|
||||||
checkIsAutofillInlineMenuListVisible: ({ sender }) =>
|
checkIsAutofillInlineMenuListVisible: ({ sender }) =>
|
||||||
this.checkIsAutofillInlineMenuListVisible(sender),
|
this.checkIsAutofillInlineMenuListVisible(sender),
|
||||||
checkIsOverlayLoginCiphersPopulated: ({ sender }) =>
|
|
||||||
this.checkIsOverlayLoginCiphersPopulated(sender),
|
|
||||||
updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender),
|
updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender),
|
||||||
rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender),
|
rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender),
|
||||||
collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender),
|
collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender),
|
||||||
|
|||||||
@@ -40,21 +40,7 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
inlineMenuElements?: AutofillInlineMenuContentService,
|
inlineMenuElements?: AutofillInlineMenuContentService,
|
||||||
) {
|
) {
|
||||||
this.autofillOverlayContentService = autofillOverlayContentService;
|
this.autofillOverlayContentService = autofillOverlayContentService;
|
||||||
if (this.autofillOverlayContentService) {
|
|
||||||
this.extensionMessageHandlers = Object.assign(
|
|
||||||
this.extensionMessageHandlers,
|
|
||||||
this.autofillOverlayContentService.extensionMessageHandlers,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.autofillInlineMenuContentService = inlineMenuElements;
|
this.autofillInlineMenuContentService = inlineMenuElements;
|
||||||
if (this.autofillInlineMenuContentService) {
|
|
||||||
this.extensionMessageHandlers = Object.assign(
|
|
||||||
this.extensionMessageHandlers,
|
|
||||||
this.autofillInlineMenuContentService.extensionMessageHandlers,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.domElementVisibilityService = new DomElementVisibilityService(
|
this.domElementVisibilityService = new DomElementVisibilityService(
|
||||||
this.autofillInlineMenuContentService,
|
this.autofillInlineMenuContentService,
|
||||||
);
|
);
|
||||||
@@ -190,7 +176,7 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
sendResponse: (response?: any) => void,
|
sendResponse: (response?: any) => void,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const command: string = message.command;
|
const command: string = message.command;
|
||||||
const handler: CallableFunction | undefined = this.extensionMessageHandlers[command];
|
const handler: CallableFunction | undefined = this.getExtensionMessageHandler(command);
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -204,6 +190,18 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
return true;
|
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
|
* Handles destroying the autofill init content script. Removes all
|
||||||
* listeners, timeouts, and object instances to prevent memory leaks.
|
* listeners, timeouts, and object instances to prevent memory leaks.
|
||||||
|
|||||||
Reference in New Issue
Block a user