2012-08-28 02:43:57 +00:00
|
|
|
/* 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 Cu = Components.utils;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2014-05-27 19:47:04 +00:00
|
|
|
// This module exposes a subset of the functionnalities of the parent DOM
|
|
|
|
// Registry to content processes, to be be used from the AppsService component.
|
2012-08-28 02:43:57 +00:00
|
|
|
|
2014-05-27 19:47:04 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["DOMApplicationRegistry"];
|
2012-08-28 02:43:57 +00:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-08-29 14:31:10 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-08-28 02:43:57 +00:00
|
|
|
|
|
|
|
function debug(s) {
|
|
|
|
//dump("-*- AppsServiceChild.jsm: " + s + "\n");
|
|
|
|
}
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.DOMApplicationRegistry = {
|
2012-08-28 02:43:57 +00:00
|
|
|
init: function init() {
|
2014-05-27 19:47:04 +00:00
|
|
|
debug("init");
|
2012-08-28 02:43:57 +00:00
|
|
|
this.cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
|
|
|
|
.getService(Ci.nsISyncMessageSender);
|
|
|
|
|
2014-05-27 19:47:04 +00:00
|
|
|
["Webapps:AddApp", "Webapps:RemoveApp"].forEach((function(aMsgName) {
|
2012-08-28 02:43:57 +00:00
|
|
|
this.cpmm.addMessageListener(aMsgName, this);
|
|
|
|
}).bind(this));
|
|
|
|
|
|
|
|
// We need to prime the cache with the list of apps.
|
2014-05-27 19:47:04 +00:00
|
|
|
// XXX shoud we do this async and block callers if it's not yet there?
|
|
|
|
this.webapps = this.cpmm.sendSyncMessage("Webapps:GetList", { })[0];
|
2013-01-31 06:50:28 +00:00
|
|
|
|
|
|
|
// We need a fast mapping from localId -> app, so we add an index.
|
|
|
|
this.localIdIndex = { };
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
let app = this.webapps[id];
|
|
|
|
this.localIdIndex[app.localId] = app;
|
|
|
|
}
|
|
|
|
|
2012-08-29 14:31:10 +00:00
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
2014-05-27 19:47:04 +00:00
|
|
|
// cpmm.addMessageListener causes the DOMApplicationRegistry object to live
|
|
|
|
// forever if we don't clean up properly.
|
2012-08-29 14:31:10 +00:00
|
|
|
this.webapps = null;
|
2014-05-27 19:47:04 +00:00
|
|
|
["Webapps:AddApp", "Webapps:RemoveApp"].forEach((function(aMsgName) {
|
2012-08-29 14:31:10 +00:00
|
|
|
this.cpmm.removeMessageListener(aMsgName, this);
|
2014-05-27 19:47:04 +00:00
|
|
|
}).bind(this));
|
2012-08-28 02:43:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
|
|
|
debug("Received " + aMessage.name + " message.");
|
2014-05-27 19:47:04 +00:00
|
|
|
let msg = aMessage.json;
|
2012-08-28 02:43:57 +00:00
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Webapps:AddApp":
|
|
|
|
this.webapps[msg.id] = msg.app;
|
2013-01-31 06:50:28 +00:00
|
|
|
this.localIdIndex[msg.app.localId] = msg.app;
|
2012-08-28 02:43:57 +00:00
|
|
|
break;
|
|
|
|
case "Webapps:RemoveApp":
|
2013-01-31 06:50:28 +00:00
|
|
|
delete this.localIdIndex[this.webapps[msg.id].localId];
|
2012-08-28 02:43:57 +00:00
|
|
|
delete this.webapps[msg.id];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
|
|
|
|
debug("getAppByManifestURL " + aManifestURL);
|
|
|
|
return AppsUtils.getAppByManifestURL(this.webapps, aManifestURL);
|
|
|
|
},
|
|
|
|
|
|
|
|
getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
|
|
|
|
debug("getAppLocalIdByManifestURL " + aManifestURL);
|
|
|
|
return AppsUtils.getAppLocalIdByManifestURL(this.webapps, aManifestURL);
|
|
|
|
},
|
|
|
|
|
2012-10-19 10:43:17 +00:00
|
|
|
getCSPByLocalId: function(aLocalId) {
|
|
|
|
debug("getCSPByLocalId:" + aLocalId);
|
|
|
|
return AppsUtils.getCSPByLocalId(this.webapps, aLocalId);
|
|
|
|
},
|
|
|
|
|
2013-01-25 09:57:14 +00:00
|
|
|
getAppLocalIdByStoreId: function(aStoreId) {
|
|
|
|
debug("getAppLocalIdByStoreId:" + aStoreId);
|
|
|
|
return AppsUtils.getAppLocalIdByStoreId(this.webapps, aStoreId);
|
|
|
|
},
|
|
|
|
|
2012-08-28 02:43:57 +00:00
|
|
|
getAppByLocalId: function getAppByLocalId(aLocalId) {
|
|
|
|
debug("getAppByLocalId " + aLocalId);
|
2013-01-31 06:50:28 +00:00
|
|
|
let app = this.localIdIndex[aLocalId];
|
|
|
|
if (!app) {
|
|
|
|
debug("Ouch, No app!");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-04-21 15:30:15 +00:00
|
|
|
return new mozIApplication(app);
|
2012-08-28 02:43:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
|
|
|
|
debug("getManifestURLByLocalId " + aLocalId);
|
|
|
|
return AppsUtils.getManifestURLByLocalId(this.webapps, aLocalId);
|
2012-08-31 14:34:28 +00:00
|
|
|
},
|
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
getCoreAppsBasePath: function getCoreAppsBasePath() {
|
|
|
|
debug("getCoreAppsBasePath() not yet supported on child!");
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
getWebAppsBasePath: function getWebAppsBasePath() {
|
|
|
|
debug("getWebAppsBasePath() not yet supported on child!");
|
|
|
|
return null;
|
2013-01-31 21:35:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getAppInfo: function getAppInfo(aAppId) {
|
2013-03-15 14:18:58 +00:00
|
|
|
return AppsUtils.getAppInfo(this.webapps, aAppId);
|
|
|
|
}
|
2012-08-28 02:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMApplicationRegistry.init();
|