Left: | ||
Right: |
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-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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 }; | 320 }; |
321 BrowserAction.prototype = { | 321 BrowserAction.prototype = { |
322 _applyChanges() | 322 _applyChanges() |
323 { | 323 { |
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 == "icon" && "setIcon" in browser.browserAction) |
331 { | 331 { |
332 let path = { | 332 let path = { |
333 16: this._changes.iconPath.replace("$size", "16"), | 333 16: this._changes.icon.path.replace("$size", "16"), |
334 19: this._changes.iconPath.replace("$size", "19"), | 334 19: this._changes.icon.path.replace("$size", "19"), |
335 20: this._changes.iconPath.replace("$size", "20"), | 335 20: this._changes.icon.path.replace("$size", "20"), |
336 32: this._changes.iconPath.replace("$size", "32"), | 336 32: this._changes.icon.path.replace("$size", "32"), |
337 38: this._changes.iconPath.replace("$size", "38"), | 337 38: this._changes.icon.path.replace("$size", "38"), |
338 40: this._changes.iconPath.replace("$size", "40") | 338 40: this._changes.icon.path.replace("$size", "40") |
Sebastian Noack
2019/02/03 06:43:18
This should go after trying to use imageData. If w
Manish Jethani
2019/02/03 07:26:48
Done.
| |
339 }; | 339 }; |
340 try | 340 try |
341 { | 341 { |
342 // Try ImageData if available. | |
343 if (this._changes.icon.imageData) | |
344 { | |
345 try | |
Sebastian Noack
2019/02/03 06:43:18
Why do we need try...catch here? Can't we just che
Manish Jethani
2019/02/03 07:26:48
Yes, makes sense.
Done.
| |
346 { | |
347 return browser.browserAction.setIcon({ | |
348 tabId: this._tabId, | |
349 imageData: this._changes.icon.imageData | |
350 }); | |
351 } | |
352 catch (e) | |
353 { | |
354 } | |
355 } | |
356 | |
342 return browser.browserAction.setIcon({tabId: this._tabId, path}); | 357 return browser.browserAction.setIcon({tabId: this._tabId, path}); |
343 } | 358 } |
344 catch (e) | 359 catch (e) |
345 { | 360 { |
346 // Edge throws if passed icon sizes different than 19,20,38,40px. | 361 // Edge throws if passed icon sizes different than 19,20,38,40px. |
347 delete path[16]; | 362 delete path[16]; |
348 delete path[32]; | 363 delete path[32]; |
349 return browser.browserAction.setIcon({tabId: this._tabId, path}); | 364 return browser.browserAction.setIcon({tabId: this._tabId, path}); |
350 } | 365 } |
351 } | 366 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 this._changes = null; | 407 this._changes = null; |
393 }).catch(() => | 408 }).catch(() => |
394 { | 409 { |
395 // If the tab is prerendered, browser.browserAction.set* fails | 410 // If the tab is prerendered, browser.browserAction.set* fails |
396 // and we have to delay our changes until the currently visible tab | 411 // and we have to delay our changes until the currently visible tab |
397 // is replaced with the prerendered tab. | 412 // is replaced with the prerendered tab. |
398 browser.tabs.onReplaced.addListener(onReplaced); | 413 browser.tabs.onReplaced.addListener(onReplaced); |
399 }); | 414 }); |
400 } | 415 } |
401 }, | 416 }, |
402 setIcon(path) | 417 setIcon(path, imageData = null) |
403 { | 418 { |
404 this._addChange("iconPath", path); | 419 this._addChange("icon", {path, imageData}); |
405 }, | 420 }, |
406 setBadge(badge) | 421 setBadge(badge) |
407 { | 422 { |
408 if (!badge) | 423 if (!badge) |
409 { | 424 { |
410 this._addChange("badgeText", ""); | 425 this._addChange("badgeText", ""); |
411 } | 426 } |
412 else | 427 else |
413 { | 428 { |
414 if ("number" in badge) | 429 if ("number" in badge) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 return frames.get(0) || null; | 534 return frames.get(0) || null; |
520 } | 535 } |
521 }; | 536 }; |
522 } | 537 } |
523 | 538 |
524 return ext.onMessage._dispatch( | 539 return ext.onMessage._dispatch( |
525 message, sender, sendResponse | 540 message, sender, sendResponse |
526 ).includes(true); | 541 ).includes(true); |
527 }); | 542 }); |
528 } | 543 } |
OLD | NEW |