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

Side by Side Diff: lib/contentPolicy.js

Issue 5840485868371968: Issue 616 - Add $generichide + $genericblock filter options and enforce them. (Closed)
Patch Set: Rebased onto typeMask changes Created July 14, 2015, 4:41 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 | lib/filterClasses.js » ('j') | 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-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
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 { 155 {
156 let topWnd = wnd.top; 156 let topWnd = wnd.top;
157 if (!topWnd || !topWnd.location || !topWnd.location.href) 157 if (!topWnd || !topWnd.location || !topWnd.location.href)
158 return true; 158 return true;
159 159
160 let originWindow = Utils.getOriginWindow(wnd); 160 let originWindow = Utils.getOriginWindow(wnd);
161 let wndLocation = originWindow.location.href; 161 let wndLocation = originWindow.location.href;
162 let docDomain = getHostname(wndLocation); 162 let docDomain = getHostname(wndLocation);
163 let match = null; 163 let match = null;
164 let [sitekey, sitekeyWnd] = getSitekey(wnd); 164 let [sitekey, sitekeyWnd] = getSitekey(wnd);
165 let genericblock = { match: null };
Sebastian Noack 2015/07/14 17:23:33 Also it might be a bad idea performance-wise to cr
Sebastian Noack 2015/07/14 17:23:33 Nit: We don't add spaces at the beginning/end of a
kzar 2015/07/15 11:56:20 Acknowledged.
165 if (!match && Prefs.enabled) 166 if (!match && Prefs.enabled)
166 { 167 {
167 let testWnd = wnd; 168 let testWnd = wnd;
168 let testSitekey = sitekey; 169 let testSitekey = sitekey;
169 let testSitekeyWnd = sitekeyWnd; 170 let testSitekeyWnd = sitekeyWnd;
170 let parentWndLocation = getWindowLocation(testWnd); 171 let parentWndLocation = getWindowLocation(testWnd);
171 while (true) 172 while (true)
172 { 173 {
173 let testWndLocation = parentWndLocation; 174 let testWndLocation = parentWndLocation;
174 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 175 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
175 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); 176 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey);
176 177
177 if (match instanceof WhitelistFilter) 178 if (match instanceof WhitelistFilter)
178 { 179 {
179 FilterStorage.increaseHitCount(match, wnd); 180 FilterStorage.increaseHitCount(match, wnd);
180 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); 181 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match);
181 return true; 182 return true;
182 } 183 }
184 else if (!(genericblock.match instanceof WhitelistFilter) && contentType != Policy.type.ELEMHIDE)
Sebastian Noack 2015/07/14 17:23:33 Wouldn't genericblock.match alway be null here, he
kzar 2015/07/15 11:56:21 You're right, I think I was emulating some of the
185 {
186 let parentDocDomain = getHostname(parentWndLocation);
187 genericblock.match = defaultMatcher.matchesAny(testWndLocation, RegExp Filter.typeMap.GENERICBLOCK, parentDocDomain, false);
188 if (genericblock.match instanceof WhitelistFilter)
189 {
190 genericblock.parentDocDomain = parentDocDomain;
191 genericblock.testWnd = testWnd;
192 genericblock.testWndLocation = testWndLocation;
193 }
194 }
183 195
184 if (testWnd.parent == testWnd) 196 if (testWnd.parent == testWnd)
185 break; 197 break;
186 198
187 if (testWnd == testSitekeyWnd) 199 if (testWnd == testSitekeyWnd)
188 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); 200 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent);
189 testWnd = testWnd.parent; 201 testWnd = testWnd.parent;
190 } 202 }
191 } 203 }
192 204
193 // Data loaded by plugins should be attached to the document 205 // Data loaded by plugins should be attached to the document
194 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) 206 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement)
195 node = node.ownerDocument; 207 node = node.ownerDocument;
196 208
197 // Fix type for objects misrepresented as frames or images 209 // Fix type for objects misrepresented as frames or images
198 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) 210 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement))
199 contentType = Policy.type.OBJECT; 211 contentType = Policy.type.OBJECT;
200 212
201 let locationText = location.spec; 213 let locationText = location.spec;
202 if (!match && contentType == Policy.type.ELEMHIDE) 214 if (!match && contentType == Policy.type.ELEMHIDE)
203 { 215 {
204 let testWnd = wnd; 216 let testWnd = wnd;
205 let parentWndLocation = getWindowLocation(testWnd); 217 let parentWndLocation = getWindowLocation(testWnd);
206 while (true) 218 while (true)
207 { 219 {
208 let testWndLocation = parentWndLocation; 220 let testWndLocation = parentWndLocation;
209 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 221 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
210 let parentDocDomain = getHostname(parentWndLocation); 222 let parentDocDomain = getHostname(parentWndLocation);
223
211 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); 224 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey);
225
226 if (!(match instanceof WhitelistFilter) && (!location.domains || locatio n.domains[""]))
227 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMa p.GENERICHIDE, parentDocDomain, false);
228
212 if (match instanceof WhitelistFilter) 229 if (match instanceof WhitelistFilter)
213 { 230 {
214 FilterStorage.increaseHitCount(match, wnd); 231 FilterStorage.increaseHitCount(match, wnd);
215 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); 232 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match);
216 return true; 233 return true;
217 } 234 }
218 235
219 if (testWnd.parent == testWnd) 236 if (testWnd.parent == testWnd)
220 break; 237 break;
221 else 238 else
(...skipping 14 matching lines...) Expand all
236 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); 253 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception);
237 return true; 254 return true;
238 } 255 }
239 } 256 }
240 257
241 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); 258 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain));
242 259
243 if (!match && Prefs.enabled && contentType in Policy.typeMask) 260 if (!match && Prefs.enabled && contentType in Policy.typeMask)
244 { 261 {
245 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); 262 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey);
246 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) 263 if (match instanceof BlockingFilter)
247 { 264 {
248 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); 265 if ((!match.domains || match.domains[""]) && genericblock.match instance of WhitelistFilter)
249 if (collapse || prefCollapse) 266 {
250 schedulePostProcess(node); 267 FilterStorage.increaseHitCount(genericblock.match, wnd);
268 RequestNotifier.addNodeData(
269 genericblock.testWnd.document,
270 topWnd, contentType,
271 genericblock.parentDocDomain,
272 false, genericblock.testWndLocation,
273 genericblock.match
274 );
275 return true;
276 }
277
278 if (node.ownerDocument && !(contentType in Policy.nonVisual))
279 {
280 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse);
281 if (collapse || prefCollapse)
282 schedulePostProcess(node);
283 }
251 } 284 }
252 285
253 // Track mouse events for objects 286 // Track mouse events for objects
254 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) 287 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE)
255 { 288 {
256 node.addEventListener("mouseover", objectMouseEventHander, true); 289 node.addEventListener("mouseover", objectMouseEventHander, true);
257 node.addEventListener("mouseout", objectMouseEventHander, true); 290 node.addEventListener("mouseout", objectMouseEventHander, true);
258 } 291 }
259 } 292 }
260 293
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 if (!wnd || wnd.closed) 828 if (!wnd || wnd.closed)
796 return; 829 return;
797 830
798 if (entry.type == Policy.type.OBJECT) 831 if (entry.type == Policy.type.OBJECT)
799 { 832 {
800 node.removeEventListener("mouseover", objectMouseEventHander, true); 833 node.removeEventListener("mouseover", objectMouseEventHander, true);
801 node.removeEventListener("mouseout", objectMouseEventHander, true); 834 node.removeEventListener("mouseout", objectMouseEventHander, true);
802 } 835 }
803 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 836 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
804 } 837 }
OLDNEW
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld