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

Side by Side Diff: lib/contentPolicy.js

Issue 29329409: Issue 3208 - Don`t keep track of content policy for redirects, Gecko will do that for us (Closed)
Patch Set: Created Oct. 26, 2015, 8:37 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 */ 380 */
381 init: function() 381 init: function()
382 { 382 {
383 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 383 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
384 registrar.registerFactory(this.classID, this.classDescription, this.contract ID, this); 384 registrar.registerFactory(this.classID, this.classDescription, this.contract ID, this);
385 385
386 let catMan = Utils.categoryManager; 386 let catMan = Utils.categoryManager;
387 for (let category of this.xpcom_categories) 387 for (let category of this.xpcom_categories)
388 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true); 388 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true);
389 389
390 // http-on-opening-request is new in Gecko 18, http-on-modify-request can
391 // be used in earlier releases.
392 let httpTopic = "http-on-opening-request";
393 if (Services.vc.compare(Utils.platformVersion, "18.0") < 0)
394 httpTopic = "http-on-modify-request";
395
396 Services.obs.addObserver(this, httpTopic, true);
397 Services.obs.addObserver(this, "content-document-global-created", true); 390 Services.obs.addObserver(this, "content-document-global-created", true);
398 391
399 onShutdown.add(function() 392 onShutdown.add(function()
400 { 393 {
401 Services.obs.removeObserver(this, httpTopic);
402 Services.obs.removeObserver(this, "content-document-global-created"); 394 Services.obs.removeObserver(this, "content-document-global-created");
403 395
404 for (let category of this.xpcom_categories) 396 for (let category of this.xpcom_categories)
405 catMan.deleteCategoryEntry(category, this.contractID, false); 397 catMan.deleteCategoryEntry(category, this.contractID, false);
406 398
407 registrar.unregisterFactory(this.classID, this); 399 registrar.unregisterFactory(this.classID, this);
408
409 this.previousRequest = null;
410 }.bind(this)); 400 }.bind(this));
411 }, 401 },
412 402
413 // 403 //
414 // nsISupports interface implementation 404 // nsISupports interface implementation
415 // 405 //
416 406
417 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver, 407 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver,
418 Ci.nsIChannelEventSink, Ci.nsIFactory, Ci.nsISupportsWeakReference]), 408 Ci.nsIChannelEventSink, Ci.nsIFactory, Ci.nsISupportsWeakReference]),
419 409
(...skipping 18 matching lines...) Expand all
438 // Ignore whitelisted schemes 428 // Ignore whitelisted schemes
439 let location = Utils.unwrapURL(contentLocation); 429 let location = Utils.unwrapURL(contentLocation);
440 if (!Policy.isBlockableScheme(location)) 430 if (!Policy.isBlockableScheme(location))
441 return Ci.nsIContentPolicy.ACCEPT; 431 return Ci.nsIContentPolicy.ACCEPT;
442 432
443 // Interpret unknown types as "other" 433 // Interpret unknown types as "other"
444 if (!(contentType in Policy.typeDescr)) 434 if (!(contentType in Policy.typeDescr))
445 contentType = Policy.type.OTHER; 435 contentType = Policy.type.OTHER;
446 436
447 let result = Policy.processNode(wnd, node, contentType, location, false); 437 let result = Policy.processNode(wnd, node, contentType, location, false);
448 if (result)
449 {
450 // We didn't block this request so we will probably see it again in
451 // http-on-opening-request. Keep it so that we can associate it with the
452 // channel there - will be needed in case of redirect.
453 this.previousRequest = [location, contentType];
454 }
455 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ UEST); 438 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ UEST);
456 }, 439 },
457 440
458 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra) 441 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra)
459 { 442 {
460 return Ci.nsIContentPolicy.ACCEPT; 443 return Ci.nsIContentPolicy.ACCEPT;
461 }, 444 },
462 445
463 // 446 //
464 // nsIObserver interface implementation 447 // nsIObserver interface implementation
(...skipping 22 matching lines...) Expand all
487 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor) 470 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor)
488 .getInterface(Ci.nsIDocShell) 471 .getInterface(Ci.nsIDocShell)
489 .QueryInterface(Ci.nsIDocumentLoader) 472 .QueryInterface(Ci.nsIDocumentLoader)
490 .documentChannel; 473 .documentChannel;
491 if (channel) 474 if (channel)
492 this.observe(subject, topic, data, channel.URI); 475 this.observe(subject, topic, data, channel.URI);
493 }); 476 });
494 } 477 }
495 break; 478 break;
496 } 479 }
497 case "http-on-opening-request":
498 case "http-on-modify-request":
499 {
500 if (!(subject instanceof Ci.nsIHttpChannel))
501 return;
502
503 if (this.previousRequest && subject.URI == this.previousRequest[0] &&
504 subject instanceof Ci.nsIWritablePropertyBag)
505 {
506 // We just handled a content policy call for this request - associate
507 // the data with the channel so that we can find it in case of a redir ect.
508 subject.setProperty("abpRequestType", this.previousRequest[1]);
509 this.previousRequest = null;
510 }
511 break;
512 }
513 } 480 }
514 }, 481 },
515 482
516 // 483 //
517 // nsIChannelEventSink interface implementation 484 // nsIChannelEventSink interface implementation
518 // 485 //
519 486
520 asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback) 487 asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback)
521 { 488 {
522 let result = Cr.NS_OK; 489 let result = Cr.NS_OK;
523 try 490 try
524 { 491 {
525 // Try to retrieve previously stored request data from the channel 492 // nsILoadInfo.contentPolicyType was introduced in Gecko 35, then
526 let contentType; 493 // renamed to nsILoadInfo.externalContentPolicyType in Gecko 44.
527 if (oldChannel instanceof Ci.nsIWritablePropertyBag) 494 let loadInfo = oldChannel.loadInfo;
528 { 495 let contentType = loadInfo.externalContentPolicyType || loadInfo.contentPo licyType;
tschuster 2015/10/29 14:02:03 I would prefer an explicit `"externalContentPolicy
Wladimir Palant 2015/10/29 18:22:47 Done.
529 try 496 if (!contentType)
530 { 497 return;
531 contentType = oldChannel.getProperty("abpRequestType");
532 }
533 catch(e)
534 {
535 // No data attached, ignore this redirect
536 return;
537 }
538 }
539 498
540 let newLocation = null; 499 let newLocation = null;
541 try 500 try
542 { 501 {
543 newLocation = newChannel.URI; 502 newLocation = newChannel.URI;
544 } catch(e2) {} 503 } catch(e2) {}
545 if (!newLocation) 504 if (!newLocation)
546 return; 505 return;
547 506
548 let wnd = Utils.getRequestWindow(newChannel); 507 let wnd = Utils.getRequestWindow(newChannel);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 if (!wnd || wnd.closed) 730 if (!wnd || wnd.closed)
772 return; 731 return;
773 732
774 if (entry.type == Policy.type.OBJECT) 733 if (entry.type == Policy.type.OBJECT)
775 { 734 {
776 node.removeEventListener("mouseover", objectMouseEventHander, true); 735 node.removeEventListener("mouseover", objectMouseEventHander, true);
777 node.removeEventListener("mouseout", objectMouseEventHander, true); 736 node.removeEventListener("mouseout", objectMouseEventHander, true);
778 } 737 }
779 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 738 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
780 } 739 }
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