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/. */
7 this.EXPORTED_SYMBOLS = ["WebappsHandler"];
9 let Cc = Components.classes;
10 let Ci = Components.interfaces;
11 let Cu = Components.utils;
13 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
14 Cu.import("resource://gre/modules/Services.jsm");
15 Cu.import("resource://gre/modules/Webapps.jsm");
16 Cu.import("resource://gre/modules/AppsUtils.jsm");
17 Cu.import("resource://gre/modules/WebappsInstaller.jsm");
18 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
20 this.WebappsHandler = {
21 observe: function(subject, topic, data) {
22 data = JSON.parse(data);
26 case "webapps-ask-install":
27 let chromeWin = Services.wm.getOuterWindowWithId(data.oid);
29 this.doInstall(data, chromeWin);
31 case "webapps-launch":
32 WebappOSUtils.launch(data);
34 case "webapps-uninstall":
35 WebappOSUtils.uninstall(data);
40 doInstall: function(data, window) {
41 let jsonManifest = data.isPackage ? data.app.updateManifest : data.app.manifest;
42 let manifest = new ManifestHelper(jsonManifest, data.app.origin);
43 let name = manifest.name;
44 let bundle = Services.strings.createBundle("chrome://webapprt/locale/webapp.properties");
46 let choice = Services.prompt.confirmEx(
48 bundle.formatStringFromName("webapps.install.title", [name], 1),
49 bundle.formatStringFromName("webapps.install.description", [name], 1),
50 // Set both buttons to strings with the cancel button being default
51 Ci.nsIPromptService.BUTTON_POS_1_DEFAULT |
52 Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_0 |
53 Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_1,
54 bundle.GetStringFromName("webapps.install.install"),
55 bundle.GetStringFromName("webapps.install.dontinstall"),
60 // Perform the install if the user allows it
62 let shell = WebappsInstaller.init(data);
66 if (shell.appProfile) {
67 localDir = shell.appProfile.localDir;
70 DOMApplicationRegistry.confirmInstall(data, localDir,
71 function (aManifest) {
72 WebappsInstaller.install(data, aManifest);
76 DOMApplicationRegistry.denyInstall(data);
79 DOMApplicationRegistry.denyInstall(data);
83 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
84 Ci.nsISupportsWeakReference])
87 Services.obs.addObserver(WebappsHandler, "webapps-ask-install", false);
88 Services.obs.addObserver(WebappsHandler, "webapps-launch", false);
89 Services.obs.addObserver(WebappsHandler, "webapps-uninstall", false);