mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
Merge pull request #1491 from Hinton/feature/safari-webext
Safari Web Extension Port from App Extension
This commit is contained in:
@@ -20,7 +20,7 @@ export default class CommandsBackground {
|
||||
}
|
||||
|
||||
async init() {
|
||||
if (this.isSafari || this.isVivaldi) {
|
||||
if (this.isVivaldi) {
|
||||
BrowserApi.messageListener('commands.background', async (msg: any, sender: any, sendResponse: any) => {
|
||||
if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
|
||||
await this.processCommand(msg.shortcut, sender);
|
||||
|
||||
@@ -167,8 +167,8 @@ export default class MainBackground {
|
||||
return promise.then((result) => result.response === 'unlocked');
|
||||
}
|
||||
});
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService);
|
||||
this.secureStorageService = new BrowserStorageService(this.platformUtilsService);
|
||||
this.storageService = new BrowserStorageService();
|
||||
this.secureStorageService = new BrowserStorageService();
|
||||
this.i18nService = new I18nService(BrowserApi.getUILanguage(window));
|
||||
this.cryptoFunctionService = new WebCryptoFunctionService(window, this.platformUtilsService);
|
||||
this.consoleLogService = new ConsoleLogService(false);
|
||||
@@ -252,21 +252,18 @@ export default class MainBackground {
|
||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
||||
this.platformUtilsService, this.analytics, this.vaultTimeoutService);
|
||||
|
||||
if (!this.isSafari) {
|
||||
this.tabsBackground = new TabsBackground(this);
|
||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.vaultTimeoutService,
|
||||
this.eventService, this.totpService);
|
||||
this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.storageService,
|
||||
this.notificationsService);
|
||||
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
|
||||
this.vaultTimeoutService);
|
||||
this.windowsBackground = new WindowsBackground(this);
|
||||
}
|
||||
this.tabsBackground = new TabsBackground(this);
|
||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.vaultTimeoutService,
|
||||
this.eventService, this.totpService);
|
||||
this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.storageService,
|
||||
this.notificationsService);
|
||||
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
|
||||
this.vaultTimeoutService);
|
||||
this.windowsBackground = new WindowsBackground(this);
|
||||
}
|
||||
|
||||
async bootstrap() {
|
||||
SafariApp.init();
|
||||
this.analytics.ga('send', 'pageview', '/background.html');
|
||||
this.containerService.attachToWindow(window);
|
||||
|
||||
@@ -276,13 +273,11 @@ export default class MainBackground {
|
||||
await this.runtimeBackground.init();
|
||||
await this.commandsBackground.init();
|
||||
|
||||
if (!this.isSafari) {
|
||||
await this.tabsBackground.init();
|
||||
await this.contextMenusBackground.init();
|
||||
await this.idleBackground.init();
|
||||
await this.webRequestBackground.init();
|
||||
await this.windowsBackground.init();
|
||||
}
|
||||
await this.tabsBackground.init();
|
||||
await this.contextMenusBackground.init();
|
||||
await this.idleBackground.init();
|
||||
await this.webRequestBackground.init();
|
||||
await this.windowsBackground.init();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(async () => {
|
||||
@@ -297,7 +292,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
async setIcon() {
|
||||
if (this.isSafari || (!chrome.browserAction && !this.sidebarAction)) {
|
||||
if (!chrome.browserAction && !this.sidebarAction) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -316,7 +311,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
async refreshBadgeAndMenu(forLocked: boolean = false) {
|
||||
if (this.isSafari || !chrome.windows || !chrome.contextMenus) {
|
||||
if (!chrome.windows || !chrome.contextMenus) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -447,7 +442,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
private async buildContextMenu() {
|
||||
if (this.isSafari || !chrome.contextMenus || this.buildingContextMenu) {
|
||||
if (!chrome.contextMenus || this.buildingContextMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { CipherView } from 'jslib/models/view/cipherView';
|
||||
import { LoginUriView } from 'jslib/models/view/loginUriView';
|
||||
import { LoginView } from 'jslib/models/view/loginView';
|
||||
|
||||
import { AuthService } from 'jslib/abstractions/auth.service';
|
||||
import { AutofillService } from '../services/abstractions/autofill.service';
|
||||
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
@@ -13,10 +12,7 @@ import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { NotificationsService } from 'jslib/abstractions/notifications.service';
|
||||
import { PolicyService } from 'jslib/abstractions/policy.service';
|
||||
import { PopupUtilsService } from '../popup/services/popup-utils.service';
|
||||
import { StateService } from 'jslib/abstractions/state.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||
import { SystemService } from 'jslib/abstractions/system.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
@@ -24,7 +20,6 @@ import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
import MainBackground from './main.background';
|
||||
import { NativeMessagingBackground } from './nativeMessaging.background';
|
||||
|
||||
import { Analytics } from 'jslib/misc';
|
||||
import { Utils } from 'jslib/misc/utils';
|
||||
@@ -36,7 +31,6 @@ export default class RuntimeBackground {
|
||||
private runtime: any;
|
||||
private autofillTimeout: any;
|
||||
private pageDetailsToAutoFill: any[] = [];
|
||||
private isSafari: boolean;
|
||||
private onInstalledReason: string = null;
|
||||
|
||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||
@@ -46,19 +40,15 @@ export default class RuntimeBackground {
|
||||
private systemService: SystemService, private vaultTimeoutService: VaultTimeoutService,
|
||||
private environmentService: EnvironmentService, private policyService: PolicyService,
|
||||
private userService: UserService) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.runtime = this.isSafari ? {} : chrome.runtime;
|
||||
|
||||
// onInstalled listener must be wired up before anything else, so we do it in the ctor
|
||||
if (!this.isSafari) {
|
||||
this.runtime.onInstalled.addListener((details: any) => {
|
||||
this.onInstalledReason = details.reason;
|
||||
});
|
||||
}
|
||||
chrome.runtime.onInstalled.addListener((details: any) => {
|
||||
this.onInstalledReason = details.reason;
|
||||
});
|
||||
}
|
||||
|
||||
async init() {
|
||||
if (!this.runtime) {
|
||||
if (!chrome.runtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -399,20 +389,6 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
private async checkOnInstalled() {
|
||||
if (this.isSafari) {
|
||||
const installedVersion = await this.storageService.get<string>(ConstantsService.installedVersionKey);
|
||||
if (installedVersion == null) {
|
||||
this.onInstalledReason = 'install';
|
||||
} else if (BrowserApi.getApplicationVersion() !== installedVersion) {
|
||||
this.onInstalledReason = 'update';
|
||||
}
|
||||
|
||||
if (this.onInstalledReason != null) {
|
||||
await this.storageService.save(ConstantsService.installedVersionKey,
|
||||
BrowserApi.getApplicationVersion());
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
if (this.onInstalledReason != null) {
|
||||
if (this.onInstalledReason === 'install') {
|
||||
|
||||
Reference in New Issue
Block a user