Bumping manifests a=b2g-bump
[gecko.git] / dom / apps / InterAppConnection.js
blobaa6bf55315ad891dd213efc9738485df9aa76cfa
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
9 Cu.import("resource://gre/modules/Services.jsm");
10 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
11 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
13 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
14                                    "@mozilla.org/childprocessmessagemanager;1",
15                                    "nsIMessageSender");
17 XPCOMUtils.defineLazyServiceGetter(this, "appsService",
18                                    "@mozilla.org/AppsService;1",
19                                    "nsIAppsService");
21 const DEBUG = false;
22 function debug(aMsg) {
23   dump("-- InterAppConnection: " + Date.now() + ": " + aMsg + "\n");
26 /**
27  * MozInterAppConnection implementation.
28  */
30 function InterAppConnection() {
31   if (DEBUG) debug("InterAppConnection()");
32   this.keyword = null;
33   this.publisher = null;
34   this.subscriber = null;
37 InterAppConnection.prototype = {
38   __proto__: DOMRequestIpcHelper.prototype,
40   classDescription: "MozInterAppConnection",
42   classID: Components.ID("{9dbfa904-0718-11e3-8e77-0721a45514b8}"),
44   contractID: "@mozilla.org/dom/inter-app-connection;1",
46   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
47                                          Ci.nsISupportsWeakReference,
48                                          Ci.nsIObserver]),
50   __init: function(aKeyword, aPublisher, aSubscriber) {
51     if (DEBUG) {
52       debug("__init: aKeyword: " + aKeyword +
53             " aPublisher: " + aPublisher + " aSubscriber: " + aSubscriber);
54     }
55     this.keyword = aKeyword;
56     this.publisher = aPublisher;
57     this.subscriber = aSubscriber;
58   },
60   // Ci.nsIDOMGlobalPropertyInitializer implementation.
61   init: function(aWindow) {
62     if (DEBUG) debug("init");
64     this.initDOMRequestHelper(aWindow, []);
65     let principal = aWindow.document.nodePrincipal;
66     this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
67   },
69   cancel: function() {
70     if (DEBUG) debug("cancel");
72     cpmm.sendAsyncMessage("InterAppConnection:Cancel",
73                           { keyword: this.keyword,
74                             pubAppManifestURL: this.publisher,
75                             subAppManifestURL: this.subscriber,
76                             manifestURL: this._manifestURL });
77   }
81 /**
82  * MozInterAppConnectionRequest implementation.
83  */
85 function InterAppConnectionRequest() {
86   if (DEBUG) debug("InterAppConnectionRequest()");
87   this.keyword = null;
88   this.port = null;
91 InterAppConnectionRequest.prototype = {
92   classDescription: "MozInterAppConnectionRequest",
94   classID: Components.ID("{6a77e9e0-0645-11e3-b90b-73bb7c78e06a}"),
96   contractID: "@mozilla.org/dom/inter-app-connection-request;1",
98   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
100   __init: function(aKeyword, aPort) {
101     if (DEBUG) debug("__init: aKeyword: " + aKeyword + " aPort: " + aPort);
102     this.keyword = aKeyword;
103     this.port = aPort;
104   }
108  * InterAppConnectionRequestWrapper implementation.
110  * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a
111  * plugable way to wrap a "connection" type system message.
113  * Please see SystemMessageManager.js to know how it customizes the wrapper.
114  */
116 function InterAppConnectionRequestWrapper() {
117   if (DEBUG) debug("InterAppConnectionRequestWrapper()");
120 InterAppConnectionRequestWrapper.prototype = {
121   // nsISystemMessagesWrapper implementation.
122   wrapMessage: function(aMessage, aWindow) {
123     if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage));
125     let port = new aWindow.MozInterAppMessagePort(aMessage.messagePortID);
126     let connectionRequest =
127       new aWindow.MozInterAppConnectionRequest(aMessage.keyword, port);
129     return connectionRequest;
130   },
132   classDescription: "InterAppConnectionRequestWrapper",
134   classID: Components.ID("{d7c7a466-f91d-11e2-812a-6fab12ece58e}"),
136   contractID: "@mozilla.org/dom/system-messages/wrapper/connection;1",
138   QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper])
142 this.NSGetFactory =
143   XPCOMUtils.generateNSGetFactory([InterAppConnection,
144                                    InterAppConnectionRequest,
145                                    InterAppConnectionRequestWrapper]);