2012-04-17 07:11:53 -07: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/. */
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["WebappRT"];
|
2012-04-17 07:11:53 -07:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-06-29 15:52:43 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-08-01 17:00:39 -07:00
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-04-17 07:11:53 -07:00
|
|
|
|
2014-02-27 08:56:48 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
|
|
|
"resource://gre/modules/FileUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
|
|
|
"@mozilla.org/AppsService;1",
|
|
|
|
"nsIAppsService");
|
2012-04-17 07:11:53 -07:00
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.WebappRT = {
|
2014-03-14 14:13:25 -07:00
|
|
|
_config: null,
|
|
|
|
|
|
|
|
get config() {
|
|
|
|
if (this._config)
|
|
|
|
return this._config;
|
|
|
|
|
|
|
|
let webappFile = FileUtils.getFile("AppRegD", ["webapp.json"]);
|
|
|
|
|
|
|
|
let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
|
|
|
inputStream.init(webappFile, -1, 0, Ci.nsIFileInputStream.CLOSE_ON_EOF);
|
|
|
|
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
|
|
|
let config = json.decodeFromStream(inputStream, webappFile.fileSize);
|
|
|
|
|
|
|
|
return this._config = config;
|
|
|
|
},
|
|
|
|
|
|
|
|
// This exists to support test mode, which installs webapps after startup.
|
|
|
|
// Ideally we wouldn't have to have a setter, as tests can just delete
|
|
|
|
// the getter and then set the property. But the object to which they set it
|
|
|
|
// will have a reference to its global object, so our reference to it
|
|
|
|
// will leak that object (per bug 780674). The setter enables us to clone
|
|
|
|
// the new value so we don't actually retain a reference to it.
|
|
|
|
set config(newVal) {
|
|
|
|
this._config = JSON.parse(JSON.stringify(newVal));
|
|
|
|
},
|
|
|
|
|
2012-08-14 15:27:26 -07:00
|
|
|
get launchURI() {
|
2013-10-09 06:16:18 -07:00
|
|
|
let manifest = this.localeManifest;
|
2013-08-01 17:00:39 -07:00
|
|
|
return manifest.fullLaunchPath();
|
2013-10-09 06:16:18 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get localeManifest() {
|
|
|
|
return new ManifestHelper(this.config.app.manifest,
|
|
|
|
this.config.app.origin);
|
|
|
|
},
|
2014-02-27 08:56:48 -08:00
|
|
|
|
|
|
|
get appID() {
|
|
|
|
let manifestURL = WebappRT.config.app.manifestURL;
|
|
|
|
if (!manifestURL) {
|
|
|
|
return Ci.nsIScriptSecurityManager.NO_APP_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return appsService.getAppLocalIdByManifestURL(manifestURL);
|
|
|
|
},
|
2012-04-17 07:11:53 -07:00
|
|
|
};
|