webapprt/WebappManager.jsm
author B2G Bumper Bot <release+b2gbumper@mozilla.com>
Tue, 22 Jul 2014 07:30:28 -0700
changeset 195548 b64b42abd5f8282c08fca7ba57a70d26dbda7165
parent 193579 c43489001722a791d24c2774475bdcb9582f8d2f
child 196903 5a84a1907654185e04a58a2d40654dd7c57b12bc
permissions -rw-r--r--
Bumping gaia.json for 8 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/383735049e86 Author: Ryan VanderMeulen <rvandermeulen@mozilla.com> Desc: Merge pull request #21846 from svic/Bug_1039239 Bug 1039239 - Better NFC handover error handling ======== https://hg.mozilla.org/integration/gaia-central/rev/b40b6117be3e Author: Arno Puder <arno@puder.org> Desc: Bug 1039239 - Better NFC handover error handling ======== https://hg.mozilla.org/integration/gaia-central/rev/8eba7c0e50e3 Author: Ryan VanderMeulen <rvandermeulen@mozilla.com> Desc: Merge pull request #21837 from guilherme-pg/bug1034088-offline Bug 1034088 - Display the proper Settings panel for Find My Device when offline. ======== https://hg.mozilla.org/integration/gaia-central/rev/a57845e709a3 Author: Guilherme Goncalves <guilherme.p.gonc@gmail.com> Desc: Bug 1034088 - Display the proper Settings panel for Find My Device when offline. ======== https://hg.mozilla.org/integration/gaia-central/rev/627a576d2058 Author: Ryan VanderMeulen <rvandermeulen@mozilla.com> Desc: Merge pull request #21688 from flodolo/bug892700 Bug 892700 - Display Developer options on 2 lines if necessary ======== https://hg.mozilla.org/integration/gaia-central/rev/d6fe3b318ec0 Author: Francesco Lodolo (:flod) <flod@lodolo.net> Desc: Bug 892700 - Display Developer options on 2 lines if necessary ======== https://hg.mozilla.org/integration/gaia-central/rev/70edf8c17539 Author: Andrew Halberstadt <halbersa@gmail.com> Desc: Merge pull request #21888 from ahal/python_service Create a python runner service to run integration tests on device ======== https://hg.mozilla.org/integration/gaia-central/rev/ff1e44c2f817 Author: Andrew Halberstadt <halbersa@gmail.com> Desc: Bug 994847 - Create a python runner service for integration tests, r=mdas

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

"use strict";

this.EXPORTED_SYMBOLS = ["WebappManager"];

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

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Webapps.jsm");
Cu.import("resource://gre/modules/AppsUtils.jsm");
Cu.import("resource://gre/modules/NativeApp.jsm");
Cu.import("resource://gre/modules/WebappOSUtils.jsm");
Cu.import("resource://webapprt/modules/WebappRT.jsm");

this.WebappManager = {
  observe: function(subject, topic, data) {
    data = JSON.parse(data);
    data.mm = subject;

    switch (topic) {
      case "webapps-ask-install":
        let chromeWin = Services.wm.getOuterWindowWithId(data.oid);
        if (chromeWin)
          this.doInstall(data, chromeWin);
        break;
      case "webapps-launch":
        WebappOSUtils.launch(data);
        break;
      case "webapps-uninstall":
        WebappOSUtils.uninstall(data);
        break;
    }
  },

  update: function(aApp, aManifest, aZipPath) {
    let nativeApp = new NativeApp(aApp, aManifest,
                                  WebappRT.config.app.categories,
                                  WebappRT.config.registryDir);
    nativeApp.prepareUpdate(aApp, aManifest, aZipPath);
  },

  doInstall: function(data, window) {
    let jsonManifest = data.isPackage ? data.app.updateManifest : data.app.manifest;
    let manifest = new ManifestHelper(jsonManifest, data.app.origin);
    let name = manifest.name;
    let bundle = Services.strings.createBundle("chrome://webapprt/locale/webapp.properties");

    let choice = Services.prompt.confirmEx(
      window,
      bundle.formatStringFromName("webapps.install.title", [name], 1),
      bundle.formatStringFromName("webapps.install.description", [name], 1),
      // Set both buttons to strings with the cancel button being default
      Ci.nsIPromptService.BUTTON_POS_1_DEFAULT |
        Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_0 |
        Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_1,
      bundle.GetStringFromName("webapps.install.install"),
      bundle.GetStringFromName("webapps.install.dontinstall"),
      null,
      null,
      {});

    // Perform the install if the user allows it
    if (choice == 0) {
      let nativeApp = new NativeApp(data.app, jsonManifest,
                                    data.app.categories,
                                    WebappRT.config.registryDir);
      let localDir;
      try {
        localDir = nativeApp.createProfile();
      } catch (ex) {
        DOMApplicationRegistry.denyInstall(aData);
        return;
      }

      DOMApplicationRegistry.confirmInstall(data, localDir,
        Task.async(function*(aApp, aManifest, aZipPath) {
          yield nativeApp.install(aApp, aManifest, aZipPath);
        })
      );
    } else {
      DOMApplicationRegistry.denyInstall(data);
    }
  },

  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                         Ci.nsISupportsWeakReference])
};

Services.obs.addObserver(WebappManager, "webapps-ask-install", false);
Services.obs.addObserver(WebappManager, "webapps-launch", false);
Services.obs.addObserver(WebappManager, "webapps-uninstall", false);
Services.obs.addObserver(WebappManager, "webapps-update", false);

DOMApplicationRegistry.registerUpdateHandler(WebappManager.update);