b=639467 Use GIO in HandlerExists and GetAppDescForScheme r=karlt
authorChris Coulson <chrisccoulson@ubuntu.com>
Wed, 04 May 2011 16:10:43 +1200
changeset 69123 46a89f1c9263208b2e144dd2b1aac0da6a5ff3eb
parent 69122 3833fae240f758f70ceb18e7b3b9c0717fdc1c1f
child 69124 0c911d0c3a62f878b1fd052c36675b76ba4e3c8b
push id19867
push userktomlinson@mozilla.com
push dateSun, 08 May 2011 22:33:36 +0000
treeherdermozilla-central@46a89f1c9263 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs639467
milestone6.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
b=639467 Use GIO in HandlerExists and GetAppDescForScheme r=karlt
uriloader/exthandler/unix/nsGNOMERegistry.cpp
--- a/uriloader/exthandler/unix/nsGNOMERegistry.cpp
+++ b/uriloader/exthandler/unix/nsGNOMERegistry.cpp
@@ -55,26 +55,35 @@
 
 #ifdef MOZ_PLATFORM_MAEMO
 #include <libintl.h>
 #endif
 
 /* static */ PRBool
 nsGNOMERegistry::HandlerExists(const char *aProtocolScheme)
 {
+  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
   nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
-  if (!gconf)
-    return PR_FALSE;
+  if (giovfs) {
+    nsCOMPtr<nsIGIOMimeApp> app;
+    if (NS_FAILED(giovfs->GetAppForURIScheme(nsDependentCString(aProtocolScheme),
+                                             getter_AddRefs(app))))
+      return PR_FALSE;
+    else
+      return PR_TRUE;
+  } else if (gconf) {
+    PRBool isEnabled;
+    nsCAutoString handler;
+    if (NS_FAILED(gconf->GetAppForProtocol(nsDependentCString(aProtocolScheme), &isEnabled, handler)))
+      return PR_FALSE;
 
-  PRBool isEnabled;
-  nsCAutoString handler;
-  if (NS_FAILED(gconf->GetAppForProtocol(nsDependentCString(aProtocolScheme), &isEnabled, handler)))
-    return PR_FALSE;
+    return isEnabled;
+  }
 
-  return isEnabled;
+  return PR_FALSE;
 }
 
 // XXX Check HandlerExists() before calling LoadURL.
 //
 // If there is not a registered handler for the protocol, gnome_url_show()
 // falls back to using gnomevfs modules.  See bug 389632.  We don't want
 // this fallback to happen as we are not sure of the safety of all gnomevfs
 // modules and MIME-default applications.  (gnomevfs should be handled in
@@ -94,37 +103,46 @@ nsGNOMERegistry::LoadURL(nsIURI *aURL)
   return NS_ERROR_FAILURE;
 }
 
 /* static */ void
 nsGNOMERegistry::GetAppDescForScheme(const nsACString& aScheme,
                                      nsAString& aDesc)
 {
   nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
-  if (!gconf)
-    return;
-
-  PRBool isEnabled;
-  nsCAutoString app;
-  if (NS_FAILED(gconf->GetAppForProtocol(aScheme, &isEnabled, app)))
+  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
+  if (!gconf && !giovfs)
     return;
 
-  if (!app.IsEmpty()) {
-    // Try to only provide the executable name, as it is much simpler than with the path and arguments
-    PRInt32 firstSpace = app.FindChar(' ');
-    if (firstSpace != kNotFound) {
-      app.Truncate(firstSpace);
-      PRInt32 lastSlash = app.RFindChar('/');
-      if (lastSlash != kNotFound) {
-        app.Cut(0, lastSlash + 1);
+  nsCAutoString name;
+  if (giovfs) {
+    nsCOMPtr<nsIGIOMimeApp> app;
+    if (NS_FAILED(giovfs->GetAppForURIScheme(aScheme, getter_AddRefs(app))))
+      return;
+
+    app->GetName(name);
+  } else {
+    PRBool isEnabled;
+    if (NS_FAILED(gconf->GetAppForProtocol(aScheme, &isEnabled, name)))
+      return;
+
+    if (!name.IsEmpty()) {
+      // Try to only provide the executable name, as it is much simpler than with the path and arguments
+      PRInt32 firstSpace = name.FindChar(' ');
+      if (firstSpace != kNotFound) {
+        name.Truncate(firstSpace);
+        PRInt32 lastSlash = name.RFindChar('/');
+        if (lastSlash != kNotFound) {
+          name.Cut(0, lastSlash + 1);
+        }
       }
     }
+  }
 
-    CopyUTF8toUTF16(app, aDesc);
-  }
+  CopyUTF8toUTF16(name, aDesc);
 }
 
 
 /* static */ already_AddRefed<nsMIMEInfoBase>
 nsGNOMERegistry::GetFromExtension(const nsACString& aFileExt)
 {
   nsCAutoString mimeType;
   nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);