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

Delta Between Two Patch Sets: lib/contentPolicy.js

Issue 4559243822759936: Issue 431/432 - Remove special handling for the $sitekey option (Closed)
Left Patch Set: Created Aug. 12, 2014, 9:30 a.m.
Right Patch Set: Made changes for WebKit bug 132872 Created Sept. 1, 2014, 3:27 p.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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return true; 159 return true;
160 160
161 let originWindow = Utils.getOriginWindow(wnd); 161 let originWindow = Utils.getOriginWindow(wnd);
162 let wndLocation = originWindow.location.href; 162 let wndLocation = originWindow.location.href;
163 let docDomain = getHostname(wndLocation); 163 let docDomain = getHostname(wndLocation);
164 let match = null; 164 let match = null;
165 let [sitekey, sitekeyWnd] = getSitekey(wnd); 165 let [sitekey, sitekeyWnd] = getSitekey(wnd);
166 if (!match && Prefs.enabled) 166 if (!match && Prefs.enabled)
167 { 167 {
168 let testWnd = wnd; 168 let testWnd = wnd;
169 let testSitekey = sitekey;
170 let testSitekeyWnd = sitekeyWnd;
169 let parentWndLocation = getWindowLocation(testWnd); 171 let parentWndLocation = getWindowLocation(testWnd);
170 while (true) 172 while (true)
171 { 173 {
172 let testWndLocation = parentWndLocation; 174 let testWndLocation = parentWndLocation;
173 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); 175 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent));
174 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, sitekey ); 176 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey);
175 177
176 if (match instanceof WhitelistFilter) 178 if (match instanceof WhitelistFilter)
177 { 179 {
178 FilterStorage.increaseHitCount(match, wnd); 180 FilterStorage.increaseHitCount(match, wnd);
179 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);
180 return true; 182 return true;
181 } 183 }
182 184
183 if (testWnd.parent == testWnd) 185 if (testWnd.parent == testWnd)
184 break; 186 break;
185 else 187
186 { 188 if (testWnd == testSitekeyWnd)
187 if (testWnd == sitekeyWnd) 189 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent);
188 [sitekey, sitekeyWnd] = getSitekey(testWnd.parent); 190 testWnd = testWnd.parent;
189 testWnd = testWnd.parent;
190 }
Wladimir Palant 2014/08/14 19:58:15 Nit: I'd put these lines without an |else| block h
Thomas Greiner 2014/08/29 15:57:29 Done.
191 } 191 }
192 } 192 }
193 193
194 // Data loaded by plugins should be attached to the document 194 // Data loaded by plugins should be attached to the document
195 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) 195 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement)
196 node = node.ownerDocument; 196 node = node.ownerDocument;
197 197
198 // Fix type for objects misrepresented as frames or images 198 // Fix type for objects misrepresented as frames or images
199 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) 199 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement))
200 contentType = Policy.type.OBJECT; 200 contentType = Policy.type.OBJECT;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 FilterStorage.increaseHitCount(exception, wnd); 236 FilterStorage.increaseHitCount(exception, wnd);
237 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdP arty, locationText, exception); 237 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdP arty, locationText, exception);
238 return true; 238 return true;
239 } 239 }
240 } 240 }
241 241
242 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); 242 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain));
243 243
244 if (!match && Prefs.enabled) 244 if (!match && Prefs.enabled)
245 { 245 {
246 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, sitekey); 246 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, sitekey);
Wladimir Palant 2014/08/14 19:58:15 This is the sitekey of the top-level window, not t
Thomas Greiner 2014/08/29 15:57:29 Done.
247 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) 247 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual))
248 { 248 {
249 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); 249 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse);
250 if (collapse || prefCollapse) 250 if (collapse || prefCollapse)
251 schedulePostProcess(node); 251 schedulePostProcess(node);
252 } 252 }
253 253
254 // Track mouse events for objects 254 // Track mouse events for objects
255 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) 255 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE)
256 { 256 {
(...skipping 16 matching lines...) Expand all
273 * @return {Boolean} 273 * @return {Boolean}
274 */ 274 */
275 isBlockableScheme: function(location) 275 isBlockableScheme: function(location)
276 { 276 {
277 return !(location.scheme in Policy.whitelistSchemes); 277 return !(location.scheme in Policy.whitelistSchemes);
278 }, 278 },
279 279
280 /** 280 /**
281 * Checks whether a page is whitelisted. 281 * Checks whether a page is whitelisted.
282 * @param {String} url 282 * @param {String} url
283 * @param {String} (optional) parentUrl location of the parent page 283 * @param {String} [parentUrl] location of the parent page
284 * @param {String} (optional) sitekey public key provided on the page 284 * @param {String} [sitekey] public key provided on the page
Wladimir Palant 2014/08/14 19:58:15 Please see https://code.google.com/p/jsdoc-toolkit
Thomas Greiner 2014/08/29 15:57:29 Done. I was using the syntax used in lib/filterCla
285 * @return {Filter} filter that matched the URL or null if not whitelisted 285 * @return {Filter} filter that matched the URL or null if not whitelisted
286 */ 286 */
287 isWhitelisted: function(url, parentUrl, sitekey) 287 isWhitelisted: function(url, parentUrl, sitekey)
288 { 288 {
289 if (!url) 289 if (!url)
290 return null; 290 return null;
291 291
292 // Do not apply exception rules to schemes on our whitelistschemes list. 292 // Do not apply exception rules to schemes on our whitelistschemes list.
293 let match = /^([\w\-]+):/.exec(url); 293 let match = /^([\w\-]+):/.exec(url);
294 if (match && match[1] in Policy.whitelistSchemes) 294 if (match && match[1] in Policy.whitelistSchemes)
295 return null; 295 return null;
296 296
297 if (!parentUrl) 297 if (!parentUrl)
298 parentUrl = url; 298 parentUrl = url;
299 299
300 // Ignore fragment identifier 300 // Ignore fragment identifier
301 let index = url.indexOf("#"); 301 let index = url.indexOf("#");
302 if (index >= 0) 302 if (index >= 0)
303 url = url.substring(0, index); 303 url = url.substring(0, index);
304 304
305 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false, sitekey); 305 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false, sitekey);
306 return (result instanceof WhitelistFilter ? result : null); 306 return (result instanceof WhitelistFilter ? result : null);
307 }, 307 },
308 308
309 /** 309 /**
310 * Checks whether the page loaded in a window is whitelisted. 310 * Checks whether the page loaded in a window is whitelisted for indication in the UI.
311 * @param wnd {nsIDOMWindow} 311 * @param wnd {nsIDOMWindow}
312 * @return {Filter} matching exception rule or null if not whitelisted 312 * @return {Filter} matching exception rule or null if not whitelisted
313 */ 313 */
314 isWindowWhitelisted: function(wnd) 314 isWindowWhitelisted: function(wnd)
315 { 315 {
316 let url = getWindowLocation(wnd); 316 return Policy.isWhitelisted(getWindowLocation(wnd));
317 let parentUrl = (wnd.parent) ? getWindowLocation(wnd.parent) : url;
318 let [sitekey, sitekeyWnd] = getSitekey(wnd);
319 return Policy.isWhitelisted(url, parentUrl, sitekey);
Wladimir Palant 2014/08/14 19:58:15 This function is meant to be used from the UI, its
Thomas Greiner 2014/08/29 15:57:29 Done. I'll create an issue for that.
320 }, 317 },
321 318
322 /** 319 /**
323 * Asynchronously re-checks filters for given nodes. 320 * Asynchronously re-checks filters for given nodes.
324 */ 321 */
325 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry) 322 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry)
326 { 323 {
327 // Ignore nodes that have been blocked already 324 // Ignore nodes that have been blocked already
328 if (entry.filter && !(entry.filter instanceof WhitelistFilter)) 325 if (entry.filter && !(entry.filter instanceof WhitelistFilter))
329 return; 326 return;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 673 }
677 } 674 }
678 675
679 /** 676 /**
680 * Retrieves the sitekey of a window. 677 * Retrieves the sitekey of a window.
681 */ 678 */
682 function getSitekey(wnd) 679 function getSitekey(wnd)
683 { 680 {
684 let sitekey = null; 681 let sitekey = null;
685 682
686 if (Utils.crypto) 683 while (true)
Wladimir Palant 2014/08/14 19:58:15 This is a pointless assumption about the inner wor
Thomas Greiner 2014/08/29 15:57:29 Done.
687 { 684 {
688 while (wnd) 685 if (wnd.document && wnd.document.documentElement)
Wladimir Palant 2014/08/14 19:58:15 This is misleading: we don't expect wnd to ever be
Thomas Greiner 2014/08/29 15:57:29 Done.
689 { 686 {
690 if (wnd.document && wnd.document.documentElement) 687 let keydata = wnd.document.documentElement.getAttribute("data-adblockkey") ;
691 { 688 if (keydata && keydata.indexOf("_") >= 0)
692 let foundKey = wnd.document.documentElement.getAttribute("data-adblockke y"); 689 {
693 if (foundKey && foundKey.indexOf("_") > - 1) 690 let [key, signature] = keydata.split("_", 2);
Wladimir Palant 2014/08/14 19:58:15 The original code uses ">= 0" here, why change it
Thomas Greiner 2014/08/29 15:57:29 Done.
694 { 691 key = key.replace(/=/g, "");
695 let [key, signature] = foundKey.split("_", 2); 692
696 693 // Website specifies a key but is the signature valid?
697 // Website specifies a key but is the signature valid? 694 let uri = Services.io.newURI(getWindowLocation(wnd), null, null);
698 let uri = Services.io.newURI(getWindowLocation(wnd), null, null); 695 let host = uri.asciiHost;
699 let host = uri.asciiHost; 696 if (uri.port > 0)
700 if (uri.port > 0) 697 host += ":" + uri.port;
701 host += ":" + uri.port; 698 let params = [
702 let params = [ 699 uri.path.replace(/#.*/, ""), // REQUEST_URI
703 uri.path.replace(/#.*/, ""), // REQUEST_URI 700 host, // HTTP_HOST
704 host, // HTTP_HOST 701 Utils.httpProtocol.userAgent // HTTP_USER_AGENT
705 Utils.httpProtocol.userAgent // HTTP_USER_AGENT 702 ];
706 ]; 703 if (Utils.verifySignature(key, signature, params.join("\0")))
707 if (Utils.verifySignature(key, signature, params.join("\0"))) 704 return [key, wnd];
708 sitekey = foundKey; 705 }
Wladimir Palant 2014/08/14 19:58:15 The current code will ignore a valid key further u
Thomas Greiner 2014/08/29 15:57:29 Done.
709 } 706 }
710 break; 707
711 } 708 if (wnd === wnd.parent)
712 709 break;
713 if (wnd === wnd.top) 710
Wladimir Palant 2014/08/14 19:58:15 I would compare to the parent here, as in the orig
Thomas Greiner 2014/08/29 15:57:29 Done.
714 break; 711 wnd = wnd.parent;
715
716 wnd = wnd.parent;
717 }
718 } 712 }
719 713
720 return [sitekey, wnd]; 714 return [sitekey, wnd];
721 } 715 }
722 716
723 /** 717 /**
724 * Retrieves the location of a window. 718 * Retrieves the location of a window.
725 * @param wnd {nsIDOMWindow} 719 * @param wnd {nsIDOMWindow}
726 * @return {String} window location or null on failure 720 * @return {String} window location or null on failure
727 */ 721 */
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 if (!wnd || wnd.closed) 789 if (!wnd || wnd.closed)
796 return; 790 return;
797 791
798 if (entry.type == Policy.type.OBJECT) 792 if (entry.type == Policy.type.OBJECT)
799 { 793 {
800 node.removeEventListener("mouseover", objectMouseEventHander, true); 794 node.removeEventListener("mouseover", objectMouseEventHander, true);
801 node.removeEventListener("mouseout", objectMouseEventHander, true); 795 node.removeEventListener("mouseout", objectMouseEventHander, true);
802 } 796 }
803 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 797 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
804 } 798 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld