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: Addressed feedback Created Aug. 16, 2016, 8:32 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 _iconDetails: function() 179 _legacySetIcon: function(details)
182 { 180 {
183 var details = {tabId: this._tabId, path: {}}; 181 var legacyDetails = {};
184 for (var size of supportedIconSizes) 182 for (var key in details)
185 details.path[size] = this._changes.iconPath.replace("$size", size); 183 {
186 return details; 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 }
187 }, 205 },
188 _applyChanges: function() 206 _applyChanges: function()
189 { 207 {
190 if ("iconPath" in this._changes) 208 if ("iconPath" in this._changes)
191 { 209 {
192 try 210 this._safeSetIcon({
193 { 211 tabId: this._tabId,
194 chrome.browserAction.setIcon(this._iconDetails()); 212 path: {
195 } 213 16: this._changes.iconPath.replace("$size", "16"),
196 catch (e) 214 19: this._changes.iconPath.replace("$size", "19"),
197 { 215 20: this._changes.iconPath.replace("$size", "20"),
198 // Edge and newer versions of Chrome prefer different icon sizes, but 216 32: this._changes.iconPath.replace("$size", "32"),
199 // older versions of Chrome cannot handle them being present! 217 38: this._changes.iconPath.replace("$size", "38"),
200 supportedIconSizes.splice(2); 218 40: this._changes.iconPath.replace("$size", "40")
201 chrome.browserAction.setIcon(this._iconDetails()); 219 }
202 } 220 });
203 } 221 }
204 222
205 if ("badgeText" in this._changes) 223 if ("badgeText" in this._changes)
206 { 224 {
207 chrome.browserAction.setBadgeText({ 225 chrome.browserAction.setBadgeText({
208 tabId: this._tabId, 226 tabId: this._tabId,
209 text: this._changes.badgeText 227 text: this._changes.badgeText
210 }); 228 });
211 } 229 }
212 230
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 ext.windows = { 622 ext.windows = {
605 create: function(createData, callback) 623 create: function(createData, callback)
606 { 624 {
607 chrome.windows.create(createData, function(createdWindow) 625 chrome.windows.create(createData, function(createdWindow)
608 { 626 {
609 afterTabLoaded(callback)(createdWindow.tabs[0]); 627 afterTabLoaded(callback)(createdWindow.tabs[0]);
610 }); 628 });
611 } 629 }
612 }; 630 };
613 })(); 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