mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
[PM-5189] Refactoring implementation
This commit is contained in:
@@ -975,7 +975,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
|
|
||||||
port.onDisconnect.addListener(this.handlePortOnDisconnect);
|
port.onDisconnect.addListener(this.handlePortOnDisconnect);
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
command: `initAutofillOverlay${isInlineMenuListPort ? "List" : "Button"}`,
|
command: `initAutofillInlineMenu${isInlineMenuListPort ? "List" : "Button"}`,
|
||||||
iframeUrl: chrome.runtime.getURL(`overlay/${isInlineMenuListPort ? "list" : "button"}.html`),
|
iframeUrl: chrome.runtime.getURL(`overlay/${isInlineMenuListPort ? "list" : "button"}.html`),
|
||||||
pageTitle: chrome.i18n.getMessage(
|
pageTitle: chrome.i18n.getMessage(
|
||||||
isInlineMenuListPort ? "bitwardenVault" : "bitwardenOverlayButton",
|
isInlineMenuListPort ? "bitwardenVault" : "bitwardenOverlayButton",
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ type InitAutofillOverlayButtonMessage = UpdateAuthStatusMessage & {
|
|||||||
|
|
||||||
type OverlayButtonWindowMessageHandlers = {
|
type OverlayButtonWindowMessageHandlers = {
|
||||||
[key: string]: CallableFunction;
|
[key: string]: CallableFunction;
|
||||||
initAutofillOverlayButton: ({ message }: { message: InitAutofillOverlayButtonMessage }) => void;
|
initAutofillInlineMenuButton: ({
|
||||||
|
message,
|
||||||
|
}: {
|
||||||
|
message: InitAutofillOverlayButtonMessage;
|
||||||
|
}) => void;
|
||||||
checkAutofillInlineMenuButtonFocused: () => void;
|
checkAutofillInlineMenuButtonFocused: () => void;
|
||||||
updateAutofillOverlayButtonAuthStatus: ({
|
updateAutofillOverlayButtonAuthStatus: ({
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ type AutofillOverlayIframeExtensionMessageParam = {
|
|||||||
|
|
||||||
type BackgroundPortMessageHandlers = {
|
type BackgroundPortMessageHandlers = {
|
||||||
[key: string]: CallableFunction;
|
[key: string]: CallableFunction;
|
||||||
initAutofillOverlayButton: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
initAutofillInlineMenuButton: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
||||||
initAutofillOverlayList: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
initAutofillInlineMenuList: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
||||||
updateIframePosition: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
updateIframePosition: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
||||||
updateInlineMenuHidden: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
updateInlineMenuHidden: ({ message }: AutofillOverlayIframeExtensionMessageParam) => void;
|
||||||
updateAutofillInlineMenuColorScheme: () => void;
|
updateAutofillInlineMenuColorScheme: () => void;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type InitAutofillOverlayListMessage = OverlayListMessage & {
|
|||||||
|
|
||||||
type OverlayListWindowMessageHandlers = {
|
type OverlayListWindowMessageHandlers = {
|
||||||
[key: string]: CallableFunction;
|
[key: string]: CallableFunction;
|
||||||
initAutofillOverlayList: ({ message }: { message: InitAutofillOverlayListMessage }) => void;
|
initAutofillInlineMenuList: ({ message }: { message: InitAutofillOverlayListMessage }) => void;
|
||||||
checkAutofillInlineMenuListFocused: () => void;
|
checkAutofillInlineMenuListFocused: () => void;
|
||||||
updateOverlayListCiphers: ({ message }: { message: UpdateOverlayListCiphersMessage }) => void;
|
updateOverlayListCiphers: ({ message }: { message: UpdateOverlayListCiphersMessage }) => void;
|
||||||
focusInlineMenuList: () => void;
|
focusInlineMenuList: () => void;
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ export type InitOverlayElementMessage = AutofillOverlayMenuContainerMessage & {
|
|||||||
|
|
||||||
export type AutofillOverlayMenuContainerWindowMessageHandlers = {
|
export type AutofillOverlayMenuContainerWindowMessageHandlers = {
|
||||||
[key: string]: CallableFunction;
|
[key: string]: CallableFunction;
|
||||||
initAutofillOverlayList: (message: InitOverlayElementMessage) => void;
|
initAutofillInlineMenuList: (message: InitOverlayElementMessage) => void;
|
||||||
initAutofillOverlayButton: (message: InitOverlayElementMessage) => void;
|
initAutofillInlineMenuButton: (message: InitOverlayElementMessage) => void;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
it("sets the port key and posts the message to the overlay page iframe", () => {
|
it("sets the port key and posts the message to the overlay page iframe", () => {
|
||||||
const portKey = "portKey";
|
const portKey = "portKey";
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayButton",
|
command: "initAutofillInlineMenuButton",
|
||||||
portKey,
|
portKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
|
|
||||||
it("passes the message on to the iframe element", () => {
|
it("passes the message on to the iframe element", () => {
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.Light,
|
theme: ThemeType.Light,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
it("sets a light theme based on the user's system preferences", () => {
|
it("sets a light theme based on the user's system preferences", () => {
|
||||||
window.matchMedia = jest.fn(() => mock<MediaQueryList>({ matches: false }));
|
window.matchMedia = jest.fn(() => mock<MediaQueryList>({ matches: false }));
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.System,
|
theme: ThemeType.System,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
autofillOverlayIframeService["iframe"].contentWindow.postMessage,
|
autofillOverlayIframeService["iframe"].contentWindow.postMessage,
|
||||||
).toHaveBeenCalledWith(
|
).toHaveBeenCalledWith(
|
||||||
{
|
{
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.Light,
|
theme: ThemeType.Light,
|
||||||
},
|
},
|
||||||
"*",
|
"*",
|
||||||
@@ -267,7 +267,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
it("sets a dark theme based on the user's system preferences", () => {
|
it("sets a dark theme based on the user's system preferences", () => {
|
||||||
window.matchMedia = jest.fn(() => mock<MediaQueryList>({ matches: true }));
|
window.matchMedia = jest.fn(() => mock<MediaQueryList>({ matches: true }));
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.System,
|
theme: ThemeType.System,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
autofillOverlayIframeService["iframe"].contentWindow.postMessage,
|
autofillOverlayIframeService["iframe"].contentWindow.postMessage,
|
||||||
).toHaveBeenCalledWith(
|
).toHaveBeenCalledWith(
|
||||||
{
|
{
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.Dark,
|
theme: ThemeType.Dark,
|
||||||
},
|
},
|
||||||
"*",
|
"*",
|
||||||
@@ -287,7 +287,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
|
|
||||||
it("updates the border to match the `dark` theme", () => {
|
it("updates the border to match the `dark` theme", () => {
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.Dark,
|
theme: ThemeType.Dark,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
|
|
||||||
it("updates the border to match the `nord` theme", () => {
|
it("updates the border to match the `nord` theme", () => {
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.Nord,
|
theme: ThemeType.Nord,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -319,7 +319,7 @@ describe("AutofillOverlayIframeService", () => {
|
|||||||
|
|
||||||
it("updates the border to match the `solarizedDark` theme", () => {
|
it("updates the border to match the `solarizedDark` theme", () => {
|
||||||
const message = {
|
const message = {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
theme: ThemeType.SolarizedDark,
|
theme: ThemeType.SolarizedDark,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf
|
|||||||
private mutationObserverIterations = 0;
|
private mutationObserverIterations = 0;
|
||||||
private mutationObserverIterationsResetTimeout: number | NodeJS.Timeout;
|
private mutationObserverIterationsResetTimeout: number | NodeJS.Timeout;
|
||||||
private readonly backgroundPortMessageHandlers: BackgroundPortMessageHandlers = {
|
private readonly backgroundPortMessageHandlers: BackgroundPortMessageHandlers = {
|
||||||
initAutofillOverlayButton: ({ message }) => this.initAutofillOverlay(message),
|
initAutofillInlineMenuButton: ({ message }) => this.initAutofillInlineMenu(message),
|
||||||
initAutofillOverlayList: ({ message }) => this.initAutofillOverlay(message),
|
initAutofillInlineMenuList: ({ message }) => this.initAutofillInlineMenu(message),
|
||||||
updateIframePosition: ({ message }) => this.updateIframePosition(message.styles),
|
updateIframePosition: ({ message }) => this.updateIframePosition(message.styles),
|
||||||
updateInlineMenuHidden: ({ message }) => this.updateElementStyles(this.iframe, message.styles),
|
updateInlineMenuHidden: ({ message }) => this.updateElementStyles(this.iframe, message.styles),
|
||||||
updateAutofillInlineMenuColorScheme: () => this.updateAutofillInlineMenuColorScheme(),
|
updateAutofillInlineMenuColorScheme: () => this.updateAutofillInlineMenuColorScheme(),
|
||||||
@@ -189,10 +189,10 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf
|
|||||||
* @param message
|
* @param message
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private initAutofillOverlay(message: AutofillOverlayIframeExtensionMessage) {
|
private initAutofillInlineMenu(message: AutofillOverlayIframeExtensionMessage) {
|
||||||
this.portKey = message.portKey;
|
this.portKey = message.portKey;
|
||||||
if (message.command === "initAutofillOverlayList") {
|
if (message.command === "initAutofillInlineMenuList") {
|
||||||
this.initAutofillOverlayList(message);
|
this.initAutofillInlineMenuList(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ class AutofillOverlayIframeService implements AutofillOverlayIframeServiceInterf
|
|||||||
*
|
*
|
||||||
* @param message - The message sent from the iframe
|
* @param message - The message sent from the iframe
|
||||||
*/
|
*/
|
||||||
private initAutofillOverlayList(message: AutofillOverlayIframeExtensionMessage) {
|
private initAutofillInlineMenuList(message: AutofillOverlayIframeExtensionMessage) {
|
||||||
const { theme } = message;
|
const { theme } = message;
|
||||||
let borderColor: string;
|
let borderColor: string;
|
||||||
let verifiedTheme = theme;
|
let verifiedTheme = theme;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe("AutofillOverlayButton", () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("initAutofillOverlayButton", () => {
|
describe("initAutofillInlineMenuButton", () => {
|
||||||
it("creates the button element with the locked icon when the user's auth status is not Unlocked", async () => {
|
it("creates the button element with the locked icon when the user's auth status is not Unlocked", async () => {
|
||||||
postWindowMessage(
|
postWindowMessage(
|
||||||
createInitAutofillOverlayButtonMessageMock({
|
createInitAutofillOverlayButtonMessageMock({
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class AutofillOverlayButton extends AutofillOverlayPageElement {
|
|||||||
private readonly logoIconElement: HTMLElement;
|
private readonly logoIconElement: HTMLElement;
|
||||||
private readonly logoLockedIconElement: HTMLElement;
|
private readonly logoLockedIconElement: HTMLElement;
|
||||||
private readonly overlayButtonWindowMessageHandlers: OverlayButtonWindowMessageHandlers = {
|
private readonly overlayButtonWindowMessageHandlers: OverlayButtonWindowMessageHandlers = {
|
||||||
initAutofillOverlayButton: ({ message }) => this.initAutofillOverlayButton(message),
|
initAutofillInlineMenuButton: ({ message }) => this.initAutofillInlineMenuButton(message),
|
||||||
checkAutofillInlineMenuButtonFocused: () => this.checkButtonFocused(),
|
checkAutofillInlineMenuButtonFocused: () => this.checkButtonFocused(),
|
||||||
updateAutofillOverlayButtonAuthStatus: ({ message }) =>
|
updateAutofillOverlayButtonAuthStatus: ({ message }) =>
|
||||||
this.updateAuthStatus(message.authStatus),
|
this.updateAuthStatus(message.authStatus),
|
||||||
@@ -48,7 +48,7 @@ class AutofillOverlayButton extends AutofillOverlayPageElement {
|
|||||||
* @param translations - The translations to apply to the page
|
* @param translations - The translations to apply to the page
|
||||||
* @param portKey - Background generated key that allows the port to communicate with the background
|
* @param portKey - Background generated key that allows the port to communicate with the background
|
||||||
*/
|
*/
|
||||||
private async initAutofillOverlayButton({
|
private async initAutofillInlineMenuButton({
|
||||||
authStatus,
|
authStatus,
|
||||||
styleSheetUrl,
|
styleSheetUrl,
|
||||||
translations,
|
translations,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ describe("AutofillOverlayList", () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("initAutofillOverlayList", () => {
|
describe("initAutofillInlineMenuList", () => {
|
||||||
describe("the locked overlay for an unauthenticated user", () => {
|
describe("the locked overlay for an unauthenticated user", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
postWindowMessage(
|
postWindowMessage(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class AutofillOverlayList extends AutofillOverlayPageElement {
|
|||||||
private currentCipherIndex = 0;
|
private currentCipherIndex = 0;
|
||||||
private readonly showCiphersPerPage = 6;
|
private readonly showCiphersPerPage = 6;
|
||||||
private readonly overlayListWindowMessageHandlers: OverlayListWindowMessageHandlers = {
|
private readonly overlayListWindowMessageHandlers: OverlayListWindowMessageHandlers = {
|
||||||
initAutofillOverlayList: ({ message }) => this.initAutofillOverlayList(message),
|
initAutofillInlineMenuList: ({ message }) => this.initAutofillInlineMenuList(message),
|
||||||
checkAutofillInlineMenuListFocused: () => this.checkInlineMenuListFocused(),
|
checkAutofillInlineMenuListFocused: () => this.checkInlineMenuListFocused(),
|
||||||
updateOverlayListCiphers: ({ message }) => this.updateListItems(message.ciphers),
|
updateOverlayListCiphers: ({ message }) => this.updateListItems(message.ciphers),
|
||||||
focusInlineMenuList: () => this.focusInlineMenuList(),
|
focusInlineMenuList: () => this.focusInlineMenuList(),
|
||||||
@@ -46,7 +46,7 @@ class AutofillOverlayList extends AutofillOverlayPageElement {
|
|||||||
* @param ciphers - The ciphers to display in the overlay list.
|
* @param ciphers - The ciphers to display in the overlay list.
|
||||||
* @param portKey - Background generated key that allows the port to communicate with the background.
|
* @param portKey - Background generated key that allows the port to communicate with the background.
|
||||||
*/
|
*/
|
||||||
private async initAutofillOverlayList({
|
private async initAutofillInlineMenuList({
|
||||||
translations,
|
translations,
|
||||||
styleSheetUrl,
|
styleSheetUrl,
|
||||||
theme,
|
theme,
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ export class AutofillOverlayMenuContainer {
|
|||||||
tabIndex: "-1",
|
tabIndex: "-1",
|
||||||
};
|
};
|
||||||
private windowMessageHandlers: AutofillOverlayMenuContainerWindowMessageHandlers = {
|
private windowMessageHandlers: AutofillOverlayMenuContainerWindowMessageHandlers = {
|
||||||
initAutofillOverlayList: (message) => this.handleInitOverlayIframe(message),
|
initAutofillInlineMenuList: (message) => this.handleInitOverlayIframe(message),
|
||||||
initAutofillOverlayButton: (message) => this.handleInitOverlayIframe(message),
|
initAutofillInlineMenuButton: (message) => this.handleInitOverlayIframe(message),
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ function createInitAutofillOverlayButtonMessageMock(
|
|||||||
customFields = {},
|
customFields = {},
|
||||||
): InitAutofillOverlayButtonMessage {
|
): InitAutofillOverlayButtonMessage {
|
||||||
return {
|
return {
|
||||||
command: "initAutofillOverlayButton",
|
command: "initAutofillInlineMenuButton",
|
||||||
translations: overlayPagesTranslations,
|
translations: overlayPagesTranslations,
|
||||||
styleSheetUrl: "https://jest-testing-website.com",
|
styleSheetUrl: "https://jest-testing-website.com",
|
||||||
authStatus: AuthenticationStatus.Unlocked,
|
authStatus: AuthenticationStatus.Unlocked,
|
||||||
@@ -199,7 +199,7 @@ function createInitAutofillOverlayListMessageMock(
|
|||||||
customFields = {},
|
customFields = {},
|
||||||
): InitAutofillOverlayListMessage {
|
): InitAutofillOverlayListMessage {
|
||||||
return {
|
return {
|
||||||
command: "initAutofillOverlayList",
|
command: "initAutofillInlineMenuList",
|
||||||
translations: overlayPagesTranslations,
|
translations: overlayPagesTranslations,
|
||||||
styleSheetUrl: "https://jest-testing-website.com",
|
styleSheetUrl: "https://jest-testing-website.com",
|
||||||
theme: ThemeType.Light,
|
theme: ThemeType.Light,
|
||||||
|
|||||||
Reference in New Issue
Block a user