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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 _applyChanges() | 326 _applyChanges() |
327 { | 327 { |
328 if ("iconPath" in this._changes) | 328 if ("iconPath" in this._changes) |
329 { | 329 { |
330 // Firefox for Android displays the browser action not as an icon but | 330 // Firefox for Android displays the browser action not as an icon but |
331 // as a menu item. There is no icon, but such an option may be added in | 331 // as a menu item. There is no icon, but such an option may be added in |
332 // the future. | 332 // the future. |
333 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 | 333 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 |
334 if ("setIcon" in chrome.browserAction) | 334 if ("setIcon" in chrome.browserAction) |
335 { | 335 { |
336 chrome.browserAction.setIcon({ | 336 let path = { |
337 tabId: this._tabId, | 337 16: this._changes.iconPath.replace("$size", "16"), |
338 path: { | 338 19: this._changes.iconPath.replace("$size", "19"), |
339 16: this._changes.iconPath.replace("$size", "16"), | 339 20: this._changes.iconPath.replace("$size", "20"), |
340 19: this._changes.iconPath.replace("$size", "19"), | 340 32: this._changes.iconPath.replace("$size", "32"), |
341 20: this._changes.iconPath.replace("$size", "20"), | 341 38: this._changes.iconPath.replace("$size", "38"), |
342 32: this._changes.iconPath.replace("$size", "32"), | 342 40: this._changes.iconPath.replace("$size", "40") |
343 38: this._changes.iconPath.replace("$size", "38"), | 343 }; |
344 40: this._changes.iconPath.replace("$size", "40") | 344 try |
345 } | 345 { |
346 }); | 346 chrome.browserAction.setIcon({tabId: this._tabId, path}); |
| 347 } |
| 348 catch (e) |
| 349 { |
| 350 // Edge throws if passed icon sizes different than 19,20,38,40px. |
| 351 delete path[16]; |
| 352 delete path[32]; |
| 353 chrome.browserAction.setIcon({tabId: this._tabId, path}); |
| 354 } |
347 } | 355 } |
348 } | 356 } |
349 | 357 |
350 if ("badgeText" in this._changes) | 358 if ("badgeText" in this._changes) |
351 { | 359 { |
352 // There is no badge on Firefox for Android; the browser action is | 360 // There is no badge on Firefox for Android; the browser action is |
353 // simply a menu item. | 361 // simply a menu item. |
354 if ("setBadgeText" in chrome.browserAction) | 362 if ("setBadgeText" in chrome.browserAction) |
355 { | 363 { |
356 chrome.browserAction.setBadgeText({ | 364 chrome.browserAction.setBadgeText({ |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 items[key] = value; | 686 items[key] = value; |
679 chrome.storage.local.set(items, callback); | 687 chrome.storage.local.set(items, callback); |
680 }, | 688 }, |
681 remove(key, callback) | 689 remove(key, callback) |
682 { | 690 { |
683 chrome.storage.local.remove(key, callback); | 691 chrome.storage.local.remove(key, callback); |
684 }, | 692 }, |
685 onChanged: chrome.storage.onChanged | 693 onChanged: chrome.storage.onChanged |
686 }; | 694 }; |
687 | 695 |
688 /* Options */ | |
689 | |
690 ext.showOptions = callback => | |
691 { | |
692 let info = require("info"); | |
693 | |
694 if ("openOptionsPage" in chrome.runtime && | |
695 // We don't use runtime.openOptionsPage on Firefox for Android because | |
696 // we have a different options page for mobile. | |
697 info.application != "fennec") | |
698 { | |
699 if (!callback) | |
700 { | |
701 chrome.runtime.openOptionsPage(); | |
702 } | |
703 else | |
704 { | |
705 chrome.runtime.openOptionsPage(() => | |
706 { | |
707 if (chrome.runtime.lastError) | |
708 return; | |
709 | |
710 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => | |
711 { | |
712 if (tabs.length > 0) | |
713 { | |
714 if (tabs[0].status == "complete") | |
715 callback(new Page(tabs[0])); | |
716 else | |
717 afterTabLoaded(callback)(tabs[0]); | |
718 } | |
719 }); | |
720 }); | |
721 } | |
722 } | |
723 else | |
724 { | |
725 // Edge does not yet support runtime.openOptionsPage (tested version 38) | |
726 let optionsUrl = "options.html"; | |
727 | |
728 // Firefox for Android has its own options page. | |
729 if (info.application == "fennec") | |
730 optionsUrl = "mobile-options.html"; | |
731 | |
732 chrome.tabs.query({}, tabs => | |
733 { | |
734 // We find a tab ourselves because Edge has a bug when quering tabs | |
735 // with extension URL protocol: | |
736 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/
8094141/ | |
737 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/
8604703/ | |
738 // Firefox won't let us query for moz-extension:// pages either, though | |
739 // starting with Firefox 56 an extension can query for its own URLs: | |
740 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354 | |
741 let fullOptionsUrl = ext.getURL(optionsUrl); | |
742 let tab = tabs.find(element => element.url == fullOptionsUrl); | |
743 if (tab) | |
744 { | |
745 // Firefox for Android doesn't support the windows API, and the | |
746 // mobile browser has only one window anyway. | |
747 if ("windows" in chrome) | |
748 chrome.windows.update(tab.windowId, {focused: true}); | |
749 | |
750 chrome.tabs.update(tab.id, {active: true}); | |
751 | |
752 if (callback) | |
753 callback(new Page(tab)); | |
754 } | |
755 else | |
756 { | |
757 // We don't use fullOptionsUrl here because of this Edge issue: | |
758 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issue
s/10276332 | |
759 ext.pages.open(optionsUrl, callback); | |
760 } | |
761 }); | |
762 } | |
763 }; | |
764 | |
765 /* Windows */ | 696 /* Windows */ |
766 ext.windows = { | 697 ext.windows = { |
767 create(createData, callback) | 698 create(createData, callback) |
768 { | 699 { |
769 chrome.windows.create(createData, createdWindow => | 700 chrome.windows.create(createData, createdWindow => |
770 { | 701 { |
771 afterTabLoaded(callback)(createdWindow.tabs[0]); | 702 afterTabLoaded(callback)(createdWindow.tabs[0]); |
772 }); | 703 }); |
773 } | 704 } |
774 }; | 705 }; |
775 }()); | 706 }()); |
LEFT | RIGHT |