From a9c910805372a109b4c17fd191ec6893bd6d1838 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 11 Dec 2020 15:25:35 +0100 Subject: [PATCH] Remove more old safari app ext code --- src/background/main.background.ts | 1 - src/browser/safariApp.ts | 40 ----------- src/content/notificationBar.ts | 77 +++++----------------- src/notification/bar.js | 47 +++++-------- src/popup/accounts/two-factor.component.ts | 1 - 5 files changed, 31 insertions(+), 135 deletions(-) diff --git a/src/background/main.background.ts b/src/background/main.background.ts index c6282f01904..c35cb0cabd0 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -261,7 +261,6 @@ export default class MainBackground { } async bootstrap() { - SafariApp.init(); this.analytics.ga('send', 'pageview', '/background.html'); this.containerService.attachToWindow(window); diff --git a/src/browser/safariApp.ts b/src/browser/safariApp.ts index b78f7993967..b53d3754b7c 100644 --- a/src/browser/safariApp.ts +++ b/src/browser/safariApp.ts @@ -1,23 +1,6 @@ import { BrowserApi } from './browserApi'; export class SafariApp { - static init() { - if ((window as any).bitwardenSafariAppInited) { - return; - } - (window as any).bitwardenSafariAppInited = true; - - if (BrowserApi.isSafariApi) { - (window as any).bitwardenSafariAppRequests = - new Map void, timeoutDate: Date }>(); - (window as any).bitwardenSafariAppMessageListeners = - new Map void>(); - (window as any).bitwardenSafariAppMessageReceiver = (message: any) => { - SafariApp.receiveMessageFromApp(message); - }; - } - } - static sendMessageToApp(command: string, data: any = null, resolveNow = false): Promise { if (!BrowserApi.isSafariApi) { return Promise.resolve(null); @@ -35,27 +18,4 @@ export class SafariApp { }); }); } - - static addMessageListener(name: string, callback: (message: any, sender: any, response: any) => void) { - (window as any).bitwardenSafariAppMessageListeners.set(name, callback); - } - - static sendMessageToListeners(message: any, sender: any, response: any) { - (window as any).bitwardenSafariAppMessageListeners.forEach((f: any) => f(message, sender, response)); - } - - private static receiveMessageFromApp(message: any) { - if (message == null) { - return; - } - if ((message.id == null || message.id === '') && message.command === 'app_message') { - try { - const msg = JSON.parse(message.data); - SafariApp.sendMessageToListeners(msg, { - id: 'app_message', - tab: message.senderTab, - }, null); - } catch { } - } - } } diff --git a/src/content/notificationBar.ts b/src/content/notificationBar.ts index 4974f53ad8c..f199cb1e94b 100644 --- a/src/content/notificationBar.ts +++ b/src/content/notificationBar.ts @@ -17,71 +17,31 @@ document.addEventListener('DOMContentLoaded', (event) => { const logInButtonNames = new Set(['log in', 'sign in', 'login', 'go', 'submit', 'continue', 'next']); const changePasswordButtonNames = new Set(['save password', 'update password', 'change password', 'change']); const changePasswordButtonContainsNames = new Set(['pass', 'change', 'contras', 'senha']); - let notificationBarData = null; - const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && - navigator.userAgent.indexOf('Chrome') === -1; let disabledAddLoginNotification = false; let disabledChangedPasswordNotification = false; - if (isSafari) { - if ((window as any).__bitwardenFrameId == null) { - (window as any).__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999)); - } - if (inIframe) { + + chrome.storage.local.get('neverDomains', (ndObj: any) => { + const domains = ndObj.neverDomains; + if (domains != null && domains.hasOwnProperty(window.location.hostname)) { return; } - const responseCommand = 'notificationBarDataResponse'; - safari.extension.dispatchMessage('bitwarden', { - command: 'bgGetDataForTab', - responseCommand: responseCommand, - bitwardenFrameId: (window as any).__bitwardenFrameId, - }); - safari.self.addEventListener('message', (msgEvent: any) => { - const msg = JSON.parse(msgEvent.message.msg); - if (msg.bitwardenFrameId != null && (window as any).__bitwardenFrameId !== msg.bitwardenFrameId) { - return; - } - if (msg.command === responseCommand && msg.data) { - notificationBarData = msg.data; - if (notificationBarData.neverDomains && - notificationBarData.neverDomains.hasOwnProperty(window.location.hostname)) { - return; - } - - disabledAddLoginNotification = notificationBarData.disabledAddLoginNotification === true; - disabledChangedPasswordNotification = notificationBarData.disabledChangedPasswordNotification === true; + chrome.storage.local.get('disableAddLoginNotification', (disAddObj: any) => { + disabledAddLoginNotification = disAddObj != null && disAddObj.disableAddLoginNotification === true; + chrome.storage.local.get('disableChangedPasswordNotification', (disChangedObj: any) => { + disabledChangedPasswordNotification = disChangedObj != null && + disChangedObj.disableChangedPasswordNotification === true; if (!disabledAddLoginNotification || !disabledChangedPasswordNotification) { collectIfNeededWithTimeout(); } - } - - processMessages(msg, () => { /* do nothing on send response for Safari */ }); - }, false); - return; - } else { - chrome.storage.local.get('neverDomains', (ndObj: any) => { - const domains = ndObj.neverDomains; - if (domains != null && domains.hasOwnProperty(window.location.hostname)) { - return; - } - - chrome.storage.local.get('disableAddLoginNotification', (disAddObj: any) => { - disabledAddLoginNotification = disAddObj != null && disAddObj.disableAddLoginNotification === true; - chrome.storage.local.get('disableChangedPasswordNotification', (disChangedObj: any) => { - disabledChangedPasswordNotification = disChangedObj != null && - disChangedObj.disableChangedPasswordNotification === true; - if (!disabledAddLoginNotification || !disabledChangedPasswordNotification) { - collectIfNeededWithTimeout(); - } - }); }); }); + }); - chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => { - processMessages(msg, sendResponse); - }); - } + chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => { + processMessages(msg, sendResponse); + }); function processMessages(msg: any, sendResponse: Function) { if (msg.command === 'openNotificationBar') { @@ -470,7 +430,7 @@ document.addEventListener('DOMContentLoaded', (event) => { } function closeExistingAndOpenBar(type: string, typeData: any) { - let barPage = (isSafari ? 'app/' : '') + 'notification/bar.html'; + let barPage = 'notification/bar.html'; switch (type) { case 'info': barPage = barPage + '?info=' + typeData.text; @@ -510,7 +470,7 @@ document.addEventListener('DOMContentLoaded', (event) => { return; } - const barPageUrl: string = isSafari ? (safari.extension.baseURI + barPage) : chrome.extension.getURL(barPage); + const barPageUrl: string = chrome.extension.getURL(barPage); const iframe = document.createElement('iframe'); iframe.style.cssText = 'height: 42px; width: 100%; border: 0; min-height: initial;'; @@ -580,11 +540,6 @@ document.addEventListener('DOMContentLoaded', (event) => { } function sendPlatformMessage(msg: any) { - if (isSafari) { - msg.bitwardenFrameId = (window as any).__bitwardenFrameId; - safari.extension.dispatchMessage('bitwarden', msg); - } else { - chrome.runtime.sendMessage(msg); - } + chrome.runtime.sendMessage(msg); } }); diff --git a/src/notification/bar.js b/src/notification/bar.js index c882bd29313..a5e55ca6647 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -3,34 +3,21 @@ require('./bar.scss'); document.addEventListener('DOMContentLoaded', () => { var i18n = {}; var lang = window.navigator.language; - if (typeof safari !== 'undefined') { - const responseCommand = 'notificationBarFrameDataResponse'; - sendPlatformMessage({ - command: 'bgGetDataForTab', - responseCommand: responseCommand - }); - safari.self.addEventListener('message', (msgEvent) => { - const msg = JSON.parse(msgEvent.message.msg); - if (msg.command === responseCommand && msg.data) { - i18n = msg.data.i18n; - load(); - } - }, false); - } else { - i18n.appName = chrome.i18n.getMessage('appName'); - i18n.close = chrome.i18n.getMessage('close'); - i18n.yes = chrome.i18n.getMessage('yes'); - i18n.never = chrome.i18n.getMessage('never'); - i18n.notificationAddSave = chrome.i18n.getMessage('notificationAddSave'); - i18n.notificationNeverSave = chrome.i18n.getMessage('notificationNeverSave'); - i18n.notificationAddDesc = chrome.i18n.getMessage('notificationAddDesc'); - i18n.notificationChangeSave = chrome.i18n.getMessage('notificationChangeSave'); - i18n.notificationChangeDesc = chrome.i18n.getMessage('notificationChangeDesc'); - lang = chrome.i18n.getUILanguage(); + + i18n.appName = chrome.i18n.getMessage('appName'); + i18n.close = chrome.i18n.getMessage('close'); + i18n.yes = chrome.i18n.getMessage('yes'); + i18n.never = chrome.i18n.getMessage('never'); + i18n.notificationAddSave = chrome.i18n.getMessage('notificationAddSave'); + i18n.notificationNeverSave = chrome.i18n.getMessage('notificationNeverSave'); + i18n.notificationAddDesc = chrome.i18n.getMessage('notificationAddDesc'); + i18n.notificationChangeSave = chrome.i18n.getMessage('notificationChangeSave'); + i18n.notificationChangeDesc = chrome.i18n.getMessage('notificationChangeDesc'); + lang = chrome.i18n.getUILanguage(); - // delay 50ms so that we get proper body dimensions - setTimeout(load, 50); - } + // delay 50ms so that we get proper body dimensions + setTimeout(load, 50); + function load() { var closeButton = document.getElementById('close-button'), @@ -131,10 +118,6 @@ document.addEventListener('DOMContentLoaded', () => { } function sendPlatformMessage(msg) { - if (typeof safari !== 'undefined') { - safari.extension.dispatchMessage('bitwarden', msg); - } else { - chrome.runtime.sendMessage(msg); - } + chrome.runtime.sendMessage(msg); } }); diff --git a/src/popup/accounts/two-factor.component.ts b/src/popup/accounts/two-factor.component.ts index fe8d36ee1ff..57aef6e4d95 100644 --- a/src/popup/accounts/two-factor.component.ts +++ b/src/popup/accounts/two-factor.component.ts @@ -58,7 +58,6 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { // ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1562620 this.initU2f = false; } - const isSafari = this.platformUtilsService.isSafari(); await super.ngOnInit(); if (this.selectedProviderType == null) { return;