2012-04-17 14:11:53 +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/. */
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["WebappRT"];
|
2012-04-17 14:11:53 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-06-29 22:52:43 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-04-17 14:11:53 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "FileUtils", function() {
|
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
|
|
|
return FileUtils;
|
|
|
|
});
|
|
|
|
|
2012-06-29 22:52:43 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "DOMApplicationRegistry", function() {
|
|
|
|
Cu.import("resource://gre/modules/Webapps.jsm");
|
|
|
|
return DOMApplicationRegistry;
|
|
|
|
});
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.WebappRT = {
|
2012-08-14 22:27:26 +00:00
|
|
|
_config: null,
|
|
|
|
|
2012-04-17 14:11:53 +00:00
|
|
|
get config() {
|
2012-08-14 22:27:26 +00:00
|
|
|
if (this._config)
|
|
|
|
return this._config;
|
|
|
|
|
|
|
|
let config;
|
2012-04-17 14:11:53 +00:00
|
|
|
let webappFile = FileUtils.getFile("AppRegD", ["webapp.json"]);
|
2012-08-14 22:27:26 +00:00
|
|
|
|
2012-04-17 14:11:53 +00:00
|
|
|
let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
|
|
|
inputStream.init(webappFile, -1, 0, 0);
|
|
|
|
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
2012-08-14 22:27:26 +00:00
|
|
|
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));
|
|
|
|
},
|
|
|
|
|
|
|
|
get launchURI() {
|
|
|
|
let url = Services.io.newURI(this.config.app.origin, null, null);
|
|
|
|
if (this.config.app.manifest.launch_path) {
|
|
|
|
url = Services.io.newURI(this.config.app.manifest.launch_path, null, url);
|
|
|
|
}
|
|
|
|
return url;
|
2012-04-17 14:11:53 +00:00
|
|
|
}
|
|
|
|
};
|