Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | this.EXPORTED_SYMBOLS = ["WebappManager"]; |
michael@0 | 8 | |
michael@0 | 9 | let Cc = Components.classes; |
michael@0 | 10 | let Ci = Components.interfaces; |
michael@0 | 11 | let Cu = Components.utils; |
michael@0 | 12 | |
michael@0 | 13 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 14 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 15 | Cu.import("resource://gre/modules/Webapps.jsm"); |
michael@0 | 16 | Cu.import("resource://gre/modules/AppsUtils.jsm"); |
michael@0 | 17 | Cu.import("resource://gre/modules/NativeApp.jsm"); |
michael@0 | 18 | Cu.import("resource://gre/modules/WebappOSUtils.jsm"); |
michael@0 | 19 | Cu.import("resource://webapprt/modules/WebappRT.jsm"); |
michael@0 | 20 | |
michael@0 | 21 | this.WebappManager = { |
michael@0 | 22 | observe: function(subject, topic, data) { |
michael@0 | 23 | data = JSON.parse(data); |
michael@0 | 24 | data.mm = subject; |
michael@0 | 25 | |
michael@0 | 26 | switch (topic) { |
michael@0 | 27 | case "webapps-ask-install": |
michael@0 | 28 | let chromeWin = Services.wm.getOuterWindowWithId(data.oid); |
michael@0 | 29 | if (chromeWin) |
michael@0 | 30 | this.doInstall(data, chromeWin); |
michael@0 | 31 | break; |
michael@0 | 32 | case "webapps-launch": |
michael@0 | 33 | WebappOSUtils.launch(data); |
michael@0 | 34 | break; |
michael@0 | 35 | case "webapps-uninstall": |
michael@0 | 36 | WebappOSUtils.uninstall(data); |
michael@0 | 37 | break; |
michael@0 | 38 | } |
michael@0 | 39 | }, |
michael@0 | 40 | |
michael@0 | 41 | update: function(aApp, aManifest, aZipPath) { |
michael@0 | 42 | let nativeApp = new NativeApp(aApp, aManifest, |
michael@0 | 43 | WebappRT.config.app.categories, |
michael@0 | 44 | WebappRT.config.registryDir); |
michael@0 | 45 | nativeApp.prepareUpdate(aManifest, aZipPath); |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | doInstall: function(data, window) { |
michael@0 | 49 | let jsonManifest = data.isPackage ? data.app.updateManifest : data.app.manifest; |
michael@0 | 50 | let manifest = new ManifestHelper(jsonManifest, data.app.origin); |
michael@0 | 51 | let name = manifest.name; |
michael@0 | 52 | let bundle = Services.strings.createBundle("chrome://webapprt/locale/webapp.properties"); |
michael@0 | 53 | |
michael@0 | 54 | let choice = Services.prompt.confirmEx( |
michael@0 | 55 | window, |
michael@0 | 56 | bundle.formatStringFromName("webapps.install.title", [name], 1), |
michael@0 | 57 | bundle.formatStringFromName("webapps.install.description", [name], 1), |
michael@0 | 58 | // Set both buttons to strings with the cancel button being default |
michael@0 | 59 | Ci.nsIPromptService.BUTTON_POS_1_DEFAULT | |
michael@0 | 60 | Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_0 | |
michael@0 | 61 | Ci.nsIPromptService.BUTTON_TITLE_IS_STRING * Ci.nsIPromptService.BUTTON_POS_1, |
michael@0 | 62 | bundle.GetStringFromName("webapps.install.install"), |
michael@0 | 63 | bundle.GetStringFromName("webapps.install.dontinstall"), |
michael@0 | 64 | null, |
michael@0 | 65 | null, |
michael@0 | 66 | {}); |
michael@0 | 67 | |
michael@0 | 68 | // Perform the install if the user allows it |
michael@0 | 69 | if (choice == 0) { |
michael@0 | 70 | let nativeApp = new NativeApp(data.app, jsonManifest, |
michael@0 | 71 | WebappRT.config.app.categories, |
michael@0 | 72 | WebappRT.config.registryDir); |
michael@0 | 73 | let localDir; |
michael@0 | 74 | try { |
michael@0 | 75 | localDir = nativeApp.createProfile(); |
michael@0 | 76 | } catch (ex) { |
michael@0 | 77 | DOMApplicationRegistry.denyInstall(aData); |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | DOMApplicationRegistry.confirmInstall(data, localDir, |
michael@0 | 82 | function (aManifest, aZipPath) { |
michael@0 | 83 | nativeApp.install(aManifest, aZipPath); |
michael@0 | 84 | } |
michael@0 | 85 | ); |
michael@0 | 86 | } else { |
michael@0 | 87 | DOMApplicationRegistry.denyInstall(data); |
michael@0 | 88 | } |
michael@0 | 89 | }, |
michael@0 | 90 | |
michael@0 | 91 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, |
michael@0 | 92 | Ci.nsISupportsWeakReference]) |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | Services.obs.addObserver(WebappManager, "webapps-ask-install", false); |
michael@0 | 96 | Services.obs.addObserver(WebappManager, "webapps-launch", false); |
michael@0 | 97 | Services.obs.addObserver(WebappManager, "webapps-uninstall", false); |
michael@0 | 98 | Services.obs.addObserver(WebappManager, "webapps-update", false); |
michael@0 | 99 | |
michael@0 | 100 | DOMApplicationRegistry.registerUpdateHandler(WebappManager.update); |