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

Side by Side 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.
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 | no next file » | 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 }); 187 });
188 188
189 chrome.tabs.onRemoved.addListener(forgetTab); 189 chrome.tabs.onRemoved.addListener(forgetTab);
190 190
191 chrome.tabs.onActivated.addListener(function(details) 191 chrome.tabs.onActivated.addListener(function(details)
192 { 192 {
193 ext.pages.onActivated._dispatch(new Page({id: details.tabId})); 193 ext.pages.onActivated._dispatch(new Page({id: details.tabId}));
194 }); 194 });
195 195
196 196
197 ext.iconSizes = [16, 19, 20, 32, 38, 40];
198
197 /* Browser actions */ 199 /* Browser actions */
198 200
199 var BrowserAction = function(tabId) 201 var BrowserAction = function(tabId)
200 { 202 {
201 this._tabId = tabId; 203 this._tabId = tabId;
202 this._changes = null; 204 this._changes = null;
203 }; 205 };
204 BrowserAction.prototype = { 206 BrowserAction.prototype = {
205 _legacySetIcon: function(details)
206 {
207 var legacyDetails = {};
208 for (var key in details)
209 {
210 var value = details[key];
211 if (typeof value == "object")
212 value = {19: value[19], 38: value[38]};
213 legacyDetails[key] = value;
214 }
215 chrome.browserAction.setIcon(legacyDetails);
216 },
217 _safeSetIcon: function(details) 207 _safeSetIcon: function(details)
218 { 208 {
219 try 209 try
220 { 210 {
221 chrome.browserAction.setIcon(details); 211 chrome.browserAction.setIcon(details);
222 } 212 }
223 catch (e) 213 catch (e)
224 { 214 {
225 // Older versions of Chrome do not allow any sizes other than 19 and 38 215 // Try applying the icon the Edge way
226 // to be present, but newer versions of Chrome (and Edge) prefer 216 ext.iconSizes = [19, 20, 38, 40];
227 // different sizes. 217 try
228 this._safeSetIcon = this._legacySetIcon; 218 {
229 this._legacySetIcon(details); 219 this.applyIcon();
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
220 }
221 catch(e)
222 {
223 // Just stick to the bare minimum. Older versions of Chrome do not
224 // allow any sizes other than 19 and 38 to be present
225 ext.iconSizes = [19, 38];
226 applyIcon();
227 }
230 } 228 }
231 }, 229 },
230
231 applyIcon: function()
232 {
233 var builtPath = {};
234 currentIconPath = this._changes.iconPath;
235 ext.iconSizes.map(function(iconSize)
236 {
237 builtPath[iconSize] = currentIconPath.replace("$size", iconSize);
238 });
239
240 this._safeSetIcon({
241 tabId: this._tabId,
242 path: builtPath
243 });
244 },
245
232 _applyChanges: function() 246 _applyChanges: function()
233 { 247 {
234 if ("iconPath" in this._changes) 248 if ("iconPath" in this._changes)
235 { 249 this.applyIcon();
236 this._safeSetIcon({
237 tabId: this._tabId,
238 path: {
239 16: this._changes.iconPath.replace("$size", "16"),
240 19: this._changes.iconPath.replace("$size", "19"),
241 20: this._changes.iconPath.replace("$size", "20"),
242 32: this._changes.iconPath.replace("$size", "32"),
243 38: this._changes.iconPath.replace("$size", "38"),
244 40: this._changes.iconPath.replace("$size", "40")
245 }
246 });
247 }
248 250
249 if ("badgeText" in this._changes) 251 if ("badgeText" in this._changes)
250 { 252 {
251 chrome.browserAction.setBadgeText({ 253 chrome.browserAction.setBadgeText({
252 tabId: this._tabId, 254 tabId: this._tabId,
253 text: this._changes.badgeText 255 text: this._changes.badgeText
254 }); 256 });
255 } 257 }
256 258
257 if ("badgeColor" in this._changes) 259 if ("badgeColor" in this._changes)
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 afterTabLoaded(callback)(createdWindow.tabs[0]); 649 afterTabLoaded(callback)(createdWindow.tabs[0]);
648 }); 650 });
649 } 651 }
650 else 652 else
651 { 653 {
652 ext.pages.open(createData.url, callback); 654 ext.pages.open(createData.url, callback);
653 } 655 }
654 } 656 }
655 }; 657 };
656 })(); 658 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld