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. Created March 12, 2015, 8:33 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);
253 if (match instanceof BlockingFilter && (!match.domains || match.domains["" ]) && genericblock.match instanceof WhitelistFilter)
254 {
255 FilterStorage.increaseHitCount(genericblock.match, wnd);
256 RequestNotifier.addNodeData(
257 genericblock.testWnd.document,
258 topWnd, contentType,
259 genericblock.parentDocDomain,
260 false, genericblock.testWndLocation,
261 genericblock.match
262 );
263 return true;
264 }
265
237 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) 266 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual))
238 { 267 {
239 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); 268 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse);
240 if (collapse || prefCollapse) 269 if (collapse || prefCollapse)
241 schedulePostProcess(node); 270 schedulePostProcess(node);
242 } 271 }
243 272
244 // Track mouse events for objects 273 // Track mouse events for objects
245 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) 274 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE)
246 { 275 {
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (!wnd || wnd.closed) 808 if (!wnd || wnd.closed)
780 return; 809 return;
781 810
782 if (entry.type == Policy.type.OBJECT) 811 if (entry.type == Policy.type.OBJECT)
783 { 812 {
784 node.removeEventListener("mouseover", objectMouseEventHander, true); 813 node.removeEventListener("mouseover", objectMouseEventHander, true);
785 node.removeEventListener("mouseout", objectMouseEventHander, true); 814 node.removeEventListener("mouseout", objectMouseEventHander, true);
786 } 815 }
787 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 816 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
788 } 817 }
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