1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

api compat checks

This commit is contained in:
Kyle Spearrin 2017-09-25 20:35:54 -04:00
parent ae4079cb21
commit 185916c8a3

View File

@ -171,6 +171,7 @@ var bg_isBackground = true,
refreshBadgeAndMenu(); refreshBadgeAndMenu();
}); });
if (chrome.windows) {
chrome.windows.onFocusChanged.addListener(function (windowId) { chrome.windows.onFocusChanged.addListener(function (windowId) {
if (windowId === null || windowId < 0) { if (windowId === null || windowId < 0) {
return; return;
@ -178,7 +179,9 @@ var bg_isBackground = true,
refreshBadgeAndMenu(); refreshBadgeAndMenu();
}); });
}
if (chrome.contextMenus) {
chrome.contextMenus.onClicked.addListener(function (info, tab) { chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === 'generate-password') { if (info.menuItemId === 'generate-password') {
ga('send', { ga('send', {
@ -229,6 +232,7 @@ var bg_isBackground = true,
}); });
} }
}); });
}
if (chrome.webRequest && chrome.webRequest.onAuthRequired) { if (chrome.webRequest && chrome.webRequest.onAuthRequired) {
chrome.webRequest.onAuthRequired.addListener(function (details, callback) { chrome.webRequest.onAuthRequired.addListener(function (details, callback) {
@ -300,7 +304,7 @@ var bg_isBackground = true,
var buildingContextMenu = false; var buildingContextMenu = false;
function buildContextMenu(callback) { function buildContextMenu(callback) {
if (buildingContextMenu) { if (!chrome.contextMenus || buildingContextMenu) {
return; return;
} }
buildingContextMenu = true; buildingContextMenu = true;
@ -367,6 +371,10 @@ var bg_isBackground = true,
} }
function setIcon() { function setIcon() {
if (!chrome.browserAction.setIcon) {
return;
}
bg_userService.isAuthenticated(function (isAuthenticated) { bg_userService.isAuthenticated(function (isAuthenticated) {
bg_cryptoService.getKey().then(function (key) { bg_cryptoService.getKey().then(function (key) {
var suffix = ''; var suffix = '';
@ -388,6 +396,10 @@ var bg_isBackground = true,
} }
function refreshBadgeAndMenu() { function refreshBadgeAndMenu() {
if (!chrome.windows || !chrome.contextMenus) {
return;
}
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function (tabs) { chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function (tabs) {
var tab = null; var tab = null;
if (tabs.length > 0) { if (tabs.length > 0) {
@ -418,7 +430,7 @@ var bg_isBackground = true,
} }
function loadMenuAndUpdateBadge(url, tabId, contextMenuEnabled) { function loadMenuAndUpdateBadge(url, tabId, contextMenuEnabled) {
if (!url) { if (!chrome.browserAction.setBadgeBackgroundColor || !url) {
return; return;
} }
@ -429,6 +441,10 @@ var bg_isBackground = true,
chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' }); chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' });
if (!chrome.browserAction.setBadgeText) {
return;
}
menuOptionsLoaded = []; menuOptionsLoaded = [];
bg_loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) { bg_loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) {
logins.sort(bg_loginService.sortLoginsByLastUsedThenName); logins.sort(bg_loginService.sortLoginsByLastUsedThenName);
@ -704,7 +720,7 @@ var bg_isBackground = true,
} }
function loadContextMenuOptions(title, idSuffix, login) { function loadContextMenuOptions(title, idSuffix, login) {
if (menuOptionsLoaded.indexOf(idSuffix) > -1) { if (!chrome.contextMenus || menuOptionsLoaded.indexOf(idSuffix) > -1) {
return; return;
} }
menuOptionsLoaded.push(idSuffix); menuOptionsLoaded.push(idSuffix);