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: Removed stray semicolon Created Aug. 16, 2016, 11:24 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 | 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 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
173 var BrowserAction = function(tabId) 175 var BrowserAction = function(tabId)
174 { 176 {
175 this._tabId = tabId; 177 this._tabId = tabId;
176 this._changes = null; 178 this._changes = null;
177 }; 179 };
178 BrowserAction.prototype = { 180 BrowserAction.prototype = {
181 _safeChromeSetIcon: function(details)
182 {
183 try
184 {
185 chrome.browserAction.setIcon(details);
186 }
187 catch (e)
188 {
189 // Edge and newer versions of Chrome prefer different icon sizes, but
190 // older versions of Chrome cannot handle them being present!
191 supportedIconSizes.splice(2);
192
193 for (var key of ["path", "imageData"])
194 {
195 if (!(key in details))
196 continue;
197
198 for (var size in details[key])
199 {
200 if (details[key].hasOwnProperty(size) &&
201 supportedIconSizes.indexOf(size) == -1)
202 delete details[key][size];
203 }
204 }
205 chrome.browserAction.setIcon(details);
206 }
207 },
179 _applyChanges: function() 208 _applyChanges: function()
180 { 209 {
181 if ("iconPath" in this._changes) 210 if ("iconPath" in this._changes)
182 { 211 {
183 chrome.browserAction.setIcon({ 212 var details = {tabId: this._tabId, path: {}};
184 tabId: this._tabId, 213 for (var size of supportedIconSizes)
185 path: { 214 details.path[size] = this._changes.iconPath.replace("$size", size);
186 16: this._changes.iconPath.replace("$size", "16"), 215 this._safeChromeSetIcon(details);
187 19: this._changes.iconPath.replace("$size", "19"),
188 20: this._changes.iconPath.replace("$size", "20"),
189 32: this._changes.iconPath.replace("$size", "32"),
190 38: this._changes.iconPath.replace("$size", "38"),
191 40: this._changes.iconPath.replace("$size", "40")
192 }
193 });
194 } 216 }
195 217
196 if ("badgeText" in this._changes) 218 if ("badgeText" in this._changes)
197 { 219 {
198 chrome.browserAction.setBadgeText({ 220 chrome.browserAction.setBadgeText({
199 tabId: this._tabId, 221 tabId: this._tabId,
200 text: this._changes.badgeText 222 text: this._changes.badgeText
201 }); 223 });
202 } 224 }
203 225
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 ext.windows = { 617 ext.windows = {
596 create: function(createData, callback) 618 create: function(createData, callback)
597 { 619 {
598 chrome.windows.create(createData, function(createdWindow) 620 chrome.windows.create(createData, function(createdWindow)
599 { 621 {
600 afterTabLoaded(callback)(createdWindow.tabs[0]); 622 afterTabLoaded(callback)(createdWindow.tabs[0]);
601 }); 623 });
602 } 624 }
603 }; 625 };
604 })(); 626 })();
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