| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return Promise.all(Object.keys(this._changes).map(change => | 324 return Promise.all(Object.keys(this._changes).map(change => |
| 325 { | 325 { |
| 326 // Firefox for Android displays the browser action not as an icon but | 326 // Firefox for Android displays the browser action not as an icon but |
| 327 // as a menu item. There is no icon, but such an option may be added | 327 // as a menu item. There is no icon, but such an option may be added |
| 328 // in the future. | 328 // in the future. |
| 329 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 | 329 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 |
| 330 if (change == "iconPath" && "setIcon" in browser.browserAction) | 330 if (change == "iconPath" && "setIcon" in browser.browserAction) |
| 331 { | 331 { |
| 332 let path = { | 332 let path = { |
| 333 16: this._changes.iconPath.replace("$size", "16"), | 333 16: this._changes.iconPath.replace("$size", "16"), |
| 334 19: this._changes.iconPath.replace("$size", "19"), | |
| 335 20: this._changes.iconPath.replace("$size", "20"), | 334 20: this._changes.iconPath.replace("$size", "20"), |
| 336 32: this._changes.iconPath.replace("$size", "32"), | 335 32: this._changes.iconPath.replace("$size", "32"), |
| 337 38: this._changes.iconPath.replace("$size", "38"), | |
| 338 40: this._changes.iconPath.replace("$size", "40") | 336 40: this._changes.iconPath.replace("$size", "40") |
| 339 }; | 337 }; |
| 340 try | 338 try |
| 341 { | 339 { |
| 342 return browser.browserAction.setIcon({tabId: this._tabId, path}); | 340 return browser.browserAction.setIcon({tabId: this._tabId, path}); |
| 343 } | 341 } |
| 344 catch (e) | 342 catch (e) |
| 345 { | 343 { |
| 346 // Edge throws if passed icon sizes different than 19,20,38,40px. | 344 // Edge throws if passed icon sizes different than 19,20,38,40px. |
| 347 delete path[16]; | 345 delete path[16]; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 this._changes = null; | 398 this._changes = null; |
| 401 }).catch(() => | 399 }).catch(() => |
| 402 { | 400 { |
| 403 // If the tab is prerendered, browser.browserAction.set* fails | 401 // If the tab is prerendered, browser.browserAction.set* fails |
| 404 // and we have to delay our changes until the currently visible tab | 402 // and we have to delay our changes until the currently visible tab |
| 405 // is replaced with the prerendered tab. | 403 // is replaced with the prerendered tab. |
| 406 browser.tabs.onReplaced.addListener(onReplaced); | 404 browser.tabs.onReplaced.addListener(onReplaced); |
| 407 }); | 405 }); |
| 408 } | 406 } |
| 409 }, | 407 }, |
| 410 setIcon(path, imageData = null) | 408 setIconPath(path) |
| 411 { | 409 { |
| 412 // Use ImageData if available. | 410 this._addChange("iconPath", path); |
| 413 if (imageData) | 411 }, |
| 414 this._addChange("iconImageData", imageData); | 412 setIconImageData(imageData) |
| 415 else | 413 { |
| 416 this._addChange("iconPath", path); | 414 this._addChange("iconImageData", imageData); |
| 417 }, | 415 }, |
| 418 setBadge(badge) | 416 setBadge(badge) |
| 419 { | 417 { |
| 420 if (!badge) | 418 if (!badge) |
| 421 { | 419 { |
| 422 this._addChange("badgeText", ""); | 420 this._addChange("badgeText", ""); |
| 423 } | 421 } |
| 424 else | 422 else |
| 425 { | 423 { |
| 426 if ("number" in badge) | 424 if ("number" in badge) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 return frames.get(0) || null; | 529 return frames.get(0) || null; |
| 532 } | 530 } |
| 533 }; | 531 }; |
| 534 } | 532 } |
| 535 | 533 |
| 536 return ext.onMessage._dispatch( | 534 return ext.onMessage._dispatch( |
| 537 message, sender, sendResponse | 535 message, sender, sendResponse |
| 538 ).includes(true); | 536 ).includes(true); |
| 539 }); | 537 }); |
| 540 } | 538 } |
| LEFT | RIGHT |