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

Side by Side Diff: lib/options.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Use callback-based API for storage Created Oct. 9, 2017, 4:01 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 | « lib/notificationHelper.js ('k') | lib/popupBlocker.js » ('j') | 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 10 matching lines...) Expand all
21 21
22 const {getDecodedHostname} = require("url"); 22 const {getDecodedHostname} = require("url");
23 const {checkWhitelisted} = require("whitelisting"); 23 const {checkWhitelisted} = require("whitelisting");
24 const {port} = require("messaging"); 24 const {port} = require("messaging");
25 const info = require("info"); 25 const info = require("info");
26 26
27 const optionsUrl = "options.html"; 27 const optionsUrl = "options.html";
28 28
29 function findOptionsTab(callback) 29 function findOptionsTab(callback)
30 { 30 {
31 chrome.tabs.query({}, tabs => 31 browser.tabs.query({}, tabs =>
32 { 32 {
33 // 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
34 // extension URL protocol: 34 // extension URL protocol:
35 // 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/
36 // 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/
37 // 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
38 // starting with Firefox 56 an extension can query for its own URLs: 38 // starting with Firefox 56 an extension can query for its own URLs:
39 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354 39 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354
40 let fullOptionsUrl = ext.getURL(optionsUrl); 40 let fullOptionsUrl = ext.getURL(optionsUrl);
41 callback(tabs.find(element => element.url == fullOptionsUrl)); 41 callback(tabs.find(element => element.url == fullOptionsUrl));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 /** 80 /**
81 * Opens the options page. 81 * Opens the options page.
82 * 82 *
83 * @param {function} callback 83 * @param {function} callback
84 */ 84 */
85 exports.showOptions = callback => 85 exports.showOptions = callback =>
86 { 86 {
87 findOptionsTab(optionsTab => 87 findOptionsTab(optionsTab =>
88 { 88 {
89 // Edge does not yet support runtime.openOptionsPage (tested version 38) 89 // Edge does not yet support runtime.openOptionsPage (tested version 38)
90 if ("openOptionsPage" in chrome.runtime && 90 if ("openOptionsPage" in browser.runtime &&
91 // Some versions of Firefox for Android before version 57 do have a 91 // Some versions of Firefox for Android before version 57 do have a
92 // runtime.openOptionsPage but it doesn't do anything. 92 // runtime.openOptionsPage but it doesn't do anything.
93 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 93 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
94 (info.application != "fennec" || 94 (info.application != "fennec" ||
95 parseInt(info.applicationVersion, 10) >= 57)) 95 parseInt(info.applicationVersion, 10) >= 57))
96 { 96 {
97 chrome.runtime.openOptionsPage(() => 97 browser.runtime.openOptionsPage(() =>
98 { 98 {
99 returnShowOptionsCall(optionsTab, callback); 99 returnShowOptionsCall(optionsTab, callback);
100 }); 100 });
101 } 101 }
102 else if (optionsTab) 102 else if (optionsTab)
103 { 103 {
104 // Firefox for Android before version 57 does not support 104 // Firefox for Android before version 57 does not support
105 // runtime.openOptionsPage, nor does it support the windows API. 105 // runtime.openOptionsPage, nor does it support the windows API.
106 // Since there is effectively only one window on the mobile browser, 106 // Since there is effectively only one window on the mobile browser,
107 // there's no need to bring it into focus. 107 // there's no need to bring it into focus.
108 if ("windows" in chrome) 108 if ("windows" in browser)
109 chrome.windows.update(optionsTab.windowId, {focused: true}); 109 browser.windows.update(optionsTab.windowId, {focused: true});
110 110
111 chrome.tabs.update(optionsTab.id, {active: true}); 111 browser.tabs.update(optionsTab.id, {active: true});
112 112
113 returnShowOptionsCall(optionsTab, callback); 113 returnShowOptionsCall(optionsTab, callback);
114 } 114 }
115 else 115 else
116 { 116 {
117 // We use a relative URL here because of this Edge issue: 117 // We use a relative URL here because of this Edge issue:
118 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332 118 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10 276332
119 chrome.tabs.create({url: optionsUrl}, () => 119 browser.tabs.create({url: optionsUrl}, () =>
120 { 120 {
121 returnShowOptionsCall(optionsTab, callback); 121 returnShowOptionsCall(optionsTab, callback);
122 }); 122 });
123 } 123 }
124 }); 124 });
125 }; 125 };
126 126
127 // On Firefox for Android, open the options page directly when the browser 127 // On Firefox for Android, open the options page directly when the browser
128 // action is clicked. 128 // action is clicked.
129 chrome.browserAction.onClicked.addListener(() => 129 browser.browserAction.onClicked.addListener(() =>
130 { 130 {
131 chrome.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) => 131 browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) =>
132 { 132 {
133 let currentPage = new ext.Page(tab); 133 let currentPage = new ext.Page(tab);
134 134
135 showOptions(optionsPage => 135 showOptions(optionsPage =>
136 { 136 {
137 if (!/^https?:$/.test(currentPage.url.protocol)) 137 if (!/^https?:$/.test(currentPage.url.protocol))
138 return; 138 return;
139 139
140 optionsPage.sendMessage({ 140 optionsPage.sendMessage({
141 type: "app.respond", 141 type: "app.respond",
142 action: "showPageOptions", 142 action: "showPageOptions",
143 args: [ 143 args: [
144 { 144 {
145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), 145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""),
146 whitelisted: !!checkWhitelisted(currentPage) 146 whitelisted: !!checkWhitelisted(currentPage)
147 } 147 }
148 ] 148 ]
149 }); 149 });
150 }); 150 });
151 }); 151 });
152 }); 152 });
OLDNEW
« no previous file with comments | « lib/notificationHelper.js ('k') | lib/popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld