[tor-commits] [torbutton/master] Bug 22459: Adapt our use of the nsIContentPolicy to e10s mode

gk at torproject.org gk at torproject.org
Thu Jun 1 15:16:24 UTC 2017


commit 2e301c0a5bbc62fd5f8e66ac973c71f0bc10c81b
Author: Kathy Brade <brade at pearlcrescent.com>
Date:   Thu Jun 1 10:48:56 2017 -0400

    Bug 22459: Adapt our use of the nsIContentPolicy to e10s mode
    
    Load our content policy module as a process script instead of as a component
    so that our nsIContentPolicy filter runs in content processes.
    
    Our http-on-examine-response code that blocks redirects to internal URLs
    must continue to run in the chrome process only.
---
 src/chrome.manifest                |  4 ----
 src/components/content-policy.js   | 34 +++++++++++++++++++++++++++++-----
 src/components/startup-observer.js |  7 +++++++
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/src/chrome.manifest b/src/chrome.manifest
index ed3f5cf..75bef4e 100644
--- a/src/chrome.manifest
+++ b/src/chrome.manifest
@@ -166,10 +166,6 @@ contract @torproject.org/domain-isolator;1 {e33fd6d4-270f-475f-a96f-ff3140279f68
 
 category profile-after-change CookieJarSelector @torproject.org/cookie-jar-selector;1
 
-component {4c03be7d-492f-990e-f0da-f3689e564898} components/content-policy.js
-contract @torproject.org/content-policy;1 {4c03be7d-492f-990e-f0da-f3689e564898}
-category content-policy ContentPolicy @torproject.org/content-policy;1
-
 category profile-after-change StartupObserver @torproject.org/startup-observer;1
 category profile-after-change DomainIsolator @torproject.org/domain-isolator;1
 category profile-after-change ExtAppBlockerService @torproject.org/torbutton-extAppBlockerService;1
diff --git a/src/components/content-policy.js b/src/components/content-policy.js
index 096827b..365a5e5 100644
--- a/src/components/content-policy.js
+++ b/src/components/content-policy.js
@@ -22,13 +22,22 @@ function ContentPolicy() {
     function (enabled) {
       that.uriFingerprinting = enabled;
     });
+
+  // Register as an nsIContentPolicy filter.
+  let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+  registrar.registerFactory(this.classID, this.classDescription,
+                            this.contractID, this);
+
+  let catMan = Cc["@mozilla.org/categorymanager;1"]
+                 .getService(Ci.nsICategoryManager);
+  catMan.addCategoryEntry("content-policy", this.contractID, this.contractID,
+                          false, true);
 }
 
 ContentPolicy.prototype = {
   classDescription: "ContentPolicy",
   classID: Components.ID("{4c03be7d-492f-990e-f0da-f3689e564898}"),
   contractID: "@torproject.org/content-policy;1",
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy]),
 
   uriWhitelist: {
     // Video playback.
@@ -51,6 +60,19 @@ ContentPolicy.prototype = {
     "chrome://global/skin/dirListing/dirListing.css": Ci.nsIContentPolicy.TYPE_STYLESHEET,
   },
 
+  // nsISupports
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIFactory,
+                                         Ci.nsISupportsWeakReference]),
+
+  // nsIFactory
+  createInstance: function(outer, iid)
+  {
+    if (outer)
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    return this.QueryInterface(iid);
+  },
+
+  // nsIContentPolicy
   shouldLoad: function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) {
 
     // Accept if the user does not care, no content URI is available or scheme
@@ -121,8 +143,10 @@ var requestObserver = {
   },
 };
 
-// Firefox >= 4.0 (Old versions are extremely irrelevant).
-var NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPolicy]);
+// Create a content policy object; initialization is done in the contructor.
+var cp = new ContentPolicy();
 
-// Register the request observer to handle redirects.
-requestObserver.start();
+// In the chrome process, register the request observer to handle redirects.
+if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT) {
+  requestObserver.start();
+}
diff --git a/src/components/startup-observer.js b/src/components/startup-observer.js
index 6698b0b..65ca659 100644
--- a/src/components/startup-observer.js
+++ b/src/components/startup-observer.js
@@ -60,6 +60,13 @@ function StartupObserver() {
     } catch(e) {
       this.logger.log(4, "Early proxy change failed. Will try again at profile load. Error: "+e);
     }
+
+    // Arrange for our nsIContentPolicy filter to be loaded in the
+    // default (chrome) process as well as in each content process.
+    let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
+                 .getService(Ci.nsIProcessScriptLoader);
+    ppmm.loadProcessScript("resource://torbutton/components/content-policy.js",
+                           true);
 }
 
 StartupObserver.prototype = {





More information about the tor-commits mailing list