Skip to content

Commit

Permalink
Merge branch 'main' into autofill/pm-5880-refactor-browser-platform-u…
Browse files Browse the repository at this point in the history
…tils-service-to-remove-window-reference
  • Loading branch information
cagonzalezcs authored Mar 4, 2024
2 parents f33c6a1 + bf6fd39 commit ce00415
Show file tree
Hide file tree
Showing 124 changed files with 1,936 additions and 978 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ jobs:
token: '${{ secrets.GITHUB_TOKEN }}'
initial-status: 'in_progress'
environment-url: http://vault.bitwarden.com
environment: 'Web Vault - Production'
environment: 'Web Vault - US Production Cloud'
description: 'Deployment ${{ needs.setup.outputs.release_version }} from branch ${{ github.ref_name }}'
task: release

Expand Down
262 changes: 131 additions & 131 deletions apps/browser/src/_locales/ar/messages.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/browser/src/_locales/pt_PT/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@
"message": "Inicie o Duo e siga os passos para concluir o início de sessão."
},
"duoRequiredForAccount": {
"message": "A verificação em dois passos Duo é necessária para a sua conta."
"message": "A verificação de dois passos Duo é necessária para a sua conta."
},
"popoutTheExtensionToCompleteLogin": {
"message": "Abra a extensão para concluir o início de sessão."
Expand Down
10 changes: 5 additions & 5 deletions apps/browser/src/_locales/sr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2709,10 +2709,10 @@
"message": "Покренути DUO и пратите кораке да бисте завршили пријављивање."
},
"duoRequiredForAccount": {
"message": "Duo two-step login is required for your account."
"message": "Duo пријава у два корака је потребна за ваш налог."
},
"popoutTheExtensionToCompleteLogin": {
"message": "Popout the extension to complete login."
"message": "Искачући додатак да бисте довршили пријаву."
},
"popoutExtension": {
"message": "Popout extension"
Expand Down Expand Up @@ -2995,15 +2995,15 @@
"description": "Button text for the setting that allows overriding the default browser autofill settings"
},
"saveCipherAttemptSuccess": {
"message": "Credentials saved successfully!",
"message": "Акредитиви су успешно сачувани!",
"description": "Notification message for when saving credentials has succeeded."
},
"updateCipherAttemptSuccess": {
"message": "Credentials updated successfully!",
"message": "Акредитиви су успешно ажурирани!",
"description": "Notification message for when updating credentials has succeeded."
},
"saveCipherAttemptFailed": {
"message": "Error saving credentials. Check console for details.",
"message": "Грешка при чувању акредитива. Проверите конзолу за детаље.",
"description": "Notification message for when saving credentials has failed."
}
}
12 changes: 6 additions & 6 deletions apps/browser/src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@
"message": "启动 DUO 并按照步骤完成登录。"
},
"duoRequiredForAccount": {
"message": "您的账户需要 Duo 两步登录。"
"message": "您的账户要求使用 Duo 两步登录。"
},
"popoutTheExtensionToCompleteLogin": {
"message": "弹出扩展以完成登录。"
Expand Down Expand Up @@ -2971,15 +2971,15 @@
"description": "Label indicating the most common import formats"
},
"overrideDefaultBrowserAutofillTitle": {
"message": "将 Bitwarden 设置为您的默认密码管理器",
"message": "将 Bitwarden 设置为您的默认密码管理器吗",
"description": "Dialog title facilitating the ability to override a chrome browser's default autofill behavior"
},
"overrideDefaultBrowserAutofillDescription": {
"message": "忽略此设置可能会导致 Bitwarden 自动填充菜单与浏览器自带功能产生冲突。",
"description": "Dialog message facilitating the ability to override a chrome browser's default autofill behavior"
},
"overrideDefaultBrowserAutoFillSettings": {
"message": "将 Bitwarden 设置为您的默认密码管理器",
"message": "将 Bitwarden 设置为您的默认密码管理器",
"description": "Label for the setting that allows overriding the default browser autofill settings"
},
"privacyPermissionAdditionNotGrantedTitle": {
Expand All @@ -2995,15 +2995,15 @@
"description": "Button text for the setting that allows overriding the default browser autofill settings"
},
"saveCipherAttemptSuccess": {
"message": "Credentials saved successfully!",
"message": "凭据保存成功!",
"description": "Notification message for when saving credentials has succeeded."
},
"updateCipherAttemptSuccess": {
"message": "Credentials updated successfully!",
"message": "凭据更新成功!",
"description": "Notification message for when updating credentials has succeeded."
},
"saveCipherAttemptFailed": {
"message": "Error saving credentials. Check console for details.",
"message": "保存凭据时出错。检查控制台以获取详细信息。",
"description": "Notification message for when saving credentials has failed."
}
}
2 changes: 1 addition & 1 deletion apps/browser/src/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,7 @@
}
},
"tryAgain": {
"message": "Try again"
"message": "再試一次"
},
"verificationRequiredForActionSetPinToContinue": {
"message": "Verification required for this action. Set a PIN to continue."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type NotificationBackgroundExtensionMessageHandlers = {
bgReopenUnlockPopout: ({ sender }: BackgroundSenderParam) => Promise<void>;
checkNotificationQueue: ({ sender }: BackgroundSenderParam) => Promise<void>;
collectPageDetailsResponse: ({ message }: BackgroundMessageParam) => Promise<void>;
getWebVaultUrlForNotification: () => string;
};

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1332,5 +1332,23 @@ describe("NotificationBackground", () => {
expect(openUnlockWindowSpy).toHaveBeenCalled();
});
});

describe("getWebVaultUrlForNotification", () => {
it("returns the web vault url", async () => {
const message: NotificationBackgroundExtensionMessage = {
command: "getWebVaultUrlForNotification",
};
const webVaultUrl = "https://example.com";
const environmentServiceSpy = jest
.spyOn(environmentService, "getWebVaultUrl")
.mockReturnValueOnce(webVaultUrl);

sendExtensionRuntimeMessage(message);
await flushPromises();

expect(environmentServiceSpy).toHaveBeenCalled();
expect(environmentServiceSpy).toHaveReturnedWith(webVaultUrl);
});
});
});
});
22 changes: 6 additions & 16 deletions apps/browser/src/autofill/background/notification.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { ThemeType } from "@bitwarden/common/platform/enums";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
Expand Down Expand Up @@ -58,6 +57,7 @@ export default class NotificationBackground {
bgUnlockPopoutOpened: ({ message, sender }) => this.unlockVault(message, sender.tab),
checkNotificationQueue: ({ sender }) => this.checkNotificationQueue(sender.tab),
bgReopenUnlockPopout: ({ sender }) => this.openUnlockPopout(sender.tab),
getWebVaultUrlForNotification: () => this.getWebVaultUrl(),
};

constructor(
Expand Down Expand Up @@ -134,11 +134,9 @@ export default class NotificationBackground {
notificationQueueMessage: NotificationQueueMessageItem,
) {
const notificationType = notificationQueueMessage.type;
const webVaultURL = this.environmentService.getWebVaultUrl();
const typeData: Record<string, any> = {
isVaultLocked: notificationQueueMessage.wasVaultLocked,
theme: await this.getCurrentTheme(),
webVaultURL,
theme: await this.stateService.getTheme(),
};

switch (notificationType) {
Expand All @@ -158,18 +156,6 @@ export default class NotificationBackground {
});
}

private async getCurrentTheme() {
const theme = await this.stateService.getTheme();

if (theme !== ThemeType.System) {
return theme;
}

return window.matchMedia("(prefers-color-scheme: dark)").matches
? ThemeType.Dark
: ThemeType.Light;
}

/**
* Removes any login messages from the notification queue that
* are associated with the specified tab.
Expand Down Expand Up @@ -636,6 +622,10 @@ export default class NotificationBackground {
return await firstValueFrom(this.folderService.folderViews$);
}

private getWebVaultUrl(): string {
return this.environmentService.getWebVaultUrl();
}

private async removeIndividualVault(): Promise<boolean> {
return await firstValueFrom(
this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership),
Expand Down
41 changes: 34 additions & 7 deletions apps/browser/src/autofill/content/notification-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "../background/abstractions/notification.background";
import AutofillField from "../models/autofill-field";
import { WatchedForm } from "../models/watched-form";
import { NotificationBarIframeInitData } from "../notification/abstractions/notification-bar";
import { FormData } from "../services/abstractions/autofill.service";
import { GlobalSettings, UserSettings } from "../types";
import { getFromLocalStorage, setupExtensionDisconnectAction } from "../utils";
Expand Down Expand Up @@ -856,33 +857,36 @@ async function loadNotificationBar() {

// Notification Bar Functions (open, close, height adjustment, etc.)
function closeExistingAndOpenBar(type: string, typeData: any) {
const barQueryParams = {
const notificationBarInitData: NotificationBarIframeInitData = {
type,
isVaultLocked: typeData.isVaultLocked,
theme: typeData.theme,
removeIndividualVault: typeData.removeIndividualVault,
webVaultURL: typeData.webVaultURL,
importType: typeData.importType,
};
const barQueryString = new URLSearchParams(barQueryParams).toString();
const barPage = "notification/bar.html?" + barQueryString;
const notificationBarUrl = "notification/bar.html";

const frame = document.getElementById("bit-notification-bar-iframe") as HTMLIFrameElement;
if (frame != null && frame.src.indexOf(barPage) >= 0) {
if (frame != null && frame.src.indexOf(notificationBarUrl) >= 0) {
return;
}

closeBar(false);
openBar(type, barPage);
openBar(type, notificationBarUrl, notificationBarInitData);
}

function openBar(type: string, barPage: string) {
function openBar(
type: string,
barPage: string,
notificationBarInitData: NotificationBarIframeInitData,
) {
barType = type;

if (document.body == null) {
return;
}

setupInitNotificationBarMessageListener(notificationBarInitData);
const barPageUrl: string = chrome.runtime.getURL(barPage);

notificationBarIframe = document.createElement("iframe");
Expand All @@ -901,7 +905,30 @@ async function loadNotificationBar() {
document.body.appendChild(frameDiv);

(notificationBarIframe.contentWindow.location as any) = barPageUrl;
}

function setupInitNotificationBarMessageListener(initData: NotificationBarIframeInitData) {
const handleInitNotificationBarMessage = (event: MessageEvent) => {
const { source, data } = event;
if (
source !== notificationBarIframe.contentWindow ||
data?.command !== "initNotificationBar"
) {
return;
}

notificationBarIframe.contentWindow.postMessage(
{ command: "initNotificationBar", initData },
"*",
);
injectSpacer();
window.removeEventListener("message", handleInitNotificationBarMessage);
};

window.addEventListener("message", handleInitNotificationBarMessage);
}

function injectSpacer() {
const spacer = document.createElement("div");
spacer.id = "bit-notification-bar-spacer";
spacer.style.cssText = "height: 42px;";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { SaveOrUpdateCipherResult } from "../../background/abstractions/notification.background";
type NotificationBarIframeInitData = {
type?: string;
isVaultLocked?: boolean;
theme?: string;
removeIndividualVault?: boolean;
importType?: string;
};

type NotificationBarWindowMessage = {
[key: string]: any;
command: string;
error?: string;
initData?: NotificationBarIframeInitData;
};

type NotificationBarWindowMessageHandlers = {
[key: string]: CallableFunction;
saveCipherAttemptCompleted: ({ message }: { message: SaveOrUpdateCipherResult }) => void;
initNotificationBar: ({ message }: { message: NotificationBarWindowMessage }) => void;
saveCipherAttemptCompleted: ({ message }: { message: NotificationBarWindowMessage }) => void;
};

export { NotificationBarWindowMessage, NotificationBarWindowMessageHandlers };
export {
NotificationBarIframeInitData,
NotificationBarWindowMessage,
NotificationBarWindowMessageHandlers,
};
Loading

0 comments on commit ce00415

Please sign in to comment.