| OLD | NEW |
| 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; |
| 26 | 27 |
| 27 function findOptionsTab(callback) | 28 function findOptionsTab(callback) |
| 28 { | 29 { |
| 29 browser.tabs.query({}, tabs => | 30 browser.tabs.query({}, tabs => |
| 30 { | 31 { |
| 31 // We find a tab ourselves because Edge has a bug when quering tabs with | 32 // We find a tab ourselves because Edge has a bug when quering tabs with |
| 32 // extension URL protocol: | 33 // 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/8094
141/ |
| 34 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8604
703/ | 35 // 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 // Firefox won't let us query for moz-extension:// pages either, though |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // We need to clear the popup URL on Firefox for Android in order for the | 180 // We need to clear the popup URL on Firefox for Android in order for the |
| 180 // options page to open instead of the bubble. Unfortunately there's a bug[1] | 181 // 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 | 182 // 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 | 183 // Firefox from the manifest at all, instead setting it here only for |
| 183 // non-mobile. | 184 // non-mobile. |
| 184 // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1414613 | 185 // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1414613 |
| 185 if ("getBrowserInfo" in browser.runtime) | 186 if ("getBrowserInfo" in browser.runtime) |
| 186 { | 187 { |
| 187 browser.runtime.getBrowserInfo().then(browserInfo => | 188 browser.runtime.getBrowserInfo().then(browserInfo => |
| 188 { | 189 { |
| 189 if (browserInfo.name != "Fennec") | 190 if (browserInfo.name == "Fennec") |
| 190 browser.browserAction.setPopup({popup: "popup.html"}); | 191 browser.browserAction.setPopup({popup: null}); |
| 191 }); | 192 }); |
| 192 } | 193 } |
| 193 else | |
| 194 { | |
| 195 browser.browserAction.setPopup({popup: "popup.html"}); | |
| 196 } | |
| 197 | 194 |
| 198 // On Firefox for Android, open the options page directly when the browser | 195 // On Firefox for Android, open the options page directly when the browser |
| 199 // action is clicked. | 196 // action is clicked. |
| 200 browser.browserAction.onClicked.addListener(() => | 197 browser.browserAction.onClicked.addListener(() => |
| 201 { | 198 { |
| 202 browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) => | 199 browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) => |
| 203 { | 200 { |
| 204 let currentPage = new ext.Page(tab); | 201 let currentPage = new ext.Page(tab); |
| 205 | 202 |
| 206 showOptions((optionsPage, port) => | 203 showOptions((optionsPage, port) => |
| 207 { | 204 { |
| 208 if (!/^https?:$/.test(currentPage.url.protocol)) | 205 if (!/^https?:$/.test(currentPage.url.protocol)) |
| 209 return; | 206 return; |
| 210 | 207 |
| 211 port.postMessage({ | 208 port.postMessage({ |
| 212 type: "app.respond", | 209 type: "app.respond", |
| 213 action: "showPageOptions", | 210 action: "showPageOptions", |
| 214 args: [ | 211 args: [ |
| 215 { | 212 { |
| 216 host: currentPage.url.hostname.replace(/^www\./, ""), | 213 host: currentPage.url.hostname.replace(/^www\./, ""), |
| 217 whitelisted: !!checkWhitelisted(currentPage) | 214 whitelisted: !!checkWhitelisted(currentPage) |
| 218 } | 215 } |
| 219 ] | 216 ] |
| 220 }); | 217 }); |
| 221 }); | 218 }); |
| 222 }); | 219 }); |
| 223 }); | 220 }); |
| OLD | NEW |