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:
@@ -364,9 +364,10 @@ 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 =
|
||||||
? new BrowserMessagingPrivateModeBackgroundService()
|
this.isPrivateMode && BrowserApi.isManifestVersion(2)
|
||||||
: new BrowserMessagingService();
|
? new BrowserMessagingPrivateModeBackgroundService()
|
||||||
|
: new BrowserMessagingService();
|
||||||
this.logService = new ConsoleLogService(false);
|
this.logService = new ConsoleLogService(false);
|
||||||
this.cryptoFunctionService = new WebCryptoFunctionService(self);
|
this.cryptoFunctionService = new WebCryptoFunctionService(self);
|
||||||
this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
|
this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
|
||||||
@@ -408,13 +409,14 @@ export default class MainBackground {
|
|||||||
storageServiceProvider,
|
storageServiceProvider,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.encryptService = flagEnabled("multithreadDecryption")
|
this.encryptService =
|
||||||
? new MultithreadEncryptServiceImplementation(
|
flagEnabled("multithreadDecryption") && BrowserApi.isManifestVersion(2)
|
||||||
this.cryptoFunctionService,
|
? new MultithreadEncryptServiceImplementation(
|
||||||
this.logService,
|
this.cryptoFunctionService,
|
||||||
true,
|
this.logService,
|
||||||
)
|
true,
|
||||||
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
|
)
|
||||||
|
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
|
||||||
|
|
||||||
this.singleUserStateProvider = new DefaultSingleUserStateProvider(
|
this.singleUserStateProvider = new DefaultSingleUserStateProvider(
|
||||||
storageServiceProvider,
|
storageServiceProvider,
|
||||||
@@ -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);
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user