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 // Some versions of Firefox for Android before version 57 do have a | |
696 // runtime.openOptionsPage but it doesn't do anything. | |
697 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 | |
698 (info.application != "fennec" || | |
699 parseInt(info.applicationVersion, 10) >= 57)) | |
700 { | |
701 if (!callback) | |
702 { | |
703 chrome.runtime.openOptionsPage(); | |
704 } | |
705 else | |
706 { | |
707 chrome.runtime.openOptionsPage(() => | |
708 { | |
709 if (chrome.runtime.lastError) | |
710 return; | |
711 | |
712 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => | |
713 { | |
714 if (tabs.length > 0) | |
715 { | |
716 if (tabs[0].status == "complete") | |
717 callback(new Page(tabs[0])); | |
718 else | |
719 afterTabLoaded(callback)(tabs[0]); | |
720 } | |
721 }); | |
722 }); | |
723 } | |
724 } | |
725 else | |
726 { | |
727 // Edge does not yet support runtime.openOptionsPage (tested version 38) | |
728 chrome.tabs.query({}, tabs => | |
729 { | |
730 // We find a tab ourselves because Edge has a bug when quering tabs | |
731 // with extension URL protocol: | |
732 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/
8094141/ | |
733 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/
8604703/ | |
734 // Firefox won't let us query for moz-extension:// pages either, though | |
735 // starting with Firefox 56 an extension can query for its own URLs: | |
736 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354 | |
737 let optionsUrl = "options.html"; | |
738 let fullOptionsUrl = ext.getURL(optionsUrl); | |
739 let tab = tabs.find(element => element.url == fullOptionsUrl); | |
740 if (tab) | |
741 { | |
742 // Firefox for Android before version 57 does not support | |
743 // runtime.openOptionsPage, nor does it support the windows API. | |
744 // Since there is effectively only one window on the mobile browser, | |
745 // there's no need to bring it into focus. | |
746 if ("windows" in chrome) | |
747 chrome.windows.update(tab.windowId, {focused: true}); | |
748 | |
749 chrome.tabs.update(tab.id, {active: true}); | |
750 | |
751 if (callback) | |
752 { | |
753 if (tab.status == "complete") | |
754 callback(new Page(tab)); | |
755 else | |
756 afterTabLoaded(callback)(tab); | |
757 } | |
758 } | |
759 else | |
760 { | |
761 // We don't use fullOptionsUrl here because of this Edge issue: | |
762 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issue
s/10276332 | |
763 ext.pages.open(optionsUrl, callback); | |
764 } | |
765 }); | |
766 } | |
767 }; | |
768 | |
769 /* Windows */ | 696 /* Windows */ |
770 ext.windows = { | 697 ext.windows = { |
771 create(createData, callback) | 698 create(createData, callback) |
772 { | 699 { |
773 chrome.windows.create(createData, createdWindow => | 700 chrome.windows.create(createData, createdWindow => |
774 { | 701 { |
775 afterTabLoaded(callback)(createdWindow.tabs[0]); | 702 afterTabLoaded(callback)(createdWindow.tabs[0]); |
776 }); | 703 }); |
777 } | 704 } |
778 }; | 705 }; |
779 }()); | 706 }()); |
LEFT | RIGHT |