1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-16 01:21:48 +01: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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 15 deletions

View File

@ -364,9 +364,10 @@ export default class MainBackground {
const logoutCallback = async (expired: boolean, userId?: UserId) =>
await this.logout(expired, userId);
this.messagingService = this.popupOnlyContext
? new BrowserMessagingPrivateModeBackgroundService()
: new BrowserMessagingService();
this.messagingService =
this.isPrivateMode && BrowserApi.isManifestVersion(2)
? new BrowserMessagingPrivateModeBackgroundService()
: new BrowserMessagingService();
this.logService = new ConsoleLogService(false);
this.cryptoFunctionService = new WebCryptoFunctionService(self);
this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
@ -408,13 +409,14 @@ export default class MainBackground {
storageServiceProvider,
);
this.encryptService = flagEnabled("multithreadDecryption")
? new MultithreadEncryptServiceImplementation(
this.cryptoFunctionService,
this.logService,
true,
)
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
this.encryptService =
flagEnabled("multithreadDecryption") && BrowserApi.isManifestVersion(2)
? new MultithreadEncryptServiceImplementation(
this.cryptoFunctionService,
this.logService,
true,
)
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
this.singleUserStateProvider = new DefaultSingleUserStateProvider(
storageServiceProvider,
@ -558,10 +560,13 @@ export default class MainBackground {
const backgroundMessagingService = new (class extends MessagingServiceAbstraction {
// AuthService should send the messages to the background not popup.
send = (subscriber: string, arg: any = {}) => {
if (BrowserApi.isManifestVersion(3)) {
that.messagingService.send(subscriber, arg);
return;
}
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.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
that.runtimeBackground.processMessage(message, that as any);
void that.runtimeBackground.processMessage(message, that as any);
};
})();

View File

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

View File

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