Bug 917642 - [Helix] Please update the helix blobs. r=nhirata
[gecko.git] / webapprt / WebappRT.jsm
blobe68e5d645eda79a048c19790324c34e8acd4971b
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 this.EXPORTED_SYMBOLS = ["WebappRT"];
7 const Cc = Components.classes;
8 const Ci = Components.interfaces;
9 const Cu = Components.utils;
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
12 Cu.import("resource://gre/modules/Services.jsm");
13 Cu.import("resource://gre/modules/AppsUtils.jsm");
15 XPCOMUtils.defineLazyGetter(this, "FileUtils", function() {
16   Cu.import("resource://gre/modules/FileUtils.jsm");
17   return FileUtils;
18 });
20 this.WebappRT = {
21   _config: null,
23   get config() {
24     if (this._config)
25       return this._config;
27     let webappFile = FileUtils.getFile("AppRegD", ["webapp.json"]);
29     let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
30                       createInstance(Ci.nsIFileInputStream);
31     inputStream.init(webappFile, -1, 0, Ci.nsIFileInputStream.CLOSE_ON_EOF);
32     let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
33     let config = json.decodeFromStream(inputStream, webappFile.fileSize);
35     return this._config = config;
36   },
38   // This exists to support test mode, which installs webapps after startup.
39   // Ideally we wouldn't have to have a setter, as tests can just delete
40   // the getter and then set the property.  But the object to which they set it
41   // will have a reference to its global object, so our reference to it
42   // will leak that object (per bug 780674).  The setter enables us to clone
43   // the new value so we don't actually retain a reference to it.
44   set config(newVal) {
45     this._config = JSON.parse(JSON.stringify(newVal));
46   },
48   get launchURI() {
49     let manifest = this.localeManifest;
50     return manifest.fullLaunchPath();
51   },
53   get localeManifest() {
54     return new ManifestHelper(this.config.app.manifest,
55                               this.config.app.origin);
56   },