author Ed Morley <emorley@mozilla.com>
Mon, 11 Feb 2013 15:41:36 +0000
changeset 121506 d509e44cae3effde6814bb08c7c8cf9808197917
parent 111947 5ce71981e005a52d4cb0b831ad3db9284f2fb356
child 141029 357e720b5a377ecf0e6fa6da9a82059dc5f98581
permissions -rw-r--r--
Backout 1646e649878a (bug 835698) on suspicion of causing mochitest-1 shutdown hangs on Windows on a rather sad looking CLOSED TREE

/* 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/. */

this.EXPORTED_SYMBOLS = ["WebappRT"];

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;


XPCOMUtils.defineLazyGetter(this, "FileUtils", function() {
  return FileUtils;

XPCOMUtils.defineLazyGetter(this, "DOMApplicationRegistry", function() {
  return DOMApplicationRegistry;

this.WebappRT = {
  _config: null,

  get config() {
    if (this._config)
      return this._config;

    let config;
    let webappFile = FileUtils.getFile("AppRegD", ["webapp.json"]);

    let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
    inputStream.init(webappFile, -1, 0, 0);
    let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
    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;