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

Delta Between Two Patch Sets: lib/contentPolicy.js

Issue 5840485868371968: Issue 616 - Add $generichide + $genericblock filter options and enforce them. (Closed)
Left Patch Set: Addressed Thomas' feedback Created Sept. 3, 2015, 12:35 p.m.
Right Patch Set: Remove extra parenthesis Created Sept. 28, 2015, 10:15 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 | lib/filterClasses.js » ('j') | 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-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 = null; 165 let nogeneric = false;
166 let generichide = null;
Wladimir Palant 2015/09/03 13:09:42 It's either a blocking rule or hiding rule - so at
kzar 2015/09/05 14:39:58 Done.
167 166
168 if (!match && Prefs.enabled) 167 if (!match && Prefs.enabled)
169 { 168 {
170 let testWnd = wnd; 169 let testWnd = wnd;
171 let testSitekey = sitekey; 170 let testSitekey = sitekey;
172 let testSitekeyWnd = sitekeyWnd; 171 let testSitekeyWnd = sitekeyWnd;
173 let parentWndLocation = getWindowLocation(testWnd); 172 let parentWndLocation = getWindowLocation(testWnd);
174 while (true) 173 while (true)
175 { 174 {
176 let testWndLocation = parentWndLocation; 175 let testWndLocation = parentWndLocation;
177 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 176 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
178 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); 177 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey);
179 178
180 if (match instanceof WhitelistFilter) 179 if (match instanceof WhitelistFilter)
181 { 180 {
182 FilterStorage.increaseHitCount(match, wnd); 181 FilterStorage.increaseHitCount(match, wnd);
183 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); 182 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match);
184 return true; 183 return true;
185 } 184 }
186 185
187 if (contentType != Policy.type.ELEMHIDE) 186 let genericType = (contentType == Policy.type.ELEMHIDE ?
188 { 187 RegExpFilter.typeMap.GENERICHIDE :
189 let parentDocDomain = getHostname(parentWndLocation); 188 RegExpFilter.typeMap.GENERICBLOCK);
190 let genericblockMatch = defaultMatcher.matchesAny( 189 let parentDocDomain = getHostname(parentWndLocation);
191 testWndLocation, RegExpFilter.typeMap.GENERICBLOCK, 190 let nogenericMatch = defaultMatcher.matchesAny(
192 parentDocDomain, false, testSitekey 191 testWndLocation, genericType, parentDocDomain, false, testSitekey
193 ); 192 );
194 if (genericblockMatch instanceof WhitelistFilter) 193 if (nogenericMatch instanceof WhitelistFilter)
195 { 194 {
196 genericblock = { 195 nogeneric = true;
197 match: genericblockMatch, 196
198 parentDocDomain: parentDocDomain, 197 FilterStorage.increaseHitCount(nogenericMatch, wnd);
199 testWnd: testWnd, 198 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType,
200 testWndLocation: testWndLocation 199 parentDocDomain, false, testWndLocation,
201 }; 200 nogenericMatch);
202 }
203 } 201 }
204 202
205 if (testWnd.parent == testWnd) 203 if (testWnd.parent == testWnd)
206 break; 204 break;
207 205
208 if (testWnd == testSitekeyWnd) 206 if (testWnd == testSitekeyWnd)
209 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); 207 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent);
210 testWnd = testWnd.parent; 208 testWnd = testWnd.parent;
211 } 209 }
212 } 210 }
213 211
214 // Data loaded by plugins should be attached to the document 212 // Data loaded by plugins should be attached to the document
215 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) 213 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement)
216 node = node.ownerDocument; 214 node = node.ownerDocument;
217 215
218 // Fix type for objects misrepresented as frames or images 216 // Fix type for objects misrepresented as frames or images
219 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) 217 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement))
220 contentType = Policy.type.OBJECT; 218 contentType = Policy.type.OBJECT;
221 219
222 let locationText = location.spec; 220 let locationText = location.spec;
223 if (!match && contentType == Policy.type.ELEMHIDE) 221 if (!match && contentType == Policy.type.ELEMHIDE)
224 { 222 {
225 let testWnd = wnd; 223 let testWnd = wnd;
226 let parentWndLocation = getWindowLocation(testWnd); 224 let parentWndLocation = getWindowLocation(testWnd);
227 while (true) 225 while (true)
228 { 226 {
229 let testWndLocation = parentWndLocation; 227 let testWndLocation = parentWndLocation;
230 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 228 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
231 let parentDocDomain = getHostname(parentWndLocation); 229 let parentDocDomain = getHostname(parentWndLocation);
232
233 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); 230 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey);
234
235 if (match instanceof WhitelistFilter) 231 if (match instanceof WhitelistFilter)
236 { 232 {
237 FilterStorage.increaseHitCount(match, wnd); 233 FilterStorage.increaseHitCount(match, wnd);
238 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); 234 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match);
239 return true; 235 return true;
240 }
241
242 let generichideMatch = defaultMatcher.matchesAny(
243 testWndLocation, RegExpFilter.typeMap.GENERICHIDE,
244 parentDocDomain, false, sitekey
245 );
246 if (generichideMatch instanceof WhitelistFilter)
247 {
248 generichide = {
249 match: generichideMatch,
250 parentDocDomain: parentDocDomain,
251 testWnd: testWnd,
252 testWndLocation: testWndLocation
253 };
254 } 236 }
Wladimir Palant 2015/09/03 13:09:42 This is simply duplicating the logic from above. I
kzar 2015/09/05 14:39:58 Done.
255 237
256 if (testWnd.parent == testWnd) 238 if (testWnd.parent == testWnd)
257 break; 239 break;
258 else 240 else
259 testWnd = testWnd.parent; 241 testWnd = testWnd.parent;
260 } 242 }
261 243
262 match = location; 244 match = location;
263 locationText = match.text.replace(/^.*?#/, '#'); 245 locationText = match.text.replace(/^.*?#/, '#');
264 location = locationText; 246 location = locationText;
265 247
266 if (!match.isActiveOnDomain(docDomain)) 248 if (!match.isActiveOnDomain(docDomain))
267 return true; 249 return true;
268 250
269 let exception = ElemHide.getException(match, docDomain); 251 let exception = ElemHide.getException(match, docDomain);
270 if (exception) 252 if (exception)
271 { 253 {
272 FilterStorage.increaseHitCount(exception, wnd); 254 FilterStorage.increaseHitCount(exception, wnd);
273 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); 255 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception);
274 return true; 256 return true;
275 } 257 }
276 258
277 if (generichide && match && match.isGeneric()) 259 if (nogeneric && match.isGeneric())
278 {
279 FilterStorage.increaseHitCount(generichide.match, wnd);
280 RequestNotifier.addNodeData(
281 generichide.testWnd.document,
282 topWnd, contentType,
283 generichide.parentDocDomain,
284 false, generichide.testWndLocation,
285 generichide.match
286 );
287 return true; 260 return true;
288 }
289 } 261 }
290 262
291 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); 263 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain));
292 264
293 if (!match && Prefs.enabled && contentType in Policy.typeMask) 265 if (!match && Prefs.enabled && contentType in Policy.typeMask)
294 { 266 {
295 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); 267 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e],
296 if (match instanceof BlockingFilter) 268 docDomain, thirdParty, sitekey, nogeneri c);
297 { 269 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual))
298 if (genericblock && match.isGeneric()) 270 {
Wladimir Palant 2015/09/03 13:09:43 What if there are multiple filters potentially mat
kzar 2015/09/04 15:49:10 Hmm good point, any suggestions? In the other revi
Wladimir Palant 2015/09/04 16:16:23 Why another search? Just pass specificOnly and be
kzar 2015/09/05 14:39:58 Oh, of course! Done.
299 { 271 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse);
300 FilterStorage.increaseHitCount(genericblock.match, wnd); 272 if (collapse || prefCollapse)
301 RequestNotifier.addNodeData( 273 schedulePostProcess(node);
302 genericblock.testWnd.document,
303 topWnd, contentType,
304 genericblock.parentDocDomain,
305 false, genericblock.testWndLocation,
306 genericblock.match
307 );
308 return true;
309 }
310
311 if (node.ownerDocument && !(contentType in Policy.nonVisual))
312 {
313 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse);
314 if (collapse || prefCollapse)
315 schedulePostProcess(node);
316 }
317 } 274 }
318 275
319 // Track mouse events for objects 276 // Track mouse events for objects
320 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) 277 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE)
321 { 278 {
322 node.addEventListener("mouseover", objectMouseEventHander, true); 279 node.addEventListener("mouseover", objectMouseEventHander, true);
323 node.addEventListener("mouseout", objectMouseEventHander, true); 280 node.addEventListener("mouseout", objectMouseEventHander, true);
324 } 281 }
325 } 282 }
326 283
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 if (!wnd || wnd.closed) 818 if (!wnd || wnd.closed)
862 return; 819 return;
863 820
864 if (entry.type == Policy.type.OBJECT) 821 if (entry.type == Policy.type.OBJECT)
865 { 822 {
866 node.removeEventListener("mouseover", objectMouseEventHander, true); 823 node.removeEventListener("mouseover", objectMouseEventHander, true);
867 node.removeEventListener("mouseout", objectMouseEventHander, true); 824 node.removeEventListener("mouseout", objectMouseEventHander, true);
868 } 825 }
869 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 826 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
870 } 827 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld