toolkit/modules/RemoteAddonsChild.jsm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial