 Issue 4559243822759936:
  Issue 431/432 - Remove special handling for the $sitekey option  (Closed)
    
  
    Issue 4559243822759936:
  Issue 431/432 - Remove special handling for the $sitekey option  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 processNode: function(wnd, node, contentType, location, collapse) | 155 processNode: function(wnd, node, contentType, location, collapse) | 
| 156 { | 156 { | 
| 157 let topWnd = wnd.top; | 157 let topWnd = wnd.top; | 
| 158 if (!topWnd || !topWnd.location || !topWnd.location.href) | 158 if (!topWnd || !topWnd.location || !topWnd.location.href) | 
| 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 if (!match && Prefs.enabled) | 166 if (!match && Prefs.enabled) | 
| 166 { | 167 { | 
| 167 let testWnd = wnd; | 168 let testWnd = wnd; | 
| 169 let testSitekey = sitekey; | |
| 170 let testSitekeyWnd = sitekeyWnd; | |
| 168 let parentWndLocation = getWindowLocation(testWnd); | 171 let parentWndLocation = getWindowLocation(testWnd); | 
| 169 while (true) | 172 while (true) | 
| 170 { | 173 { | 
| 171 let testWndLocation = parentWndLocation; | 174 let testWndLocation = parentWndLocation; | 
| 172 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 175 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 
| 173 | 176 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); | 
| 174 let siteKey = getSiteKey(node, testWnd); | |
| 175 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, siteKey ); | |
| 
Wladimir Palant
2014/08/01 10:50:21
The logic here seems wrong to me. I've extended th
 
Thomas Greiner
2014/08/11 17:18:15
Done.
 | |
| 176 | 177 | 
| 177 if (match instanceof WhitelistFilter) | 178 if (match instanceof WhitelistFilter) | 
| 178 { | 179 { | 
| 179 FilterStorage.increaseHitCount(match, wnd); | 180 FilterStorage.increaseHitCount(match, wnd); | 
| 180 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); | 
| 181 return true; | 182 return true; | 
| 182 } | 183 } | 
| 183 | 184 | 
| 184 if (testWnd.parent == testWnd) | 185 if (testWnd.parent == testWnd) | 
| 185 break; | 186 break; | 
| 186 else | 187 | 
| 187 testWnd = testWnd.parent; | 188 if (testWnd == testSitekeyWnd) | 
| 189 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | |
| 190 testWnd = testWnd.parent; | |
| 188 } | 191 } | 
| 189 } | 192 } | 
| 190 | 193 | 
| 191 // Data loaded by plugins should be attached to the document | 194 // Data loaded by plugins should be attached to the document | 
| 192 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) | 195 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) | 
| 193 node = node.ownerDocument; | 196 node = node.ownerDocument; | 
| 194 | 197 | 
| 195 // Fix type for objects misrepresented as frames or images | 198 // Fix type for objects misrepresented as frames or images | 
| 196 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)) | 
| 197 contentType = Policy.type.OBJECT; | 200 contentType = Policy.type.OBJECT; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 FilterStorage.increaseHitCount(exception, wnd); | 236 FilterStorage.increaseHitCount(exception, wnd); | 
| 234 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdP arty, locationText, exception); | 237 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdP arty, locationText, exception); | 
| 235 return true; | 238 return true; | 
| 236 } | 239 } | 
| 237 } | 240 } | 
| 238 | 241 | 
| 239 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); | 242 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); | 
| 240 | 243 | 
| 241 if (!match && Prefs.enabled) | 244 if (!match && Prefs.enabled) | 
| 242 { | 245 { | 
| 243 let docLocation = getWindowLocation(wnd); | 246 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, sitekey); | 
| 244 let siteKey = getSiteKey(node, wnd); | |
| 245 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, docLocation, siteKey); | |
| 246 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) | 247 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) | 
| 247 { | 248 { | 
| 248 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); | 249 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); | 
| 249 if (collapse || prefCollapse) | 250 if (collapse || prefCollapse) | 
| 250 schedulePostProcess(node); | 251 schedulePostProcess(node); | 
| 251 } | 252 } | 
| 252 | 253 | 
| 253 // Track mouse events for objects | 254 // Track mouse events for objects | 
| 254 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) | 
| 255 { | 256 { | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 272 * @return {Boolean} | 273 * @return {Boolean} | 
| 273 */ | 274 */ | 
| 274 isBlockableScheme: function(location) | 275 isBlockableScheme: function(location) | 
| 275 { | 276 { | 
| 276 return !(location.scheme in Policy.whitelistSchemes); | 277 return !(location.scheme in Policy.whitelistSchemes); | 
| 277 }, | 278 }, | 
| 278 | 279 | 
| 279 /** | 280 /** | 
| 280 * Checks whether a page is whitelisted. | 281 * Checks whether a page is whitelisted. | 
| 281 * @param {String} url | 282 * @param {String} url | 
| 282 * @param {String} parentUrl location of the parent page | 283 * @param {String} [parentUrl] location of the parent page | 
| 283 * @param {String} siteKey public key provided on the page | 284 * @param {String} [sitekey] public key provided on the page | 
| 284 * @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 | 
| 285 */ | 286 */ | 
| 286 isWhitelisted: function(url, parentUrl, siteKey) | 287 isWhitelisted: function(url, parentUrl, sitekey) | 
| 
Wladimir Palant
2014/08/01 10:50:21
If you change the parameters here you probably wan
 
Thomas Greiner
2014/08/11 17:18:15
Done.
 | |
| 287 { | 288 { | 
| 288 if (!url) | 289 if (!url) | 
| 289 return null; | 290 return null; | 
| 290 | 291 | 
| 291 // Do not apply exception rules to schemes on our whitelistschemes list. | 292 // Do not apply exception rules to schemes on our whitelistschemes list. | 
| 292 let match = /^([\w\-]+):/.exec(url); | 293 let match = /^([\w\-]+):/.exec(url); | 
| 293 if (match && match[1] in Policy.whitelistSchemes) | 294 if (match && match[1] in Policy.whitelistSchemes) | 
| 294 return null; | 295 return null; | 
| 295 | 296 | 
| 296 if (!parentUrl) | 297 if (!parentUrl) | 
| 297 parentUrl = url; | 298 parentUrl = url; | 
| 
Wladimir Palant
2014/08/01 10:50:21
If parentUrl is no longer optional then this code
 
Thomas Greiner
2014/08/11 17:18:15
Technically, it's still optional since it's only r
 | |
| 298 | 299 | 
| 299 // Ignore fragment identifier | 300 // Ignore fragment identifier | 
| 300 let index = url.indexOf("#"); | 301 let index = url.indexOf("#"); | 
| 301 if (index >= 0) | 302 if (index >= 0) | 
| 302 url = url.substring(0, index); | 303 url = url.substring(0, index); | 
| 303 | 304 | 
| 304 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false, parentUrl, siteKey); | 305 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false, sitekey); | 
| 305 return (result instanceof WhitelistFilter ? result : null); | 306 return (result instanceof WhitelistFilter ? result : null); | 
| 306 }, | 307 }, | 
| 307 | 308 | 
| 308 /** | 309 /** | 
| 309 * 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. | 
| 310 * @param wnd {nsIDOMWindow} | 311 * @param wnd {nsIDOMWindow} | 
| 311 * @return {Filter} matching exception rule or null if not whitelisted | 312 * @return {Filter} matching exception rule or null if not whitelisted | 
| 312 */ | 313 */ | 
| 313 isWindowWhitelisted: function(wnd) | 314 isWindowWhitelisted: function(wnd) | 
| 314 { | 315 { | 
| 315 return Policy.isWhitelisted(getWindowLocation(wnd)); | 316 return Policy.isWhitelisted(getWindowLocation(wnd)); | 
| 316 }, | 317 }, | 
| 317 | |
| 318 | 318 | 
| 319 /** | 319 /** | 
| 320 * Asynchronously re-checks filters for given nodes. | 320 * Asynchronously re-checks filters for given nodes. | 
| 321 */ | 321 */ | 
| 322 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry) | 322 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry) | 
| 323 { | 323 { | 
| 324 // Ignore nodes that have been blocked already | 324 // Ignore nodes that have been blocked already | 
| 325 if (entry.filter && !(entry.filter instanceof WhitelistFilter)) | 325 if (entry.filter && !(entry.filter instanceof WhitelistFilter)) | 
| 326 return; | 326 return; | 
| 327 | 327 | 
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 } | 669 } | 
| 670 catch(e) | 670 catch(e) | 
| 671 { | 671 { | 
| 672 return null; | 672 return null; | 
| 673 } | 673 } | 
| 674 } | 674 } | 
| 675 | 675 | 
| 676 /** | 676 /** | 
| 677 * Retrieves the sitekey of a window. | 677 * Retrieves the sitekey of a window. | 
| 678 */ | 678 */ | 
| 679 function getSiteKey(node, wnd) | 679 function getSitekey(wnd) | 
| 
Wladimir Palant
2014/08/01 10:50:21
Why pass in node parameter that isn't used?
 
Thomas Greiner
2014/08/11 17:18:15
Done.
 | |
| 680 { | 680 { | 
| 681 if (wnd.document && wnd.document.documentElement) | 681 let sitekey = null; | 
| 682 return wnd.document.documentElement.getAttribute("data-adblockkey"); | 682 | 
| 683 | 683 while (true) | 
| 684 return null; | 684 { | 
| 685 if (wnd.document && wnd.document.documentElement) | |
| 686 { | |
| 687 let keydata = wnd.document.documentElement.getAttribute("data-adblockkey") ; | |
| 688 if (keydata && keydata.indexOf("_") >= 0) | |
| 689 { | |
| 690 let [key, signature] = keydata.split("_", 2); | |
| 691 key = key.replace(/=/g, ""); | |
| 692 | |
| 693 // Website specifies a key but is the signature valid? | |
| 694 let uri = Services.io.newURI(getWindowLocation(wnd), null, null); | |
| 695 let host = uri.asciiHost; | |
| 696 if (uri.port > 0) | |
| 697 host += ":" + uri.port; | |
| 698 let params = [ | |
| 699 uri.path.replace(/#.*/, ""), // REQUEST_URI | |
| 700 host, // HTTP_HOST | |
| 701 Utils.httpProtocol.userAgent // HTTP_USER_AGENT | |
| 702 ]; | |
| 703 if (Utils.verifySignature(key, signature, params.join("\0"))) | |
| 704 return [key, wnd]; | |
| 705 } | |
| 706 } | |
| 707 | |
| 708 if (wnd === wnd.parent) | |
| 709 break; | |
| 710 | |
| 711 wnd = wnd.parent; | |
| 712 } | |
| 713 | |
| 714 return [sitekey, wnd]; | |
| 685 } | 715 } | 
| 686 | 716 | 
| 687 /** | 717 /** | 
| 688 * Retrieves the location of a window. | 718 * Retrieves the location of a window. | 
| 689 * @param wnd {nsIDOMWindow} | 719 * @param wnd {nsIDOMWindow} | 
| 690 * @return {String} window location or null on failure | 720 * @return {String} window location or null on failure | 
| 691 */ | 721 */ | 
| 692 function getWindowLocation(wnd) | 722 function getWindowLocation(wnd) | 
| 693 { | 723 { | 
| 694 if ("name" in wnd && wnd.name == "messagepane") | 724 if ("name" in wnd && wnd.name == "messagepane") | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 if (!wnd || wnd.closed) | 789 if (!wnd || wnd.closed) | 
| 760 return; | 790 return; | 
| 761 | 791 | 
| 762 if (entry.type == Policy.type.OBJECT) | 792 if (entry.type == Policy.type.OBJECT) | 
| 763 { | 793 { | 
| 764 node.removeEventListener("mouseover", objectMouseEventHander, true); | 794 node.removeEventListener("mouseover", objectMouseEventHander, true); | 
| 765 node.removeEventListener("mouseout", objectMouseEventHander, true); | 795 node.removeEventListener("mouseout", objectMouseEventHander, true); | 
| 766 } | 796 } | 
| 767 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; | 797 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; | 
| 768 } | 798 } | 
| LEFT | RIGHT |