1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

[PM-7370] Remove usage of BrowserMessagingPrivateModeBackgroundService and MultithreadEncryptService from manifest v3 (#8654)

This commit is contained in:
Cesar Gonzalez
2024-04-10 11:23:02 -05:00
committed by GitHub
parent 744f3a4d1c
commit 1e7329d1ef
3 changed files with 37 additions and 15 deletions

View File

@@ -364,7 +364,8 @@ export default class MainBackground {
const logoutCallback = async (expired: boolean, userId?: UserId) => const logoutCallback = async (expired: boolean, userId?: UserId) =>
await this.logout(expired, userId); await this.logout(expired, userId);
this.messagingService = this.popupOnlyContext this.messagingService =
this.isPrivateMode && BrowserApi.isManifestVersion(2)
? new BrowserMessagingPrivateModeBackgroundService() ? new BrowserMessagingPrivateModeBackgroundService()
: new BrowserMessagingService(); : new BrowserMessagingService();
this.logService = new ConsoleLogService(false); this.logService = new ConsoleLogService(false);
@@ -408,7 +409,8 @@ export default class MainBackground {
storageServiceProvider, storageServiceProvider,
); );
this.encryptService = flagEnabled("multithreadDecryption") this.encryptService =
flagEnabled("multithreadDecryption") && BrowserApi.isManifestVersion(2)
? new MultithreadEncryptServiceImplementation( ? new MultithreadEncryptServiceImplementation(
this.cryptoFunctionService, this.cryptoFunctionService,
this.logService, this.logService,
@@ -558,10 +560,13 @@ export default class MainBackground {
const backgroundMessagingService = new (class extends MessagingServiceAbstraction { const backgroundMessagingService = new (class extends MessagingServiceAbstraction {
// AuthService should send the messages to the background not popup. // AuthService should send the messages to the background not popup.
send = (subscriber: string, arg: any = {}) => { send = (subscriber: string, arg: any = {}) => {
if (BrowserApi.isManifestVersion(3)) {
that.messagingService.send(subscriber, arg);
return;
}
const message = Object.assign({}, { command: subscriber }, arg); const message = Object.assign({}, { command: subscriber }, arg);
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. void that.runtimeBackground.processMessage(message, that as any);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
that.runtimeBackground.processMessage(message, that as any);
}; };
})(); })();

View File

@@ -93,6 +93,10 @@ export class SessionSyncer {
} }
async update(serializedValue: any) { async update(serializedValue: any) {
if (!serializedValue) {
return;
}
const unBuiltValue = JSON.parse(serializedValue); const unBuiltValue = JSON.parse(serializedValue);
if (!BrowserApi.isManifestVersion(3) && BrowserApi.isBackgroundPage(self)) { if (!BrowserApi.isManifestVersion(3) && BrowserApi.isBackgroundPage(self)) {
await this.memoryStorageService.save(this.metaData.sessionKey, serializedValue); await this.memoryStorageService.save(this.metaData.sessionKey, serializedValue);
@@ -104,6 +108,10 @@ export class SessionSyncer {
} }
private async updateSession(value: any) { private async updateSession(value: any) {
if (!value) {
return;
}
const serializedValue = JSON.stringify(value); const serializedValue = JSON.stringify(value);
if (BrowserApi.isManifestVersion(3) || BrowserApi.isBackgroundPage(self)) { if (BrowserApi.isManifestVersion(3) || BrowserApi.isBackgroundPage(self)) {
await this.memoryStorageService.save(this.metaData.sessionKey, serializedValue); await this.memoryStorageService.save(this.metaData.sessionKey, serializedValue);

View File

@@ -62,6 +62,7 @@ import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/p
import { import {
AbstractMemoryStorageService, AbstractMemoryStorageService,
AbstractStorageService, AbstractStorageService,
ObservableStorageService,
} from "@bitwarden/common/platform/abstractions/storage.service"; } from "@bitwarden/common/platform/abstractions/storage.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
@@ -157,7 +158,7 @@ const safeProviders: SafeProvider[] = [
safeProvider({ safeProvider({
provide: MessagingService, provide: MessagingService,
useFactory: () => { useFactory: () => {
return needsBackgroundInit return needsBackgroundInit && BrowserApi.isManifestVersion(2)
? new BrowserMessagingPrivateModePopupService() ? new BrowserMessagingPrivateModePopupService()
: new BrowserMessagingService(); : new BrowserMessagingService();
}, },
@@ -369,7 +370,15 @@ const safeProviders: SafeProvider[] = [
}), }),
safeProvider({ safeProvider({
provide: OBSERVABLE_MEMORY_STORAGE, provide: OBSERVABLE_MEMORY_STORAGE,
useClass: ForegroundMemoryStorageService, useFactory: () => {
if (BrowserApi.isManifestVersion(2)) {
return new ForegroundMemoryStorageService();
}
return getBgService<AbstractStorageService & ObservableStorageService>(
"memoryStorageForStateProviders",
)();
},
deps: [], deps: [],
}), }),
safeProvider({ safeProvider({