1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 06:23:38 +00:00

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

This reverts commit e30a1ebc5d.
This commit is contained in:
Cesar Gonzalez
2024-06-19 05:11:27 -05:00
parent 97778a2bc8
commit ab1b841543
6 changed files with 18 additions and 39 deletions

View File

@@ -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 = {

View File

@@ -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");
}

View File

@@ -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",

View File

@@ -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<AutofillOverlayContentExtensionMessage, "command">,
) {
private sendPortMessage(command: string, message: Omit<AutofillExtensionMessage, "command">) {
this.port.postMessage({ command, ...message });
}

View File

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

View File

@@ -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<AutofillOverlayContentExtensionMessage, "command">,
) {
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.