api compat checks

This commit is contained in:
Kyle Spearrin 2017-09-25 20:35:54 -04:00
parent ae4079cb21
commit 185916c8a3
1 changed files with 73 additions and 57 deletions

View File

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