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");
14 XPCOMUtils.defineLazyGetter(this, "FileUtils", function() {
15 Cu.import("resource://gre/modules/FileUtils.jsm");
19 XPCOMUtils.defineLazyGetter(this, "DOMApplicationRegistry", function() {
20 Cu.import("resource://gre/modules/Webapps.jsm");
21 return DOMApplicationRegistry;
32 let webappFile = FileUtils.getFile("AppRegD", ["webapp.json"]);
34 let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
35 createInstance(Ci.nsIFileInputStream);
36 inputStream.init(webappFile, -1, 0, 0);
37 let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
38 config = json.decodeFromStream(inputStream, webappFile.fileSize);
40 return this._config = config;
43 // This exists to support test mode, which installs webapps after startup.
44 // Ideally we wouldn't have to have a setter, as tests can just delete
45 // the getter and then set the property. But the object to which they set it
46 // will have a reference to its global object, so our reference to it
47 // will leak that object (per bug 780674). The setter enables us to clone
48 // the new value so we don't actually retain a reference to it.
50 this._config = JSON.parse(JSON.stringify(newVal));
54 let url = Services.io.newURI(this.config.app.origin, null, null);
55 if (this.config.app.manifest.launch_path) {
56 url = Services.io.newURI(this.config.app.manifest.launch_path, null, url);