From effc578374d6db06eac852f2c56903f942ee51ae Mon Sep 17 00:00:00 2001 From: Felipe Gomes Date: Fri, 29 Jun 2012 13:46:21 -0700 Subject: [PATCH] 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 | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/dom/apps/src/Webapps.jsm b/dom/apps/src/Webapps.jsm index ecee89a3db9..3af4cca665c 100644 --- a/dom/apps/src/Webapps.jsm +++ b/dom/apps/src/Webapps.jsm @@ -35,6 +35,7 @@ XPCOMUtils.defineLazyGetter(this, "ppmm", function() { let DOMApplicationRegistry = { appsFile: null, webapps: { }, + allAppsLaunchable: false, init: function() { this.messages = ["Webapps:Install", "Webapps:Uninstall", @@ -445,6 +446,61 @@ let DOMApplicationRegistry = { } } 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 + } };