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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/icon.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 170
171 /* Browser actions */ 171 /* Browser actions */
172 172
173 var BrowserAction = function(tabId) 173 var BrowserAction = function(tabId)
174 { 174 {
175 this._tabId = tabId; 175 this._tabId = tabId;
176 this._changes = null; 176 this._changes = null;
177 }; 177 };
178 BrowserAction.prototype = { 178 BrowserAction.prototype = {
179 _legacySetIcon: function(details)
180 {
181 var legacyDetails = {};
182 for (var key in details)
183 {
184 var value = details[key];
185 if (typeof value == "object")
186 value = {19: value[19], 38: value[38]};
187 legacyDetails[key] = value;
188 }
189 chrome.browserAction.setIcon(legacyDetails);
190 },
191 _safeSetIcon: function(details)
192 {
193 try
194 {
195 chrome.browserAction.setIcon(details);
196 }
197 catch (e)
198 {
199 // Older versions of Chrome do not allow any sizes other than 19 and 38
200 // to be present, but newer versions of Chrome (and Edge) prefer
201 // different sizes.
202 this._safeSetIcon = this._legacySetIcon;
203 this._legacySetIcon(details);
204 }
205 },
179 _applyChanges: function() 206 _applyChanges: function()
180 { 207 {
181 if ("iconPath" in this._changes) 208 if ("iconPath" in this._changes)
182 { 209 {
183 chrome.browserAction.setIcon({ 210 this._safeSetIcon({
184 tabId: this._tabId, 211 tabId: this._tabId,
185 path: { 212 path: {
186 16: this._changes.iconPath.replace("$size", "16"), 213 16: this._changes.iconPath.replace("$size", "16"),
187 19: this._changes.iconPath.replace("$size", "19"), 214 19: this._changes.iconPath.replace("$size", "19"),
188 20: this._changes.iconPath.replace("$size", "20"), 215 20: this._changes.iconPath.replace("$size", "20"),
189 32: this._changes.iconPath.replace("$size", "32"), 216 32: this._changes.iconPath.replace("$size", "32"),
190 38: this._changes.iconPath.replace("$size", "38"), 217 38: this._changes.iconPath.replace("$size", "38"),
191 40: this._changes.iconPath.replace("$size", "40") 218 40: this._changes.iconPath.replace("$size", "40")
192 } 219 }
193 }); 220 });
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 ext.windows = { 622 ext.windows = {
596 create: function(createData, callback) 623 create: function(createData, callback)
597 { 624 {
598 chrome.windows.create(createData, function(createdWindow) 625 chrome.windows.create(createData, function(createdWindow)
599 { 626 {
600 afterTabLoaded(callback)(createdWindow.tabs[0]); 627 afterTabLoaded(callback)(createdWindow.tabs[0]);
601 }); 628 });
602 } 629 }
603 }; 630 };
604 })(); 631 })();
OLDNEW
« 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