mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
support for safari in notification bar
This commit is contained in:
parent
175169cb7c
commit
0229ef328a
@ -1,4 +1,8 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function (event) {
|
document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
|
if (window.location.hostname.indexOf('bitwarden.com') > -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var pageDetails = [],
|
var pageDetails = [],
|
||||||
formData = [],
|
formData = [],
|
||||||
barType = null,
|
barType = null,
|
||||||
@ -8,9 +12,38 @@
|
|||||||
collectIfNeededTimeout = null,
|
collectIfNeededTimeout = null,
|
||||||
observeDomTimeout = null,
|
observeDomTimeout = null,
|
||||||
iframed = isIframed(),
|
iframed = isIframed(),
|
||||||
submitButtonNames = ['log in', 'sign in', 'login', 'go', 'submit', 'continue', 'next'];
|
submitButtonNames = ['log in', 'sign in', 'login', 'go', 'submit', 'continue', 'next'],
|
||||||
|
notificationBarData = null,
|
||||||
|
isSafariApi = (typeof safari !== 'undefined');
|
||||||
|
|
||||||
if (window.location.hostname.indexOf('bitwarden.com') === -1) {
|
if (isSafariApi) {
|
||||||
|
const responseCommand = 'notificationBarDataResponse';
|
||||||
|
safari.self.tab.dispatchMessage('bitwarden', {
|
||||||
|
command: 'bgGetNotificationBarData',
|
||||||
|
responseCommand: responseCommand
|
||||||
|
});
|
||||||
|
safari.self.addEventListener('message', function (msgEvent) {
|
||||||
|
const msg = msgEvent.message;
|
||||||
|
if (msg.command === responseCommand && msg.data) {
|
||||||
|
notificationBarData = msg.data;
|
||||||
|
if (notificationBarData.neverDomains &&
|
||||||
|
notificationBarData.neverDomains.hasOwnProperty(window.location.hostname)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notificationBarData.disableAddLoginNotification === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
collectIfNeededWithTimeout();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
processMessages(msg, function () { /* do nothing on send response for Safari */ });
|
||||||
|
}, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
chrome.storage.local.get('neverDomains', function (obj) {
|
chrome.storage.local.get('neverDomains', function (obj) {
|
||||||
var domains = obj.neverDomains;
|
var domains = obj.neverDomains;
|
||||||
if (domains && domains.hasOwnProperty(window.location.hostname)) {
|
if (domains && domains.hasOwnProperty(window.location.hostname)) {
|
||||||
@ -19,16 +52,17 @@
|
|||||||
|
|
||||||
chrome.storage.local.get('disableAddLoginNotification', function (obj) {
|
chrome.storage.local.get('disableAddLoginNotification', function (obj) {
|
||||||
if (!obj || !obj.disableAddLoginNotification) {
|
if (!obj || !obj.disableAddLoginNotification) {
|
||||||
if (collectIfNeededTimeout) {
|
collectIfNeededWithTimeout();
|
||||||
clearTimeout(collectIfNeededTimeout);
|
|
||||||
}
|
|
||||||
collectIfNeededTimeout = setTimeout(collectIfNeeded, 1000);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
||||||
|
processMessages(msg, sendResponse);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
function processMessages(msg, sendResponse) {
|
||||||
if (msg.command === 'openNotificationBar') {
|
if (msg.command === 'openNotificationBar') {
|
||||||
if (iframed) {
|
if (iframed) {
|
||||||
return;
|
return;
|
||||||
@ -59,7 +93,7 @@
|
|||||||
sendResponse();
|
sendResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
function isIframed() {
|
function isIframed() {
|
||||||
try {
|
try {
|
||||||
@ -125,6 +159,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function collectIfNeededWithTimeout() {
|
||||||
|
if (collectIfNeededTimeout) {
|
||||||
|
clearTimeout(collectIfNeededTimeout);
|
||||||
|
}
|
||||||
|
collectIfNeededTimeout = setTimeout(collectIfNeeded, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
function collectIfNeeded() {
|
function collectIfNeeded() {
|
||||||
if (pageHref !== window.location.href) {
|
if (pageHref !== window.location.href) {
|
||||||
pageHref = window.location.href;
|
pageHref = window.location.href;
|
||||||
@ -148,7 +189,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function collect() {
|
function collect() {
|
||||||
chrome.runtime.sendMessage({
|
sendPlatformMessage({
|
||||||
command: 'bgCollectPageDetails',
|
command: 'bgCollectPageDetails',
|
||||||
sender: 'notificationBar'
|
sender: 'notificationBar'
|
||||||
});
|
});
|
||||||
@ -296,7 +337,7 @@
|
|||||||
form.dataset.bitwardenProcessed = '0';
|
form.dataset.bitwardenProcessed = '0';
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
chrome.runtime.sendMessage({
|
sendPlatformMessage({
|
||||||
command: 'bgAddLogin',
|
command: 'bgAddLogin',
|
||||||
login: login
|
login: login
|
||||||
});
|
});
|
||||||
@ -344,8 +385,10 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var barPageUrl = isSafariApi ? (safari.extension.baseURI + barPage) : chrome.extension.getURL(barPage);
|
||||||
|
|
||||||
var iframe = document.createElement('iframe');
|
var iframe = document.createElement('iframe');
|
||||||
iframe.src = chrome.extension.getURL(barPage);
|
iframe.src = barPageUrl;
|
||||||
iframe.style.cssText = 'height: 42px; width: 100%; border: 0;';
|
iframe.style.cssText = 'height: 42px; width: 100%; border: 0;';
|
||||||
iframe.id = 'bit-notification-bar-iframe';
|
iframe.id = 'bit-notification-bar-iframe';
|
||||||
|
|
||||||
@ -378,7 +421,7 @@
|
|||||||
|
|
||||||
switch (barType) {
|
switch (barType) {
|
||||||
case 'add':
|
case 'add':
|
||||||
chrome.runtime.sendMessage({
|
sendPlatformMessage({
|
||||||
command: 'bgAddClose'
|
command: 'bgAddClose'
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -402,4 +445,13 @@
|
|||||||
el.style.height = heightStyle;
|
el.style.height = heightStyle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendPlatformMessage(msg) {
|
||||||
|
if (isSafariApi) {
|
||||||
|
safari.self.tab.dispatchMessage('bitwarden', msg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chrome.runtime.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user