1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-27 04:03:00 +02:00

Guard Background Only and MV2 Only Actions (#8773)

This commit is contained in:
Justin Baur 2024-04-17 09:13:05 -05:00 committed by GitHub
parent a72b7f3d21
commit 0c557c6ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 104 additions and 104 deletions

View File

@ -342,11 +342,11 @@ export default class MainBackground {
private syncTimeout: any; private syncTimeout: any;
private isSafari: boolean; private isSafari: boolean;
private nativeMessagingBackground: NativeMessagingBackground; private nativeMessagingBackground: NativeMessagingBackground;
popupOnlyContext: boolean;
constructor(public isPrivateMode: boolean = false) {
this.popupOnlyContext = isPrivateMode || BrowserApi.isManifestVersion(3);
constructor(
public isPrivateMode: boolean = false,
public popupOnlyContext: boolean = false,
) {
// Services // Services
const lockedCallback = async (userId?: string) => { const lockedCallback = async (userId?: string) => {
if (this.notificationsService != null) { if (this.notificationsService != null) {
@ -889,6 +889,7 @@ export default class MainBackground {
this.isSafari = this.platformUtilsService.isSafari(); this.isSafari = this.platformUtilsService.isSafari();
// Background // Background
if (!this.popupOnlyContext) {
this.runtimeBackground = new RuntimeBackground( this.runtimeBackground = new RuntimeBackground(
this, this,
this.autofillService, this.autofillService,
@ -964,7 +965,7 @@ export default class MainBackground {
this.notificationBackground, this.notificationBackground,
this.overlayBackground, this.overlayBackground,
); );
if (!this.popupOnlyContext) {
const contextMenuClickedHandler = new ContextMenuClickedHandler( const contextMenuClickedHandler = new ContextMenuClickedHandler(
(options) => this.platformUtilsService.copyToClipboard(options.text), (options) => this.platformUtilsService.copyToClipboard(options.text),
async (_tab) => { async (_tab) => {
@ -1006,11 +1007,6 @@ export default class MainBackground {
this.notificationsService, this.notificationsService,
this.accountService, this.accountService,
); );
this.webRequestBackground = new WebRequestBackground(
this.platformUtilsService,
this.cipherService,
this.authService,
);
this.usernameGenerationService = new UsernameGenerationService( this.usernameGenerationService = new UsernameGenerationService(
this.cryptoService, this.cryptoService,
@ -1032,34 +1028,40 @@ export default class MainBackground {
this.authService, this.authService,
this.cipherService, this.cipherService,
); );
if (BrowserApi.isManifestVersion(2)) {
this.webRequestBackground = new WebRequestBackground(
this.platformUtilsService,
this.cipherService,
this.authService,
);
}
} }
} }
async bootstrap() { async bootstrap() {
this.containerService.attachToGlobal(self); this.containerService.attachToGlobal(self);
await this.stateService.init(); await this.stateService.init({ runMigrations: !this.isPrivateMode });
await this.vaultTimeoutService.init(true);
await (this.i18nService as I18nService).init(); await (this.i18nService as I18nService).init();
await (this.eventUploadService as EventUploadService).init(true); (this.eventUploadService as EventUploadService).init(true);
this.twoFactorService.init();
if (!this.popupOnlyContext) {
await this.vaultTimeoutService.init(true);
await this.runtimeBackground.init(); await this.runtimeBackground.init();
await this.notificationBackground.init(); await this.notificationBackground.init();
this.filelessImporterBackground.init(); this.filelessImporterBackground.init();
await this.commandsBackground.init(); await this.commandsBackground.init();
this.twoFactorService.init();
await this.overlayBackground.init(); await this.overlayBackground.init();
await this.tabsBackground.init(); await this.tabsBackground.init();
if (!this.popupOnlyContext) {
this.contextMenusBackground?.init(); this.contextMenusBackground?.init();
}
await this.idleBackground.init(); await this.idleBackground.init();
if (BrowserApi.isManifestVersion(2)) {
await this.webRequestBackground.init(); await this.webRequestBackground.init();
}
await this.fido2Service.init(); }
if (this.platformUtilsService.isFirefox() && !this.isPrivateMode) { if (this.platformUtilsService.isFirefox() && !this.isPrivateMode) {
// Set Private Mode windows to the default icon - they do not share state with the background page // Set Private Mode windows to the default icon - they do not share state with the background page
@ -1082,9 +1084,7 @@ export default class MainBackground {
if (!this.isPrivateMode) { if (!this.isPrivateMode) {
await this.refreshBadge(); await this.refreshBadge();
} }
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. await this.fullSync(true);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.fullSync(true);
setTimeout(() => this.notificationsService.init(), 2500); setTimeout(() => this.notificationsService.init(), 2500);
resolve(); resolve();
}, 500); }, 500);
@ -1205,7 +1205,7 @@ export default class MainBackground {
BrowserApi.sendMessage("updateBadge"); BrowserApi.sendMessage("updateBadge");
} }
await this.refreshBadge(); await this.refreshBadge();
await this.mainContextMenuHandler.noAccess(); await this.mainContextMenuHandler?.noAccess();
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
this.notificationsService.updateConnection(false); this.notificationsService.updateConnection(false);

View File

@ -120,7 +120,7 @@ const mainBackground: MainBackground = needsBackgroundInit
: BrowserApi.getBackgroundPage().bitwardenMain; : BrowserApi.getBackgroundPage().bitwardenMain;
function createLocalBgService() { function createLocalBgService() {
const localBgService = new MainBackground(isPrivateMode); const localBgService = new MainBackground(isPrivateMode, true);
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
localBgService.bootstrap(); localBgService.bootstrap();