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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 { | 692 { |
693 chrome.storage.local.remove(key, callback); | 693 chrome.storage.local.remove(key, callback); |
694 }, | 694 }, |
695 onChanged: chrome.storage.onChanged | 695 onChanged: chrome.storage.onChanged |
696 }; | 696 }; |
697 | 697 |
698 /* Options */ | 698 /* Options */ |
699 | 699 |
700 ext.showOptions = callback => | 700 ext.showOptions = callback => |
701 { | 701 { |
702 let info = require("info"); | |
703 | |
702 if ("openOptionsPage" in chrome.runtime && | 704 if ("openOptionsPage" in chrome.runtime && |
703 // Firefox for Android does have a runtime.openOptionsPage but it | 705 // Some versions of Firefox for Android before version 57 do have a |
704 // doesn't do anything. | 706 // runtime.openOptionsPage but it doesn't do anything. |
705 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 | 707 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 |
706 require("info").application != "fennec") | 708 (info.application != "fennec" || |
709 parseInt(info.applicationVersion, 10) >= 57)) | |
707 { | 710 { |
708 if (!callback) | 711 if (!callback) |
709 { | 712 { |
710 chrome.runtime.openOptionsPage(); | 713 chrome.runtime.openOptionsPage(); |
711 } | 714 } |
712 else | 715 else |
713 { | 716 { |
714 chrome.runtime.openOptionsPage(() => | 717 chrome.runtime.openOptionsPage(() => |
715 { | 718 { |
716 if (chrome.runtime.lastError) | 719 if (chrome.runtime.lastError) |
717 return; | 720 return; |
718 | 721 |
719 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => | 722 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => |
720 { | 723 { |
721 if (tabs.length > 0) | 724 if (tabs.length > 0) |
722 { | 725 { |
723 if (tabs[0].status == "complete") | 726 if (tabs[0].status == "complete") |
724 callback(new Page(tabs[0])); | 727 callback(new Page(tabs[0])); |
725 else | 728 else |
726 afterTabLoaded(callback)(tabs[0]); | 729 afterTabLoaded(callback)(tabs[0]); |
727 } | 730 } |
728 }); | 731 }); |
729 }); | 732 }); |
730 } | 733 } |
731 } | 734 } |
732 else | 735 else if ("windows" in chrome) |
733 { | 736 { |
734 // Edge does not yet support runtime.openOptionsPage (tested version 38) | 737 // Edge does not yet support runtime.openOptionsPage (tested version 38) |
735 // nor does Firefox for Android, | |
736 // and so this workaround needs to stay for now. | 738 // and so this workaround needs to stay for now. |
737 // We are not using extension.getURL to get the absolute path here | 739 // We are not using extension.getURL to get the absolute path here |
738 // because of the Edge issue: | 740 // because of the Edge issue: |
739 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332/ | 741 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332/ |
740 let open = win => | 742 let optionsUrl = "options.html"; |
741 { | 743 let fullOptionsUrl = ext.getURL(optionsUrl); |
742 let optionsUrl = "options.html"; | 744 |
743 let fullOptionsUrl = ext.getURL("options.html"); | 745 chrome.tabs.query({}, tabs => |
744 | 746 { |
745 // We find a tab ourselves because Edge has a bug when quering tabs | 747 // We find a tab ourselves because Edge has a bug when quering tabs |
746 // with extension URL protocol: | 748 // with extension URL protocol: |
747 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/ | 749 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/ |
748 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/ | 750 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/ |
749 function isOptionsTab(element) | 751 let tab = tabs.find(element => element.url == fullOptionsUrl); |
750 { | 752 if (tab) |
751 return element.url == fullOptionsUrl; | 753 { |
752 } | 754 chrome.windows.update(tab.windowId, {focused: true}); |
753 chrome.tabs.query({}, tabs => | 755 chrome.tabs.update(tab.id, {active: true}); |
Oleksandr
2017/08/28 01:38:36
Passing {} is the only way to get all tabs, it see
| |
754 { | 756 |
755 if (tabs && (tabs.findIndex(isOptionsTab) >= 0)) | 757 if (callback) |
Sebastian Noack
2017/08/29 02:08:21
Calling findIndex()/find() twice is redundant. Jus
| |
756 { | 758 callback(new Page(tab)); |
757 let tab = tabs.find(isOptionsTab); | 759 } |
758 if ("windows" in chrome) | 760 else |
759 chrome.windows.update(tab.windowId, {focused: true}); | 761 { |
760 | 762 ext.pages.open(optionsUrl, callback); |
761 chrome.tabs.update(tab.id, {active: true}); | 763 } |
762 | 764 }); |
763 if (callback) | 765 } |
764 callback(new Page(tab)); | 766 else |
765 } | 767 { |
766 else | 768 // Firefox for Android before version 57 does not support |
767 { | 769 // runtime.openOptionsPage, nor does it support the windows API. Since |
768 ext.pages.open(optionsUrl, callback); | 770 // there is effectively only one window on the mobile browser, there's no |
769 } | 771 // need to bring it into focus. |
770 }); | 772 ext.pages.open("options.html", callback); |
771 }; | |
772 | |
773 if ("windows" in chrome) | |
774 { | |
775 chrome.windows.getLastFocused(open); | |
776 } | |
777 else | |
778 { | |
779 // Firefox for Android does not support the windows API. Since there is | |
780 // effectively only one window on the mobile browser, there's no need | |
781 // to bring it into focus. | |
782 open(); | |
783 } | |
784 } | 773 } |
785 }; | 774 }; |
786 | 775 |
787 /* Windows */ | 776 /* Windows */ |
788 ext.windows = { | 777 ext.windows = { |
789 create(createData, callback) | 778 create(createData, callback) |
790 { | 779 { |
791 chrome.windows.create(createData, createdWindow => | 780 chrome.windows.create(createData, createdWindow => |
792 { | 781 { |
793 afterTabLoaded(callback)(createdWindow.tabs[0]); | 782 afterTabLoaded(callback)(createdWindow.tabs[0]); |
794 }); | 783 }); |
795 } | 784 } |
796 }; | 785 }; |
797 }()); | 786 }()); |
LEFT | RIGHT |