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

Side by Side Diff: lib/cssInjection.js

Issue 29555932: Issue 5781 - Merge messages for regular and emulated element hiding filters (Closed)
Patch Set: Created Sept. 25, 2017, 11:07 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
« include.preload.js ('K') | « include.preload.js ('k') | 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-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 cssInjection */ 18 /** @module cssInjection */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {RegExpFilter} = require("filterClasses"); 22 const {RegExpFilter} = require("filterClasses");
23 const {ElemHide} = require("elemHide"); 23 const {ElemHide} = require("elemHide");
24 const {ElemHideEmulation} = require("elemHideEmulation");
24 const {checkWhitelisted} = require("whitelisting"); 25 const {checkWhitelisted} = require("whitelisting");
25 const {extractHostFromFrame} = require("url"); 26 const {extractHostFromFrame} = require("url");
26 const {port} = require("messaging"); 27 const {port} = require("messaging");
27 const devtools = require("devtools"); 28 const devtools = require("devtools");
28 29
29 const userStyleSheetsSupported = "extensionTypes" in chrome && 30 const userStyleSheetsSupported = "extensionTypes" in chrome &&
30 "CSSOrigin" in chrome.extensionTypes; 31 "CSSOrigin" in chrome.extensionTypes;
31 32
32 function hideElements(tabId, frameId, selectors) 33 function hideElements(tabId, frameId, selectors)
33 { 34 {
34 chrome.tabs.insertCSS(tabId, { 35 chrome.tabs.insertCSS(tabId, {
35 code: selectors.join(", ") + "{display: none !important;}", 36 code: selectors.join(", ") + "{display: none !important;}",
36 cssOrigin: "user", 37 cssOrigin: "user",
37 frameId, 38 frameId,
38 matchAboutBlank: true, 39 matchAboutBlank: true,
39 runAt: "document_start" 40 runAt: "document_start"
40 }); 41 });
41 } 42 }
42 43
43 port.on("elemhide.getSelectors", (msg, sender) => 44 port.on("elemhide.getSelectors", (msg, sender) =>
44 { 45 {
45 let selectors = []; 46 let selectors = [];
47 let emulated = [];
Manish Jethani 2017/09/26 11:50:18 How about we call this emulationPatterns, similar
Sebastian Noack 2017/09/26 21:50:40 Done.
46 let trace = devtools && devtools.hasPanel(sender.page); 48 let trace = devtools && devtools.hasPanel(sender.page);
47 let inject = !userStyleSheetsSupported; 49 let inject = !userStyleSheetsSupported;
48 50
49 if (!checkWhitelisted(sender.page, sender.frame, 51 if (!checkWhitelisted(sender.page, sender.frame,
50 RegExpFilter.typeMap.DOCUMENT | 52 RegExpFilter.typeMap.DOCUMENT |
51 RegExpFilter.typeMap.ELEMHIDE)) 53 RegExpFilter.typeMap.ELEMHIDE))
52 { 54 {
55 let hostname = extractHostFromFrame(sender.frame);
Manish Jethani 2017/09/26 11:50:18 I notice that this is a change in behavior, the ol
Sebastian Noack 2017/09/26 21:50:40 You are right, and extractHostFromFrame() should b
53 let specificOnly = checkWhitelisted(sender.page, sender.frame, 56 let specificOnly = checkWhitelisted(sender.page, sender.frame,
54 RegExpFilter.typeMap.GENERICHIDE); 57 RegExpFilter.typeMap.GENERICHIDE);
58
55 selectors = ElemHide.getSelectorsForDomain( 59 selectors = ElemHide.getSelectorsForDomain(
56 extractHostFromFrame(sender.frame), 60 hostname,
57 specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING 61 specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING
58 ); 62 );
63
64 for (let filter of ElemHideEmulation.getRulesForDomain(hostname))
65 emulated.push({selector: filter.selector, text: filter.text});
Manish Jethani 2017/09/26 11:50:18 Just an idea, this could be written idiomatically
Sebastian Noack 2017/09/26 21:50:40 This will result in less efficient code for two re
Manish Jethani 2017/09/26 22:45:18 Fair enough. I just checked on both Node.js and C
59 } 66 }
60 67
61 if (!inject && selectors.length > 0) 68 if (!inject && selectors.length > 0)
62 hideElements(sender.page.id, sender.frame.id, selectors); 69 hideElements(sender.page.id, sender.frame.id, selectors);
63 70
64 let response = {trace, inject}; 71 let response = {trace, inject, emulated};
Manish Jethani 2017/09/26 11:50:18 Maybe not as part of this very change, but we shou
Sebastian Noack 2017/09/26 21:50:40 It seems you misunderstand the concept of emulatio
Manish Jethani 2017/09/26 22:45:18 Yes, it seems I misunderstood. I was thinking we c
65 if (trace || inject) 72 if (trace || inject)
66 response.selectors = selectors; 73 response.selectors = selectors;
67 74
68 return response; 75 return response;
69 }); 76 });
70 77
71 port.on("elemhide.injectSelectors", (msg, sender) => 78 port.on("elemhide.injectSelectors", (msg, sender) =>
72 { 79 {
73 hideElements(sender.page.id, sender.frame.id, msg.selectors); 80 hideElements(sender.page.id, sender.frame.id, msg.selectors);
74 }); 81 });
OLDNEW
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld