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/Services.jsm");
14 Cu.import("resource://gre/modules/Webapps.jsm");
15 Cu.import("resource://gre/modules/WebappsInstaller.jsm");
16 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
18 this.WebappsHandler = {
20 Services.obs.addObserver(this, "webapps-ask-install", false);
21 Services.obs.addObserver(this, "webapps-launch", false);
22 Services.obs.addObserver(this, "webapps-uninstall", false);
25 observe: function(subject, topic, data) {
26 data = JSON.parse(data);
30 case "webapps-ask-install":
31 let chromeWin = this._getWindowByOuterId(data.oid);
33 this.doInstall(data, chromeWin);
35 case "webapps-launch":
36 WebappOSUtils.launch(data);
38 case "webapps-uninstall":
39 WebappOSUtils.uninstall(data);
44 _getWindowByOuterId: function(outerId) {
45 let someWindow = Services.wm.getMostRecentWindow(null);
50 let content = someWindow.QueryInterface(Ci.nsIInterfaceRequestor).
51 getInterface(Ci.nsIDOMWindowUtils).
52 getOuterWindowWithId(outerId);
56 doInstall: function(data, window) {
57 let {name} = data.app.manifest;
58 let bundle = Services.strings.createBundle("chrome://webapprt/locale/webapp.properties");
60 let choice = Services.prompt.confirmEx(
62 bundle.formatStringFromName("webapps.install.title", [name], 1),
63 bundle.formatStringFromName("webapps.install.description", [name], 1),
64 // Set both buttons to strings with the cancel button being default
65 Ci.nsIPromptService.BUTTON_POS_1_DEFAULT |
66 Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_0 |
67 Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_1,
68 bundle.GetStringFromName("webapps.install.install"),
69 bundle.GetStringFromName("webapps.install.dontinstall"),
74 // Perform the install if the user allows it
75 if (choice == 0 && WebappsInstaller.install(data)) {
76 DOMApplicationRegistry.confirmInstall(data);
79 DOMApplicationRegistry.denyInstall(data);