2012-06-21 21:06:24 +00:00
|
|
|
/* 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";
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["WebappsHandler"];
|
2012-06-21 21:06:24 +00:00
|
|
|
|
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
let Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Webapps.jsm");
|
|
|
|
Cu.import("resource://gre/modules/WebappsInstaller.jsm");
|
2012-07-16 18:22:16 +00:00
|
|
|
Cu.import("resource://gre/modules/WebappOSUtils.jsm");
|
2012-06-21 21:06:24 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.WebappsHandler = {
|
2012-06-21 21:06:24 +00:00
|
|
|
init: function() {
|
|
|
|
Services.obs.addObserver(this, "webapps-ask-install", false);
|
|
|
|
Services.obs.addObserver(this, "webapps-launch", false);
|
2012-08-09 01:04:48 +00:00
|
|
|
Services.obs.addObserver(this, "webapps-uninstall", false);
|
2012-06-21 21:06:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
data = JSON.parse(data);
|
2012-09-18 17:34:55 +00:00
|
|
|
data.mm = subject;
|
2012-06-21 21:06:24 +00:00
|
|
|
|
|
|
|
switch (topic) {
|
|
|
|
case "webapps-ask-install":
|
2013-05-07 16:34:21 +00:00
|
|
|
let chromeWin = Services.wm.getOuterWindowById(data.oid);
|
2012-06-21 21:06:24 +00:00
|
|
|
if (chromeWin)
|
|
|
|
this.doInstall(data, chromeWin);
|
|
|
|
break;
|
|
|
|
case "webapps-launch":
|
2012-07-16 18:22:16 +00:00
|
|
|
WebappOSUtils.launch(data);
|
2012-06-21 21:06:24 +00:00
|
|
|
break;
|
2012-08-09 01:04:48 +00:00
|
|
|
case "webapps-uninstall":
|
|
|
|
WebappOSUtils.uninstall(data);
|
|
|
|
break;
|
2012-06-21 21:06:24 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
doInstall: function(data, window) {
|
|
|
|
let {name} = data.app.manifest;
|
|
|
|
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 && WebappsInstaller.install(data)) {
|
|
|
|
DOMApplicationRegistry.confirmInstall(data);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DOMApplicationRegistry.denyInstall(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|