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

Side by Side Diff: lib/contentPolicy.js

Issue 11751005: Fix redirect blocking (http-on-modify-request notification fires delayed starting with Firefox 18) (Closed)
Patch Set: Created Sept. 13, 2013, 9:21 a.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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 */ 364 */
365 init: function() 365 init: function()
366 { 366 {
367 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 367 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
368 registrar.registerFactory(this.classID, this.classDescription, this.contract ID, this); 368 registrar.registerFactory(this.classID, this.classDescription, this.contract ID, this);
369 369
370 let catMan = Utils.categoryManager; 370 let catMan = Utils.categoryManager;
371 for each (let category in this.xpcom_categories) 371 for each (let category in this.xpcom_categories)
372 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true); 372 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true);
373 373
374 Services.obs.addObserver(this, "http-on-modify-request", true); 374 // http-on-opening-request is new in Gecko 18, http-on-modify-request can
375 // be used in earlier releases.
376 let httpTopic = "http-on-opening-request";
377 if (Services.vc.compare(Utils.platformVersion, "18.0") < 0)
378 httpTopic = "http-on-modify-request";
379
380 Services.obs.addObserver(this, httpTopic, true);
375 Services.obs.addObserver(this, "content-document-global-created", true); 381 Services.obs.addObserver(this, "content-document-global-created", true);
376 Services.obs.addObserver(this, "xpcom-category-entry-removed", true); 382 Services.obs.addObserver(this, "xpcom-category-entry-removed", true);
377 Services.obs.addObserver(this, "xpcom-category-cleared", true); 383 Services.obs.addObserver(this, "xpcom-category-cleared", true);
378 384
379 onShutdown.add(function() 385 onShutdown.add(function()
380 { 386 {
381 // Our category observers should be removed before changing category 387 // Our category observers should be removed before changing category
382 // memberships, just in case. 388 // memberships, just in case.
383 Services.obs.removeObserver(this, "http-on-modify-request"); 389 Services.obs.removeObserver(this, httpTopic);
384 Services.obs.removeObserver(this, "content-document-global-created"); 390 Services.obs.removeObserver(this, "content-document-global-created");
385 Services.obs.removeObserver(this, "xpcom-category-entry-removed"); 391 Services.obs.removeObserver(this, "xpcom-category-entry-removed");
386 Services.obs.removeObserver(this, "xpcom-category-cleared"); 392 Services.obs.removeObserver(this, "xpcom-category-cleared");
387 393
388 for each (let category in this.xpcom_categories) 394 for each (let category in this.xpcom_categories)
389 catMan.deleteCategoryEntry(category, this.contractID, false); 395 catMan.deleteCategoryEntry(category, this.contractID, false);
390 396
391 // This needs to run asynchronously, see bug 753687 397 // This needs to run asynchronously, see bug 753687
392 Utils.runAsync(function() 398 Utils.runAsync(function()
393 { 399 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 return Ci.nsIContentPolicy.ACCEPT; 435 return Ci.nsIContentPolicy.ACCEPT;
430 436
431 // Interpret unknown types as "other" 437 // Interpret unknown types as "other"
432 if (!(contentType in Policy.typeDescr)) 438 if (!(contentType in Policy.typeDescr))
433 contentType = Policy.type.OTHER; 439 contentType = Policy.type.OTHER;
434 440
435 let result = Policy.processNode(wnd, node, contentType, location, false); 441 let result = Policy.processNode(wnd, node, contentType, location, false);
436 if (result) 442 if (result)
437 { 443 {
438 // We didn't block this request so we will probably see it again in 444 // We didn't block this request so we will probably see it again in
439 // http-on-modify-request. Keep it so that we can associate it with the 445 // http-on-opening-request. Keep it so that we can associate it with the
440 // channel there - will be needed in case of redirect. 446 // channel there - will be needed in case of redirect.
441 this.previousRequest = [location, contentType]; 447 this.previousRequest = [location, contentType];
442 } 448 }
443 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ UEST); 449 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ UEST);
444 }, 450 },
445 451
446 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra) 452 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode , mimeType, extra)
447 { 453 {
448 return Ci.nsIContentPolicy.ACCEPT; 454 return Ci.nsIContentPolicy.ACCEPT;
449 }, 455 },
(...skipping 12 matching lines...) Expand all
462 468
463 let uri = additional || Utils.makeURI(subject.location.href); 469 let uri = additional || Utils.makeURI(subject.location.href);
464 if (!Policy.processNode(subject.opener, subject.opener.document, Policy. type.POPUP, uri, false)) 470 if (!Policy.processNode(subject.opener, subject.opener.document, Policy. type.POPUP, uri, false))
465 { 471 {
466 subject.stop(); 472 subject.stop();
467 Utils.runAsync(subject.close, subject); 473 Utils.runAsync(subject.close, subject);
468 } 474 }
469 else if (uri.spec == "about:blank") 475 else if (uri.spec == "about:blank")
470 { 476 {
471 // An about:blank pop-up most likely means that a load will be 477 // An about:blank pop-up most likely means that a load will be
472 // initiated synchronously. Set a flag for our "http-on-modify-request " 478 // initiated synchronously. Set a flag for our "http-on-opening-reques t"
473 // handler. 479 // handler.
474 this.expectingPopupLoad = true; 480 this.expectingPopupLoad = true;
475 Utils.runAsync(function() 481 Utils.runAsync(function()
476 { 482 {
477 this.expectingPopupLoad = false; 483 this.expectingPopupLoad = false;
478 }); 484 });
479 } 485 }
480 break; 486 break;
481 } 487 }
488 case "http-on-opening-request":
482 case "http-on-modify-request": 489 case "http-on-modify-request":
483 { 490 {
484 if (!(subject instanceof Ci.nsIHttpChannel)) 491 if (!(subject instanceof Ci.nsIHttpChannel))
485 return; 492 return;
486 493
487 if (this.previousRequest && subject.URI == this.previousRequest[0] && 494 if (this.previousRequest && subject.URI == this.previousRequest[0] &&
488 subject instanceof Ci.nsIWritablePropertyBag) 495 subject instanceof Ci.nsIWritablePropertyBag)
489 { 496 {
490 // We just handled a content policy call for this request - associate 497 // We just handled a content policy call for this request - associate
491 // the data with the channel so that we can find it in case of a redir ect. 498 // the data with the channel so that we can find it in case of a redir ect.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 if (!wnd || wnd.closed) 745 if (!wnd || wnd.closed)
739 return; 746 return;
740 747
741 if (entry.type == Policy.type.OBJECT) 748 if (entry.type == Policy.type.OBJECT)
742 { 749 {
743 node.removeEventListener("mouseover", objectMouseEventHander, true); 750 node.removeEventListener("mouseover", objectMouseEventHander, true);
744 node.removeEventListener("mouseout", objectMouseEventHander, true); 751 node.removeEventListener("mouseout", objectMouseEventHander, true);
745 } 752 }
746 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 753 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
747 } 754 }
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