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

Delta Between Two Patch Sets: 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/
Left Patch Set: Check for chrome.windows instead Created Aug. 16, 2017, 8:15 p.m.
Right Patch Set: Check for "Fennec" explicitly Created Aug. 24, 2017, 10:33 a.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 | « no previous file | no next file » | no next file with change/comment »
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-2017 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 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 getKey(page, frame), specificOnly 112 getKey(page, frame), specificOnly
112 ); 113 );
113 114
114 if (!filter) 115 if (!filter)
115 { 116 {
116 let filterText = url.replace(/^[\w-]+:\/+(?:www\.)?/, "||"); 117 let filterText = url.replace(/^[\w-]+:\/+(?:www\.)?/, "||");
117 118
118 if (specificOnly) 119 if (specificOnly)
119 filterText += "$domain=" + docDomain; 120 filterText += "$domain=" + docDomain;
120 121
121 if (filters.indexOf(filterText) == -1) 122 if (!filters.includes(filterText))
122 filters.push(filterText); 123 filters.push(filterText);
123 } 124 }
124 } 125 }
125 126
126 // If we couldn't generate any blocking filters, fallback to element hiding 127 // If we couldn't generate any blocking filters, fallback to element hiding
127 if (filters.length == 0 && !checkWhitelisted(page, frame, 128 if (filters.length == 0 && !checkWhitelisted(page, frame,
128 RegExpFilter.typeMap.ELEMHIDE)) 129 RegExpFilter.typeMap.ELEMHIDE))
129 { 130 {
130 // Generate CSS selectors based on the element's "id" and 131 // Generate CSS selectors based on the element's "id" and
131 // "class" attribute. 132 // "class" attribute.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 page.sendMessage({type: "composer.content.contextMenuClicked"}); 174 page.sendMessage({type: "composer.content.contextMenuClicked"});
174 } 175 }
175 }; 176 };
176 177
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
184 // Firefox for Android does not support the windows API, which is 185 // We don't support the filter composer on Firefox for Android, because the
185 // required for the composer to work. 186 // user experience on mobile is quite different.
Wladimir Palant 2017/08/17 12:22:49 Not really, we could fall back to creating a new t
Manish Jethani 2017/08/17 13:25:19 Do you think it makes sense to make the composer w
Sebastian Noack 2017/08/18 09:23:01 Also, the user experience when selecting elements
Wladimir Palant 2017/08/18 20:52:32 Ok, fine with me.
Sebastian Noack 2017/08/23 12:00:35 Perhaps we should rather check for `info.applicati
Manish Jethani 2017/08/24 10:34:59 Done.
186 "windows" in chrome) 187 if (info.application != "fennec" &&
188 !filter && Prefs.shouldShowBlockElementMenu && readyPages.has(page))
187 { 189 {
188 page.contextMenus.create(contextMenuItem); 190 page.contextMenus.create(contextMenuItem);
189 } 191 }
190 } 192 }
191 193
192 FilterNotifier.on("page.WhitelistingStateRevalidate", updateContextMenu); 194 FilterNotifier.on("page.WhitelistingStateRevalidate", updateContextMenu);
193 195
194 Prefs.on("shouldShowBlockElementMenu", () => 196 Prefs.on("shouldShowBlockElementMenu", () =>
195 { 197 {
196 ext.pages.query({}, pages => 198 ext.pages.query({}, pages =>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 258
257 port.on("composer.quoteCSS", (message, sender) => 259 port.on("composer.quoteCSS", (message, sender) =>
258 { 260 {
259 return quoteCSS(message.CSS); 261 return quoteCSS(message.CSS);
260 }); 262 });
261 263
262 ext.pages.onLoading.addListener(page => 264 ext.pages.onLoading.addListener(page =>
263 { 265 {
264 page.sendMessage({type: "composer.content.finished"}); 266 page.sendMessage({type: "composer.content.finished"});
265 }); 267 });
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld