Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-present eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 /** @module options */ | |
19 | |
20 "use strict"; | |
21 | |
22 const {port} = require("messaging"); | |
23 const info = require("info"); | |
24 | |
25 const optionsUrl = "options.html"; | |
26 | |
27 function findOptionsTab(callback) | |
28 { | |
29 chrome.tabs.query({}, tabs => | |
30 { | |
31 // We find a tab ourselves because Edge has a bug when quering tabs with | |
32 // extension URL protocol: | |
33 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8094 141/ | |
34 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8604 703/ | |
35 // Firefox won't let us query for moz-extension:// pages either, though | |
36 // starting with Firefox 56 an extension can query for its own URLs: | |
37 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354 | |
38 let fullOptionsUrl = ext.getURL(optionsUrl); | |
39 callback(tabs.find(element => element.url == fullOptionsUrl)); | |
40 }); | |
41 } | |
42 | |
43 function returnShowOptionsCall(optionsTab, callback) | |
44 { | |
45 if (!callback) | |
46 return; | |
47 | |
48 if (optionsTab) | |
49 { | |
50 callback(new ext.Page(optionsTab)); | |
51 } | |
52 else | |
53 { | |
54 // If we don't already have an options page, it means we've just opened | |
55 // one, in which case we must find the tab, wait for it to be ready, and | |
56 // then return the call. | |
57 findOptionsTab(tab => | |
58 { | |
59 function onMessage(message, sender) | |
60 { | |
61 if (message.type == "app.listen" && | |
62 sender.page && sender.page.id == page.id) | |
63 { | |
64 port.off("app.listen"); | |
65 callback(page); | |
66 } | |
67 } | |
68 | |
69 let page = new ext.Page(tab); | |
Manish Jethani
2017/09/27 12:50:13
Create a Page object and release the tab reference
| |
70 port.on("app.listen", onMessage); | |
71 }); | |
72 } | |
73 } | |
74 | |
75 /** | |
76 * Opens the options page. | |
77 * | |
78 * @param {function} callback | |
79 * @static | |
80 */ | |
81 exports.showOptions = callback => | |
82 { | |
83 findOptionsTab(optionsTab => | |
Manish Jethani
2017/09/27 12:50:14
Now we first try to find the options tab, since th
| |
84 { | |
85 // Edge does not yet support runtime.openOptionsPage (tested version 38) | |
86 if ("openOptionsPage" in chrome.runtime && | |
87 // Some versions of Firefox for Android before version 57 do have a | |
88 // runtime.openOptionsPage but it doesn't do anything. | |
89 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 | |
90 (info.application != "fennec" || | |
91 parseInt(info.applicationVersion, 10) >= 57)) | |
92 { | |
93 chrome.runtime.openOptionsPage(() => | |
94 { | |
95 if (chrome.runtime.lastError) | |
96 return; | |
97 | |
98 returnShowOptionsCall(optionsTab, callback); | |
99 }); | |
100 } | |
101 else if (optionsTab) | |
102 { | |
103 // Firefox for Android before version 57 does not support | |
104 // runtime.openOptionsPage, nor does it support the windows API. | |
105 // Since there is effectively only one window on the mobile browser, | |
106 // there's no need to bring it into focus. | |
107 if ("windows" in chrome) | |
108 chrome.windows.update(optionsTab.windowId, {focused: true}); | |
109 | |
110 chrome.tabs.update(optionsTab.id, {active: true}); | |
111 | |
112 returnShowOptionsCall(optionsTab, callback); | |
113 } | |
114 else | |
115 { | |
116 // We don't use fullOptionsUrl here because of this Edge issue: | |
117 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332 | |
118 chrome.tabs.create({url: optionsUrl}, () => | |
Manish Jethani
2017/09/27 12:50:13
I've changed this to chrome.tabs.create, from ext.
| |
119 { | |
120 returnShowOptionsCall(optionsTab, callback); | |
121 }); | |
122 } | |
123 }); | |
124 }; | |
OLD | NEW |