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

Side by Side Diff: lib/options.js

Issue 29782593: Noissue - Don't hard-code options and popup URL (Closed)
Patch Set: Created May 15, 2018, 1:22 p.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module options */ 18 /** @module options */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {checkWhitelisted} = require("./whitelisting"); 22 const {checkWhitelisted} = require("./whitelisting");
23 const info = require("../buildtools/info"); 23 const info = require("../buildtools/info");
24 24
25 const optionsUrl = "options.html"; 25 const manifest = browser.runtime.getManifest();
26 const optionsUrl = manifest.options_page || manifest.options_ui.page;
kzar 2018/05/15 13:32:31 I trust you got it right, but i wonder where manif
Sebastian Noack 2018/05/15 14:17:15 That is correct, but there is also Microsoft Edge
27 const popupUrl = manifest.browser_action.default_popup;
kzar 2018/05/15 13:32:31 I don't see this one for gecko.
Sebastian Noack 2018/05/15 14:17:15 Argh, right. We removed the popup URL from the man
26 28
27 function findOptionsTab(callback) 29 function findOptionsTab(callback)
28 { 30 {
29 browser.tabs.query({}, tabs => 31 browser.tabs.query({}, tabs =>
30 { 32 {
31 // We find a tab ourselves because Edge has a bug when quering tabs with 33 // We find a tab ourselves because Edge has a bug when quering tabs with
32 // extension URL protocol: 34 // extension URL protocol:
33 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8094 141/ 35 // 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/ 36 // 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 37 // Firefox won't let us query for moz-extension:// pages either, though
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // options page to open instead of the bubble. Unfortunately there's a bug[1] 182 // options page to open instead of the bubble. Unfortunately there's a bug[1]
181 // which prevents us from doing that, so we must avoid setting the URL on 183 // which prevents us from doing that, so we must avoid setting the URL on
182 // Firefox from the manifest at all, instead setting it here only for 184 // Firefox from the manifest at all, instead setting it here only for
183 // non-mobile. 185 // non-mobile.
184 // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1414613 186 // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1414613
185 if ("getBrowserInfo" in browser.runtime) 187 if ("getBrowserInfo" in browser.runtime)
186 { 188 {
187 browser.runtime.getBrowserInfo().then(browserInfo => 189 browser.runtime.getBrowserInfo().then(browserInfo =>
188 { 190 {
189 if (browserInfo.name != "Fennec") 191 if (browserInfo.name != "Fennec")
190 browser.browserAction.setPopup({popup: "popup.html"}); 192 browser.browserAction.setPopup({popup: popupUrl});
191 }); 193 });
192 } 194 }
193 else 195 else
194 { 196 {
195 browser.browserAction.setPopup({popup: "popup.html"}); 197 browser.browserAction.setPopup({popup: popupUrl});
196 } 198 }
197 199
198 // On Firefox for Android, open the options page directly when the browser 200 // On Firefox for Android, open the options page directly when the browser
199 // action is clicked. 201 // action is clicked.
200 browser.browserAction.onClicked.addListener(() => 202 browser.browserAction.onClicked.addListener(() =>
201 { 203 {
202 browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) => 204 browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) =>
203 { 205 {
204 let currentPage = new ext.Page(tab); 206 let currentPage = new ext.Page(tab);
205 207
206 showOptions((optionsPage, port) => 208 showOptions((optionsPage, port) =>
207 { 209 {
208 if (!/^https?:$/.test(currentPage.url.protocol)) 210 if (!/^https?:$/.test(currentPage.url.protocol))
209 return; 211 return;
210 212
211 port.postMessage({ 213 port.postMessage({
212 type: "app.respond", 214 type: "app.respond",
213 action: "showPageOptions", 215 action: "showPageOptions",
214 args: [ 216 args: [
215 { 217 {
216 host: currentPage.url.hostname.replace(/^www\./, ""), 218 host: currentPage.url.hostname.replace(/^www\./, ""),
217 whitelisted: !!checkWhitelisted(currentPage) 219 whitelisted: !!checkWhitelisted(currentPage)
218 } 220 }
219 ] 221 ]
220 }); 222 });
221 }); 223 });
222 }); 224 });
223 }); 225 });
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