| OLD | NEW |
| 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 Loading... |
| 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 _iconDetails: function() |
| 182 { |
| 183 var details = {tabId: this._tabId, path: {}}; |
| 184 for (var size of supportedIconSizes) |
| 185 details.path[size] = this._changes.iconPath.replace("$size", size); |
| 186 return details; |
| 187 }, |
| 179 _applyChanges: function() | 188 _applyChanges: function() |
| 180 { | 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(this._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 // Edge and newer versions of Chrome prefer different icon sizes, but |
| 190 38: this._changes.iconPath.replace("$size", "38"), | 199 // older versions of Chrome cannot handle them being present! |
| 191 40: this._changes.iconPath.replace("$size", "40") | 200 supportedIconSizes.splice(2); |
| 192 } | 201 chrome.browserAction.setIcon(this._iconDetails()); |
| 193 }); | 202 } |
| 194 } | 203 } |
| 195 | 204 |
| 196 if ("badgeText" in this._changes) | 205 if ("badgeText" in this._changes) |
| 197 { | 206 { |
| 198 chrome.browserAction.setBadgeText({ | 207 chrome.browserAction.setBadgeText({ |
| 199 tabId: this._tabId, | 208 tabId: this._tabId, |
| 200 text: this._changes.badgeText | 209 text: this._changes.badgeText |
| 201 }); | 210 }); |
| 202 } | 211 } |
| 203 | 212 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 ext.windows = { | 604 ext.windows = { |
| 596 create: function(createData, callback) | 605 create: function(createData, callback) |
| 597 { | 606 { |
| 598 chrome.windows.create(createData, function(createdWindow) | 607 chrome.windows.create(createData, function(createdWindow) |
| 599 { | 608 { |
| 600 afterTabLoaded(callback)(createdWindow.tabs[0]); | 609 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 601 }); | 610 }); |
| 602 } | 611 } |
| 603 }; | 612 }; |
| 604 })(); | 613 })(); |
| OLD | NEW |