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

Delta Between Two Patch Sets: lib/options.js

Issue 29536764: Issue 5587, 5748 - Use mobile options page on Firefox for Android (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Wait for app.listen Created Sept. 27, 2017, 12:45 p.m.
Right Patch Set: Remove workaround for FOUC issue and update adblockplusui dependency Created Oct. 5, 2017, 1:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/notificationHelper.js ('k') | metadata.chrome » ('j') | options.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 {getDecodedHostname} = require("url");
23 const {checkWhitelisted} = require("whitelisting");
22 const {port} = require("messaging"); 24 const {port} = require("messaging");
23 const info = require("info"); 25 const info = require("info");
24 26
25 const optionsUrl = "options.html"; 27 const optionsUrl = "options.html";
26 28
27 function findOptionsTab(callback) 29 function findOptionsTab(callback)
28 { 30 {
29 chrome.tabs.query({}, tabs => 31 chrome.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
(...skipping 17 matching lines...) Expand all
49 { 51 {
50 callback(new ext.Page(optionsTab)); 52 callback(new ext.Page(optionsTab));
51 } 53 }
52 else 54 else
53 { 55 {
54 // If we don't already have an options page, it means we've just opened 56 // 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 57 // one, in which case we must find the tab, wait for it to be ready, and
56 // then return the call. 58 // then return the call.
57 findOptionsTab(tab => 59 findOptionsTab(tab =>
58 { 60 {
61 if (!tab)
62 return;
63
59 function onMessage(message, sender) 64 function onMessage(message, sender)
60 { 65 {
61 if (message.type == "app.listen" && 66 if (message.type == "app.listen" &&
62 sender.page && sender.page.id == page.id) 67 sender.page && sender.page.id == tab.id)
63 { 68 {
64 port.off("app.listen"); 69 port.off("app.listen", onMessage);
65 callback(page); 70 callback(new ext.Page(tab));
66 } 71 }
67 } 72 }
68 73
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); 74 port.on("app.listen", onMessage);
71 }); 75 });
72 } 76 }
73 } 77 }
74 78
79 let showOptions =
75 /** 80 /**
76 * Opens the options page. 81 * Opens the options page.
77 * 82 *
78 * @param {function} callback 83 * @param {function} callback
79 * @static
80 */ 84 */
81 exports.showOptions = callback => 85 exports.showOptions = callback =>
82 { 86 {
83 findOptionsTab(optionsTab => 87 findOptionsTab(optionsTab =>
Manish Jethani 2017/09/27 12:50:14 Now we first try to find the options tab, since th
84 { 88 {
85 // Edge does not yet support runtime.openOptionsPage (tested version 38) 89 // Edge does not yet support runtime.openOptionsPage (tested version 38)
86 if ("openOptionsPage" in chrome.runtime && 90 if ("openOptionsPage" in chrome.runtime &&
87 // 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
88 // runtime.openOptionsPage but it doesn't do anything. 92 // runtime.openOptionsPage but it doesn't do anything.
89 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 93 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945
90 (info.application != "fennec" || 94 (info.application != "fennec" ||
91 parseInt(info.applicationVersion, 10) >= 57)) 95 parseInt(info.applicationVersion, 10) >= 57))
92 { 96 {
93 chrome.runtime.openOptionsPage(() => 97 chrome.runtime.openOptionsPage(() =>
94 { 98 {
95 if (chrome.runtime.lastError)
96 return;
97
98 returnShowOptionsCall(optionsTab, callback); 99 returnShowOptionsCall(optionsTab, callback);
99 }); 100 });
100 } 101 }
101 else if (optionsTab) 102 else if (optionsTab)
102 { 103 {
103 // Firefox for Android before version 57 does not support 104 // Firefox for Android before version 57 does not support
104 // runtime.openOptionsPage, nor does it support the windows API. 105 // runtime.openOptionsPage, nor does it support the windows API.
105 // Since there is effectively only one window on the mobile browser, 106 // Since there is effectively only one window on the mobile browser,
106 // there's no need to bring it into focus. 107 // there's no need to bring it into focus.
107 if ("windows" in chrome) 108 if ("windows" in chrome)
108 chrome.windows.update(optionsTab.windowId, {focused: true}); 109 chrome.windows.update(optionsTab.windowId, {focused: true});
109 110
110 chrome.tabs.update(optionsTab.id, {active: true}); 111 chrome.tabs.update(optionsTab.id, {active: true});
111 112
112 returnShowOptionsCall(optionsTab, callback); 113 returnShowOptionsCall(optionsTab, callback);
113 } 114 }
114 else 115 else
115 { 116 {
116 // We don't use fullOptionsUrl here because of this Edge issue: 117 // We use a relative URL here because of this Edge issue:
117 // 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
118 chrome.tabs.create({url: optionsUrl}, () => 119 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 {
120 returnShowOptionsCall(optionsTab, callback); 121 returnShowOptionsCall(optionsTab, callback);
121 }); 122 });
122 } 123 }
123 }); 124 });
124 }; 125 };
126
127 // On Firefox for Android, open the options page directly when the browser
128 // action is clicked.
129 chrome.browserAction.onClicked.addListener(() =>
130 {
131 ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
132 {
133 let currentPage = pages[0];
134
135 showOptions(optionsPage =>
136 {
137 if (!/^https?:$/.test(currentPage.url.protocol))
138 return;
139
140 optionsPage.sendMessage({
141 type: "app.respond",
142 action: "showPageOptions",
143 args: [
144 {
145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""),
146 whitelisted: !!checkWhitelisted(currentPage)
147 }
148 ]
149 });
150 });
151 });
152 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld