Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/DOMRequestHelper.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | XPCOMUtils.defineLazyServiceGetter(this, "cpmm", |
michael@0 | 14 | "@mozilla.org/childprocessmessagemanager;1", |
michael@0 | 15 | "nsIMessageSender"); |
michael@0 | 16 | |
michael@0 | 17 | XPCOMUtils.defineLazyServiceGetter(this, "appsService", |
michael@0 | 18 | "@mozilla.org/AppsService;1", |
michael@0 | 19 | "nsIAppsService"); |
michael@0 | 20 | |
michael@0 | 21 | const DEBUG = false; |
michael@0 | 22 | function debug(aMsg) { |
michael@0 | 23 | dump("-- InterAppConnection: " + Date.now() + ": " + aMsg + "\n"); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * MozInterAppConnection implementation. |
michael@0 | 28 | */ |
michael@0 | 29 | |
michael@0 | 30 | function InterAppConnection() { |
michael@0 | 31 | if (DEBUG) debug("InterAppConnection()"); |
michael@0 | 32 | this.keyword = null; |
michael@0 | 33 | this.publisher = null; |
michael@0 | 34 | this.subscriber = null; |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | InterAppConnection.prototype = { |
michael@0 | 38 | __proto__: DOMRequestIpcHelper.prototype, |
michael@0 | 39 | |
michael@0 | 40 | classDescription: "MozInterAppConnection", |
michael@0 | 41 | |
michael@0 | 42 | classID: Components.ID("{9dbfa904-0718-11e3-8e77-0721a45514b8}"), |
michael@0 | 43 | |
michael@0 | 44 | contractID: "@mozilla.org/dom/inter-app-connection;1", |
michael@0 | 45 | |
michael@0 | 46 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer, |
michael@0 | 47 | Ci.nsISupportsWeakReference, |
michael@0 | 48 | Ci.nsIObserver]), |
michael@0 | 49 | |
michael@0 | 50 | __init: function(aKeyword, aPublisher, aSubscriber) { |
michael@0 | 51 | if (DEBUG) { |
michael@0 | 52 | debug("__init: aKeyword: " + aKeyword + |
michael@0 | 53 | " aPublisher: " + aPublisher + " aSubscriber: " + aSubscriber); |
michael@0 | 54 | } |
michael@0 | 55 | this.keyword = aKeyword; |
michael@0 | 56 | this.publisher = aPublisher; |
michael@0 | 57 | this.subscriber = aSubscriber; |
michael@0 | 58 | }, |
michael@0 | 59 | |
michael@0 | 60 | // Ci.nsIDOMGlobalPropertyInitializer implementation. |
michael@0 | 61 | init: function(aWindow) { |
michael@0 | 62 | if (DEBUG) debug("init"); |
michael@0 | 63 | |
michael@0 | 64 | this.initDOMRequestHelper(aWindow, []); |
michael@0 | 65 | let principal = aWindow.document.nodePrincipal; |
michael@0 | 66 | this._manifestURL = appsService.getManifestURLByLocalId(principal.appId); |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | cancel: function() { |
michael@0 | 70 | if (DEBUG) debug("cancel"); |
michael@0 | 71 | |
michael@0 | 72 | cpmm.sendAsyncMessage("InterAppConnection:Cancel", |
michael@0 | 73 | { keyword: this.keyword, |
michael@0 | 74 | pubAppManifestURL: this.publisher, |
michael@0 | 75 | subAppManifestURL: this.subscriber, |
michael@0 | 76 | manifestURL: this._manifestURL }); |
michael@0 | 77 | } |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * MozInterAppConnectionRequest implementation. |
michael@0 | 83 | */ |
michael@0 | 84 | |
michael@0 | 85 | function InterAppConnectionRequest() { |
michael@0 | 86 | if (DEBUG) debug("InterAppConnectionRequest()"); |
michael@0 | 87 | this.keyword = null; |
michael@0 | 88 | this.port = null; |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | InterAppConnectionRequest.prototype = { |
michael@0 | 92 | classDescription: "MozInterAppConnectionRequest", |
michael@0 | 93 | |
michael@0 | 94 | classID: Components.ID("{6a77e9e0-0645-11e3-b90b-73bb7c78e06a}"), |
michael@0 | 95 | |
michael@0 | 96 | contractID: "@mozilla.org/dom/inter-app-connection-request;1", |
michael@0 | 97 | |
michael@0 | 98 | QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]), |
michael@0 | 99 | |
michael@0 | 100 | __init: function(aKeyword, aPort) { |
michael@0 | 101 | if (DEBUG) debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort); |
michael@0 | 102 | this.keyword = aKeyword; |
michael@0 | 103 | this.port = aPort; |
michael@0 | 104 | } |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * InterAppConnectionRequestWrapper implementation. |
michael@0 | 109 | * |
michael@0 | 110 | * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a |
michael@0 | 111 | * plugable way to wrap a "connection" type system message. |
michael@0 | 112 | * |
michael@0 | 113 | * Please see SystemMessageManager.js to know how it customizes the wrapper. |
michael@0 | 114 | */ |
michael@0 | 115 | |
michael@0 | 116 | function InterAppConnectionRequestWrapper() { |
michael@0 | 117 | if (DEBUG) debug("InterAppConnectionRequestWrapper()"); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | InterAppConnectionRequestWrapper.prototype = { |
michael@0 | 121 | // nsISystemMessagesWrapper implementation. |
michael@0 | 122 | wrapMessage: function(aMessage, aWindow) { |
michael@0 | 123 | if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage)); |
michael@0 | 124 | |
michael@0 | 125 | let port = new aWindow.MozInterAppMessagePort(aMessage.messagePortID); |
michael@0 | 126 | let connectionRequest = |
michael@0 | 127 | new aWindow.MozInterAppConnectionRequest(aMessage.keyword, port); |
michael@0 | 128 | |
michael@0 | 129 | return connectionRequest; |
michael@0 | 130 | }, |
michael@0 | 131 | |
michael@0 | 132 | classDescription: "InterAppConnectionRequestWrapper", |
michael@0 | 133 | |
michael@0 | 134 | classID: Components.ID("{d7c7a466-f91d-11e2-812a-6fab12ece58e}"), |
michael@0 | 135 | |
michael@0 | 136 | contractID: "@mozilla.org/dom/system-messages/wrapper/connection;1", |
michael@0 | 137 | |
michael@0 | 138 | QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper]) |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | this.NSGetFactory = |
michael@0 | 143 | XPCOMUtils.generateNSGetFactory([InterAppConnection, |
michael@0 | 144 | InterAppConnectionRequest, |
michael@0 | 145 | InterAppConnectionRequestWrapper]); |