1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

Revert "Safari Web Extension Port from App Extension"

This commit is contained in:
Chad Scharf
2021-01-13 17:08:33 -05:00
committed by GitHub
parent ebd2439edd
commit 336f8f3117
47 changed files with 1950 additions and 664 deletions

View File

@@ -989,6 +989,35 @@
End 1Password Extension
*/
if ((typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1) {
if (window.__bitwardenFrameId == null) {
window.__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999));
}
safari.self.addEventListener('message', function (msgEvent) {
var msg = JSON.parse(msgEvent.message.msg);
if (msg.bitwardenFrameId != null && window.__bitwardenFrameId !== msg.bitwardenFrameId) {
return;
}
if (msg.command === 'collectPageDetails') {
var pageDetails = collect(document);
var pageDetailsObj = JSON.parse(pageDetails);
safari.extension.dispatchMessage('bitwarden', {
command: 'collectPageDetailsResponse',
tab: msg.tab,
details: pageDetailsObj,
sender: msg.sender,
bitwardenFrameId: window.__bitwardenFrameId
});
}
else if (msg.command === 'fillForm') {
fill(document, msg.fillScript);
}
}, false);
return;
}
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.command === 'collectPageDetails') {
var pageDetails = collect(document);

View File

@@ -3,17 +3,44 @@ document.addEventListener('DOMContentLoaded', (event) => {
let filledThisHref = false;
let delayFillTimeout: number;
const enabledKey = 'enableAutoFillOnPageLoad';
chrome.storage.local.get(enabledKey, (obj: any) => {
if (obj != null && obj[enabledKey] === true) {
setInterval(() => doFillIfNeeded(), 500);
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (isSafari) {
if ((window as any).__bitwardenFrameId == null) {
(window as any).__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999));
}
});
chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => {
if (msg.command === 'fillForm' && pageHref === msg.url) {
filledThisHref = true;
}
});
const responseCommand = 'autofillerAutofillOnPageLoadEnabledResponse';
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.autofillEnabled === true) {
setInterval(() => doFillIfNeeded(), 500);
} else if (msg.command === 'fillForm' && pageHref === msg.url) {
filledThisHref = true;
}
}, false);
return;
} else {
const enabledKey = 'enableAutoFillOnPageLoad';
chrome.storage.local.get(enabledKey, (obj: any) => {
if (obj != null && obj[enabledKey] === true) {
setInterval(() => doFillIfNeeded(), 500);
}
});
chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => {
if (msg.command === 'fillForm' && pageHref === msg.url) {
filledThisHref = true;
}
});
}
function doFillIfNeeded(force: boolean = false) {
if (force || pageHref !== window.location.href) {
@@ -37,7 +64,12 @@ document.addEventListener('DOMContentLoaded', (event) => {
sender: 'autofiller',
};
chrome.runtime.sendMessage(msg);
if (isSafari) {
msg.bitwardenFrameId = (window as any).__bitwardenFrameId;
safari.extension.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
}
}
});

View File

@@ -17,30 +17,71 @@ 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;
chrome.storage.local.get('neverDomains', (ndObj: any) => {
const domains = ndObj.neverDomains;
if (domains != null && domains.hasOwnProperty(window.location.hostname)) {
if (isSafari) {
if ((window as any).__bitwardenFrameId == null) {
(window as any).__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999));
}
if (inIframe) {
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;
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;
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') {
@@ -429,7 +470,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
}
function closeExistingAndOpenBar(type: string, typeData: any) {
let barPage = 'notification/bar.html';
let barPage = (isSafari ? 'app/' : '') + 'notification/bar.html';
switch (type) {
case 'info':
barPage = barPage + '?info=' + typeData.text;
@@ -469,7 +510,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
return;
}
const barPageUrl: string = chrome.extension.getURL(barPage);
const barPageUrl: string = isSafari ? (safari.extension.baseURI + barPage) : chrome.extension.getURL(barPage);
const iframe = document.createElement('iframe');
iframe.style.cssText = 'height: 42px; width: 100%; border: 0; min-height: initial;';
@@ -539,6 +580,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
}
function sendPlatformMessage(msg: any) {
chrome.runtime.sendMessage(msg);
if (isSafari) {
msg.bitwardenFrameId = (window as any).__bitwardenFrameId;
safari.extension.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
}
});

View File

@@ -45,6 +45,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
shortcut: shortcut,
};
chrome.runtime.sendMessage(msg);
if (isSafari) {
msg.bitwardenFrameId = (window as any).__bitwardenFrameId;
safari.extension.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
}
});

View File

@@ -3,6 +3,15 @@ window.addEventListener('message', (event) => {
return;
if (event.data.command && (event.data.command === 'authResult')) {
if (typeof chrome === typeof undefined) {
safari.extension.dispatchMessage('bitwarden', {
command: event.data.command,
code: event.data.code,
state: event.data.state,
referrer: event.source.location.hostname,
});
return;
}
chrome.runtime.sendMessage({
command: event.data.command,
code: event.data.code,