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

Unified Diff: chrome/ext/background.js

Issue 29366791: Issue 4699 - Edge does not support 16px and 32px icons (Closed)
Patch Set: Created Dec. 5, 2016, 5:25 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
===================================================================
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -194,6 +194,8 @@
});
+ ext.iconSizes = [16, 19, 20, 32, 38, 40];
+
/* Browser actions */
var BrowserAction = function(tabId)
@@ -202,18 +204,6 @@
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
@@ -222,29 +212,41 @@
}
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);
Oleksandr 2016/12/05 05:29:59 In this case, the `this` pointer is refreshed for
kzar 2016/12/05 16:17:56 Well a BrowserAction is created for each page, so
+ // Try applying the icon the Edge way
+ ext.iconSizes = [19, 20, 38, 40];
+ try
+ {
+ this.applyIcon();
+ }
+ catch(e)
+ {
+ // Just stick to the bare minimum. Older versions of Chrome do not
+ // allow any sizes other than 19 and 38 to be present
+ ext.iconSizes = [19, 38];
+ applyIcon();
+ }
}
},
+
+ applyIcon: function()
+ {
+ var builtPath = {};
+ currentIconPath = this._changes.iconPath;
+ ext.iconSizes.map(function(iconSize)
+ {
+ builtPath[iconSize] = currentIconPath.replace("$size", iconSize);
+ });
+
+ this._safeSetIcon({
+ tabId: this._tabId,
+ path: builtPath
+ });
+ },
+
_applyChanges: function()
{
if ("iconPath" in this._changes)
- {
- this._safeSetIcon({
- 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")
- }
- });
- }
+ this.applyIcon();
if ("badgeText" in this._changes)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld