Bug 774142. Support webapp uninstallation on Linux through mozApps.uninstall function. r=felipe
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Wed, 08 Aug 2012 18:04:48 -0700
changeset 107387 bcd9fb49866b47aca81e0db06bfe7fb2d20c355c
parent 107386 5556678cfd6c10e134c85c7dc5caa0713f23470f
child 107388 e8049b1a59263e10a53527b77d3be636c8b07813
push id1490
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 18:29:50 +0000
treeherdermozilla-beta@f335e7dacdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs774142
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 774142. Support webapp uninstallation on Linux through mozApps.uninstall function. r=felipe
browser/modules/webappsUI.jsm
dom/apps/src/Webapps.jsm
toolkit/webapps/WebappOSUtils.jsm
webapprt/WebappsHandler.jsm
--- a/browser/modules/webappsUI.jsm
+++ b/browser/modules/webappsUI.jsm
@@ -13,35 +13,40 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Webapps.jsm");
 Cu.import("resource://gre/modules/WebappsInstaller.jsm");
 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
 
 let webappsUI = {
   init: function webappsUI_init() {
     Services.obs.addObserver(this, "webapps-ask-install", false);
     Services.obs.addObserver(this, "webapps-launch", false);
+    Services.obs.addObserver(this, "webapps-uninstall", false);
   },
   
   uninit: function webappsUI_uninit() {
     Services.obs.removeObserver(this, "webapps-ask-install");
     Services.obs.removeObserver(this, "webapps-launch");
+    Services.obs.removeObserver(this, "webapps-uninstall");
   },
 
   observe: function webappsUI_observe(aSubject, aTopic, aData) {
     let data = JSON.parse(aData);
 
     switch(aTopic) {
       case "webapps-ask-install":
         let [chromeWin, browser] = this._getBrowserForId(data.oid);
         if (chromeWin)
           this.doInstall(data, browser, chromeWin);
         break;
       case "webapps-launch":
         WebappOSUtils.launch(data);
         break;
+      case "webapps-uninstall":
+        WebappOSUtils.uninstall(data);
+        break;
     }
   },
 
   openURL: function(aUrl, aOrigin) {
     let browserEnumerator = Services.wm.getEnumerator("navigator:browser");  
     let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
 
     // Check each browser instance for our URL
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -216,16 +216,17 @@ let DOMApplicationRegistry = {
       case "Webapps:Install":
         // always ask for UI to install
         Services.obs.notifyObservers(this, "webapps-ask-install", JSON.stringify(msg));
         break;
       case "Webapps:GetSelf":
         this.getSelf(msg);
         break;
       case "Webapps:Uninstall":
+        Services.obs.notifyObservers(this, "webapps-uninstall", JSON.stringify(msg));
         this.uninstall(msg);
         break;
       case "Webapps:Launch":
         Services.obs.notifyObservers(this, "webapps-launch", JSON.stringify(msg));
         break;
       case "Webapps:GetInstalled":
         this.getInstalled(msg);
         break;
--- a/toolkit/webapps/WebappOSUtils.jsm
+++ b/toolkit/webapps/WebappOSUtils.jsm
@@ -52,19 +52,19 @@ let WebappOSUtils = {
     if (appPath) {
       mwaUtils.launchAppWithIdentifier(aData.origin);
       return true;
     }
 
     return false;
 #elifdef XP_UNIX
     let origin = Services.io.newURI(aData.origin, null, null);
-    let installDir = "." + origin.scheme + ";" + origin.host;
-    if (origin.port != -1)
-      installDir += ";" + origin.port;
+    let installDir = "." + origin.scheme + ";" +
+                     origin.host +
+                     (origin.port != -1 ? ";" + origin.port : "");
 
     let exeFile = Services.dirsvc.get("Home", Ci.nsIFile);
     exeFile.append(installDir);
     exeFile.append("webapprt-stub");
 
     try {
       if (exeFile.exists()) {
         let process = Cc["@mozilla.org/process/util;1"]
@@ -72,10 +72,36 @@ let WebappOSUtils = {
         process.init(exeFile);
         process.runAsync([], 0);
         return true;
       }
     } catch (e) {}
 
     return false;
 #endif
+  },
+
+  uninstall: function(aData) {
+#ifdef XP_UNIX
+#ifndef XP_MACOSX
+    let origin = Services.io.newURI(aData.origin, null, null);
+    let installDir = "." + origin.scheme + ";" +
+                     origin.host +
+                     (origin.port != -1 ? ";" + origin.port : "");
+
+    let exeFile = Services.dirsvc.get("Home", Ci.nsIFile);
+    exeFile.append(installDir);
+    exeFile.append("webapprt-stub");
+
+    try {
+      if (exeFile.exists()) {
+        var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
+        process.init(exeFile);
+        process.runAsync(["-remove"], 1);
+        return true;
+      }
+    } catch(e) {}
+
+    return false;
+#endif
+#endif
   }
 }
--- a/webapprt/WebappsHandler.jsm
+++ b/webapprt/WebappsHandler.jsm
@@ -14,30 +14,34 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/Webapps.jsm");
 Cu.import("resource://gre/modules/WebappsInstaller.jsm");
 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
 
 let WebappsHandler = {
   init: function() {
     Services.obs.addObserver(this, "webapps-ask-install", false);
     Services.obs.addObserver(this, "webapps-launch", false);
+    Services.obs.addObserver(this, "webapps-uninstall", false);
   },
 
   observe: function(subject, topic, data) {
     data = JSON.parse(data);
 
     switch (topic) {
       case "webapps-ask-install":
         let chromeWin = this._getWindowByOuterId(data.oid);
         if (chromeWin)
           this.doInstall(data, chromeWin);
         break;
       case "webapps-launch":
         WebappOSUtils.launch(data);
         break;
+      case "webapps-uninstall":
+        WebappOSUtils.uninstall(data);
+        break;
     }
   },
 
   _getWindowByOuterId: function(outerId) {
     let someWindow = Services.wm.getMostRecentWindow(null);
     if (!someWindow) {
       return null;
     }