mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-08 19:18:02 +01:00
cleanup for safari
This commit is contained in:
parent
d8f423711a
commit
d2083c2665
@ -53,7 +53,7 @@ export default class CommandsBackground {
|
|||||||
|
|
||||||
private async generatePasswordToClipboard() {
|
private async generatePasswordToClipboard() {
|
||||||
if (this.isEdge) {
|
if (this.isEdge) {
|
||||||
// Safari does not support access to clipboard from background
|
// Edge does not support access to clipboard from background
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,11 +200,11 @@ export default class MainBackground {
|
|||||||
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
||||||
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
|
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
|
||||||
this.analytics, this.notificationsService, this.systemService, this.lockService);
|
this.analytics, this.notificationsService, this.systemService, this.lockService);
|
||||||
this.tabsBackground = new TabsBackground(this, this.platformUtilsService);
|
|
||||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
||||||
this.platformUtilsService, this.analytics, this.lockService);
|
this.platformUtilsService, this.analytics, this.lockService);
|
||||||
|
|
||||||
if (!this.isSafari) {
|
if (!this.isSafari) {
|
||||||
|
this.tabsBackground = new TabsBackground(this);
|
||||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||||
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService,
|
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService,
|
||||||
this.eventService);
|
this.eventService);
|
||||||
@ -224,10 +224,10 @@ export default class MainBackground {
|
|||||||
await (this.i18nService as I18nService).init();
|
await (this.i18nService as I18nService).init();
|
||||||
await (this.eventService as EventService).init(true);
|
await (this.eventService as EventService).init(true);
|
||||||
await this.runtimeBackground.init();
|
await this.runtimeBackground.init();
|
||||||
await this.tabsBackground.init();
|
|
||||||
await this.commandsBackground.init();
|
await this.commandsBackground.init();
|
||||||
|
|
||||||
if (!this.isSafari) {
|
if (!this.isSafari) {
|
||||||
|
await this.tabsBackground.init();
|
||||||
await this.contextMenusBackground.init();
|
await this.contextMenusBackground.init();
|
||||||
await this.idleBackground.init();
|
await this.idleBackground.init();
|
||||||
await this.webRequestBackground.init();
|
await this.webRequestBackground.init();
|
||||||
@ -364,20 +364,6 @@ export default class MainBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await SafariApp.sendMessageToApp('showPopover');
|
await SafariApp.sendMessageToApp('showPopover');
|
||||||
|
|
||||||
/*
|
|
||||||
if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const activeToolBars = safari.extension.toolbarItems.filter((tb: any) => {
|
|
||||||
return tb.browserWindow === safari.application.activeBrowserWindow;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (activeToolBars && activeToolBars.length) {
|
|
||||||
activeToolBars[0].showPopover();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async reseedStorage() {
|
async reseedStorage() {
|
||||||
|
@ -54,27 +54,7 @@ export default class RuntimeBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isSafari) {
|
|
||||||
// Reload the popup when it's opened
|
|
||||||
/*
|
|
||||||
this.runtime.addEventListener('popover', (event: any) => {
|
|
||||||
const win: Window = event.target.contentWindow;
|
|
||||||
let href = win.location.href;
|
|
||||||
if (href.indexOf('#') > -1) {
|
|
||||||
href = href.substr(0, href.indexOf('#'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (win.location.toString() === href) {
|
|
||||||
win.location.reload();
|
|
||||||
} else {
|
|
||||||
win.location.href = href;
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.checkOnInstalled();
|
await this.checkOnInstalled();
|
||||||
|
|
||||||
BrowserApi.messageListener('runtime.background', async (msg: any, sender: any, sendResponse: any) => {
|
BrowserApi.messageListener('runtime.background', async (msg: any, sender: any, sendResponse: any) => {
|
||||||
await this.processMessage(msg, sender, sendResponse);
|
await this.processMessage(msg, sender, sendResponse);
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
import MainBackground from './main.background';
|
import MainBackground from './main.background';
|
||||||
|
|
||||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
|
||||||
|
|
||||||
export default class TabsBackground {
|
export default class TabsBackground {
|
||||||
private tabs: any;
|
private tabs: any;
|
||||||
private isSafari: boolean;
|
|
||||||
|
|
||||||
constructor(private main: MainBackground, private platformUtilsService: PlatformUtilsService) {
|
constructor(private main: MainBackground) {
|
||||||
this.isSafari = this.platformUtilsService.isSafari();
|
this.tabs = chrome.tabs;
|
||||||
this.tabs = this.isSafari ? {} : chrome.tabs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
@ -16,21 +12,6 @@ export default class TabsBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isSafari) {
|
|
||||||
/*
|
|
||||||
this.tabs.addEventListener('activate', async (ev: any) => {
|
|
||||||
await this.main.refreshBadgeAndMenu();
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
this.tabs.addEventListener('navigate', async (ev: any) => {
|
|
||||||
await this.main.checkNotificationQueue();
|
|
||||||
await this.main.refreshBadgeAndMenu();
|
|
||||||
}, true);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tabs.onActivated.addListener(async (activeInfo: any) => {
|
this.tabs.onActivated.addListener(async (activeInfo: any) => {
|
||||||
await this.main.refreshBadgeAndMenu();
|
await this.main.refreshBadgeAndMenu();
|
||||||
});
|
});
|
||||||
|
@ -42,32 +42,6 @@ export class BrowserApi {
|
|||||||
} else if (BrowserApi.isSafariApi) {
|
} else if (BrowserApi.isSafariApi) {
|
||||||
const tabs = await SafariApp.sendMessageToApp('tabs_query', JSON.stringify(options));
|
const tabs = await SafariApp.sendMessageToApp('tabs_query', JSON.stringify(options));
|
||||||
return tabs != null ? JSON.parse(tabs) : null;
|
return tabs != null ? JSON.parse(tabs) : null;
|
||||||
/*
|
|
||||||
if (options.currentWindow) {
|
|
||||||
if (safari.application.activeBrowserWindow) {
|
|
||||||
wins.push(safari.application.activeBrowserWindow);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
wins = safari.application.browserWindows;
|
|
||||||
}
|
|
||||||
|
|
||||||
const returnedTabs: any[] = [];
|
|
||||||
wins.forEach((win: any) => {
|
|
||||||
if (!win.tabs) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.active && win.activeTab) {
|
|
||||||
returnedTabs.push(BrowserApi.makeTabObject(win.activeTab));
|
|
||||||
} else if (!options.active) {
|
|
||||||
win.tabs.forEach((tab: any) => {
|
|
||||||
returnedTabs.push(BrowserApi.makeTabObject(tab));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.resolve(returnedTabs);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,35 +89,6 @@ export class BrowserApi {
|
|||||||
obj: JSON.stringify(obj),
|
obj: JSON.stringify(obj),
|
||||||
options: options,
|
options: options,
|
||||||
}), true);
|
}), true);
|
||||||
/*
|
|
||||||
let t = tab.safariTab;
|
|
||||||
if (!t || !t.page) {
|
|
||||||
const win = safari.application.activeBrowserWindow;
|
|
||||||
if (safari.application.browserWindows.indexOf(win) !== tab.windowId) {
|
|
||||||
return Promise.reject('Window not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (win.tabs.length < tab.index + 1) {
|
|
||||||
return Promise.reject('Tab not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
t = win.tabs[tab.index];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.tab && obj.tab.safariTab) {
|
|
||||||
delete obj.tab.safariTab;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options != null && options.frameId != null && obj.bitwardenFrameId == null) {
|
|
||||||
obj.bitwardenFrameId = options.frameId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.page) {
|
|
||||||
t.page.dispatchMessage('bitwarden', obj);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,15 +160,6 @@ export class BrowserApi {
|
|||||||
}
|
}
|
||||||
callback(message, sender, response);
|
callback(message, sender, response);
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
safari.application.addEventListener('message', async (msgEvent: any) => {
|
|
||||||
callback(msgEvent.message, {
|
|
||||||
tab: BrowserApi.makeTabObject(msgEvent.target),
|
|
||||||
frameId: msgEvent.message != null && msgEvent.message.bitwardenFrameId != null ?
|
|
||||||
msgEvent.message.bitwardenFrameId : null,
|
|
||||||
}, () => { });
|
|
||||||
}, false);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,31 +194,6 @@ export class BrowserApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static makeTabObject(tab: any): any {
|
|
||||||
if (BrowserApi.isChromeApi) {
|
|
||||||
return tab;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tab.browserWindow) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
/*
|
|
||||||
const winIndex = safari.application.browserWindows.indexOf(tab.browserWindow);
|
|
||||||
const tabIndex = tab.browserWindow.tabs.indexOf(tab);
|
|
||||||
return {
|
|
||||||
id: winIndex + '_' + tabIndex,
|
|
||||||
index: tabIndex,
|
|
||||||
windowId: winIndex,
|
|
||||||
title: tab.title,
|
|
||||||
active: tab === tab.browserWindow.activeTab,
|
|
||||||
url: tab.url || 'about:blank',
|
|
||||||
safariTab: tab,
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
static gaFilter() {
|
static gaFilter() {
|
||||||
return process.env.ENV !== 'production';
|
return process.env.ENV !== 'production';
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { BrowserApi } from './browserApi';
|
import { BrowserApi } from './browserApi';
|
||||||
|
|
||||||
export class SafariApp {
|
export class SafariApp {
|
||||||
static inited = false;
|
|
||||||
|
|
||||||
static init() {
|
static init() {
|
||||||
if (SafariApp.inited) {
|
if ((window as any).bitwardenSafariAppInited) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SafariApp.inited = true;
|
(window as any).bitwardenSafariAppInited = true;
|
||||||
if (BrowserApi.isSafariApi) {
|
if (BrowserApi.isSafariApi) {
|
||||||
(window as any).bitwardenSafariAppRequests =
|
(window as any).bitwardenSafariAppRequests =
|
||||||
new Map<string, { resolve: (value?: unknown) => void, timeoutDate: Date }>();
|
new Map<string, { resolve: (value?: unknown) => void, timeoutDate: Date }>();
|
||||||
@ -16,7 +14,7 @@ export class SafariApp {
|
|||||||
(window as any).bitwardenSafariAppMessageReceiver = (message: any) => {
|
(window as any).bitwardenSafariAppMessageReceiver = (message: any) => {
|
||||||
SafariApp.receiveMessageFromApp(message);
|
SafariApp.receiveMessageFromApp(message);
|
||||||
};
|
};
|
||||||
setInterval(() => SafariApp.cleanupOldRequests(), 5 * 60000);
|
setInterval(() => SafariApp.cleanupOldRequests(), 5 * 60000); // every 5 mins
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
|
/*
|
||||||
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
||||||
this.ngZone.run(async () => {
|
this.ngZone.run(async () => {
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
@ -65,6 +66,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
|
|||||||
this.changeDetectorRef.detectChanges();
|
this.changeDetectorRef.detectChanges();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
const isFirefox = this.platformUtilsService.isFirefox();
|
const isFirefox = this.platformUtilsService.isFirefox();
|
||||||
if (this.popupUtilsService.inPopup(window) && isFirefox &&
|
if (this.popupUtilsService.inPopup(window) && isFirefox &&
|
||||||
@ -72,8 +74,10 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
|
|||||||
// ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1562620
|
// ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1562620
|
||||||
this.initU2f = false;
|
this.initU2f = false;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
const isSafari = this.platformUtilsService.isSafari();
|
const isSafari = this.platformUtilsService.isSafari();
|
||||||
this.showNewWindowMessage = isSafari;
|
this.showNewWindowMessage = isSafari;
|
||||||
|
*/
|
||||||
|
|
||||||
await super.ngOnInit();
|
await super.ngOnInit();
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSafari && this.selectedProviderType === TwoFactorProviderType.Email &&
|
if (/*!isSafari && */this.selectedProviderType === TwoFactorProviderType.Email &&
|
||||||
this.popupUtilsService.inPopup(window)) {
|
this.popupUtilsService.inPopup(window)) {
|
||||||
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('popup2faCloseMessage'),
|
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('popup2faCloseMessage'),
|
||||||
null, this.i18nService.t('yes'), this.i18nService.t('no'));
|
null, this.i18nService.t('yes'), this.i18nService.t('no'));
|
||||||
@ -99,6 +103,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
const isDuo = this.selectedProviderType === TwoFactorProviderType.Duo ||
|
const isDuo = this.selectedProviderType === TwoFactorProviderType.Duo ||
|
||||||
this.selectedProviderType === TwoFactorProviderType.OrganizationDuo;
|
this.selectedProviderType === TwoFactorProviderType.OrganizationDuo;
|
||||||
if (!isSafari || !isDuo) {
|
if (!isSafari || !isDuo) {
|
||||||
@ -118,6 +123,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
Loading…
Reference in New Issue
Block a user