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

Delta Between Two Patch Sets: chrome/ext/background.js

Issue 29349820: Fixes 4218 - setIcon for older, fussy versions of Chrome (Closed)
Left Patch Set: Fix icon animations too! Created Aug. 16, 2016, 9:45 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/icon.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 chrome.tabs.onRemoved.addListener(forgetTab); 163 chrome.tabs.onRemoved.addListener(forgetTab);
164 164
165 chrome.tabs.onActivated.addListener(function(details) 165 chrome.tabs.onActivated.addListener(function(details)
166 { 166 {
167 ext.pages.onActivated._dispatch(new Page({id: details.tabId})); 167 ext.pages.onActivated._dispatch(new Page({id: details.tabId}));
168 }); 168 });
169 169
170 170
171 /* Browser actions */ 171 /* Browser actions */
172 172
173 var supportedIconSizes = ["19", "38", "16", "32", "20", "40"];
174
175 var BrowserAction = function(tabId) 173 var BrowserAction = function(tabId)
176 { 174 {
177 this._tabId = tabId; 175 this._tabId = tabId;
178 this._changes = null; 176 this._changes = null;
179 }; 177 };
180 BrowserAction.prototype = { 178 BrowserAction.prototype = {
181 _safeChromeSetIcon: function(details) 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)
182 { 192 {
183 try 193 try
184 { 194 {
185 chrome.browserAction.setIcon(details); 195 chrome.browserAction.setIcon(details);
186 } 196 }
187 catch (e) 197 catch (e)
188 { 198 {
189 // Edge and newer versions of Chrome prefer different icon sizes, but 199 // Older versions of Chrome do not allow any sizes other than 19 and 38
190 // older versions of Chrome cannot handle them being present! 200 // to be present, but newer versions of Chrome (and Edge) prefer
191 supportedIconSizes.splice(2); 201 // different sizes.
192 202 this._safeSetIcon = this._legacySetIcon;
193 for (var key of ["path", "imageData"]) 203 this._legacySetIcon(details);
194 { 204 }
195 if (!(key in details)) 205 },
196 continue; 206 _applyChanges: function()
197 207 {
198 for (var size in details[key]) 208 if ("iconPath" in this._changes)
199 { 209 {
200 if (details[key].hasOwnProperty(size) && 210 this._safeSetIcon({
201 supportedIconSizes.indexOf(size) == -1) 211 tabId: this._tabId,
202 delete details[key][size]; 212 path: {
213 16: this._changes.iconPath.replace("$size", "16"),
214 19: this._changes.iconPath.replace("$size", "19"),
215 20: this._changes.iconPath.replace("$size", "20"),
216 32: this._changes.iconPath.replace("$size", "32"),
217 38: this._changes.iconPath.replace("$size", "38"),
218 40: this._changes.iconPath.replace("$size", "40")
203 } 219 }
204 }; 220 });
205 chrome.browserAction.setIcon(details);
206 }
207 },
208 _applyChanges: function()
209 {
210 if ("iconPath" in this._changes)
211 {
212 var details = {tabId: this._tabId, path: {}};
213 for (var size of supportedIconSizes)
214 details.path[size] = this._changes.iconPath.replace("$size", size);
215 this._safeChromeSetIcon(details);
216 } 221 }
217 222
218 if ("badgeText" in this._changes) 223 if ("badgeText" in this._changes)
219 { 224 {
220 chrome.browserAction.setBadgeText({ 225 chrome.browserAction.setBadgeText({
221 tabId: this._tabId, 226 tabId: this._tabId,
222 text: this._changes.badgeText 227 text: this._changes.badgeText
223 }); 228 });
224 } 229 }
225 230
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 ext.windows = { 622 ext.windows = {
618 create: function(createData, callback) 623 create: function(createData, callback)
619 { 624 {
620 chrome.windows.create(createData, function(createdWindow) 625 chrome.windows.create(createData, function(createdWindow)
621 { 626 {
622 afterTabLoaded(callback)(createdWindow.tabs[0]); 627 afterTabLoaded(callback)(createdWindow.tabs[0]);
623 }); 628 });
624 } 629 }
625 }; 630 };
626 })(); 631 })();
LEFTRIGHT
« no previous file | lib/icon.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld