Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/ext/background.js

Issue 29349820: Fixes 4218 - setIcon for older, fussy versions of Chrome (Closed)
Patch Set: Removed stray semicolon Created Aug. 16, 2016, 11:24 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/icon.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
diff --git a/chrome/ext/background.js b/chrome/ext/background.js
index fe0cd37f2fa1b68ff83ab00a5ab9a4f46811777b..1ad48281c1e10bfb20f8e2cddd9c54b55c87d1c5 100644
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -170,27 +170,49 @@
/* Browser actions */
+ var supportedIconSizes = ["19", "38", "16", "32", "20", "40"];
+
var BrowserAction = function(tabId)
{
this._tabId = tabId;
this._changes = null;
};
BrowserAction.prototype = {
+ _safeChromeSetIcon: function(details)
+ {
+ try
+ {
+ chrome.browserAction.setIcon(details);
+ }
+ catch (e)
+ {
+ // Edge and newer versions of Chrome prefer different icon sizes, but
+ // older versions of Chrome cannot handle them being present!
+ supportedIconSizes.splice(2);
+
+ for (var key of ["path", "imageData"])
+ {
+ if (!(key in details))
+ continue;
+
+ for (var size in details[key])
+ {
+ if (details[key].hasOwnProperty(size) &&
+ supportedIconSizes.indexOf(size) == -1)
+ delete details[key][size];
+ }
+ }
+ chrome.browserAction.setIcon(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: {}};
+ for (var size of supportedIconSizes)
+ details.path[size] = this._changes.iconPath.replace("$size", size);
+ this._safeChromeSetIcon(details);
}
if ("badgeText" in this._changes)
« no previous file with comments | « no previous file | lib/icon.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld