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: Addressed feedback Created Aug. 16, 2016, 4:58 p.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..810e7650c08d123c66210f317422b38b69acc895 100644
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -176,11 +176,38 @@
this._changes = null;
};
BrowserAction.prototype = {
+ _legacySetIcon: function(details)
+ {
+ var legacyDetails = {};
+ for (var key in details)
+ {
+ 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({
+ this._safeSetIcon({
tabId: this._tabId,
path: {
16: this._changes.iconPath.replace("$size", "16"),
« 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