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: Tidied up genericblock logic in contentPolicy code. Created March 13, 2015, 6:46 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 { 146 {
147 let topWnd = wnd.top; 147 let topWnd = wnd.top;
148 if (!topWnd || !topWnd.location || !topWnd.location.href) 148 if (!topWnd || !topWnd.location || !topWnd.location.href)
149 return true; 149 return true;
150 150
151 let originWindow = Utils.getOriginWindow(wnd); 151 let originWindow = Utils.getOriginWindow(wnd);
152 let wndLocation = originWindow.location.href; 152 let wndLocation = originWindow.location.href;
153 let docDomain = getHostname(wndLocation); 153 let docDomain = getHostname(wndLocation);
154 let match = null; 154 let match = null;
155 let [sitekey, sitekeyWnd] = getSitekey(wnd); 155 let [sitekey, sitekeyWnd] = getSitekey(wnd);
156 let genericblock = { match: null };
156 if (!match && Prefs.enabled) 157 if (!match && Prefs.enabled)
157 { 158 {
158 let testWnd = wnd; 159 let testWnd = wnd;
159 let testSitekey = sitekey; 160 let testSitekey = sitekey;
160 let testSitekeyWnd = sitekeyWnd; 161 let testSitekeyWnd = sitekeyWnd;
161 let parentWndLocation = getWindowLocation(testWnd); 162 let parentWndLocation = getWindowLocation(testWnd);
162 while (true) 163 while (true)
163 { 164 {
164 let testWndLocation = parentWndLocation; 165 let testWndLocation = parentWndLocation;
165 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 166 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
166 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); 167 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey);
167 168
168 if (match instanceof WhitelistFilter) 169 if (match instanceof WhitelistFilter)
169 { 170 {
170 FilterStorage.increaseHitCount(match, wnd); 171 FilterStorage.increaseHitCount(match, wnd);
171 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); 172 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match);
172 return true; 173 return true;
173 } 174 }
175 else if (!(genericblock.match instanceof WhitelistFilter) && contentType != Policy.type.ELEMHIDE)
176 {
177 let parentDocDomain = getHostname(parentWndLocation);
178 genericblock.match = defaultMatcher.matchesAny(testWndLocation, "GENER ICBLOCK", parentDocDomain, false);
179 if (genericblock.match instanceof WhitelistFilter)
180 {
181 genericblock.parentDocDomain = parentDocDomain;
182 genericblock.testWnd = testWnd;
183 genericblock.testWndLocation = testWndLocation;
184 }
185 }
174 186
175 if (testWnd.parent == testWnd) 187 if (testWnd.parent == testWnd)
176 break; 188 break;
177 189
178 if (testWnd == testSitekeyWnd) 190 if (testWnd == testSitekeyWnd)
179 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); 191 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent);
180 testWnd = testWnd.parent; 192 testWnd = testWnd.parent;
181 } 193 }
182 } 194 }
183 195
184 // Data loaded by plugins should be attached to the document 196 // Data loaded by plugins should be attached to the document
185 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) 197 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement)
186 node = node.ownerDocument; 198 node = node.ownerDocument;
187 199
188 // Fix type for objects misrepresented as frames or images 200 // Fix type for objects misrepresented as frames or images
189 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) 201 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement))
190 contentType = Policy.type.OBJECT; 202 contentType = Policy.type.OBJECT;
191 203
192 let locationText = location.spec; 204 let locationText = location.spec;
193 if (!match && contentType == Policy.type.ELEMHIDE) 205 if (!match && contentType == Policy.type.ELEMHIDE)
194 { 206 {
195 let testWnd = wnd; 207 let testWnd = wnd;
196 let parentWndLocation = getWindowLocation(testWnd); 208 let parentWndLocation = getWindowLocation(testWnd);
197 while (true) 209 while (true)
198 { 210 {
199 let testWndLocation = parentWndLocation; 211 let testWndLocation = parentWndLocation;
200 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 212 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
201 let parentDocDomain = getHostname(parentWndLocation); 213 let parentDocDomain = getHostname(parentWndLocation);
202 match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc Domain, false); 214 match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc Domain, false);
215
216 if (!(match instanceof WhitelistFilter) && (!location.domains || locatio n.domains[""]))
217 match = defaultMatcher.matchesAny(testWndLocation, "GENERICHIDE", pare ntDocDomain, false);
218
203 if (match instanceof WhitelistFilter) 219 if (match instanceof WhitelistFilter)
204 { 220 {
205 FilterStorage.increaseHitCount(match, wnd); 221 FilterStorage.increaseHitCount(match, wnd);
206 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); 222 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match);
207 return true; 223 return true;
208 } 224 }
209 225
210 if (testWnd.parent == testWnd) 226 if (testWnd.parent == testWnd)
211 break; 227 break;
212 else 228 else
(...skipping 14 matching lines...) Expand all
227 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); 243 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception);
228 return true; 244 return true;
229 } 245 }
230 } 246 }
231 247
232 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); 248 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain));
233 249
234 if (!match && Prefs.enabled) 250 if (!match && Prefs.enabled)
235 { 251 {
236 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, sitekey); 252 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, sitekey);
237 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) 253 if (match instanceof BlockingFilter)
238 { 254 {
239 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); 255 if ((!match.domains || match.domains[""]) && genericblock.match instance of WhitelistFilter)
240 if (collapse || prefCollapse) 256 {
241 schedulePostProcess(node); 257 FilterStorage.increaseHitCount(genericblock.match, wnd);
258 RequestNotifier.addNodeData(
259 genericblock.testWnd.document,
260 topWnd, contentType,
261 genericblock.parentDocDomain,
262 false, genericblock.testWndLocation,
263 genericblock.match
264 );
265 return true;
266 }
267
268 if (node.ownerDocument && !(contentType in Policy.nonVisual))
269 {
270 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse);
271 if (collapse || prefCollapse)
272 schedulePostProcess(node);
273 }
242 } 274 }
243 275
244 // Track mouse events for objects 276 // Track mouse events for objects
245 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)
246 { 278 {
247 node.addEventListener("mouseover", objectMouseEventHander, true); 279 node.addEventListener("mouseover", objectMouseEventHander, true);
248 node.addEventListener("mouseout", objectMouseEventHander, true); 280 node.addEventListener("mouseout", objectMouseEventHander, true);
249 } 281 }
250 } 282 }
251 283
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (!wnd || wnd.closed) 811 if (!wnd || wnd.closed)
780 return; 812 return;
781 813
782 if (entry.type == Policy.type.OBJECT) 814 if (entry.type == Policy.type.OBJECT)
783 { 815 {
784 node.removeEventListener("mouseover", objectMouseEventHander, true); 816 node.removeEventListener("mouseover", objectMouseEventHander, true);
785 node.removeEventListener("mouseout", objectMouseEventHander, true); 817 node.removeEventListener("mouseout", objectMouseEventHander, true);
786 } 818 }
787 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 819 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
788 } 820 }
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