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

Side by Side Diff: lib/filterComposer.js

Issue 29321504: Issue 2738 - Pass bit masks to matching functions (Closed)
Patch Set: Created July 9, 2015, 2:50 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
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); 20 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url");
21 let {getKey, isFrameWhitelisted} = require("whitelisting"); 21 let {getKey, isFrameWhitelisted} = require("whitelisting");
22 let {defaultMatcher} = require("matcher"); 22 let {defaultMatcher} = require("matcher");
23 let {RegExpFilter} = require("filterClasses");
23 24
24 function escapeChar(chr) 25 function escapeChar(chr)
25 { 26 {
26 let code = chr.charCodeAt(0); 27 let code = chr.charCodeAt(0);
27 28
28 // Control characters and leading digits must be escaped based on 29 // Control characters and leading digits must be escaped based on
29 // their char code in CSS. Moreover, curly brackets aren't allowed 30 // their char code in CSS. Moreover, curly brackets aren't allowed
30 // in elemhide filters, and therefore must be escaped based on their 31 // in elemhide filters, and therefore must be escaped based on their
31 // char code as well. 32 // char code as well.
32 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) 33 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 { 92 {
92 let docDomain = extractHostFromFrame(frame); 93 let docDomain = extractHostFromFrame(frame);
93 94
94 // Add a blocking filter for each URL of the element that can be blocked 95 // Add a blocking filter for each URL of the element that can be blocked
95 for (let url of details.urls) 96 for (let url of details.urls)
96 { 97 {
97 let urlObj = new URL(url, details.baseURL); 98 let urlObj = new URL(url, details.baseURL);
98 url = stringifyURL(urlObj); 99 url = stringifyURL(urlObj);
99 100
100 let filter = defaultMatcher.whitelist.matchesAny( 101 let filter = defaultMatcher.whitelist.matchesAny(
101 url, details.type, docDomain, 102 url, RegExpFilter.toTypeMask(details.type), docDomain,
Sebastian Noack 2015/07/09 15:28:52 Same here: let docDomain = extractHostFromFrame
kzar 2015/07/12 14:28:01 Done.
102 isThirdParty(urlObj, docDomain), 103 isThirdParty(urlObj, docDomain),
103 getKey(page, frame) 104 getKey(page, frame)
104 ); 105 );
105 106
106 if (!filter) 107 if (!filter)
107 { 108 {
108 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); 109 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||");
109 110
110 if (filters.indexOf(filterText) == -1) 111 if (filters.indexOf(filterText) == -1)
111 filters.push(filterText); 112 filters.push(filterText);
(...skipping 21 matching lines...) Expand all
133 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]"); 134 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]");
134 135
135 // Add an element hiding filter for each generated CSS selector 136 // Add an element hiding filter for each generated CSS selector
136 for (let selector of selectors) 137 for (let selector of selectors)
137 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); 138 filters.push(docDomain.replace(/^www\./, "") + "##" + selector);
138 } 139 }
139 } 140 }
140 141
141 return {filters: filters, selectors: selectors}; 142 return {filters: filters, selectors: selectors};
142 }; 143 };
OLDNEW

Powered by Google App Engine
This is Rietveld