2023-01-01 16:30:09 +01:00
|
|
|
import { AvatarUpdateService as AvatarUpdateServiceAbstraction } from "@bitwarden/common/abstractions/account/avatar-update.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService as ApiServiceAbstraction } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { AppIdService as AppIdServiceAbstraction } from "@bitwarden/common/abstractions/appId.service";
|
|
|
|
import { AuditService as AuditServiceAbstraction } from "@bitwarden/common/abstractions/audit.service";
|
|
|
|
import { CollectionService as CollectionServiceAbstraction } from "@bitwarden/common/abstractions/collection.service";
|
|
|
|
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/abstractions/cryptoFunction.service";
|
2022-10-27 23:38:54 +02:00
|
|
|
import { EncryptService } from "@bitwarden/common/abstractions/encrypt.service";
|
2022-12-06 14:47:42 +01:00
|
|
|
import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service";
|
|
|
|
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ExportService as ExportServiceAbstraction } from "@bitwarden/common/abstractions/export.service";
|
|
|
|
import { FileUploadService as FileUploadServiceAbstraction } from "@bitwarden/common/abstractions/fileUpload.service";
|
|
|
|
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService as LogServiceAbstraction } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/abstractions/messaging.service";
|
|
|
|
import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service";
|
2022-11-18 22:38:28 +01:00
|
|
|
import { InternalOrganizationService as InternalOrganizationServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { PasswordGenerationService as PasswordGenerationServiceAbstraction } from "@bitwarden/common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/abstractions/platformUtils.service";
|
2022-08-08 11:04:36 +02:00
|
|
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction";
|
|
|
|
import { InternalPolicyService as InternalPolicyServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ProviderService as ProviderServiceAbstraction } from "@bitwarden/common/abstractions/provider.service";
|
|
|
|
import { SearchService as SearchServiceAbstraction } from "@bitwarden/common/abstractions/search.service";
|
|
|
|
import { SendService as SendServiceAbstraction } from "@bitwarden/common/abstractions/send.service";
|
|
|
|
import { SettingsService as SettingsServiceAbstraction } from "@bitwarden/common/abstractions/settings.service";
|
2023-01-12 21:39:33 +01:00
|
|
|
import {
|
|
|
|
AbstractMemoryStorageService,
|
|
|
|
AbstractStorageService,
|
|
|
|
} from "@bitwarden/common/abstractions/storage.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/abstractions/system.service";
|
|
|
|
import { TotpService as TotpServiceAbstraction } from "@bitwarden/common/abstractions/totp.service";
|
2022-08-10 03:31:02 +02:00
|
|
|
import { UserVerificationApiServiceAbstraction } from "@bitwarden/common/abstractions/userVerification/userVerification-api.service.abstraction";
|
|
|
|
import { UserVerificationService as UserVerificationServiceAbstraction } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { UsernameGenerationService as UsernameGenerationServiceAbstraction } from "@bitwarden/common/abstractions/usernameGeneration.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
|
2022-08-30 22:30:43 +02:00
|
|
|
import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
|
|
|
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
|
|
|
import { TokenService as TokenServiceAbstraction } from "@bitwarden/common/auth/abstractions/token.service";
|
|
|
|
import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
|
|
|
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
|
|
|
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
|
|
|
import { TokenService } from "@bitwarden/common/auth/services/token.service";
|
|
|
|
import { TwoFactorService } from "@bitwarden/common/auth/services/two-factor.service";
|
|
|
|
import { UserVerificationApiService } from "@bitwarden/common/auth/services/user-verification/user-verification-api.service";
|
|
|
|
import { UserVerificationService } from "@bitwarden/common/auth/services/user-verification/user-verification.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { StateFactory } from "@bitwarden/common/factories/stateFactory";
|
2022-10-14 18:25:50 +02:00
|
|
|
import { GlobalState } from "@bitwarden/common/models/domain/global-state";
|
2023-01-01 16:30:09 +01:00
|
|
|
import { AvatarUpdateService } from "@bitwarden/common/services/account/avatar-update.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/services/api.service";
|
|
|
|
import { AppIdService } from "@bitwarden/common/services/appId.service";
|
|
|
|
import { AuditService } from "@bitwarden/common/services/audit.service";
|
|
|
|
import { CollectionService } from "@bitwarden/common/services/collection.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ContainerService } from "@bitwarden/common/services/container.service";
|
2022-10-27 23:38:54 +02:00
|
|
|
import { EncryptServiceImplementation } from "@bitwarden/common/services/cryptography/encrypt.service.implementation";
|
|
|
|
import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/services/cryptography/multithread-encrypt.service.implementation";
|
2022-12-06 14:47:42 +01:00
|
|
|
import { EventCollectionService } from "@bitwarden/common/services/event/event-collection.service";
|
|
|
|
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ExportService } from "@bitwarden/common/services/export.service";
|
|
|
|
import { FileUploadService } from "@bitwarden/common/services/fileUpload.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { NotificationsService } from "@bitwarden/common/services/notifications.service";
|
|
|
|
import { PasswordGenerationService } from "@bitwarden/common/services/passwordGeneration.service";
|
2022-08-08 11:04:36 +02:00
|
|
|
import { PolicyApiService } from "@bitwarden/common/services/policy/policy-api.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ProviderService } from "@bitwarden/common/services/provider.service";
|
|
|
|
import { SearchService } from "@bitwarden/common/services/search.service";
|
|
|
|
import { SendService } from "@bitwarden/common/services/send.service";
|
|
|
|
import { StateMigrationService } from "@bitwarden/common/services/stateMigration.service";
|
|
|
|
import { SystemService } from "@bitwarden/common/services/system.service";
|
|
|
|
import { TotpService } from "@bitwarden/common/services/totp.service";
|
|
|
|
import { UsernameGenerationService } from "@bitwarden/common/services/usernameGeneration.service";
|
2022-08-30 22:30:43 +02:00
|
|
|
import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vaultTimeout/vaultTimeoutSettings.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
import { WebCryptoFunctionService } from "@bitwarden/common/services/webCryptoFunction.service";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
|
|
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
|
|
|
import { InternalFolderService as InternalFolderServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
|
|
|
import { SyncNotifierService as SyncNotifierServiceAbstraction } from "@bitwarden/common/vault/abstractions/sync/sync-notifier.service.abstraction";
|
|
|
|
import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
|
|
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
|
|
|
import { CipherService } from "@bitwarden/common/vault/services/cipher.service";
|
|
|
|
import { FolderApiService } from "@bitwarden/common/vault/services/folder/folder-api.service";
|
|
|
|
import { SyncNotifierService } from "@bitwarden/common/vault/services/sync/sync-notifier.service";
|
|
|
|
import { SyncService } from "@bitwarden/common/vault/services/sync/sync.service";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2023-01-31 22:08:37 +01:00
|
|
|
import ContextMenusBackground from "../autofill/background/context-menus.background";
|
|
|
|
import NotificationBackground from "../autofill/background/notification.background";
|
|
|
|
import TabsBackground from "../autofill/background/tabs.background";
|
|
|
|
import { CipherContextMenuHandler } from "../autofill/browser/cipher-context-menu-handler";
|
|
|
|
import { ContextMenuClickedHandler } from "../autofill/browser/context-menu-clicked-handler";
|
|
|
|
import { MainContextMenuHandler } from "../autofill/browser/main-context-menu-handler";
|
|
|
|
import { AutofillTabCommand } from "../autofill/commands/autofill-tab-command";
|
|
|
|
import { AutofillService as AutofillServiceAbstraction } from "../autofill/services/abstractions/autofill.service";
|
|
|
|
import AutofillService from "../autofill/services/autofill.service";
|
2018-01-12 17:09:30 +01:00
|
|
|
import { BrowserApi } from "../browser/browserApi";
|
2019-08-12 18:31:32 +02:00
|
|
|
import { SafariApp } from "../browser/safariApp";
|
2022-10-27 23:38:54 +02:00
|
|
|
import { flagEnabled } from "../flags";
|
2022-10-19 15:55:57 +02:00
|
|
|
import { UpdateBadge } from "../listeners/update-badge";
|
2022-02-24 18:14:04 +01:00
|
|
|
import { Account } from "../models/account";
|
2021-02-10 16:40:15 +01:00
|
|
|
import { PopupUtilsService } from "../popup/services/popup-utils.service";
|
2022-11-23 23:26:57 +01:00
|
|
|
import { BrowserStateService as StateServiceAbstraction } from "../services/abstractions/browser-state.service";
|
2022-08-08 13:40:09 +02:00
|
|
|
import { BrowserEnvironmentService } from "../services/browser-environment.service";
|
2023-01-30 20:04:22 +01:00
|
|
|
import { BrowserI18nService } from "../services/browser-i18n.service";
|
2022-11-23 23:26:57 +01:00
|
|
|
import { BrowserOrganizationService } from "../services/browser-organization.service";
|
|
|
|
import { BrowserPolicyService } from "../services/browser-policy.service";
|
|
|
|
import { BrowserSettingsService } from "../services/browser-settings.service";
|
|
|
|
import { BrowserStateService } from "../services/browser-state.service";
|
2021-06-22 22:11:29 +02:00
|
|
|
import { BrowserCryptoService } from "../services/browserCrypto.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
import BrowserLocalStorageService from "../services/browserLocalStorage.service";
|
2018-01-04 22:06:00 +01:00
|
|
|
import BrowserMessagingService from "../services/browserMessaging.service";
|
2022-02-15 23:06:35 +01:00
|
|
|
import BrowserMessagingPrivateModeBackgroundService from "../services/browserMessagingPrivateModeBackground.service";
|
2018-01-05 22:38:50 +01:00
|
|
|
import BrowserPlatformUtilsService from "../services/browserPlatformUtils.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
import { KeyGenerationService } from "../services/keyGeneration.service";
|
|
|
|
import { LocalBackedSessionStorageService } from "../services/localBackedSessionStorage.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import VaultTimeoutService from "../services/vaultTimeout/vaultTimeout.service";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { BrowserFolderService } from "../vault/services/browser-folder.service";
|
|
|
|
import { VaultFilterService } from "../vault/services/vault-filter.service";
|
2018-01-04 16:51:08 +01:00
|
|
|
|
2022-02-24 18:14:04 +01:00
|
|
|
import CommandsBackground from "./commands.background";
|
|
|
|
import IdleBackground from "./idle.background";
|
|
|
|
import { NativeMessagingBackground } from "./nativeMessaging.background";
|
|
|
|
import RuntimeBackground from "./runtime.background";
|
|
|
|
import WebRequestBackground from "./webRequest.background";
|
2022-01-31 20:21:06 +01:00
|
|
|
|
2017-12-05 23:04:30 +01:00
|
|
|
export default class MainBackground {
|
2018-01-09 20:26:20 +01:00
|
|
|
messagingService: MessagingServiceAbstraction;
|
2022-06-27 19:38:12 +02:00
|
|
|
storageService: AbstractStorageService;
|
|
|
|
secureStorageService: AbstractStorageService;
|
2023-01-12 21:39:33 +01:00
|
|
|
memoryStorageService: AbstractMemoryStorageService;
|
2018-04-11 20:52:49 +02:00
|
|
|
i18nService: I18nServiceAbstraction;
|
2018-01-09 20:26:20 +01:00
|
|
|
platformUtilsService: PlatformUtilsServiceAbstraction;
|
2021-07-23 20:22:53 +02:00
|
|
|
logService: LogServiceAbstraction;
|
2018-01-09 20:26:20 +01:00
|
|
|
cryptoService: CryptoServiceAbstraction;
|
2020-09-18 22:03:08 +02:00
|
|
|
cryptoFunctionService: CryptoFunctionServiceAbstraction;
|
2018-01-09 22:20:15 +01:00
|
|
|
tokenService: TokenServiceAbstraction;
|
|
|
|
appIdService: AppIdServiceAbstraction;
|
|
|
|
apiService: ApiServiceAbstraction;
|
2022-08-08 13:40:09 +02:00
|
|
|
environmentService: BrowserEnvironmentService;
|
2018-01-10 04:47:53 +01:00
|
|
|
settingsService: SettingsServiceAbstraction;
|
2018-01-10 05:05:46 +01:00
|
|
|
cipherService: CipherServiceAbstraction;
|
2022-07-08 15:40:31 +02:00
|
|
|
folderService: InternalFolderServiceAbstraction;
|
2018-01-10 05:12:14 +01:00
|
|
|
collectionService: CollectionServiceAbstraction;
|
2020-04-06 17:40:16 +02:00
|
|
|
vaultTimeoutService: VaultTimeoutServiceAbstraction;
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService: VaultTimeoutSettingsServiceAbstraction;
|
2018-01-10 05:27:15 +01:00
|
|
|
syncService: SyncServiceAbstraction;
|
2018-01-09 23:55:28 +01:00
|
|
|
passwordGenerationService: PasswordGenerationServiceAbstraction;
|
2018-01-09 23:45:17 +01:00
|
|
|
totpService: TotpServiceAbstraction;
|
2018-01-11 20:45:27 +01:00
|
|
|
autofillService: AutofillServiceAbstraction;
|
2018-01-07 06:15:12 +01:00
|
|
|
containerService: ContainerService;
|
2018-03-21 14:38:03 +01:00
|
|
|
auditService: AuditServiceAbstraction;
|
2020-08-11 22:25:07 +02:00
|
|
|
authService: AuthServiceAbstraction;
|
2018-05-17 16:57:52 +02:00
|
|
|
exportService: ExportServiceAbstraction;
|
2018-08-13 17:53:16 +02:00
|
|
|
searchService: SearchServiceAbstraction;
|
2018-08-20 23:40:39 +02:00
|
|
|
notificationsService: NotificationsServiceAbstraction;
|
2020-08-11 22:25:07 +02:00
|
|
|
stateService: StateServiceAbstraction;
|
2022-01-27 22:22:51 +01:00
|
|
|
stateMigrationService: StateMigrationService;
|
2019-02-27 15:28:16 +01:00
|
|
|
systemService: SystemServiceAbstraction;
|
2022-12-06 14:47:42 +01:00
|
|
|
eventCollectionService: EventCollectionServiceAbstraction;
|
|
|
|
eventUploadService: EventUploadServiceAbstraction;
|
2022-08-08 11:04:36 +02:00
|
|
|
policyService: InternalPolicyServiceAbstraction;
|
2021-04-07 20:43:07 +02:00
|
|
|
popupUtilsService: PopupUtilsService;
|
|
|
|
sendService: SendServiceAbstraction;
|
2021-11-16 11:50:58 +01:00
|
|
|
fileUploadService: FileUploadServiceAbstraction;
|
2022-11-18 22:38:28 +01:00
|
|
|
organizationService: InternalOrganizationServiceAbstraction;
|
2022-01-27 22:22:51 +01:00
|
|
|
providerService: ProviderServiceAbstraction;
|
2017-12-07 21:06:37 +01:00
|
|
|
keyConnectorService: KeyConnectorServiceAbstraction;
|
2021-10-18 16:41:42 +02:00
|
|
|
userVerificationService: UserVerificationServiceAbstraction;
|
2022-02-08 00:06:37 +01:00
|
|
|
twoFactorService: TwoFactorServiceAbstraction;
|
2022-05-09 14:19:18 +02:00
|
|
|
vaultFilterService: VaultFilterService;
|
2022-03-30 23:59:58 +02:00
|
|
|
usernameGenerationService: UsernameGenerationServiceAbstraction;
|
2022-06-27 19:38:12 +02:00
|
|
|
encryptService: EncryptService;
|
2022-07-08 15:40:31 +02:00
|
|
|
folderApiService: FolderApiServiceAbstraction;
|
2022-08-08 11:04:36 +02:00
|
|
|
policyApiService: PolicyApiServiceAbstraction;
|
2022-08-10 03:31:02 +02:00
|
|
|
userVerificationApiService: UserVerificationApiServiceAbstraction;
|
2022-09-27 22:25:19 +02:00
|
|
|
syncNotifierService: SyncNotifierServiceAbstraction;
|
2023-01-01 16:30:09 +01:00
|
|
|
avatarUpdateService: AvatarUpdateServiceAbstraction;
|
2023-01-07 01:31:32 +01:00
|
|
|
mainContextMenuHandler: MainContextMenuHandler;
|
|
|
|
cipherContextMenuHandler: CipherContextMenuHandler;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-07-14 20:47:45 +02:00
|
|
|
// Passed to the popup for Safari to workaround issues with theming, downloading, etc.
|
|
|
|
backgroundWindow = window;
|
|
|
|
|
2017-12-07 21:06:37 +01:00
|
|
|
onUpdatedRan: boolean;
|
|
|
|
onReplacedRan: boolean;
|
|
|
|
loginToAutoFill: CipherView = null;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2017-12-07 21:06:37 +01:00
|
|
|
private commandsBackground: CommandsBackground;
|
2017-12-07 03:54:38 +01:00
|
|
|
private contextMenusBackground: ContextMenusBackground;
|
2017-12-07 21:06:37 +01:00
|
|
|
private idleBackground: IdleBackground;
|
2020-10-11 20:45:25 +02:00
|
|
|
private notificationBackground: NotificationBackground;
|
2020-10-12 18:01:34 +02:00
|
|
|
private runtimeBackground: RuntimeBackground;
|
2020-10-21 17:18:04 +02:00
|
|
|
private tabsBackground: TabsBackground;
|
|
|
|
private webRequestBackground: WebRequestBackground;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-06 17:48:45 +02:00
|
|
|
private syncTimeout: any;
|
2020-12-09 21:11:25 +01:00
|
|
|
private isSafari: boolean;
|
|
|
|
private nativeMessagingBackground: NativeMessagingBackground;
|
2022-10-19 15:55:57 +02:00
|
|
|
popupOnlyContext: boolean;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-02-15 23:06:35 +01:00
|
|
|
constructor(public isPrivateMode: boolean = false) {
|
2022-10-19 15:55:57 +02:00
|
|
|
this.popupOnlyContext = isPrivateMode || BrowserApi.manifestVersion === 3;
|
|
|
|
|
2021-02-10 16:40:15 +01:00
|
|
|
// Services
|
2022-05-26 03:16:05 +02:00
|
|
|
const lockedCallback = async (userId?: string) => {
|
|
|
|
if (this.notificationsService != null) {
|
|
|
|
this.notificationsService.updateConnection(false);
|
|
|
|
}
|
2022-10-19 15:55:57 +02:00
|
|
|
await this.refreshBadge();
|
|
|
|
await this.refreshMenu(true);
|
2022-05-26 03:16:05 +02:00
|
|
|
if (this.systemService != null) {
|
|
|
|
await this.systemService.clearPendingClipboard();
|
2022-08-05 20:04:27 +02:00
|
|
|
await this.systemService.startProcessReload(this.authService);
|
2022-05-26 03:16:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const logoutCallback = async (expired: boolean, userId?: string) =>
|
|
|
|
await this.logout(expired, userId);
|
|
|
|
|
2023-01-03 20:13:54 +01:00
|
|
|
this.messagingService = this.popupOnlyContext
|
|
|
|
? new BrowserMessagingPrivateModeBackgroundService()
|
|
|
|
: new BrowserMessagingService();
|
2022-08-29 20:46:42 +02:00
|
|
|
this.logService = new ConsoleLogService(false);
|
|
|
|
this.cryptoFunctionService = new WebCryptoFunctionService(window);
|
|
|
|
this.storageService = new BrowserLocalStorageService();
|
|
|
|
this.secureStorageService = new BrowserLocalStorageService();
|
|
|
|
this.memoryStorageService =
|
2022-10-19 15:55:57 +02:00
|
|
|
BrowserApi.manifestVersion === 3
|
2022-08-29 20:46:42 +02:00
|
|
|
? new LocalBackedSessionStorageService(
|
2022-10-27 23:38:54 +02:00
|
|
|
new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, false),
|
2022-08-29 20:46:42 +02:00
|
|
|
new KeyGenerationService(this.cryptoFunctionService)
|
|
|
|
)
|
|
|
|
: new MemoryStorageService();
|
|
|
|
this.stateMigrationService = new StateMigrationService(
|
|
|
|
this.storageService,
|
|
|
|
this.secureStorageService,
|
|
|
|
new StateFactory(GlobalState, Account)
|
|
|
|
);
|
2022-11-23 23:26:57 +01:00
|
|
|
this.stateService = new BrowserStateService(
|
2022-08-29 20:46:42 +02:00
|
|
|
this.storageService,
|
|
|
|
this.secureStorageService,
|
|
|
|
this.memoryStorageService,
|
|
|
|
this.logService,
|
|
|
|
this.stateMigrationService,
|
|
|
|
new StateFactory(GlobalState, Account)
|
|
|
|
);
|
2020-09-18 22:03:08 +02:00
|
|
|
this.platformUtilsService = new BrowserPlatformUtilsService(
|
2021-06-22 22:11:29 +02:00
|
|
|
this.messagingService,
|
2021-07-23 20:22:53 +02:00
|
|
|
(clipboardValue, clearMs) => {
|
2018-01-04 16:51:08 +01:00
|
|
|
if (this.systemService != null) {
|
|
|
|
this.systemService.clearClipboard(clipboardValue, clearMs);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-01-04 16:51:08 +01:00
|
|
|
},
|
2020-11-30 13:41:08 +01:00
|
|
|
async () => {
|
2018-01-04 16:51:08 +01:00
|
|
|
if (this.nativeMessagingBackground != null) {
|
|
|
|
const promise = this.nativeMessagingBackground.getResponse();
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-06-25 20:56:29 +02:00
|
|
|
try {
|
2021-03-29 17:16:31 +02:00
|
|
|
await this.nativeMessagingBackground.send({ command: "biometricUnlock" });
|
2021-10-21 11:10:46 +02:00
|
|
|
} catch (e) {
|
2021-03-29 17:16:31 +02:00
|
|
|
return Promise.reject(e);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-10-21 11:10:46 +02:00
|
|
|
return promise.then((result) => result.response === "unlocked");
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2022-10-11 18:24:33 +02:00
|
|
|
},
|
|
|
|
window
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2023-01-30 20:04:22 +01:00
|
|
|
this.i18nService = new BrowserI18nService(BrowserApi.getUILanguage(window), this.stateService);
|
2022-10-27 23:38:54 +02:00
|
|
|
this.encryptService = flagEnabled("multithreadDecryption")
|
|
|
|
? new MultithreadEncryptServiceImplementation(
|
|
|
|
this.cryptoFunctionService,
|
|
|
|
this.logService,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
|
2021-09-14 13:36:34 +02:00
|
|
|
this.cryptoService = new BrowserCryptoService(
|
2021-11-09 18:59:51 +01:00
|
|
|
this.cryptoFunctionService,
|
2022-06-27 19:38:12 +02:00
|
|
|
this.encryptService,
|
2018-08-23 15:26:07 +02:00
|
|
|
this.platformUtilsService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService,
|
|
|
|
this.stateService
|
2020-04-06 17:40:16 +02:00
|
|
|
);
|
2022-01-27 22:22:51 +01:00
|
|
|
this.tokenService = new TokenService(this.stateService);
|
2017-12-05 23:04:30 +01:00
|
|
|
this.appIdService = new AppIdService(this.storageService);
|
2022-08-29 20:46:42 +02:00
|
|
|
this.environmentService = new BrowserEnvironmentService(this.stateService, this.logService);
|
2021-11-09 18:59:51 +01:00
|
|
|
this.apiService = new ApiService(
|
|
|
|
this.tokenService,
|
|
|
|
this.platformUtilsService,
|
|
|
|
this.environmentService,
|
2022-04-19 17:30:46 +02:00
|
|
|
this.appIdService,
|
2021-11-09 18:59:51 +01:00
|
|
|
(expired: boolean) => this.logout(expired)
|
|
|
|
);
|
2022-11-23 23:26:57 +01:00
|
|
|
this.settingsService = new BrowserSettingsService(this.stateService);
|
2018-08-23 03:47:30 +02:00
|
|
|
this.fileUploadService = new FileUploadService(this.logService, this.apiService);
|
2020-04-06 17:40:16 +02:00
|
|
|
this.cipherService = new CipherService(
|
2021-11-16 11:50:58 +01:00
|
|
|
this.cryptoService,
|
|
|
|
this.settingsService,
|
|
|
|
this.apiService,
|
|
|
|
this.fileUploadService,
|
|
|
|
this.i18nService,
|
2021-10-21 11:10:46 +02:00
|
|
|
() => this.searchService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService,
|
2022-10-27 23:38:54 +02:00
|
|
|
this.stateService,
|
|
|
|
this.encryptService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-11-23 23:26:57 +01:00
|
|
|
this.folderService = new BrowserFolderService(
|
2020-10-19 16:50:25 +02:00
|
|
|
this.cryptoService,
|
2021-04-07 17:39:59 +02:00
|
|
|
this.i18nService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.cipherService,
|
2022-07-18 14:39:12 +02:00
|
|
|
this.stateService
|
2021-04-14 23:43:09 +02:00
|
|
|
);
|
2022-07-08 15:40:31 +02:00
|
|
|
this.folderApiService = new FolderApiService(this.folderService, this.apiService);
|
2021-10-15 15:03:25 +02:00
|
|
|
this.collectionService = new CollectionService(
|
|
|
|
this.cryptoService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.i18nService,
|
|
|
|
this.stateService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2021-11-16 05:14:48 +01:00
|
|
|
this.searchService = new SearchService(this.cipherService, this.logService, this.i18nService);
|
2021-04-14 23:43:09 +02:00
|
|
|
this.sendService = new SendService(
|
|
|
|
this.cryptoService,
|
|
|
|
this.apiService,
|
|
|
|
this.fileUploadService,
|
2021-02-03 20:36:05 +01:00
|
|
|
this.i18nService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.cryptoFunctionService,
|
|
|
|
this.stateService
|
|
|
|
);
|
2022-09-27 22:25:19 +02:00
|
|
|
this.syncNotifierService = new SyncNotifierService();
|
2022-11-23 23:26:57 +01:00
|
|
|
this.organizationService = new BrowserOrganizationService(this.stateService);
|
|
|
|
this.policyService = new BrowserPolicyService(this.stateService, this.organizationService);
|
2022-08-08 11:04:36 +02:00
|
|
|
this.policyApiService = new PolicyApiService(
|
|
|
|
this.policyService,
|
|
|
|
this.apiService,
|
2023-01-11 17:12:56 +01:00
|
|
|
this.stateService
|
2021-02-03 20:36:05 +01:00
|
|
|
);
|
2021-11-09 18:59:51 +01:00
|
|
|
this.keyConnectorService = new KeyConnectorService(
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService,
|
2018-01-07 06:15:12 +01:00
|
|
|
this.cryptoService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.apiService,
|
|
|
|
this.tokenService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService,
|
2022-02-08 00:06:37 +01:00
|
|
|
this.organizationService,
|
2022-05-26 03:16:05 +02:00
|
|
|
this.cryptoFunctionService,
|
|
|
|
logoutCallback
|
2020-04-06 17:40:16 +02:00
|
|
|
);
|
2022-05-09 14:19:18 +02:00
|
|
|
this.vaultFilterService = new VaultFilterService(
|
|
|
|
this.stateService,
|
|
|
|
this.organizationService,
|
|
|
|
this.folderService,
|
|
|
|
this.cipherService,
|
|
|
|
this.collectionService,
|
|
|
|
this.policyService
|
|
|
|
);
|
2022-01-27 22:22:51 +01:00
|
|
|
|
2022-05-01 23:57:40 +02:00
|
|
|
this.twoFactorService = new TwoFactorService(this.i18nService, this.platformUtilsService);
|
|
|
|
|
2023-01-03 20:13:54 +01:00
|
|
|
// eslint-disable-next-line
|
|
|
|
const that = this;
|
|
|
|
const backgroundMessagingService = new (class extends MessagingServiceAbstraction {
|
|
|
|
// AuthService should send the messages to the background not popup.
|
|
|
|
send = (subscriber: string, arg: any = {}) => {
|
|
|
|
const message = Object.assign({}, { command: subscriber }, arg);
|
|
|
|
that.runtimeBackground.processMessage(message, that, null);
|
|
|
|
};
|
|
|
|
})();
|
2022-05-01 23:57:40 +02:00
|
|
|
this.authService = new AuthService(
|
|
|
|
this.cryptoService,
|
|
|
|
this.apiService,
|
|
|
|
this.tokenService,
|
|
|
|
this.appIdService,
|
|
|
|
this.platformUtilsService,
|
2023-01-03 20:13:54 +01:00
|
|
|
backgroundMessagingService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.logService,
|
|
|
|
this.keyConnectorService,
|
|
|
|
this.environmentService,
|
|
|
|
this.stateService,
|
|
|
|
this.twoFactorService,
|
2023-02-05 16:57:21 +01:00
|
|
|
this.i18nService,
|
|
|
|
this.encryptService
|
2022-05-01 23:57:40 +02:00
|
|
|
);
|
|
|
|
|
2022-08-30 22:30:43 +02:00
|
|
|
this.vaultTimeoutSettingsService = new VaultTimeoutSettingsService(
|
|
|
|
this.cryptoService,
|
|
|
|
this.tokenService,
|
|
|
|
this.policyService,
|
|
|
|
this.stateService
|
|
|
|
);
|
|
|
|
|
2020-04-06 17:40:16 +02:00
|
|
|
this.vaultTimeoutService = new VaultTimeoutService(
|
2018-04-11 21:59:39 +02:00
|
|
|
this.cipherService,
|
2021-05-13 02:51:07 +02:00
|
|
|
this.folderService,
|
2018-04-11 21:59:39 +02:00
|
|
|
this.collectionService,
|
2019-07-09 19:56:13 +02:00
|
|
|
this.cryptoService,
|
2021-10-15 15:03:25 +02:00
|
|
|
this.platformUtilsService,
|
2018-01-19 17:52:05 +01:00
|
|
|
this.messagingService,
|
|
|
|
this.searchService,
|
|
|
|
this.keyConnectorService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.authService,
|
2022-08-30 22:30:43 +02:00
|
|
|
this.vaultTimeoutSettingsService,
|
2022-04-27 01:11:39 +02:00
|
|
|
lockedCallback,
|
|
|
|
logoutCallback
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-08-30 22:30:43 +02:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
this.providerService = new ProviderService(this.stateService);
|
2020-08-11 22:25:07 +02:00
|
|
|
this.syncService = new SyncService(
|
2021-03-17 22:14:26 +01:00
|
|
|
this.apiService,
|
2017-12-06 05:28:31 +01:00
|
|
|
this.settingsService,
|
2021-05-13 02:51:07 +02:00
|
|
|
this.folderService,
|
2017-12-07 22:02:15 +01:00
|
|
|
this.cipherService,
|
2020-02-28 18:43:27 +01:00
|
|
|
this.cryptoService,
|
2017-12-07 04:28:33 +01:00
|
|
|
this.collectionService,
|
2017-12-07 22:02:15 +01:00
|
|
|
this.messagingService,
|
2021-10-21 11:10:46 +02:00
|
|
|
this.policyService,
|
2021-03-29 17:16:31 +02:00
|
|
|
this.sendService,
|
2021-11-09 18:59:51 +01:00
|
|
|
this.logService,
|
|
|
|
this.keyConnectorService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService,
|
|
|
|
this.providerService,
|
2022-07-08 15:40:31 +02:00
|
|
|
this.folderApiService,
|
2022-11-18 22:38:28 +01:00
|
|
|
this.organizationService,
|
2022-04-27 01:11:39 +02:00
|
|
|
logoutCallback
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-12-06 14:47:42 +01:00
|
|
|
this.eventUploadService = new EventUploadService(
|
2021-03-17 22:14:26 +01:00
|
|
|
this.apiService,
|
2022-12-06 14:47:42 +01:00
|
|
|
this.stateService,
|
|
|
|
this.logService
|
|
|
|
);
|
|
|
|
this.eventCollectionService = new EventCollectionService(
|
2017-12-07 22:02:15 +01:00
|
|
|
this.cipherService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService,
|
2022-12-06 14:47:42 +01:00
|
|
|
this.organizationService,
|
|
|
|
this.eventUploadService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2017-12-07 22:02:15 +01:00
|
|
|
this.passwordGenerationService = new PasswordGenerationService(
|
2020-02-28 18:43:27 +01:00
|
|
|
this.cryptoService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.policyService,
|
|
|
|
this.stateService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-06-23 09:53:42 +02:00
|
|
|
this.totpService = new TotpService(this.cryptoFunctionService, this.logService);
|
2019-07-12 20:54:17 +02:00
|
|
|
this.autofillService = new AutofillService(
|
2021-02-03 20:36:05 +01:00
|
|
|
this.cipherService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService,
|
2019-07-12 20:54:17 +02:00
|
|
|
this.totpService,
|
2022-12-06 14:47:42 +01:00
|
|
|
this.eventCollectionService,
|
2021-07-23 20:22:53 +02:00
|
|
|
this.logService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-09-02 03:15:19 +02:00
|
|
|
this.containerService = new ContainerService(this.cryptoService, this.encryptService);
|
2017-12-07 22:02:15 +01:00
|
|
|
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);
|
2021-05-13 02:51:07 +02:00
|
|
|
this.exportService = new ExportService(
|
|
|
|
this.folderService,
|
2021-02-03 20:36:05 +01:00
|
|
|
this.cipherService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.apiService,
|
2022-02-08 00:06:37 +01:00
|
|
|
this.cryptoService,
|
|
|
|
this.cryptoFunctionService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2017-12-07 22:02:15 +01:00
|
|
|
this.notificationsService = new NotificationsService(
|
|
|
|
this.syncService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.appIdService,
|
|
|
|
this.apiService,
|
2021-11-09 18:59:51 +01:00
|
|
|
this.environmentService,
|
2022-04-27 01:11:39 +02:00
|
|
|
logoutCallback,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.logService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.stateService,
|
2023-02-05 16:57:21 +01:00
|
|
|
this.authService,
|
|
|
|
this.messagingService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-02-15 23:06:35 +01:00
|
|
|
this.popupUtilsService = new PopupUtilsService(isPrivateMode);
|
2022-01-27 22:22:51 +01:00
|
|
|
|
2022-08-10 03:31:02 +02:00
|
|
|
this.userVerificationApiService = new UserVerificationApiService(this.apiService);
|
|
|
|
|
2020-02-28 18:43:27 +01:00
|
|
|
this.userVerificationService = new UserVerificationService(
|
|
|
|
this.cryptoService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.i18nService,
|
2022-08-10 03:31:02 +02:00
|
|
|
this.userVerificationApiService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
const systemUtilsServiceReloadCallback = () => {
|
|
|
|
const forceWindowReload =
|
|
|
|
this.platformUtilsService.isSafari() ||
|
|
|
|
this.platformUtilsService.isFirefox() ||
|
|
|
|
this.platformUtilsService.isOpera();
|
|
|
|
BrowserApi.reloadExtension(forceWindowReload ? window : null);
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.systemService = new SystemService(
|
|
|
|
this.messagingService,
|
|
|
|
this.platformUtilsService,
|
|
|
|
systemUtilsServiceReloadCallback,
|
|
|
|
this.stateService
|
|
|
|
);
|
|
|
|
|
2017-12-05 23:04:30 +01:00
|
|
|
// Other fields
|
2018-01-12 04:36:22 +01:00
|
|
|
this.isSafari = this.platformUtilsService.isSafari();
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-03-17 22:14:26 +01:00
|
|
|
// Background
|
2021-10-15 15:03:25 +02:00
|
|
|
this.runtimeBackground = new RuntimeBackground(
|
2021-12-21 15:43:35 +01:00
|
|
|
this,
|
2021-10-15 15:03:25 +02:00
|
|
|
this.autofillService,
|
2018-04-10 20:20:03 +02:00
|
|
|
this.platformUtilsService as BrowserPlatformUtilsService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.i18nService,
|
2021-10-21 11:10:46 +02:00
|
|
|
this.notificationsService,
|
|
|
|
this.systemService,
|
2021-11-09 18:59:51 +01:00
|
|
|
this.environmentService,
|
2021-04-07 17:39:59 +02:00
|
|
|
this.messagingService,
|
2021-07-23 20:22:53 +02:00
|
|
|
this.logService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2020-10-19 16:50:25 +02:00
|
|
|
this.nativeMessagingBackground = new NativeMessagingBackground(
|
2020-02-28 18:43:27 +01:00
|
|
|
this.cryptoService,
|
2021-11-09 18:59:51 +01:00
|
|
|
this.cryptoFunctionService,
|
2021-04-07 17:39:59 +02:00
|
|
|
this.runtimeBackground,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.i18nService,
|
2021-04-07 17:39:59 +02:00
|
|
|
this.messagingService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.appIdService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.platformUtilsService,
|
|
|
|
this.stateService,
|
2022-02-11 10:44:35 +01:00
|
|
|
this.logService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.authService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2018-01-17 15:12:16 +01:00
|
|
|
this.commandsBackground = new CommandsBackground(
|
2021-12-21 15:43:35 +01:00
|
|
|
this,
|
2020-02-28 18:43:27 +01:00
|
|
|
this.passwordGenerationService,
|
2021-03-17 22:14:26 +01:00
|
|
|
this.platformUtilsService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.vaultTimeoutService,
|
|
|
|
this.authService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2021-10-15 15:09:13 +02:00
|
|
|
this.notificationBackground = new NotificationBackground(
|
2021-10-15 15:03:25 +02:00
|
|
|
this.autofillService,
|
2021-02-03 20:36:05 +01:00
|
|
|
this.cipherService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.authService,
|
2021-10-21 11:10:46 +02:00
|
|
|
this.policyService,
|
2021-05-13 02:51:07 +02:00
|
|
|
this.folderService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
|
2021-10-15 15:09:13 +02:00
|
|
|
this.tabsBackground = new TabsBackground(this, this.notificationBackground);
|
2023-01-07 01:31:32 +01:00
|
|
|
if (!this.popupOnlyContext) {
|
|
|
|
const contextMenuClickedHandler = new ContextMenuClickedHandler(
|
|
|
|
(options) => this.platformUtilsService.copyToClipboard(options.text, { window: self }),
|
|
|
|
async (_tab) => {
|
|
|
|
const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {};
|
|
|
|
const password = await this.passwordGenerationService.generatePassword(options);
|
|
|
|
this.platformUtilsService.copyToClipboard(password, { window: window });
|
|
|
|
this.passwordGenerationService.addHistory(password);
|
|
|
|
},
|
|
|
|
this.authService,
|
|
|
|
this.cipherService,
|
|
|
|
new AutofillTabCommand(this.autofillService),
|
|
|
|
this.totpService,
|
|
|
|
this.eventCollectionService
|
|
|
|
);
|
|
|
|
|
|
|
|
this.contextMenusBackground = new ContextMenusBackground(contextMenuClickedHandler);
|
|
|
|
}
|
|
|
|
|
2021-02-03 20:36:05 +01:00
|
|
|
this.idleBackground = new IdleBackground(
|
2021-11-09 18:59:51 +01:00
|
|
|
this.vaultTimeoutService,
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService,
|
2018-08-23 15:26:07 +02:00
|
|
|
this.notificationsService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2021-02-03 20:36:05 +01:00
|
|
|
this.webRequestBackground = new WebRequestBackground(
|
2021-03-17 22:14:26 +01:00
|
|
|
this.platformUtilsService,
|
2021-02-03 20:36:05 +01:00
|
|
|
this.cipherService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.authService
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
|
2022-03-30 23:59:58 +02:00
|
|
|
this.usernameGenerationService = new UsernameGenerationService(
|
|
|
|
this.cryptoService,
|
2022-05-01 23:57:40 +02:00
|
|
|
this.stateService,
|
|
|
|
this.apiService
|
2022-03-30 23:59:58 +02:00
|
|
|
);
|
2023-01-01 16:30:09 +01:00
|
|
|
|
|
|
|
this.avatarUpdateService = new AvatarUpdateService(this.apiService, this.stateService);
|
2023-01-07 01:31:32 +01:00
|
|
|
|
|
|
|
if (!this.popupOnlyContext) {
|
|
|
|
this.mainContextMenuHandler = new MainContextMenuHandler(this.stateService, this.i18nService);
|
|
|
|
|
|
|
|
this.cipherContextMenuHandler = new CipherContextMenuHandler(
|
|
|
|
this.mainContextMenuHandler,
|
|
|
|
this.authService,
|
|
|
|
this.cipherService
|
|
|
|
);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2017-12-06 05:37:32 +01:00
|
|
|
async bootstrap() {
|
2022-07-22 18:41:02 +02:00
|
|
|
this.containerService.attachToGlobal(window);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.stateService.init();
|
|
|
|
|
2020-04-06 17:40:16 +02:00
|
|
|
await (this.vaultTimeoutService as VaultTimeoutService).init(true);
|
2023-01-30 20:04:22 +01:00
|
|
|
await (this.i18nService as BrowserI18nService).init();
|
2022-12-06 14:47:42 +01:00
|
|
|
await (this.eventUploadService as EventUploadService).init(true);
|
2018-01-12 18:22:55 +01:00
|
|
|
await this.runtimeBackground.init();
|
2017-12-07 22:02:15 +01:00
|
|
|
await this.notificationBackground.init();
|
2018-01-17 15:12:16 +01:00
|
|
|
await this.commandsBackground.init();
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-02-08 00:06:37 +01:00
|
|
|
this.twoFactorService.init();
|
|
|
|
|
2021-02-03 20:36:05 +01:00
|
|
|
await this.tabsBackground.init();
|
2023-01-07 01:31:32 +01:00
|
|
|
if (!this.popupOnlyContext) {
|
|
|
|
this.contextMenusBackground?.init();
|
|
|
|
}
|
2021-02-03 20:36:05 +01:00
|
|
|
await this.idleBackground.init();
|
|
|
|
await this.webRequestBackground.init();
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-03-06 22:02:57 +01:00
|
|
|
if (this.platformUtilsService.isFirefox() && !this.isPrivateMode) {
|
2022-03-09 23:09:11 +01:00
|
|
|
// Set Private Mode windows to the default icon - they do not share state with the background page
|
|
|
|
const privateWindows = await BrowserApi.getPrivateModeWindows();
|
|
|
|
privateWindows.forEach(async (win) => {
|
2022-10-19 15:55:57 +02:00
|
|
|
await new UpdateBadge(self).setBadgeIcon("", win.id);
|
2022-03-09 23:09:11 +01:00
|
|
|
});
|
|
|
|
|
2022-02-15 23:06:35 +01:00
|
|
|
BrowserApi.onWindowCreated(async (win) => {
|
|
|
|
if (win.incognito) {
|
2022-10-19 15:55:57 +02:00
|
|
|
await new UpdateBadge(self).setBadgeIcon("", win.id);
|
2022-02-15 23:06:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-07 22:02:15 +01:00
|
|
|
return new Promise<void>((resolve) => {
|
2019-02-14 06:46:28 +01:00
|
|
|
setTimeout(async () => {
|
2017-12-07 22:02:15 +01:00
|
|
|
await this.environmentService.setUrlsFromStorage();
|
2023-01-03 18:06:21 +01:00
|
|
|
if (!this.isPrivateMode) {
|
|
|
|
await this.refreshBadge();
|
|
|
|
}
|
2017-12-06 05:28:31 +01:00
|
|
|
this.fullSync(true);
|
2017-12-07 22:02:15 +01:00
|
|
|
setTimeout(() => this.notificationsService.init(), 2500);
|
2019-02-13 17:34:42 +01:00
|
|
|
resolve();
|
2021-12-21 15:43:35 +01:00
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-19 15:55:57 +02:00
|
|
|
async refreshBadge() {
|
|
|
|
await new UpdateBadge(self).run({ existingServices: this as any });
|
2018-01-04 22:06:00 +01:00
|
|
|
}
|
2017-12-07 22:02:15 +01:00
|
|
|
|
2022-10-19 15:55:57 +02:00
|
|
|
async refreshMenu(forLocked = false) {
|
2019-02-27 17:57:29 +01:00
|
|
|
if (!chrome.windows || !chrome.contextMenus) {
|
|
|
|
return;
|
2017-12-07 22:02:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 01:31:32 +01:00
|
|
|
await MainContextMenuHandler.removeAll();
|
2017-12-07 22:02:15 +01:00
|
|
|
|
2019-08-19 21:57:34 +02:00
|
|
|
if (forLocked) {
|
2023-01-07 01:31:32 +01:00
|
|
|
await this.mainContextMenuHandler?.noAccess();
|
2019-09-21 15:50:57 +02:00
|
|
|
this.onUpdatedRan = this.onReplacedRan = false;
|
|
|
|
return;
|
2018-01-18 22:17:58 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 01:31:32 +01:00
|
|
|
await this.mainContextMenuHandler?.init();
|
|
|
|
|
2020-04-06 17:40:16 +02:00
|
|
|
const tab = await BrowserApi.getTabFromCurrentWindow();
|
2018-03-04 04:48:38 +01:00
|
|
|
if (tab) {
|
2023-01-07 01:31:32 +01:00
|
|
|
await this.cipherContextMenuHandler?.update(tab.url);
|
|
|
|
this.onUpdatedRan = this.onReplacedRan = false;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
async logout(expired: boolean, userId?: string) {
|
2022-12-06 14:47:42 +01:00
|
|
|
await this.eventUploadService.uploadEvents(userId);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2017-12-07 22:02:15 +01:00
|
|
|
await Promise.all([
|
2022-01-27 22:22:51 +01:00
|
|
|
this.syncService.setLastSync(new Date(0), userId),
|
|
|
|
this.cryptoService.clearKeys(userId),
|
2020-04-06 17:40:16 +02:00
|
|
|
this.settingsService.clear(userId),
|
2017-12-07 22:02:15 +01:00
|
|
|
this.cipherService.clear(userId),
|
|
|
|
this.folderService.clear(userId),
|
2020-01-29 04:35:40 +01:00
|
|
|
this.collectionService.clear(userId),
|
|
|
|
this.policyService.clear(userId),
|
2022-01-27 22:22:51 +01:00
|
|
|
this.passwordGenerationService.clear(userId),
|
2022-08-30 22:30:43 +02:00
|
|
|
this.vaultTimeoutSettingsService.clear(userId),
|
2021-11-09 18:59:51 +01:00
|
|
|
this.keyConnectorService.clear(),
|
2022-05-09 14:19:18 +02:00
|
|
|
this.vaultFilterService.clear(),
|
2021-12-21 15:43:35 +01:00
|
|
|
]);
|
|
|
|
|
2023-01-27 11:49:35 +01:00
|
|
|
//Needs to be checked before state is cleaned
|
|
|
|
const needStorageReseed = await this.needsStorageReseed();
|
|
|
|
|
2022-02-08 15:42:42 +01:00
|
|
|
await this.stateService.clean({ userId: userId });
|
2022-02-07 21:09:43 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
if (userId == null || userId === (await this.stateService.getUserId())) {
|
|
|
|
this.searchService.clearIndex();
|
|
|
|
this.messagingService.send("doneLoggingOut", { expired: expired, userId: userId });
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2023-01-27 11:49:35 +01:00
|
|
|
if (needStorageReseed) {
|
|
|
|
await this.reseedStorage();
|
|
|
|
}
|
|
|
|
|
2022-10-19 15:55:57 +02:00
|
|
|
if (BrowserApi.manifestVersion === 3) {
|
|
|
|
BrowserApi.sendMessage("updateBadge");
|
|
|
|
}
|
|
|
|
await this.refreshBadge();
|
2023-01-07 01:31:32 +01:00
|
|
|
await this.mainContextMenuHandler.noAccess();
|
2018-08-23 15:26:07 +02:00
|
|
|
this.notificationsService.updateConnection(false);
|
2019-02-27 17:57:29 +01:00
|
|
|
await this.systemService.clearPendingClipboard();
|
2022-08-05 20:04:27 +02:00
|
|
|
await this.systemService.startProcessReload(this.authService);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2023-01-27 11:49:35 +01:00
|
|
|
private async needsStorageReseed(): Promise<boolean> {
|
|
|
|
const currentVaultTimeout = await this.stateService.getVaultTimeout();
|
|
|
|
return currentVaultTimeout == null ? false : true;
|
|
|
|
}
|
|
|
|
|
2020-04-06 17:40:16 +02:00
|
|
|
async collectPageDetailsForContentScript(tab: any, sender: string, frameId: number = null) {
|
|
|
|
if (tab == null || !tab.id) {
|
2019-02-13 17:34:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options: any = {};
|
|
|
|
if (frameId != null) {
|
|
|
|
options.frameId = frameId;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2019-02-13 17:34:42 +01:00
|
|
|
|
|
|
|
BrowserApi.tabSendMessage(
|
2021-12-21 15:43:35 +01:00
|
|
|
tab,
|
|
|
|
{
|
2017-12-07 22:02:15 +01:00
|
|
|
command: "collectPageDetails",
|
|
|
|
tab: tab,
|
|
|
|
sender: sender,
|
2021-12-21 15:43:35 +01:00
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-13 17:34:42 +01:00
|
|
|
async openPopup() {
|
|
|
|
// Chrome APIs cannot open popup
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2019-02-13 17:34:42 +01:00
|
|
|
// TODO: Do we need to open this popup?
|
|
|
|
if (!this.isSafari) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-02-13 17:34:42 +01:00
|
|
|
await SafariApp.sendMessageToApp("showPopover", null, true);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2019-02-13 17:34:42 +01:00
|
|
|
async reseedStorage() {
|
2021-12-21 15:43:35 +01:00
|
|
|
if (
|
2019-02-13 17:34:42 +01:00
|
|
|
!this.platformUtilsService.isChrome() &&
|
|
|
|
!this.platformUtilsService.isVivaldi() &&
|
|
|
|
!this.platformUtilsService.isOpera()
|
2021-12-21 15:43:35 +01:00
|
|
|
) {
|
|
|
|
return;
|
2019-02-13 17:34:42 +01:00
|
|
|
}
|
|
|
|
|
2017-12-05 23:04:30 +01:00
|
|
|
const getStorage = (): Promise<any> =>
|
2020-09-15 16:50:45 +02:00
|
|
|
new Promise((resolve) => {
|
|
|
|
chrome.storage.local.get(null, (o: any) => resolve(o));
|
2017-12-05 23:04:30 +01:00
|
|
|
});
|
|
|
|
|
2020-09-15 16:50:45 +02:00
|
|
|
const clearStorage = (): Promise<void> =>
|
|
|
|
new Promise((resolve) => {
|
|
|
|
chrome.storage.local.clear(() => resolve());
|
|
|
|
});
|
|
|
|
|
|
|
|
const storage = await getStorage();
|
|
|
|
await clearStorage();
|
|
|
|
|
2021-09-01 23:51:43 +02:00
|
|
|
for (const key in storage) {
|
2022-02-24 18:14:04 +01:00
|
|
|
// eslint-disable-next-line
|
2021-09-01 23:51:43 +02:00
|
|
|
if (!storage.hasOwnProperty(key)) {
|
|
|
|
continue;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2021-09-01 23:51:43 +02:00
|
|
|
await this.storageService.save(key, storage[key]);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2021-09-01 23:51:43 +02:00
|
|
|
}
|
|
|
|
|
2022-02-24 18:14:04 +01:00
|
|
|
private async fullSync(override = false) {
|
2017-12-06 05:28:31 +01:00
|
|
|
const syncInternal = 6 * 60 * 60 * 1000; // 6 hours
|
|
|
|
const lastSync = await this.syncService.getLastSync();
|
|
|
|
|
|
|
|
let lastSyncAgo = syncInternal + 1;
|
|
|
|
if (lastSync != null) {
|
|
|
|
lastSyncAgo = new Date().getTime() - lastSync.getTime();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2017-12-05 23:04:30 +01:00
|
|
|
|
|
|
|
if (override || lastSyncAgo >= syncInternal) {
|
|
|
|
await this.syncService.fullSync(override);
|
|
|
|
this.scheduleNextSync();
|
|
|
|
} else {
|
|
|
|
this.scheduleNextSync();
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2017-12-05 23:04:30 +01:00
|
|
|
|
|
|
|
private scheduleNextSync() {
|
|
|
|
if (this.syncTimeout) {
|
|
|
|
clearTimeout(this.syncTimeout);
|
|
|
|
}
|
|
|
|
|
2017-12-07 03:54:38 +01:00
|
|
|
this.syncTimeout = setTimeout(async () => await this.fullSync(), 5 * 60 * 1000); // check every 5 minutes
|
2017-12-05 23:04:30 +01:00
|
|
|
}
|
|
|
|
}
|