Bug 768276. Part 1 - Implement Webapps._isLaunchable on desktop platforms to verify if a webapp is launchable. r=myk
authorFelipe Gomes <felipc@gmail.com>
Fri, 29 Jun 2012 13:46:21 -0700
changeset 97981 94ea4e12bb78cef5a3dc0ec3b6f3a1fe6e34a309
parent 97980 dc013da3bb9b4f5dbdbc5e5002881b73f805cb28
child 97982 3c9c6b8e048de63581f086b1c6ab894ecdee342f
push id23017
push userryanvm@gmail.com
push dateSat, 30 Jun 2012 19:29:24 +0000
treeherdermozilla-central@4c2ddc60f360 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs768276, 756306, 762698, 756307
milestone16.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 768276. Part 1 - Implement Webapps._isLaunchable on desktop platforms to verify if a webapp is launchable. r=myk Original patches for Windows by Tim in bug 756306, for Mac by Dan in bug 762698, and for Linux by Marco in bug 756307
dom/apps/src/Webapps.jsm
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -30,16 +30,17 @@ XPCOMUtils.defineLazyGetter(this, "ppmm"
   // are in a different directory (currently the Firefox profile that installed
   // the webapp); otherwise, they're in the current profile.
   const DIRECTORY_NAME = WEBAPP_RUNTIME ? "WebappRegD" : "ProfD";
 #endif
 
 let DOMApplicationRegistry = {
   appsFile: null,
   webapps: { },
+  allAppsLaunchable: false,
 
   init: function() {
     this.messages = ["Webapps:Install", "Webapps:Uninstall",
                     "Webapps:GetSelf", "Webapps:GetInstalled",
                     "Webapps:Launch", "Webapps:GetAll"];
 
     this.messages.forEach((function(msgName) {
       ppmm.addMessageListener(msgName, this);
@@ -440,16 +441,71 @@ let DOMApplicationRegistry = {
       delete this.webapps[id];
       let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
       try {
         dir.remove(true);
       } catch (e) {
       }
     }
     this._saveApps(aCallback);
+  },
+
+  _isLaunchable: function(aOrigin) {
+    if (this.allAppsLaunchable)
+      return true;
+
+#ifdef XP_WIN
+    let uninstallKey = Cc["@mozilla.org/windows-registry-key;1"]
+                         .createInstance(Ci.nsIWindowsRegKey);
+    try {
+      uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
+                        "SOFTWARE\\Microsoft\\Windows\\" +
+                        "CurrentVersion\\Uninstall\\" +
+                        aOrigin,
+                        uninstallKey.ACCESS_READ);
+      uninstallKey.close();
+      return true;
+    } catch (ex) {
+      return false;
+    }
+#elifdef XP_MACOSX
+    let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]
+                     .createInstance(Ci.nsIMacWebAppUtils);
+
+    return !!mwaUtils.pathForAppWithIdentifier(aOrigin);
+#elifdef XP_UNIX
+    let env = Cc["@mozilla.org/process/environment;1"]
+                .getService(Ci.nsIEnvironment);
+    let xdg_data_home_env = env.get("XDG_DATA_HOME");
+
+    let desktopINI;
+    if (xdg_data_home_env != "") {
+      desktopINI = Cc["@mozilla.org/file/local;1"]
+                     .createInstance(Ci.nsIFile);
+      desktopINI.initWithPath(xdg_data_home_env);
+    }
+    else {
+      desktopINI = Services.dirsvc.get("Home", Ci.nsIFile);
+      desktopINI.append(".local");
+      desktopINI.append("share");
+    }
+    desktopINI.append("applications");
+
+    let origin = Services.io.newURI(aOrigin, null, null);
+    let uniqueName = origin.scheme + ";" +
+                     origin.host +
+                     (origin.port != -1 ? ";" + origin.port : "");
+
+    desktopINI.append("owa-" + uniqueName + ".desktop");
+
+    return desktopINI.exists();
+#else
+    return true;
+#endif
+
   }
 };
 
 /**
  * Appcache download observer
  */
 AppcacheObserver = function(aApp) {
   this.app = aApp;