michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/DOMRequestHelper.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "cpmm", michael@0: "@mozilla.org/childprocessmessagemanager;1", michael@0: "nsIMessageSender"); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "appsService", michael@0: "@mozilla.org/AppsService;1", michael@0: "nsIAppsService"); michael@0: michael@0: const DEBUG = false; michael@0: function debug(aMsg) { michael@0: dump("-- InterAppConnection: " + Date.now() + ": " + aMsg + "\n"); michael@0: } michael@0: michael@0: /** michael@0: * MozInterAppConnection implementation. michael@0: */ michael@0: michael@0: function InterAppConnection() { michael@0: if (DEBUG) debug("InterAppConnection()"); michael@0: this.keyword = null; michael@0: this.publisher = null; michael@0: this.subscriber = null; michael@0: }; michael@0: michael@0: InterAppConnection.prototype = { michael@0: __proto__: DOMRequestIpcHelper.prototype, michael@0: michael@0: classDescription: "MozInterAppConnection", michael@0: michael@0: classID: Components.ID("{9dbfa904-0718-11e3-8e77-0721a45514b8}"), michael@0: michael@0: contractID: "@mozilla.org/dom/inter-app-connection;1", michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer, michael@0: Ci.nsISupportsWeakReference, michael@0: Ci.nsIObserver]), michael@0: michael@0: __init: function(aKeyword, aPublisher, aSubscriber) { michael@0: if (DEBUG) { michael@0: debug("__init: aKeyword: " + aKeyword + michael@0: " aPublisher: " + aPublisher + " aSubscriber: " + aSubscriber); michael@0: } michael@0: this.keyword = aKeyword; michael@0: this.publisher = aPublisher; michael@0: this.subscriber = aSubscriber; michael@0: }, michael@0: michael@0: // Ci.nsIDOMGlobalPropertyInitializer implementation. michael@0: init: function(aWindow) { michael@0: if (DEBUG) debug("init"); michael@0: michael@0: this.initDOMRequestHelper(aWindow, []); michael@0: let principal = aWindow.document.nodePrincipal; michael@0: this._manifestURL = appsService.getManifestURLByLocalId(principal.appId); michael@0: }, michael@0: michael@0: cancel: function() { michael@0: if (DEBUG) debug("cancel"); michael@0: michael@0: cpmm.sendAsyncMessage("InterAppConnection:Cancel", michael@0: { keyword: this.keyword, michael@0: pubAppManifestURL: this.publisher, michael@0: subAppManifestURL: this.subscriber, michael@0: manifestURL: this._manifestURL }); michael@0: } michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * MozInterAppConnectionRequest implementation. michael@0: */ michael@0: michael@0: function InterAppConnectionRequest() { michael@0: if (DEBUG) debug("InterAppConnectionRequest()"); michael@0: this.keyword = null; michael@0: this.port = null; michael@0: }; michael@0: michael@0: InterAppConnectionRequest.prototype = { michael@0: classDescription: "MozInterAppConnectionRequest", michael@0: michael@0: classID: Components.ID("{6a77e9e0-0645-11e3-b90b-73bb7c78e06a}"), michael@0: michael@0: contractID: "@mozilla.org/dom/inter-app-connection-request;1", michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]), michael@0: michael@0: __init: function(aKeyword, aPort) { michael@0: if (DEBUG) debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort); michael@0: this.keyword = aKeyword; michael@0: this.port = aPort; michael@0: } michael@0: }; michael@0: michael@0: /** michael@0: * InterAppConnectionRequestWrapper implementation. michael@0: * michael@0: * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a michael@0: * plugable way to wrap a "connection" type system message. michael@0: * michael@0: * Please see SystemMessageManager.js to know how it customizes the wrapper. michael@0: */ michael@0: michael@0: function InterAppConnectionRequestWrapper() { michael@0: if (DEBUG) debug("InterAppConnectionRequestWrapper()"); michael@0: } michael@0: michael@0: InterAppConnectionRequestWrapper.prototype = { michael@0: // nsISystemMessagesWrapper implementation. michael@0: wrapMessage: function(aMessage, aWindow) { michael@0: if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage)); michael@0: michael@0: let port = new aWindow.MozInterAppMessagePort(aMessage.messagePortID); michael@0: let connectionRequest = michael@0: new aWindow.MozInterAppConnectionRequest(aMessage.keyword, port); michael@0: michael@0: return connectionRequest; michael@0: }, michael@0: michael@0: classDescription: "InterAppConnectionRequestWrapper", michael@0: michael@0: classID: Components.ID("{d7c7a466-f91d-11e2-812a-6fab12ece58e}"), michael@0: michael@0: contractID: "@mozilla.org/dom/system-messages/wrapper/connection;1", michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper]) michael@0: } michael@0: michael@0: michael@0: this.NSGetFactory = michael@0: XPCOMUtils.generateNSGetFactory([InterAppConnection, michael@0: InterAppConnectionRequest, michael@0: InterAppConnectionRequestWrapper]);