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

Side by Side Diff: lib/filterComposer.js

Issue 29516679: Issue 5347 - Do not show composer menu item on Firefox for Android (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Aug. 15, 2017, 11:40 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 filterComposer */ 18 /** @module filterComposer */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {defaultMatcher} = require("matcher"); 22 const {defaultMatcher} = require("matcher");
23 const {RegExpFilter} = require("filterClasses"); 23 const {RegExpFilter} = require("filterClasses");
24 const {FilterNotifier} = require("filterNotifier"); 24 const {FilterNotifier} = require("filterNotifier");
25 const {Prefs} = require("prefs"); 25 const {Prefs} = require("prefs");
26 const {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); 26 const {extractHostFromFrame, stringifyURL, isThirdParty} = require("url");
27 const {getKey, checkWhitelisted} = require("whitelisting"); 27 const {getKey, checkWhitelisted} = require("whitelisting");
28 const {port} = require("messaging"); 28 const {port} = require("messaging");
29 const info = require("info");
29 30
30 let readyPages = new ext.PageMap(); 31 let readyPages = new ext.PageMap();
31 32
32 /** 33 /**
33 * Checks whether the given page is ready to use the filter composer 34 * Checks whether the given page is ready to use the filter composer
34 * 35 *
35 * @param {Page} page 36 * @param {Page} page
36 * @return {boolean} 37 * @return {boolean}
37 */ 38 */
38 exports.isPageReady = page => 39 exports.isPageReady = page =>
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 function updateContextMenu(page, filter) 178 function updateContextMenu(page, filter)
178 { 179 {
179 page.contextMenus.remove(contextMenuItem); 180 page.contextMenus.remove(contextMenuItem);
180 181
181 if (typeof filter == "undefined") 182 if (typeof filter == "undefined")
182 filter = checkWhitelisted(page); 183 filter = checkWhitelisted(page);
183 if (!filter && Prefs.shouldShowBlockElementMenu && readyPages.has(page)) 184 if (!filter && Prefs.shouldShowBlockElementMenu && readyPages.has(page))
184 page.contextMenus.create(contextMenuItem); 185 page.contextMenus.create(contextMenuItem);
185 } 186 }
186 187
188 function shouldDisable()
189 {
190 // Disable the composer if the browser is unknown or if it's
Manish Jethani 2017/08/15 23:50:06 We have to cover null and "unknown" as well, becau
191 // "Fennec" (Firefox for Android).
192 return !info.application || info.application == "unknown" ||
193 info.application == "fennec";
194 }
195
187 FilterNotifier.on("page.WhitelistingStateRevalidate", updateContextMenu); 196 FilterNotifier.on("page.WhitelistingStateRevalidate", updateContextMenu);
188 197
189 Prefs.on("shouldShowBlockElementMenu", () => 198 Prefs.on("shouldShowBlockElementMenu", () =>
190 { 199 {
191 ext.pages.query({}, pages => 200 ext.pages.query({}, pages =>
192 { 201 {
193 for (let page of pages) 202 for (let page of pages)
194 updateContextMenu(page); 203 updateContextMenu(page);
195 }); 204 });
196 }); 205 });
197 206
198 port.on("composer.ready", (message, sender) => 207 port.on("composer.ready", (message, sender) =>
199 { 208 {
200 readyPages.set(sender.page, null); 209 if (!shouldDisable())
210 readyPages.set(sender.page, null);
211
201 updateContextMenu(sender.page); 212 updateContextMenu(sender.page);
202 }); 213 });
203 214
204 port.on("composer.openDialog", (message, sender) => 215 port.on("composer.openDialog", (message, sender) =>
205 { 216 {
206 return new Promise(resolve => 217 return new Promise(resolve =>
207 { 218 {
208 ext.windows.create({ 219 ext.windows.create({
209 url: ext.getURL("composer.html"), 220 url: ext.getURL("composer.html"),
210 left: 50, 221 left: 50,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 }); 260 });
250 }); 261 });
251 262
252 port.on("composer.quoteCSS", (message, sender) => 263 port.on("composer.quoteCSS", (message, sender) =>
253 { 264 {
254 return quoteCSS(message.CSS); 265 return quoteCSS(message.CSS);
255 }); 266 });
256 267
257 ext.pages.onLoading.addListener(page => 268 ext.pages.onLoading.addListener(page =>
258 { 269 {
270 if (shouldDisable())
Manish Jethani 2017/08/15 23:50:06 If we simply cut off the communication between com
271 return;
272
259 page.sendMessage({type: "composer.content.finished"}); 273 page.sendMessage({type: "composer.content.finished"});
260 }); 274 });
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