Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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.
| |
173 | 172 |
174 var BrowserAction = function(tabId) | 173 var BrowserAction = function(tabId) |
175 { | 174 { |
176 this._tabId = tabId; | 175 this._tabId = tabId; |
177 this._changes = null; | 176 this._changes = null; |
178 }; | 177 }; |
179 BrowserAction.prototype = { | 178 BrowserAction.prototype = { |
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) | |
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 } | |
205 }, | |
180 _applyChanges: function() | 206 _applyChanges: function() |
181 { | 207 { |
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 | |
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(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 if (supportedIconSizes.length == 2) | 216 32: this._changes.iconPath.replace("$size", "32"), |
199 throw(e); | 217 38: this._changes.iconPath.replace("$size", "38"), |
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
| |
200 | 218 40: this._changes.iconPath.replace("$size", "40") |
201 // Edge and newer versions of Chrome prefer different icon sizes, but | 219 } |
202 // older versions of Chrome cannot handle them being present! | 220 }); |
203 supportedIconSizes.splice(2); | |
204 chrome.browserAction.setIcon(iconDetails()); | |
205 } | |
206 } | 221 } |
207 | 222 |
208 if ("badgeText" in this._changes) | 223 if ("badgeText" in this._changes) |
209 { | 224 { |
210 chrome.browserAction.setBadgeText({ | 225 chrome.browserAction.setBadgeText({ |
211 tabId: this._tabId, | 226 tabId: this._tabId, |
212 text: this._changes.badgeText | 227 text: this._changes.badgeText |
213 }); | 228 }); |
214 } | 229 } |
215 | 230 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 ext.windows = { | 622 ext.windows = { |
608 create: function(createData, callback) | 623 create: function(createData, callback) |
609 { | 624 { |
610 chrome.windows.create(createData, function(createdWindow) | 625 chrome.windows.create(createData, function(createdWindow) |
611 { | 626 { |
612 afterTabLoaded(callback)(createdWindow.tabs[0]); | 627 afterTabLoaded(callback)(createdWindow.tabs[0]); |
613 }); | 628 }); |
614 } | 629 } |
615 }; | 630 }; |
616 })(); | 631 })(); |
LEFT | RIGHT |