gecko-dev/dom/apps/InterAppConnection.js
Birunthan Mohanathas b09d89b288 Bug 1058101 - Flatten dom/apps/src/ into parent directory. r=mccr8
--HG--
rename : dom/apps/src/AppDownloadManager.jsm => dom/apps/AppDownloadManager.jsm
rename : dom/apps/src/AppsService.js => dom/apps/AppsService.js
rename : dom/apps/src/AppsService.manifest => dom/apps/AppsService.manifest
rename : dom/apps/src/AppsServiceChild.jsm => dom/apps/AppsServiceChild.jsm
rename : dom/apps/src/AppsUtils.jsm => dom/apps/AppsUtils.jsm
rename : dom/apps/src/FreeSpaceWatcher.jsm => dom/apps/FreeSpaceWatcher.jsm
rename : dom/apps/src/InterAppComm.cpp => dom/apps/InterAppComm.cpp
rename : dom/apps/src/InterAppComm.h => dom/apps/InterAppComm.h
rename : dom/apps/src/InterAppComm.manifest => dom/apps/InterAppComm.manifest
rename : dom/apps/src/InterAppCommService.js => dom/apps/InterAppCommService.js
rename : dom/apps/src/InterAppCommService.jsm => dom/apps/InterAppCommService.jsm
rename : dom/apps/src/InterAppConnection.js => dom/apps/InterAppConnection.js
rename : dom/apps/src/InterAppMessagePort.js => dom/apps/InterAppMessagePort.js
rename : dom/apps/src/OfflineCacheInstaller.jsm => dom/apps/OfflineCacheInstaller.jsm
rename : dom/apps/src/OperatorApps.jsm => dom/apps/OperatorApps.jsm
rename : dom/apps/src/PermissionsInstaller.jsm => dom/apps/PermissionsInstaller.jsm
rename : dom/apps/src/PermissionsTable.jsm => dom/apps/PermissionsTable.jsm
rename : dom/apps/src/ScriptPreloader.jsm => dom/apps/ScriptPreloader.jsm
rename : dom/apps/src/StoreTrustAnchor.jsm => dom/apps/StoreTrustAnchor.jsm
rename : dom/apps/src/Webapps.js => dom/apps/Webapps.js
rename : dom/apps/src/Webapps.jsm => dom/apps/Webapps.jsm
rename : dom/apps/src/Webapps.manifest => dom/apps/Webapps.manifest
2014-08-27 10:12:06 -07:00

146 lines
4.4 KiB
JavaScript

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