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

Remove safari only code from autofill.

This commit is contained in:
Hinton 2020-12-11 16:13:50 +01:00
parent a9c9108053
commit 9fb80823ba
5 changed files with 12 additions and 81 deletions

View File

@ -989,35 +989,6 @@
End 1Password Extension 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) { chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.command === 'collectPageDetails') { if (msg.command === 'collectPageDetails') {
var pageDetails = collect(document); var pageDetails = collect(document);

View File

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

View File

@ -20,7 +20,6 @@ document.addEventListener('DOMContentLoaded', (event) => {
let disabledAddLoginNotification = false; let disabledAddLoginNotification = false;
let disabledChangedPasswordNotification = false; let disabledChangedPasswordNotification = false;
chrome.storage.local.get('neverDomains', (ndObj: any) => { chrome.storage.local.get('neverDomains', (ndObj: any) => {
const domains = ndObj.neverDomains; const domains = ndObj.neverDomains;
if (domains != null && domains.hasOwnProperty(window.location.hostname)) { if (domains != null && domains.hasOwnProperty(window.location.hostname)) {

View File

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

View File

@ -68,8 +68,6 @@ export class PopupUtilsService {
chrome.tabs.create({ chrome.tabs.create({
url: href, url: href,
}); });
} else if ((typeof safari !== 'undefined')) {
// Safari can't open popup in full page tab :(
} }
} }
} }