1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-24 21:41:33 +01:00

Revert "[PM-5189] Working through content script port improvement"

This reverts commit 857008413f.
This commit is contained in:
Cesar Gonzalez 2024-06-19 05:10:16 -05:00
parent ce35ce4183
commit cecf00cf64
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
5 changed files with 46 additions and 24 deletions

View File

@ -94,15 +94,21 @@ export type BackgroundOnMessageHandlerParams = BackgroundMessageParam & Backgrou
export type OverlayBackgroundExtensionMessageHandlers = { export type OverlayBackgroundExtensionMessageHandlers = {
[key: string]: CallableFunction; [key: string]: CallableFunction;
closeAutofillInlineMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
checkIsInlineMenuCiphersPopulated: ({ sender }: BackgroundSenderParam) => void; checkIsInlineMenuCiphersPopulated: ({ sender }: BackgroundSenderParam) => void;
updateIsFieldCurrentlyFilling: ({ message }: BackgroundMessageParam) => void; updateIsFieldCurrentlyFilling: ({ message }: BackgroundMessageParam) => void;
checkIsFieldCurrentlyFilling: () => boolean; checkIsFieldCurrentlyFilling: () => boolean;
getAutofillInlineMenuVisibility: () => void; getAutofillInlineMenuVisibility: () => void;
toggleAutofillInlineMenuHidden: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
checkIsAutofillInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void; checkIsAutofillInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void;
checkIsAutofillInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void; checkIsAutofillInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void;
getCurrentTabFrameId: ({ sender }: BackgroundSenderParam) => number; getCurrentTabFrameId: ({ sender }: BackgroundSenderParam) => number;
updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
triggerSubFrameFocusInRebuild: ({ sender }: BackgroundSenderParam) => void;
destroyAutofillInlineMenuListeners: ({
message,
sender,
}: BackgroundOnMessageHandlerParams) => void;
collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void; collectPageDetailsResponse: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
unlockCompleted: ({ message }: BackgroundMessageParam) => void; unlockCompleted: ({ message }: BackgroundMessageParam) => void;
addedCipher: () => void; addedCipher: () => void;
@ -131,19 +137,18 @@ export type OverlayContentScriptPortMessageHandlers = {
updateFocusedFieldData: ({ message, port }: PortOnMessageHandlerParams) => void; updateFocusedFieldData: ({ message, port }: PortOnMessageHandlerParams) => void;
updateIsFieldCurrentlyFocused: ({ message }: PortMessageParam) => void; updateIsFieldCurrentlyFocused: ({ message }: PortMessageParam) => void;
openAutofillInlineMenu: () => void; openAutofillInlineMenu: () => void;
closeAutofillInlineMenu: ({ message, port }: PortOnMessageHandlerParams) => void;
checkAutofillInlineMenuFocused: () => void; checkAutofillInlineMenuFocused: () => void;
focusAutofillInlineMenuList: () => void; focusAutofillInlineMenuList: () => void;
updateAutofillInlineMenuPosition: ({ updateAutofillInlineMenuPosition: ({
message, message,
port, port,
}: PortOnMessageHandlerParams) => Promise<void>; }: PortOnMessageHandlerParams) => Promise<void>;
updateSubFrameData: ({ message, port }: PortOnMessageHandlerParams) => void;
triggerSubFrameFocusInRebuild: ({ port }: PortConnectionParam) => void;
destroyAutofillInlineMenuListeners: ({ message, port }: PortOnMessageHandlerParams) => void;
}; };
export type InlineMenuButtonPortMessageHandlers = { export type InlineMenuButtonPortMessageHandlers = {
[key: string]: CallableFunction; [key: string]: CallableFunction;
closeAutofillInlineMenu: ({ message, port }: PortOnMessageHandlerParams) => void;
triggerDelayedAutofillInlineMenuClosure: ({ port }: PortConnectionParam) => void; triggerDelayedAutofillInlineMenuClosure: ({ port }: PortConnectionParam) => void;
autofillInlineMenuButtonClicked: ({ port }: PortConnectionParam) => void; autofillInlineMenuButtonClicked: ({ port }: PortConnectionParam) => void;
autofillInlineMenuBlurred: () => void; autofillInlineMenuBlurred: () => void;
@ -153,6 +158,7 @@ export type InlineMenuButtonPortMessageHandlers = {
export type InlineMenuListPortMessageHandlers = { export type InlineMenuListPortMessageHandlers = {
[key: string]: CallableFunction; [key: string]: CallableFunction;
closeAutofillInlineMenu: ({ message, port }: PortOnMessageHandlerParams) => void;
checkAutofillInlineMenuButtonFocused: () => void; checkAutofillInlineMenuButtonFocused: () => void;
autofillInlineMenuBlurred: () => void; autofillInlineMenuBlurred: () => void;
unlockVault: ({ port }: PortConnectionParam) => void; unlockVault: ({ port }: PortConnectionParam) => void;

View File

@ -77,16 +77,22 @@ export class OverlayBackground implements OverlayBackgroundInterface {
private isFieldCurrentlyFilling: boolean = false; private isFieldCurrentlyFilling: boolean = false;
private iconsServerUrl: string; private iconsServerUrl: string;
private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = { private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = {
closeAutofillInlineMenu: ({ message, sender }) => this.closeInlineMenu(sender, message),
checkIsInlineMenuCiphersPopulated: ({ sender }) => checkIsInlineMenuCiphersPopulated: ({ sender }) =>
this.checkIsInlineMenuCiphersPopulated(sender), this.checkIsInlineMenuCiphersPopulated(sender),
updateIsFieldCurrentlyFilling: ({ message }) => this.updateIsFieldCurrentlyFilling(message), updateIsFieldCurrentlyFilling: ({ message }) => this.updateIsFieldCurrentlyFilling(message),
checkIsFieldCurrentlyFilling: () => this.checkIsFieldCurrentlyFilling(), checkIsFieldCurrentlyFilling: () => this.checkIsFieldCurrentlyFilling(),
getAutofillInlineMenuVisibility: () => this.getInlineMenuVisibility(), getAutofillInlineMenuVisibility: () => this.getInlineMenuVisibility(),
toggleAutofillInlineMenuHidden: ({ message, sender }) =>
this.toggleInlineMenuHidden(message, sender),
checkIsAutofillInlineMenuButtonVisible: ({ sender }) => checkIsAutofillInlineMenuButtonVisible: ({ sender }) =>
this.checkIsInlineMenuButtonVisible(sender), this.checkIsInlineMenuButtonVisible(sender),
checkIsAutofillInlineMenuListVisible: ({ sender }) => this.checkIsInlineMenuListVisible(sender), checkIsAutofillInlineMenuListVisible: ({ sender }) => this.checkIsInlineMenuListVisible(sender),
getCurrentTabFrameId: ({ sender }) => this.getSenderFrameId(sender), getCurrentTabFrameId: ({ sender }) => this.getSenderFrameId(sender),
updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender),
triggerSubFrameFocusInRebuild: ({ sender }) => this.triggerSubFrameFocusInRebuild(sender),
destroyAutofillInlineMenuListeners: ({ message, sender }) =>
this.triggerDestroyInlineMenuListeners(sender.tab, message.subFrameData.frameId),
collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender), collectPageDetailsResponse: ({ message, sender }) => this.storePageDetails(message, sender),
unlockCompleted: ({ message }) => this.unlockCompleted(message), unlockCompleted: ({ message }) => this.unlockCompleted(message),
addedCipher: () => this.updateInlineMenuCiphers(), addedCipher: () => this.updateInlineMenuCiphers(),
@ -101,16 +107,14 @@ export class OverlayBackground implements OverlayBackgroundInterface {
updateFocusedFieldData: ({ message, port }) => this.setFocusedFieldData(message, port), updateFocusedFieldData: ({ message, port }) => this.setFocusedFieldData(message, port),
updateIsFieldCurrentlyFocused: ({ message }) => this.updateIsFieldCurrentlyFocused(message), updateIsFieldCurrentlyFocused: ({ message }) => this.updateIsFieldCurrentlyFocused(message),
openAutofillInlineMenu: () => this.openInlineMenu(false), openAutofillInlineMenu: () => this.openInlineMenu(false),
closeAutofillInlineMenu: ({ message, port }) => this.closeInlineMenu(port.sender, message),
checkAutofillInlineMenuFocused: () => this.checkInlineMenuFocused(), checkAutofillInlineMenuFocused: () => this.checkInlineMenuFocused(),
focusAutofillInlineMenuList: () => this.focusInlineMenuList(), focusAutofillInlineMenuList: () => this.focusInlineMenuList(),
updateAutofillInlineMenuPosition: ({ message, port }) => updateAutofillInlineMenuPosition: ({ message, port }) =>
this.updateInlineMenuPosition(message, port.sender), this.updateInlineMenuPosition(message, port.sender),
updateSubFrameData: ({ message, port }) => this.updateSubFrameData(message, port),
triggerSubFrameFocusInRebuild: ({ port }) => this.triggerSubFrameFocusInRebuild(port),
destroyAutofillInlineMenuListeners: ({ message, port }) =>
this.triggerDestroyInlineMenuListeners(port.sender.tab, message.subFrameData.frameId),
}; };
private readonly inlineMenuButtonPortMessageHandlers: InlineMenuButtonPortMessageHandlers = { private readonly inlineMenuButtonPortMessageHandlers: InlineMenuButtonPortMessageHandlers = {
closeAutofillInlineMenu: ({ message, port }) => this.closeInlineMenu(port.sender, message),
triggerDelayedAutofillInlineMenuClosure: ({ port }) => this.triggerDelayedInlineMenuClosure(), triggerDelayedAutofillInlineMenuClosure: ({ port }) => this.triggerDelayedInlineMenuClosure(),
autofillInlineMenuButtonClicked: ({ port }) => this.handleInlineMenuButtonClicked(port), autofillInlineMenuButtonClicked: ({ port }) => this.handleInlineMenuButtonClicked(port),
autofillInlineMenuBlurred: () => this.checkInlineMenuListFocused(), autofillInlineMenuBlurred: () => this.checkInlineMenuListFocused(),
@ -119,6 +123,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
updateAutofillInlineMenuColorScheme: () => this.updateInlineMenuButtonColorScheme(), updateAutofillInlineMenuColorScheme: () => this.updateInlineMenuButtonColorScheme(),
}; };
private readonly inlineMenuListPortMessageHandlers: InlineMenuListPortMessageHandlers = { private readonly inlineMenuListPortMessageHandlers: InlineMenuListPortMessageHandlers = {
closeAutofillInlineMenu: ({ message, port }) => this.closeInlineMenu(port.sender, message),
checkAutofillInlineMenuButtonFocused: () => this.checkInlineMenuButtonFocused(), checkAutofillInlineMenuButtonFocused: () => this.checkInlineMenuButtonFocused(),
autofillInlineMenuBlurred: () => this.checkInlineMenuButtonFocused(), autofillInlineMenuBlurred: () => this.checkInlineMenuButtonFocused(),
unlockVault: ({ port }) => this.unlockVault(port), unlockVault: ({ port }) => this.unlockVault(port),
@ -327,7 +332,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
*/ */
private updateSubFrameData( private updateSubFrameData(
message: OverlayBackgroundExtensionMessage, message: OverlayBackgroundExtensionMessage,
{ sender }: chrome.runtime.Port, sender: chrome.runtime.MessageSender,
) { ) {
const subFrameOffsetsForTab = this.subFrameOffsetsForTab[sender.tab.id]; const subFrameOffsetsForTab = this.subFrameOffsetsForTab[sender.tab.id];
if (subFrameOffsetsForTab) { if (subFrameOffsetsForTab) {

View File

@ -1,7 +1,7 @@
import { EVENTS } from "@bitwarden/common/autofill/constants"; import { EVENTS } from "@bitwarden/common/autofill/constants";
import { ThemeType } from "@bitwarden/common/platform/enums"; import { ThemeType } from "@bitwarden/common/platform/enums";
import { sendExtensionMessage, setElementStyles } from "../../../utils"; import { setElementStyles } from "../../../utils";
import { import {
BackgroundPortMessageHandlers, BackgroundPortMessageHandlers,
AutofillInlineMenuIframeService as AutofillInlineMenuIframeServiceInterface, AutofillInlineMenuIframeService as AutofillInlineMenuIframeServiceInterface,
@ -9,7 +9,6 @@ import {
} from "../abstractions/autofill-inline-menu-iframe.service"; } from "../abstractions/autofill-inline-menu-iframe.service";
export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframeServiceInterface { export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframeServiceInterface {
private readonly sendExtensionMessage = sendExtensionMessage;
private readonly setElementStyles = setElementStyles; private readonly setElementStyles = setElementStyles;
private port: chrome.runtime.Port | null = null; private port: chrome.runtime.Port | null = null;
private portKey: string; private portKey: string;
@ -305,7 +304,7 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
* mutation observer is triggered excessively. * mutation observer is triggered excessively.
*/ */
private forceCloseInlineMenu() { private forceCloseInlineMenu() {
void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true }); void this.port.postMessage({ command: "closeAutofillInlineMenu", forceClose: true });
} }
private handleFadeInInlineMenuIframe() { private handleFadeInInlineMenuIframe() {

View File

@ -45,7 +45,6 @@ export type AutofillOverlayContentExtensionMessage = {
focusedFieldData?: FocusedFieldData; focusedFieldData?: FocusedFieldData;
isFieldCurrentlyFocused?: boolean; isFieldCurrentlyFocused?: boolean;
forceCloseInlineMenu?: boolean; forceCloseInlineMenu?: boolean;
subFrameData?: SubFrameOffsetData;
} & OverlayAddNewItemMessage; } & OverlayAddNewItemMessage;
export interface AutofillOverlayContentService { export interface AutofillOverlayContentService {

View File

@ -204,7 +204,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
this.mostRecentlyFocusedField?.blur(); this.mostRecentlyFocusedField?.blur();
if (isClosingInlineMenu) { if (isClosingInlineMenu) {
void this.sendExtensionMessage("closeAutofillInlineMenu"); this.sendPortMessage("closeAutofillInlineMenu");
} }
} }
@ -249,7 +249,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
if (direction === RedirectFocusDirection.Current) { if (direction === RedirectFocusDirection.Current) {
this.focusMostRecentlyFocusedField(); this.focusMostRecentlyFocusedField();
this.closeInlineMenuOnRedirectTimeout = globalThis.setTimeout( this.closeInlineMenuOnRedirectTimeout = globalThis.setTimeout(
() => this.sendExtensionMessage("closeAutofillInlineMenu"), () => this.sendPortMessage("closeAutofillInlineMenu"),
100, 100,
); );
return; return;
@ -361,7 +361,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
private handleFormFieldKeyupEvent = async (event: KeyboardEvent) => { private handleFormFieldKeyupEvent = async (event: KeyboardEvent) => {
const eventCode = event.code; const eventCode = event.code;
if (eventCode === "Escape") { if (eventCode === "Escape") {
void this.sendExtensionMessage("closeAutofillInlineMenu", { this.sendPortMessage("closeAutofillInlineMenu", {
forceCloseInlineMenu: true, forceCloseInlineMenu: true,
}); });
return; return;
@ -427,7 +427,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
this.storeModifiedFormElement(formFieldElement); this.storeModifiedFormElement(formFieldElement);
if (await this.hideInlineMenuListOnFilledField(formFieldElement)) { if (await this.hideInlineMenuListOnFilledField(formFieldElement)) {
void this.sendExtensionMessage("closeAutofillInlineMenu", { this.sendPortMessage("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseInlineMenu: true, forceCloseInlineMenu: true,
}); });
@ -519,7 +519,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
(initiallyFocusedField !== this.mostRecentlyFocusedField && (initiallyFocusedField !== this.mostRecentlyFocusedField &&
(await this.hideInlineMenuListOnFilledField(formFieldElement as FillableFormFieldElement))) (await this.hideInlineMenuListOnFilledField(formFieldElement as FillableFormFieldElement)))
) { ) {
void this.sendExtensionMessage("closeAutofillInlineMenu", { this.sendPortMessage("closeAutofillInlineMenu", {
overlayElement: AutofillOverlayElement.List, overlayElement: AutofillOverlayElement.List,
forceCloseInlineMenu: true, forceCloseInlineMenu: true,
}); });
@ -576,6 +576,19 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
}); });
} }
/**
* Sends a message that facilitates hiding the inline menu elements.
*
* @param isHidden - Indicates if the inline menu elements should be hidden.
* @param setTransparentInlineMenu - Indicates if the inline menu is closing.
*/
private toggleInlineMenuHidden(isHidden: boolean, setTransparentInlineMenu: boolean = false) {
void this.sendExtensionMessage("toggleAutofillInlineMenuHidden", {
isInlineMenuHidden: isHidden,
setTransparentInlineMenu,
});
}
/** /**
* Updates the data used to position the inline menu elements in relation * Updates the data used to position the inline menu elements in relation
* to the most recently focused form field. * to the most recently focused form field.
@ -925,7 +938,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
subFrameData.subFrameDepth++; subFrameData.subFrameDepth++;
if (subFrameData.subFrameDepth >= MAX_SUB_FRAME_DEPTH) { if (subFrameData.subFrameDepth >= MAX_SUB_FRAME_DEPTH) {
this.sendPortMessage("destroyAutofillInlineMenuListeners", { subFrameData }); void this.sendExtensionMessage("destroyAutofillInlineMenuListeners", { subFrameData });
return; return;
} }
@ -957,7 +970,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
return; return;
} }
this.sendPortMessage("updateSubFrameData", { subFrameData }); void this.sendExtensionMessage("updateSubFrameData", { subFrameData });
}; };
/** /**
@ -994,7 +1007,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
} }
this.unsetMostRecentlyFocusedField(); this.unsetMostRecentlyFocusedField();
void this.sendExtensionMessage("closeAutofillInlineMenu", { this.sendPortMessage("closeAutofillInlineMenu", {
forceCloseInlineMenu: true, forceCloseInlineMenu: true,
}); });
}; };
@ -1062,7 +1075,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
}; };
private handleSubFrameFocusInEvent = () => { private handleSubFrameFocusInEvent = () => {
this.sendPortMessage("triggerSubFrameFocusInRebuild"); void this.sendExtensionMessage("triggerSubFrameFocusInRebuild");
globalThis.removeEventListener(EVENTS.FOCUS, this.handleSubFrameFocusInEvent); globalThis.removeEventListener(EVENTS.FOCUS, this.handleSubFrameFocusInEvent);
globalThis.document.body.removeEventListener( globalThis.document.body.removeEventListener(