toolkit/modules/RemoteAddonsChild.jsm

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 // -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2 // This Source Code Form is subject to the terms of the Mozilla Public
     3 // License, v. 2.0. If a copy of the MPL was not distributed with this
     4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6 this.EXPORTED_SYMBOLS = ["RemoteAddonsChild"];
     8 const Ci = Components.interfaces;
     9 const Cc = Components.classes;
    10 const Cu = Components.utils;
    12 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    13 Cu.import('resource://gre/modules/Services.jsm');
    15 /**
    16  * This code registers an nsIContentPolicy in the child process. When
    17  * it runs, it notifies the parent that it needs to run its own
    18  * nsIContentPolicy list. If any policy in the parent rejects the load,
    19  * that answer is returned to the child.
    20  */
    21 let ContentPolicyChild = {
    22   _classDescription: "Addon shim content policy",
    23   _classID: Components.ID("6e869130-635c-11e2-bcfd-0800200c9a66"),
    24   _contractID: "@mozilla.org/addon-child/policy;1",
    26   /**
    27    * We only notify the parent of the load if it has any
    28    * non-builtin policies registered.
    29    */
    30   _childNeedsHook: false,
    32   init: function(aContentGlobal) {
    33     let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    34     registrar.registerFactory(this._classID, this._classDescription, this._contractID, this);
    36     var catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
    37     catMan.addCategoryEntry("content-policy", this._contractID, this._contractID, false, true);
    39     let policiesToIgnore = [];
    40     let services = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager)
    41                                                        .enumerateCategory("content-policy");
    42     while (services.hasMoreElements()) {
    43       let item = services.getNext();
    44       let name = item.QueryInterface(Components.interfaces.nsISupportsCString).toString();
    45       policiesToIgnore.push(name);
    46     }
    48     let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
    49                .getService(Ci.nsISyncMessageSender);
    50     cpmm.addMessageListener("Addons:ContentPolicy:NeedHook", this);
    51     cpmm.sendAsyncMessage("Addons:ContentPolicy:IgnorePolicies", { "policies": policiesToIgnore });
    52   },
    54   receiveMessage: function(aMessage) {
    55     switch (aMessage.name) {
    56       case "Addons:ContentPolicy:NeedHook":
    57         this._childNeedsHook = aMessage.data.needed;
    58         break;
    59     }
    60   },
    62   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver,
    63                                          Ci.nsIChannelEventSink, Ci.nsIFactory,
    64                                          Ci.nsISupportsWeakReference]),
    66   shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra) {
    67     if (!this._childNeedsHook)
    68       return Ci.nsIContentPolicy.ACCEPT;
    70     let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
    71                .getService(Ci.nsISyncMessageSender);
    72     var rval = cpmm.sendRpcMessage("Addons:ContentPolicy:Run", {
    73       contentType: contentType,
    74       mimeTypeGuess: mimeTypeGuess
    75     }, {
    76       contentLocation: contentLocation,
    77       requestOrigin: requestOrigin,
    78       node: node
    79     });
    80     if (rval.length != 1)
    81       return Ci.nsIContentPolicy.ACCEPT;
    83     return rval[0];
    84   },
    86   shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) {
    87     return Ci.nsIContentPolicy.ACCEPT;
    88   },
    90   createInstance: function(outer, iid) {
    91     if (outer)
    92       throw Cr.NS_ERROR_NO_AGGREGATION;
    93     return this.QueryInterface(iid);
    94   },
    95 };
    97 let RemoteAddonsChild = {
    98   initialized: false,
   100   init: function(aContentGlobal) {
   101     if (this.initialized)
   102       return;
   104     this.initialized = true;
   106     ContentPolicyChild.init(aContentGlobal);
   107   },
   108 };

mercurial