1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-01 00:10:39 +02:00

check for chrome.webRequest.onAuthRequired avail

This commit is contained in:
Kyle Spearrin 2017-09-15 09:47:47 -04:00
parent 1ea07a6ced
commit a260d269ec

View File

@ -230,69 +230,71 @@ var bg_isBackground = true,
}
});
chrome.webRequest.onAuthRequired.addListener(function (details, callback) {
if (!details.url || pendingAuthRequests.indexOf(details.requestId) != -1) {
if (callback) {
callback();
if (chrome.webRequest && chrome.webRequest.onAuthRequired) {
chrome.webRequest.onAuthRequired.addListener(function (details, callback) {
if (!details.url || pendingAuthRequests.indexOf(details.requestId) != -1) {
if (callback) {
callback();
}
return;
}
return;
}
var domain = bg_utilsService.getDomain(details.url);
if (!domain) {
if (callback) {
callback();
var domain = bg_utilsService.getDomain(details.url);
if (!domain) {
if (callback) {
callback();
}
return;
}
return;
}
pendingAuthRequests.push(details.requestId);
pendingAuthRequests.push(details.requestId);
if (bg_utilsService.isFirefox()) {
return new Promise(function (resolve, reject) {
if (bg_utilsService.isFirefox()) {
return new Promise(function (resolve, reject) {
bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) {
if (!logins || logins.length !== 1) {
reject();
return;
}
resolve({
authCredentials: {
username: logins[0].username,
password: logins[0].password
}
});
}, function () {
reject();
});
});
}
else {
bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) {
if (!logins || logins.length !== 1) {
reject();
callback();
return;
}
resolve({
callback({
authCredentials: {
username: logins[0].username,
password: logins[0].password
}
});
}, function () {
reject();
});
});
}
else {
bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) {
if (!logins || logins.length !== 1) {
callback();
return;
}
callback({
authCredentials: {
username: logins[0].username,
password: logins[0].password
}
});
}, function () {
callback();
});
}
}, { urls: ['http://*/*', 'https://*/*'] }, [bg_utilsService.isFirefox() ? 'blocking' : 'asyncBlocking']);
}
}, { urls: ['http://*/*', 'https://*/*'] }, [bg_utilsService.isFirefox() ? 'blocking' : 'asyncBlocking']);
chrome.webRequest.onCompleted.addListener(completeAuthRequest, { urls: ['http://*/*'] });
chrome.webRequest.onErrorOccurred.addListener(completeAuthRequest, { urls: ['http://*/*'] });
chrome.webRequest.onCompleted.addListener(completeAuthRequest, { urls: ['http://*/*'] });
chrome.webRequest.onErrorOccurred.addListener(completeAuthRequest, { urls: ['http://*/*'] });
function completeAuthRequest(details) {
var i = pendingAuthRequests.indexOf(details.requestId);
if (i > -1) {
pendingAuthRequests.splice(i, 1);
function completeAuthRequest(details) {
var i = pendingAuthRequests.indexOf(details.requestId);
if (i > -1) {
pendingAuthRequests.splice(i, 1);
}
}
}