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: Created Aug. 15, 2016, 8:17 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 | 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
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 var supportedIconSizes = ["19", "38", "16", "32", "20", "40"];
Sebastian Noack 2016/08/15 21:22:16 Nit: Preserve the blank line.
kzar 2016/08/16 08:33:40 Done.
172 173
173 var BrowserAction = function(tabId) 174 var BrowserAction = function(tabId)
174 { 175 {
175 this._tabId = tabId; 176 this._tabId = tabId;
176 this._changes = null; 177 this._changes = null;
177 }; 178 };
178 BrowserAction.prototype = { 179 BrowserAction.prototype = {
179 _applyChanges: function() 180 _applyChanges: function()
180 { 181 {
182 var iconDetails = function()
Sebastian Noack 2016/08/15 21:22:16 For consistency with the surrounding code, make it
kzar 2016/08/16 08:33:40 Done.
183 {
184 var details = {tabId: this._tabId, path: {}};
185 for (var size of supportedIconSizes)
186 details.path[size] = this._changes.iconPath.replace("$size", size);
187 return details;
188 }.bind(this);
189
181 if ("iconPath" in this._changes) 190 if ("iconPath" in this._changes)
182 { 191 {
183 chrome.browserAction.setIcon({ 192 try
184 tabId: this._tabId, 193 {
185 path: { 194 chrome.browserAction.setIcon(iconDetails());
186 16: this._changes.iconPath.replace("$size", "16"), 195 }
187 19: this._changes.iconPath.replace("$size", "19"), 196 catch (e)
188 20: this._changes.iconPath.replace("$size", "20"), 197 {
189 32: this._changes.iconPath.replace("$size", "32"), 198 if (supportedIconSizes.length == 2)
190 38: this._changes.iconPath.replace("$size", "38"), 199 throw(e);
Sebastian Noack 2016/08/15 22:13:05 This branch is redundant. It's not that we would e
kzar 2016/08/16 08:33:40 Oh yea, it would just be called twice but who care
191 40: this._changes.iconPath.replace("$size", "40") 200
192 } 201 // Edge and newer versions of Chrome prefer different icon sizes, but
193 }); 202 // older versions of Chrome cannot handle them being present!
203 supportedIconSizes.splice(2);
204 chrome.browserAction.setIcon(iconDetails());
205 }
194 } 206 }
195 207
196 if ("badgeText" in this._changes) 208 if ("badgeText" in this._changes)
197 { 209 {
198 chrome.browserAction.setBadgeText({ 210 chrome.browserAction.setBadgeText({
199 tabId: this._tabId, 211 tabId: this._tabId,
200 text: this._changes.badgeText 212 text: this._changes.badgeText
201 }); 213 });
202 } 214 }
203 215
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 ext.windows = { 607 ext.windows = {
596 create: function(createData, callback) 608 create: function(createData, callback)
597 { 609 {
598 chrome.windows.create(createData, function(createdWindow) 610 chrome.windows.create(createData, function(createdWindow)
599 { 611 {
600 afterTabLoaded(callback)(createdWindow.tabs[0]); 612 afterTabLoaded(callback)(createdWindow.tabs[0]);
601 }); 613 });
602 } 614 }
603 }; 615 };
604 })(); 616 })();
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