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: Use camelCase for genericblockMatch variable name Created July 15, 2015, 3:09 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
166 if (!match && Prefs.enabled) 167 if (!match && Prefs.enabled)
167 { 168 {
168 let testWnd = wnd; 169 let testWnd = wnd;
169 let testSitekey = sitekey; 170 let testSitekey = sitekey;
170 let testSitekeyWnd = sitekeyWnd; 171 let testSitekeyWnd = sitekeyWnd;
171 let parentWndLocation = getWindowLocation(testWnd); 172 let parentWndLocation = getWindowLocation(testWnd);
172 while (true) 173 while (true)
173 { 174 {
174 let testWndLocation = parentWndLocation; 175 let testWndLocation = parentWndLocation;
175 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 176 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
176 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); 177 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey);
177 178
178 if (match instanceof WhitelistFilter) 179 if (match instanceof WhitelistFilter)
179 { 180 {
180 FilterStorage.increaseHitCount(match, wnd); 181 FilterStorage.increaseHitCount(match, wnd);
181 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);
182 return true; 183 return true;
183 } 184 }
184 else if (contentType != Policy.type.ELEMHIDE) 185
185 { 186 let genericType = (contentType == Policy.type.ELEMHIDE ?
186 let parentDocDomain = getHostname(parentWndLocation); 187 RegExpFilter.typeMap.GENERICHIDE :
187 let genericblockMatch = defaultMatcher.matchesAny(testWndLocation, Reg ExpFilter.typeMap.GENERICBLOCK, parentDocDomain, false); 188 RegExpFilter.typeMap.GENERICBLOCK);
Thomas Greiner 2015/08/20 11:36:06 You forgot to pass the sitekey as the last paramet
kzar 2015/08/25 17:42:07 Done.
188 if (genericblockMatch instanceof WhitelistFilter) 189 let parentDocDomain = getHostname(parentWndLocation);
189 { 190 let nogenericMatch = defaultMatcher.matchesAny(
190 genericblock = { 191 testWndLocation, genericType, parentDocDomain, false, testSitekey
191 match: genericblockMatch, 192 );
192 parentDocDomain: parentDocDomain, 193 if (nogenericMatch instanceof WhitelistFilter)
193 testWnd: testWnd, 194 {
194 testWndLocation: testWndLocation 195 nogeneric = true;
195 }; 196
196 } 197 FilterStorage.increaseHitCount(nogenericMatch, wnd);
198 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType,
199 parentDocDomain, false, testWndLocation,
200 nogenericMatch);
197 } 201 }
198 202
199 if (testWnd.parent == testWnd) 203 if (testWnd.parent == testWnd)
200 break; 204 break;
201 205
202 if (testWnd == testSitekeyWnd) 206 if (testWnd == testSitekeyWnd)
203 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); 207 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent);
204 testWnd = testWnd.parent; 208 testWnd = testWnd.parent;
205 } 209 }
206 } 210 }
207 211
208 // Data loaded by plugins should be attached to the document 212 // Data loaded by plugins should be attached to the document
209 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) 213 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement)
210 node = node.ownerDocument; 214 node = node.ownerDocument;
211 215
212 // Fix type for objects misrepresented as frames or images 216 // Fix type for objects misrepresented as frames or images
213 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))
214 contentType = Policy.type.OBJECT; 218 contentType = Policy.type.OBJECT;
215 219
216 let locationText = location.spec; 220 let locationText = location.spec;
217 if (!match && contentType == Policy.type.ELEMHIDE) 221 if (!match && contentType == Policy.type.ELEMHIDE)
218 { 222 {
219 let testWnd = wnd; 223 let testWnd = wnd;
220 let parentWndLocation = getWindowLocation(testWnd); 224 let parentWndLocation = getWindowLocation(testWnd);
221 while (true) 225 while (true)
222 { 226 {
223 let testWndLocation = parentWndLocation; 227 let testWndLocation = parentWndLocation;
224 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 228 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
225 let parentDocDomain = getHostname(parentWndLocation); 229 let parentDocDomain = getHostname(parentWndLocation);
226
227 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); 230 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey);
228
229 if (!(match instanceof WhitelistFilter) && (!location.domains || locatio n.domains[""]))
Thomas Greiner 2015/08/20 11:36:06 What about filters that don't specify domains but
Thomas Greiner 2015/08/20 11:36:06 I guess you meant to write (!match.domains || mat
kzar 2015/08/25 17:42:07 Done.
230 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMa p.GENERICHIDE, parentDocDomain, false);
231
232 if (match instanceof WhitelistFilter) 231 if (match instanceof WhitelistFilter)
233 { 232 {
234 FilterStorage.increaseHitCount(match, wnd); 233 FilterStorage.increaseHitCount(match, wnd);
235 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); 234 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match);
236 return true; 235 return true;
237 } 236 }
238 237
239 if (testWnd.parent == testWnd) 238 if (testWnd.parent == testWnd)
240 break; 239 break;
241 else 240 else
242 testWnd = testWnd.parent; 241 testWnd = testWnd.parent;
243 } 242 }
244 243
245 match = location; 244 match = location;
246 locationText = match.text.replace(/^.*?#/, '#'); 245 locationText = match.text.replace(/^.*?#/, '#');
247 location = locationText; 246 location = locationText;
248 247
249 if (!match.isActiveOnDomain(docDomain)) 248 if (!match.isActiveOnDomain(docDomain))
250 return true; 249 return true;
251 250
252 let exception = ElemHide.getException(match, docDomain); 251 let exception = ElemHide.getException(match, docDomain);
253 if (exception) 252 if (exception)
254 { 253 {
255 FilterStorage.increaseHitCount(exception, wnd); 254 FilterStorage.increaseHitCount(exception, wnd);
256 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); 255 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception);
257 return true; 256 return true;
258 } 257 }
258
259 if (nogeneric && match.isGeneric())
260 return true;
259 } 261 }
260 262
261 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); 263 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain));
262 264
263 if (!match && Prefs.enabled && contentType in Policy.typeMask) 265 if (!match && Prefs.enabled && contentType in Policy.typeMask)
264 { 266 {
265 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); 267 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e],
266 if (match instanceof BlockingFilter) 268 docDomain, thirdParty, sitekey, nogeneri c);
267 { 269 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual))
268 if ((!match.domains || match.domains[""]) && genericblock) 270 {
269 { 271 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse);
270 FilterStorage.increaseHitCount(genericblock.match, wnd); 272 if (collapse || prefCollapse)
271 RequestNotifier.addNodeData( 273 schedulePostProcess(node);
272 genericblock.testWnd.document,
273 topWnd, contentType,
274 genericblock.parentDocDomain,
275 false, genericblock.testWndLocation,
276 genericblock.match
277 );
278 return true;
279 }
280
281 if (node.ownerDocument && !(contentType in Policy.nonVisual))
282 {
283 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse);
284 if (collapse || prefCollapse)
285 schedulePostProcess(node);
286 }
287 } 274 }
288 275
289 // Track mouse events for objects 276 // Track mouse events for objects
290 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)
291 { 278 {
292 node.addEventListener("mouseover", objectMouseEventHander, true); 279 node.addEventListener("mouseover", objectMouseEventHander, true);
293 node.addEventListener("mouseout", objectMouseEventHander, true); 280 node.addEventListener("mouseout", objectMouseEventHander, true);
294 } 281 }
295 } 282 }
296 283
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 if (!wnd || wnd.closed) 818 if (!wnd || wnd.closed)
832 return; 819 return;
833 820
834 if (entry.type == Policy.type.OBJECT) 821 if (entry.type == Policy.type.OBJECT)
835 { 822 {
836 node.removeEventListener("mouseover", objectMouseEventHander, true); 823 node.removeEventListener("mouseover", objectMouseEventHander, true);
837 node.removeEventListener("mouseout", objectMouseEventHander, true); 824 node.removeEventListener("mouseout", objectMouseEventHander, true);
838 } 825 }
839 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 826 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
840 } 827 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld