diff --git a/core/state-manager.js b/core/state-manager.js index 31a021f..681bfec 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -123,15 +123,24 @@ stateManager._removeTab = function (tabIdentifier) { stateManager._updateTab = function (details) { - let tabIdentifier, frameIdentifier; + let tabDomain, domainIsWhitelisted, tabIdentifier, frameIdentifier; + + tabDomain = helpers.extractDomainFromUrl(details.url); + domainIsWhitelisted = stateManager._domainIsWhitelisted(tabDomain); - tabIdentifier = details.tabId; frameIdentifier = details.frameId; + tabIdentifier = details.tabId; - if (tabIdentifier === -1 || frameIdentifier !== 0) { + if (frameIdentifier !== 0 || tabIdentifier === -1) { return; } + if (domainIsWhitelisted) { + stateManager._setIconDisabled(tabIdentifier); + } else { + stateManager._setIconDefault(tabIdentifier); + } + chrome.browserAction.setTitle({ 'tabId': tabIdentifier, 'title': 'Decentraleyes' @@ -182,12 +191,62 @@ stateManager._removeIconBadgeFromTab = function (tab) { stateManager._clearBadgeText(tab.id); }; +stateManager._domainIsWhitelisted = function (domain) { + + if (domain !== null) { + + let whitelistRecord, isWhitelisted; + + whitelistRecord = requestAnalyzer.whitelistedDomains[domain]; + isWhitelisted = Boolean(whitelistRecord); + + return isWhitelisted; + } + + return false; +}; + +stateManager._setIconDefault = function (tabIdentifier) { + + wrappers.setIcon({ + 'path': stateManager.defaultIconPath, + 'tabId': tabIdentifier + }); +}; + +stateManager._setIconDisabled = function (tabIdentifier) { + + wrappers.setIcon({ + 'path': stateManager.disabledIconPath, + 'tabId': tabIdentifier + }); +}; + /** * Initializations */ stateManager.requests = {}; stateManager.tabs = {}; + +stateManager.defaultIconPath = { + '18': chrome.runtime.getURL('icons/action/icon18-default.png'), + '19': chrome.runtime.getURL('icons/action/icon19-default.png'), + '32': chrome.runtime.getURL('icons/action/icon32-default.png'), + '36': chrome.runtime.getURL('icons/action/icon36-default.png'), + '38': chrome.runtime.getURL('icons/action/icon38-default.png'), + '64': chrome.runtime.getURL('icons/action/icon64-default.png') +}; + +stateManager.disabledIconPath = { + '18': chrome.runtime.getURL('icons/action/icon18-disabled.png'), + '19': chrome.runtime.getURL('icons/action/icon19-disabled.png'), + '32': chrome.runtime.getURL('icons/action/icon32-disabled.png'), + '36': chrome.runtime.getURL('icons/action/icon36-disabled.png'), + '38': chrome.runtime.getURL('icons/action/icon38-disabled.png'), + '64': chrome.runtime.getURL('icons/action/icon64-disabled.png') +}; + stateManager.validHosts = []; for (let mapping in mappings) { diff --git a/icons/action/icon18.png b/icons/action/icon18-default.png similarity index 100% rename from icons/action/icon18.png rename to icons/action/icon18-default.png diff --git a/icons/action/icon18-disabled.png b/icons/action/icon18-disabled.png new file mode 100644 index 0000000..a068a8c Binary files /dev/null and b/icons/action/icon18-disabled.png differ diff --git a/icons/action/icon19.png b/icons/action/icon19-default.png similarity index 100% rename from icons/action/icon19.png rename to icons/action/icon19-default.png diff --git a/icons/action/icon19-disabled.png b/icons/action/icon19-disabled.png new file mode 100644 index 0000000..3ff257b Binary files /dev/null and b/icons/action/icon19-disabled.png differ diff --git a/icons/action/icon32.png b/icons/action/icon32-default.png similarity index 100% rename from icons/action/icon32.png rename to icons/action/icon32-default.png diff --git a/icons/action/icon32-disabled.png b/icons/action/icon32-disabled.png new file mode 100644 index 0000000..60344fd Binary files /dev/null and b/icons/action/icon32-disabled.png differ diff --git a/icons/action/icon36.png b/icons/action/icon36-default.png similarity index 100% rename from icons/action/icon36.png rename to icons/action/icon36-default.png diff --git a/icons/action/icon36-disabled.png b/icons/action/icon36-disabled.png new file mode 100644 index 0000000..8abada5 Binary files /dev/null and b/icons/action/icon36-disabled.png differ diff --git a/icons/action/icon38.png b/icons/action/icon38-default.png similarity index 100% rename from icons/action/icon38.png rename to icons/action/icon38-default.png diff --git a/icons/action/icon38-disabled.png b/icons/action/icon38-disabled.png new file mode 100644 index 0000000..469c00a Binary files /dev/null and b/icons/action/icon38-disabled.png differ diff --git a/icons/action/icon64.png b/icons/action/icon64-default.png similarity index 100% rename from icons/action/icon64.png rename to icons/action/icon64-default.png diff --git a/manifest.json b/manifest.json index 806d9ae..d6742d2 100644 --- a/manifest.json +++ b/manifest.json @@ -32,12 +32,12 @@ "browser_action": { "default_icon": { - "18": "icons/action/icon18.png", - "19": "icons/action/icon19.png", - "32": "icons/action/icon32.png", - "36": "icons/action/icon36.png", - "38": "icons/action/icon38.png", - "64": "icons/action/icon64.png" + "18": "icons/action/icon18-default.png", + "19": "icons/action/icon19-default.png", + "32": "icons/action/icon32-default.png", + "36": "icons/action/icon36-default.png", + "38": "icons/action/icon38-default.png", + "64": "icons/action/icon64-default.png" }, "default_popup": "pages/popup/popup.html", "browser_style": false diff --git a/modules/internal/wrappers.js b/modules/internal/wrappers.js index faf1033..9800786 100644 --- a/modules/internal/wrappers.js +++ b/modules/internal/wrappers.js @@ -36,3 +36,10 @@ wrappers.setBadgeText = function (details) { chrome.browserAction.setBadgeText(details); } }; + +wrappers.setIcon = function (details) { + + if (chrome.browserAction.setIcon !== undefined) { + chrome.browserAction.setIcon(details); + } +};