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-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 == "icon" && "setIcon" in browser.browserAction) | 330 if (change == "iconPath" && "setIcon" in browser.browserAction) |
331 { | 331 { |
332 let path = { | 332 let path = { |
333 16: this._changes.icon.path.replace("$size", "16"), | 333 16: this._changes.iconPath.replace("$size", "16"), |
334 19: this._changes.icon.path.replace("$size", "19"), | 334 20: this._changes.iconPath.replace("$size", "20"), |
335 20: this._changes.icon.path.replace("$size", "20"), | 335 32: this._changes.iconPath.replace("$size", "32"), |
336 32: this._changes.icon.path.replace("$size", "32"), | 336 40: this._changes.iconPath.replace("$size", "40") |
337 38: this._changes.icon.path.replace("$size", "38"), | |
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 }; | 337 }; |
340 try | 338 try |
341 { | 339 { |
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 | |
357 return browser.browserAction.setIcon({tabId: this._tabId, path}); | 340 return browser.browserAction.setIcon({tabId: this._tabId, path}); |
358 } | 341 } |
359 catch (e) | 342 catch (e) |
360 { | 343 { |
361 // 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. |
362 delete path[16]; | 345 delete path[16]; |
363 delete path[32]; | 346 delete path[32]; |
364 return browser.browserAction.setIcon({tabId: this._tabId, path}); | 347 return browser.browserAction.setIcon({tabId: this._tabId, path}); |
365 } | 348 } |
366 } | 349 } |
367 | 350 |
351 if (change == "iconImageData" && "setIcon" in browser.browserAction) | |
352 { | |
353 return browser.browserAction.setIcon({ | |
354 tabId: this._tabId, | |
355 imageData: this._changes.iconImageData | |
356 }); | |
357 } | |
358 | |
368 // There is no badge on Firefox for Android; the browser action is | 359 // There is no badge on Firefox for Android; the browser action is |
369 // simply a menu item. | 360 // simply a menu item. |
370 if (change == "badgeText" && "setBadgeText" in browser.browserAction) | 361 if (change == "badgeText" && "setBadgeText" in browser.browserAction) |
371 return browser.browserAction.setBadgeText({ | 362 return browser.browserAction.setBadgeText({ |
372 tabId: this._tabId, | 363 tabId: this._tabId, |
373 text: this._changes.badgeText | 364 text: this._changes.badgeText |
374 }); | 365 }); |
375 | 366 |
376 // There is no badge on Firefox for Android; the browser action is | 367 // There is no badge on Firefox for Android; the browser action is |
377 // simply a menu item. | 368 // simply a menu item. |
(...skipping 29 matching lines...) Expand all Loading... | |
407 this._changes = null; | 398 this._changes = null; |
408 }).catch(() => | 399 }).catch(() => |
409 { | 400 { |
410 // If the tab is prerendered, browser.browserAction.set* fails | 401 // If the tab is prerendered, browser.browserAction.set* fails |
411 // 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 |
412 // is replaced with the prerendered tab. | 403 // is replaced with the prerendered tab. |
413 browser.tabs.onReplaced.addListener(onReplaced); | 404 browser.tabs.onReplaced.addListener(onReplaced); |
414 }); | 405 }); |
415 } | 406 } |
416 }, | 407 }, |
417 setIcon(path, imageData = null) | 408 setIconPath(path) |
418 { | 409 { |
419 this._addChange("icon", {path, imageData}); | 410 this._addChange("iconPath", path); |
411 }, | |
412 setIconImageData(imageData) | |
413 { | |
414 this._addChange("iconImageData", imageData); | |
420 }, | 415 }, |
421 setBadge(badge) | 416 setBadge(badge) |
422 { | 417 { |
423 if (!badge) | 418 if (!badge) |
424 { | 419 { |
425 this._addChange("badgeText", ""); | 420 this._addChange("badgeText", ""); |
426 } | 421 } |
427 else | 422 else |
428 { | 423 { |
429 if ("number" in badge) | 424 if ("number" in badge) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 return frames.get(0) || null; | 529 return frames.get(0) || null; |
535 } | 530 } |
536 }; | 531 }; |
537 } | 532 } |
538 | 533 |
539 return ext.onMessage._dispatch( | 534 return ext.onMessage._dispatch( |
540 message, sender, sendResponse | 535 message, sender, sendResponse |
541 ).includes(true); | 536 ).includes(true); |
542 }); | 537 }); |
543 } | 538 } |
LEFT | RIGHT |