Index: chrome/ext/background.js |
diff --git a/chrome/ext/background.js b/chrome/ext/background.js |
index fe0cd37f2fa1b68ff83ab00a5ab9a4f46811777b..e35da6cf985cd3fbed209016b37e5ced1f6ff77c 100644 |
--- a/chrome/ext/background.js |
+++ b/chrome/ext/background.js |
@@ -176,21 +176,45 @@ |
this._changes = null; |
}; |
BrowserAction.prototype = { |
+ _legacySetIcon: function(details) |
+ { |
+ var legacyDetails = {}; |
+ for (var key in details) |
+ { |
+ if (details.hasOwnProperty(key)) |
Sebastian Noack
2016/08/16 16:49:11
Is this case worth to be considered? As far as I c
kzar
2016/08/16 16:59:17
Done.
|
+ { |
+ var value = details[key]; |
+ if (typeof value == "object") |
+ value = {19: value[19], 38: value[38]}; |
+ legacyDetails[key] = value; |
+ } |
+ } |
+ chrome.browserAction.setIcon(legacyDetails); |
+ }, |
+ _safeSetIcon: function(details) |
+ { |
+ try |
+ { |
+ chrome.browserAction.setIcon(details); |
+ } |
+ catch (e) |
+ { |
+ // Older versions of Chrome do not allow any sizes other than 19 and 38 |
+ // to be present, but newer versions of Chrome (and Edge) prefer |
+ // different sizes. |
+ this._safeSetIcon = this._legacySetIcon; |
+ this._legacySetIcon(details); |
+ } |
+ }, |
_applyChanges: function() |
{ |
if ("iconPath" in this._changes) |
{ |
- chrome.browserAction.setIcon({ |
- tabId: this._tabId, |
- path: { |
- 16: this._changes.iconPath.replace("$size", "16"), |
- 19: this._changes.iconPath.replace("$size", "19"), |
- 20: this._changes.iconPath.replace("$size", "20"), |
- 32: this._changes.iconPath.replace("$size", "32"), |
- 38: this._changes.iconPath.replace("$size", "38"), |
- 40: this._changes.iconPath.replace("$size", "40") |
- } |
- }); |
+ var details = {tabId: this._tabId, path: {}}; |
Sebastian Noack
2016/08/16 16:49:11
This change here isn't even necessary, and while i
kzar
2016/08/16 16:59:17
Done.
|
+ let sizes = [16, 19, 20, 32, 38, 40]; |
+ for (var size of sizes) |
+ details.path[size] = this._changes.iconPath.replace("$size", size); |
+ this._safeSetIcon(details); |
} |
if ("badgeText" in this._changes) |