Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: ext/background.js

Issue 29527877: Issue 5582 - Workaround Edge bug in tabs.query (Closed)
Patch Set: Rebase to master tip Created Aug. 29, 2017, 11:48 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 { 725 {
726 if (tabs[0].status == "complete") 726 if (tabs[0].status == "complete")
727 callback(new Page(tabs[0])); 727 callback(new Page(tabs[0]));
728 else 728 else
729 afterTabLoaded(callback)(tabs[0]); 729 afterTabLoaded(callback)(tabs[0]);
730 } 730 }
731 }); 731 });
732 }); 732 });
733 } 733 }
734 } 734 }
735 else 735 else if ("windows" in chrome)
736 { 736 {
737 // Edge does not yet support runtime.openOptionsPage (tested version 38) 737 // Edge does not yet support runtime.openOptionsPage (tested version 38)
738 // nor does Firefox for Android before version 57,
Oleksandr 2017/08/29 11:49:58 Remove this line, since this is really an Edge spe
739 // and so this workaround needs to stay for now. 738 // and so this workaround needs to stay for now.
740 // 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
741 // because of the Edge issue: 740 // because of the Edge issue:
742 // 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/
743 if ("windows" in chrome) 742 let optionsUrl = "options.html";
743 let fullOptionsUrl = ext.getURL(optionsUrl);
744
745 chrome.tabs.query({}, tabs =>
744 { 746 {
745 chrome.windows.getLastFocused(win => 747 // We find a tab ourselves because Edge has a bug when quering tabs
748 // with extension URL protocol:
749 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8094141/
750 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ 8604703/
751 let tab = tabs.find(element => element.url == fullOptionsUrl);
752 if (tab)
746 { 753 {
747 let optionsUrl = "options.html"; 754 chrome.windows.update(tab.windowId, {focused: true});
748 let queryInfo = {url: optionsUrl}; 755 chrome.tabs.update(tab.id, {active: true});
749 756
750 if (win) 757 if (callback)
751 queryInfo.windowId = win.id; 758 callback(new Page(tab));
752 759 }
753 chrome.tabs.query(queryInfo, tabs => 760 else
754 { 761 {
755 if (tabs.length > 0) 762 ext.pages.open(optionsUrl, callback);
756 { 763 }
757 let tab = tabs[0]; 764 });
758 765 }
759 if ("windows" in chrome) 766 else
760 chrome.windows.update(tab.windowId, {focused: true}); 767 {
761 768 // Firefox for Android does not support the windows API. Since there is
Manish Jethani 2017/08/29 12:09:59 Maybe it's a good idea to update this comment here
762 chrome.tabs.update(tab.id, {active: true}); 769 // effectively only one window on the mobile browser, there's no need
763 770 // to bring it into focus.
764 if (callback) 771 ext.pages.open("options.html", callback);
765 callback(new Page(tab));
766 }
767 else
768 {
769 ext.pages.open(optionsUrl, callback);
770 }
771 });
772 });
773 }
774 else
775 {
776 // Firefox for Android does not support the windows API. Since there is
777 // effectively only one window on the mobile browser, there's no need
778 // to bring it into focus.
779 ext.pages.open("options.html", callback);
780 }
781 } 772 }
782 }; 773 };
783 774
784 /* Windows */ 775 /* Windows */
785 ext.windows = { 776 ext.windows = {
786 create(createData, callback) 777 create(createData, callback)
787 { 778 {
788 chrome.windows.create(createData, createdWindow => 779 chrome.windows.create(createData, createdWindow =>
789 { 780 {
790 afterTabLoaded(callback)(createdWindow.tabs[0]); 781 afterTabLoaded(callback)(createdWindow.tabs[0]);
791 }); 782 });
792 } 783 }
793 }; 784 };
794 }()); 785 }());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld