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

Side by Side Diff: lib/contentPolicy.js

Issue 29329547: Issue 3208 - Move isBlockableScheme call from shouldLoad() into processNode() (Closed)
Patch Set: Fixed typo Created Nov. 1, 2015, 12:23 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 | no next file » | 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 * @param location {String} 115 * @param location {String}
116 * @param collapse {Boolean} true to force hiding of the node 116 * @param collapse {Boolean} true to force hiding of the node
117 * @return {Boolean} false if the node should be blocked 117 * @return {Boolean} false if the node should be blocked
118 */ 118 */
119 processNode: function(wnd, node, contentType, location, collapse) 119 processNode: function(wnd, node, contentType, location, collapse)
120 { 120 {
121 let topWnd = wnd.top; 121 let topWnd = wnd.top;
122 if (!topWnd || !topWnd.location || !topWnd.location.href) 122 if (!topWnd || !topWnd.location || !topWnd.location.href)
123 return true; 123 return true;
124 124
125 // Ignore whitelisted schemes
126 if (!this.isBlockableScheme(location))
127 return true;
128
125 // Interpret unknown types as "other" 129 // Interpret unknown types as "other"
126 if (!this.contentTypes.has(contentType)) 130 if (!this.contentTypes.has(contentType))
127 contentType = "OTHER"; 131 contentType = "OTHER";
128 132
129 let originWindow = Utils.getOriginWindow(wnd); 133 let originWindow = Utils.getOriginWindow(wnd);
130 let wndLocation = originWindow.location.href; 134 let wndLocation = originWindow.location.href;
131 let docDomain = getHostname(wndLocation); 135 let docDomain = getHostname(wndLocation);
132 let match = null; 136 let match = null;
133 let [sitekey, sitekeyWnd] = getSitekey(wnd); 137 let [sitekey, sitekeyWnd] = getSitekey(wnd);
134 let nogeneric = false; 138 let nogeneric = false;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Store node data 252 // Store node data
249 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdParty , location, match); 253 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdParty , location, match);
250 if (match) 254 if (match)
251 addHit(match); 255 addHit(match);
252 256
253 return !match || match instanceof WhitelistFilter; 257 return !match || match instanceof WhitelistFilter;
254 }, 258 },
255 259
256 /** 260 /**
257 * Checks whether the location's scheme is blockable. 261 * Checks whether the location's scheme is blockable.
258 * @param location {nsIURI} 262 * @param location {nsIURI|String}
259 * @return {Boolean} 263 * @return {Boolean}
260 */ 264 */
261 isBlockableScheme: function(location) 265 isBlockableScheme: function(location)
262 { 266 {
263 return !this.whitelistSchemes.has(location.scheme); 267 let scheme;
268 if (typeof location == "string")
269 {
270 let match = /^([\w\-]+):/.exec(location);
271 scheme = match ? match[1] : null;
272 }
273 else
274 scheme = location.scheme;
275 return !this.whitelistSchemes.has(scheme);
264 }, 276 },
265 277
266 /** 278 /**
267 * Checks whether a page is whitelisted. 279 * Checks whether a page is whitelisted.
268 * @param {String} url 280 * @param {String} url
269 * @param {String} [parentUrl] location of the parent page 281 * @param {String} [parentUrl] location of the parent page
270 * @param {String} [sitekey] public key provided on the page 282 * @param {String} [sitekey] public key provided on the page
271 * @return {Filter} filter that matched the URL or null if not whitelisted 283 * @return {Filter} filter that matched the URL or null if not whitelisted
272 */ 284 */
273 isWhitelisted: function(url, parentUrl, sitekey) 285 isWhitelisted: function(url, parentUrl, sitekey)
274 { 286 {
275 if (!url) 287 if (!url)
276 return null; 288 return null;
277 289
278 // Do not apply exception rules to schemes on our whitelistschemes list. 290 // Do not apply exception rules to schemes on our whitelistschemes list.
279 let match = /^([\w\-]+):/.exec(url); 291 if (!this.isBlockableScheme(url))
280 if (match && this.whitelistSchemes.has(match[1]))
281 return null; 292 return null;
282 293
283 if (!parentUrl) 294 if (!parentUrl)
284 parentUrl = url; 295 parentUrl = url;
285 296
286 // Ignore fragment identifier 297 // Ignore fragment identifier
287 let index = url.indexOf("#"); 298 let index = url.indexOf("#");
288 if (index >= 0) 299 if (index >= 0)
289 url = url.substring(0, index); 300 url = url.substring(0, index);
290 301
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 return Ci.nsIContentPolicy.ACCEPT; 384 return Ci.nsIContentPolicy.ACCEPT;
374 385
375 // Ignore standalone objects 386 // Ignore standalone objects
376 if (contentType == Ci.nsIContentPolicy.TYPE_OBJECT && node.ownerDocument && !/^text\/|[+\/]xml$/.test(node.ownerDocument.contentType)) 387 if (contentType == Ci.nsIContentPolicy.TYPE_OBJECT && node.ownerDocument && !/^text\/|[+\/]xml$/.test(node.ownerDocument.contentType))
377 return Ci.nsIContentPolicy.ACCEPT; 388 return Ci.nsIContentPolicy.ACCEPT;
378 389
379 let wnd = Utils.getWindow(node); 390 let wnd = Utils.getWindow(node);
380 if (!wnd) 391 if (!wnd)
381 return Ci.nsIContentPolicy.ACCEPT; 392 return Ci.nsIContentPolicy.ACCEPT;
382 393
383 // Ignore whitelisted schemes
384 let location = Utils.unwrapURL(contentLocation); 394 let location = Utils.unwrapURL(contentLocation);
385 if (!Policy.isBlockableScheme(location))
386 return Ci.nsIContentPolicy.ACCEPT;
387
388 let result = Policy.processNode(wnd, node, types.get(contentType), location. spec, false); 395 let result = Policy.processNode(wnd, node, types.get(contentType), location. spec, false);
389 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ UEST); 396 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ UEST);
390 }, 397 },
391 398
392 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra) 399 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra)
393 { 400 {
394 return Ci.nsIContentPolicy.ACCEPT; 401 return Ci.nsIContentPolicy.ACCEPT;
395 }, 402 },
396 403
397 // 404 //
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 if (!wnd || wnd.closed) 685 if (!wnd || wnd.closed)
679 return; 686 return;
680 687
681 if (entry.type == "OBJECT") 688 if (entry.type == "OBJECT")
682 { 689 {
683 node.removeEventListener("mouseover", objectMouseEventHander, true); 690 node.removeEventListener("mouseover", objectMouseEventHander, true);
684 node.removeEventListener("mouseout", objectMouseEventHander, true); 691 node.removeEventListener("mouseout", objectMouseEventHander, true);
685 } 692 }
686 Policy.processNode(wnd, node, entry.type, entry.location, true); 693 Policy.processNode(wnd, node, entry.type, entry.location, true);
687 } 694 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld