1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01:00

Remove more old safari app ext code

This commit is contained in:
Hinton 2020-12-11 15:25:35 +01:00
parent 25a2af903a
commit a9c9108053
5 changed files with 31 additions and 135 deletions

View File

@ -261,7 +261,6 @@ export default class MainBackground {
} }
async bootstrap() { async bootstrap() {
SafariApp.init();
this.analytics.ga('send', 'pageview', '/background.html'); this.analytics.ga('send', 'pageview', '/background.html');
this.containerService.attachToWindow(window); this.containerService.attachToWindow(window);

View File

@ -1,23 +1,6 @@
import { BrowserApi } from './browserApi'; import { BrowserApi } from './browserApi';
export class SafariApp { 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<string, { resolve: (value?: unknown) => void, timeoutDate: Date }>();
(window as any).bitwardenSafariAppMessageListeners =
new Map<string, (message: any, sender: any, response: any) => void>();
(window as any).bitwardenSafariAppMessageReceiver = (message: any) => {
SafariApp.receiveMessageFromApp(message);
};
}
}
static sendMessageToApp(command: string, data: any = null, resolveNow = false): Promise<any> { static sendMessageToApp(command: string, data: any = null, resolveNow = false): Promise<any> {
if (!BrowserApi.isSafariApi) { if (!BrowserApi.isSafariApi) {
return Promise.resolve(null); 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 { }
}
}
} }

View File

@ -17,71 +17,31 @@ document.addEventListener('DOMContentLoaded', (event) => {
const logInButtonNames = new Set(['log in', 'sign in', 'login', 'go', 'submit', 'continue', 'next']); 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 changePasswordButtonNames = new Set(['save password', 'update password', 'change password', 'change']);
const changePasswordButtonContainsNames = new Set(['pass', 'change', 'contras', 'senha']); 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 disabledAddLoginNotification = false;
let disabledChangedPasswordNotification = false; let disabledChangedPasswordNotification = false;
if (isSafari) {
if ((window as any).__bitwardenFrameId == null) { chrome.storage.local.get('neverDomains', (ndObj: any) => {
(window as any).__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999)); const domains = ndObj.neverDomains;
} if (domains != null && domains.hasOwnProperty(window.location.hostname)) {
if (inIframe) {
return; return;
} }
const responseCommand = 'notificationBarDataResponse'; chrome.storage.local.get('disableAddLoginNotification', (disAddObj: any) => {
safari.extension.dispatchMessage('bitwarden', { disabledAddLoginNotification = disAddObj != null && disAddObj.disableAddLoginNotification === true;
command: 'bgGetDataForTab', chrome.storage.local.get('disableChangedPasswordNotification', (disChangedObj: any) => {
responseCommand: responseCommand, disabledChangedPasswordNotification = disChangedObj != null &&
bitwardenFrameId: (window as any).__bitwardenFrameId, disChangedObj.disableChangedPasswordNotification === true;
});
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;
if (!disabledAddLoginNotification || !disabledChangedPasswordNotification) { if (!disabledAddLoginNotification || !disabledChangedPasswordNotification) {
collectIfNeededWithTimeout(); 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) => { chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => {
processMessages(msg, sendResponse); processMessages(msg, sendResponse);
}); });
}
function processMessages(msg: any, sendResponse: Function) { function processMessages(msg: any, sendResponse: Function) {
if (msg.command === 'openNotificationBar') { if (msg.command === 'openNotificationBar') {
@ -470,7 +430,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
} }
function closeExistingAndOpenBar(type: string, typeData: any) { function closeExistingAndOpenBar(type: string, typeData: any) {
let barPage = (isSafari ? 'app/' : '') + 'notification/bar.html'; let barPage = 'notification/bar.html';
switch (type) { switch (type) {
case 'info': case 'info':
barPage = barPage + '?info=' + typeData.text; barPage = barPage + '?info=' + typeData.text;
@ -510,7 +470,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
return; 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'); const iframe = document.createElement('iframe');
iframe.style.cssText = 'height: 42px; width: 100%; border: 0; min-height: initial;'; iframe.style.cssText = 'height: 42px; width: 100%; border: 0; min-height: initial;';
@ -580,11 +540,6 @@ document.addEventListener('DOMContentLoaded', (event) => {
} }
function sendPlatformMessage(msg: any) { function sendPlatformMessage(msg: any) {
if (isSafari) { chrome.runtime.sendMessage(msg);
msg.bitwardenFrameId = (window as any).__bitwardenFrameId;
safari.extension.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
} }
}); });

View File

@ -3,34 +3,21 @@ require('./bar.scss');
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
var i18n = {}; var i18n = {};
var lang = window.navigator.language; 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();
// delay 50ms so that we get proper body dimensions i18n.appName = chrome.i18n.getMessage('appName');
setTimeout(load, 50); 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);
function load() { function load() {
var closeButton = document.getElementById('close-button'), var closeButton = document.getElementById('close-button'),
@ -131,10 +118,6 @@ document.addEventListener('DOMContentLoaded', () => {
} }
function sendPlatformMessage(msg) { function sendPlatformMessage(msg) {
if (typeof safari !== 'undefined') { chrome.runtime.sendMessage(msg);
safari.extension.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
} }
}); });

View File

@ -58,7 +58,6 @@ 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();
await super.ngOnInit(); await super.ngOnInit();
if (this.selectedProviderType == null) { if (this.selectedProviderType == null) {
return; return;