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

Side by Side Diff: lib/contentPolicy.js

Issue 29321478: Issue 2738 - Make RegExpFilter.matches() take a bit mask instead of content type string (Closed)
Patch Set: Created July 9, 2015, 1:45 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 /** 18 /**
19 * @fileOverview Content policy implementation, responsible for blocking things. 19 * @fileOverview Content policy implementation, responsible for blocking things.
20 */ 20 */
21 21
22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
23 Cu.import("resource://gre/modules/Services.jsm"); 23 Cu.import("resource://gre/modules/Services.jsm");
24 24
25 let {Utils} = require("utils"); 25 let {Utils} = require("utils");
26 let {Prefs} = require("prefs"); 26 let {Prefs} = require("prefs");
27 let {FilterStorage} = require("filterStorage"); 27 let {FilterStorage} = require("filterStorage");
28 let {BlockingFilter, WhitelistFilter} = require("filterClasses"); 28 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses");
29 let {defaultMatcher} = require("matcher"); 29 let {defaultMatcher} = require("matcher");
30 let {objectMouseEventHander} = require("objectTabs"); 30 let {objectMouseEventHander} = require("objectTabs");
31 let {RequestNotifier} = require("requestNotifier"); 31 let {RequestNotifier} = require("requestNotifier");
32 let {ElemHide} = require("elemHide"); 32 let {ElemHide} = require("elemHide");
33 33
34 /** 34 /**
35 * List of explicitly supported content types 35 * List of explicitly supported content types
36 * @type string[] 36 * @type string[]
37 */ 37 */
38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"]; 38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"];
(...skipping 21 matching lines...) Expand all
60 */ 60 */
61 type: {}, 61 type: {},
62 62
63 /** 63 /**
64 * Map of content type names by their identifiers (reverse of type map). 64 * Map of content type names by their identifiers (reverse of type map).
65 * @type Object 65 * @type Object
66 */ 66 */
67 typeDescr: {}, 67 typeDescr: {},
68 68
69 /** 69 /**
70 * Map of numerical content types with their corresponding masks
71 * @type Object
72 */
73 typeMask: {},
74
75 /**
70 * Map of localized content type names by their identifiers. 76 * Map of localized content type names by their identifiers.
71 * @type Object 77 * @type Object
72 */ 78 */
73 localizedDescr: {}, 79 localizedDescr: {},
74 80
75 /** 81 /**
76 * Lists the non-visual content types. 82 * Lists the non-visual content types.
77 * @type Object 83 * @type Object
78 */ 84 */
79 nonVisual: {}, 85 nonVisual: {},
(...skipping 12 matching lines...) Expand all
92 // type constant by type description and type description by type constant 98 // type constant by type description and type description by type constant
93 let iface = Ci.nsIContentPolicy; 99 let iface = Ci.nsIContentPolicy;
94 for (let typeName of contentTypes) 100 for (let typeName of contentTypes)
95 { 101 {
96 if ("TYPE_" + typeName in iface) 102 if ("TYPE_" + typeName in iface)
97 { 103 {
98 let id = iface["TYPE_" + typeName]; 104 let id = iface["TYPE_" + typeName];
99 this.type[typeName] = id; 105 this.type[typeName] = id;
100 this.typeDescr[id] = typeName; 106 this.typeDescr[id] = typeName;
101 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow erCase()); 107 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow erCase());
108 this.typeMask[id] = RegExpFilter.toTypeMask(typeName);
102 } 109 }
103 } 110 }
104 111
105 this.type.ELEMHIDE = 0xFFFD; 112 this.type.ELEMHIDE = 0xFFFD;
106 this.typeDescr[0xFFFD] = "ELEMHIDE"; 113 this.typeDescr[0xFFFD] = "ELEMHIDE";
107 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); 114 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide");
115 this.typeMask[0xFFFD] = RegExpFilter.toTypeMask("ELEMHIDE");
108 116
109 this.type.POPUP = 0xFFFE; 117 this.type.POPUP = 0xFFFE;
110 this.typeDescr[0xFFFE] = "POPUP"; 118 this.typeDescr[0xFFFE] = "POPUP";
111 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); 119 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup");
120 this.typeMask[0xFFFE] = RegExpFilter.toTypeMask("POPUP");
121
122 this.defaultTypeMask = RegExpFilter.toTypeMask("");
Wladimir Palant 2015/07/10 21:07:00 It's a bit mask - the default is always 0.
kzar 2015/07/12 13:59:39 Egad, that was stupid of me. Done.
112 123
113 for (let type of nonVisualTypes) 124 for (let type of nonVisualTypes)
114 this.nonVisual[this.type[type]] = true; 125 this.nonVisual[this.type[type]] = true;
115 126
116 // whitelisted URL schemes 127 // whitelisted URL schemes
117 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) 128 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" "))
118 this.whitelistSchemes[scheme] = true; 129 this.whitelistSchemes[scheme] = true;
119 130
120 // Generate class identifier used to collapse node and register correspondin g 131 // Generate class identifier used to collapse node and register correspondin g
121 // stylesheet. 132 // stylesheet.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 let locationText = location.spec; 203 let locationText = location.spec;
193 if (!match && contentType == Policy.type.ELEMHIDE) 204 if (!match && contentType == Policy.type.ELEMHIDE)
194 { 205 {
195 let testWnd = wnd; 206 let testWnd = wnd;
196 let parentWndLocation = getWindowLocation(testWnd); 207 let parentWndLocation = getWindowLocation(testWnd);
197 while (true) 208 while (true)
198 { 209 {
199 let testWndLocation = parentWndLocation; 210 let testWndLocation = parentWndLocation;
200 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 211 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
201 let parentDocDomain = getHostname(parentWndLocation); 212 let parentDocDomain = getHostname(parentWndLocation);
202 match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc Domain, false, sitekey); 213 match = defaultMatcher.matchesAny(testWndLocation, Policy.typeMask[Polic y.type.ELEMHIDE], parentDocDomain, false, sitekey);
203 if (match instanceof WhitelistFilter) 214 if (match instanceof WhitelistFilter)
204 { 215 {
205 FilterStorage.increaseHitCount(match, wnd); 216 FilterStorage.increaseHitCount(match, wnd);
206 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); 217 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match);
207 return true; 218 return true;
208 } 219 }
209 220
210 if (testWnd.parent == testWnd) 221 if (testWnd.parent == testWnd)
211 break; 222 break;
212 else 223 else
(...skipping 13 matching lines...) Expand all
226 FilterStorage.increaseHitCount(exception, wnd); 237 FilterStorage.increaseHitCount(exception, wnd);
227 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); 238 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception);
228 return true; 239 return true;
229 } 240 }
230 } 241 }
231 242
232 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); 243 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain));
233 244
234 if (!match && Prefs.enabled) 245 if (!match && Prefs.enabled)
235 { 246 {
236 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, sitekey); 247 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e] || Policy.defaultTypeMask, docDomain, thirdParty, sitekey);
Wladimir Palant 2015/07/10 21:07:00 This cannot possibly return a match if type mask i
kzar 2015/07/12 13:59:39 Done.
237 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) 248 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual))
238 { 249 {
239 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); 250 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse);
240 if (collapse || prefCollapse) 251 if (collapse || prefCollapse)
241 schedulePostProcess(node); 252 schedulePostProcess(node);
242 } 253 }
243 254
244 // Track mouse events for objects 255 // Track mouse events for objects
245 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) 256 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE)
246 { 257 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return null; 296 return null;
286 297
287 if (!parentUrl) 298 if (!parentUrl)
288 parentUrl = url; 299 parentUrl = url;
289 300
290 // Ignore fragment identifier 301 // Ignore fragment identifier
291 let index = url.indexOf("#"); 302 let index = url.indexOf("#");
292 if (index >= 0) 303 if (index >= 0)
293 url = url.substring(0, index); 304 url = url.substring(0, index);
294 305
295 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false, sitekey); 306 let result = defaultMatcher.matchesAny(url, Policy.typeMask[Policy.type.DOCU MENT], getHostname(parentUrl), false, sitekey);
296 return (result instanceof WhitelistFilter ? result : null); 307 return (result instanceof WhitelistFilter ? result : null);
297 }, 308 },
298 309
299 /** 310 /**
300 * Checks whether the page loaded in a window is whitelisted for indication in the UI. 311 * Checks whether the page loaded in a window is whitelisted for indication in the UI.
301 * @param wnd {nsIDOMWindow} 312 * @param wnd {nsIDOMWindow}
302 * @return {Filter} matching exception rule or null if not whitelisted 313 * @return {Filter} matching exception rule or null if not whitelisted
303 */ 314 */
304 isWindowWhitelisted: function(wnd) 315 isWindowWhitelisted: function(wnd)
305 { 316 {
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 if (!wnd || wnd.closed) 797 if (!wnd || wnd.closed)
787 return; 798 return;
788 799
789 if (entry.type == Policy.type.OBJECT) 800 if (entry.type == Policy.type.OBJECT)
790 { 801 {
791 node.removeEventListener("mouseover", objectMouseEventHander, true); 802 node.removeEventListener("mouseover", objectMouseEventHander, true);
792 node.removeEventListener("mouseout", objectMouseEventHander, true); 803 node.removeEventListener("mouseout", objectMouseEventHander, true);
793 } 804 }
794 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 805 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
795 } 806 }
OLDNEW
« no previous file with comments | « chrome/content/ui/sidebar.js ('k') | lib/filterClasses.js » ('j') | lib/filterClasses.js » ('J')

Powered by Google App Engine
This is Rietveld