a8a561
diff -up thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp.moz-694870-backout thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp
a8a561
--- thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp.moz-694870-backout	2016-04-07 23:33:34.000000000 +0200
a8a561
+++ thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp	2016-05-10 15:17:28.973860591 +0200
a8a561
@@ -6,50 +6,95 @@
a8a561
 #include "nsGNOMERegistry.h"
a8a561
 #include "nsString.h"
a8a561
 #include "nsIComponentManager.h"
a8a561
+#include "nsIFile.h"
a8a561
 #include "nsMIMEInfoUnix.h"
a8a561
 #include "nsAutoPtr.h"
a8a561
+#include "nsIGConfService.h"
a8a561
+#include "nsIGnomeVFSService.h"
a8a561
 #include "nsIGIOService.h"
a8a561
 
a8a561
+#ifdef MOZ_WIDGET_GTK
a8a561
+#include <glib.h>
a8a561
+#include <glib-object.h>
a8a561
+#endif
a8a561
+
a8a561
 /* static */ bool
a8a561
 nsGNOMERegistry::HandlerExists(const char *aProtocolScheme)
a8a561
 {
a8a561
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
a8a561
-  if (!giovfs) {
a8a561
-    return false;
a8a561
-  }
a8a561
+  nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
a8a561
+  if (giovfs) {
a8a561
+    nsCOMPtr<nsIGIOMimeApp> app;
a8a561
+    if (NS_FAILED(giovfs->GetAppForURIScheme(nsDependentCString(aProtocolScheme),
a8a561
+                                             getter_AddRefs(app))))
a8a561
+      return false;
a8a561
+    else
a8a561
+      return true;
a8a561
+  } else if (gconf) {
a8a561
+    bool isEnabled;
a8a561
+    nsAutoCString handler;
a8a561
+    if (NS_FAILED(gconf->GetAppForProtocol(nsDependentCString(aProtocolScheme), &isEnabled, handler)))
a8a561
+      return false;
a8a561
 
a8a561
-  nsCOMPtr<nsIGIOMimeApp> app;
a8a561
-  return NS_SUCCEEDED(giovfs->GetAppForURIScheme(nsDependentCString(aProtocolScheme),
a8a561
-                                                 getter_AddRefs(app)));
a8a561
+    return isEnabled;
a8a561
+  }
a8a561
+  return false;
a8a561
 }
a8a561
 
a8a561
 // XXX Check HandlerExists() before calling LoadURL.
a8a561
+//
a8a561
+// If there is not a registered handler for the protocol, gnome_url_show()
a8a561
+// falls back to using gnomevfs modules.  See bug 389632.  We don't want
a8a561
+// this fallback to happen as we are not sure of the safety of all gnomevfs
a8a561
+// modules and MIME-default applications.  (gnomevfs should be handled in
a8a561
+// nsGnomeVFSProtocolHandler.)
a8a561
 
a8a561
 /* static */ nsresult
a8a561
 nsGNOMERegistry::LoadURL(nsIURI *aURL)
a8a561
 {
a8a561
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
a8a561
-  if (!giovfs) {
a8a561
-    return NS_ERROR_FAILURE;
a8a561
-  }
a8a561
+  if (giovfs)
a8a561
+    return giovfs->ShowURI(aURL);
a8a561
+  nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
a8a561
+  if (gnomevfs)
a8a561
+    return gnomevfs->ShowURI(aURL);
a8a561
 
a8a561
-  return giovfs->ShowURI(aURL);
a8a561
+  return NS_ERROR_FAILURE;
a8a561
 }
a8a561
 
a8a561
 /* static */ void
a8a561
 nsGNOMERegistry::GetAppDescForScheme(const nsACString& aScheme,
a8a561
                                      nsAString& aDesc)
a8a561
 {
a8a561
+  nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
a8a561
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
a8a561
-  if (!giovfs)
a8a561
+  if (!gconf && !giovfs)
a8a561
     return;
a8a561
 
a8a561
   nsAutoCString name;
a8a561
-  nsCOMPtr<nsIGIOMimeApp> app;
a8a561
-  if (NS_FAILED(giovfs->GetAppForURIScheme(aScheme, getter_AddRefs(app))))
a8a561
-    return;
a8a561
-
a8a561
-  app->GetName(name);
a8a561
+  if (giovfs) {
a8a561
+    nsCOMPtr<nsIGIOMimeApp> app;
a8a561
+    if (NS_FAILED(giovfs->GetAppForURIScheme(aScheme, getter_AddRefs(app))))
a8a561
+      return;
a8a561
+
a8a561
+    app->GetName(name);
a8a561
+  } else {
a8a561
+    bool isEnabled;
a8a561
+    if (NS_FAILED(gconf->GetAppForProtocol(aScheme, &isEnabled, name)))
a8a561
+      return;
a8a561
+
a8a561
+    if (!name.IsEmpty()) {
a8a561
+      // Try to only provide the executable name, as it is much simpler than with the path and arguments
a8a561
+      int32_t firstSpace = name.FindChar(' ');
a8a561
+      if (firstSpace != kNotFound) {
a8a561
+        name.Truncate(firstSpace);
a8a561
+        int32_t lastSlash = name.RFindChar('/');
a8a561
+        if (lastSlash != kNotFound) {
a8a561
+          name.Cut(0, lastSlash + 1);
a8a561
+        }
a8a561
+      }
a8a561
+    }
a8a561
+  }
a8a561
 
a8a561
   CopyUTF8toUTF16(name, aDesc);
a8a561
 }
a8a561
@@ -60,15 +105,22 @@ nsGNOMERegistry::GetFromExtension(const
a8a561
 {
a8a561
   nsAutoCString mimeType;
a8a561
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
a8a561
-  if (!giovfs) {
a8a561
-    return nullptr;
a8a561
-  }
a8a561
-
a8a561
-  // Get the MIME type from the extension, then call GetFromType to
a8a561
-  // fill in the MIMEInfo.
a8a561
-  if (NS_FAILED(giovfs->GetMimeTypeFromExtension(aFileExt, mimeType)) ||
a8a561
-      mimeType.EqualsLiteral("application/octet-stream")) {
a8a561
-    return nullptr;
a8a561
+  if (giovfs) {
a8a561
+    // Get the MIME type from the extension, then call GetFromType to
a8a561
+    // fill in the MIMEInfo.
a8a561
+    if (NS_FAILED(giovfs->GetMimeTypeFromExtension(aFileExt, mimeType)) ||
a8a561
+        mimeType.EqualsLiteral("application/octet-stream")) {
a8a561
+      return nullptr;
a8a561
+    }
a8a561
+  } else {
a8a561
+    /* Fallback to GnomeVFS */
a8a561
+    nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
a8a561
+    if (!gnomevfs)
a8a561
+      return nullptr;
a8a561
+
a8a561
+    if (NS_FAILED(gnomevfs->GetMimeTypeFromExtension(aFileExt, mimeType)) ||
a8a561
+        mimeType.EqualsLiteral("application/octet-stream"))
a8a561
+      return nullptr;
a8a561
   }
a8a561
 
a8a561
   RefPtr<nsMIMEInfoBase> mi = GetFromType(mimeType);
a8a561
@@ -89,17 +141,28 @@ nsGNOMERegistry::GetFromType(const nsACS
a8a561
   nsAutoCString description;
a8a561
 
a8a561
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
a8a561
-  if (!giovfs) {
a8a561
-    return nullptr;
a8a561
-  }
a8a561
-
a8a561
-  nsCOMPtr<nsIGIOMimeApp> gioHandlerApp;
a8a561
-  if (NS_FAILED(giovfs->GetAppForMimeType(aMIMEType, getter_AddRefs(gioHandlerApp))) ||
a8a561
-      !gioHandlerApp) {
a8a561
-    return nullptr;
a8a561
+  if (giovfs) {
a8a561
+    nsCOMPtr<nsIGIOMimeApp> gioHandlerApp;
a8a561
+    if (NS_FAILED(giovfs->GetAppForMimeType(aMIMEType, getter_AddRefs(gioHandlerApp))) ||
a8a561
+        !gioHandlerApp) {
a8a561
+      return nullptr;
a8a561
+    }
a8a561
+    gioHandlerApp->GetName(name);
a8a561
+    giovfs->GetDescriptionForMimeType(aMIMEType, description);
a8a561
+  } else {
a8a561
+    /* Fallback to GnomeVFS*/
a8a561
+    nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
a8a561
+    if (!gnomevfs)
a8a561
+      return nullptr;
a8a561
+
a8a561
+    nsCOMPtr<nsIGnomeVFSMimeApp> gnomeHandlerApp;
a8a561
+    if (NS_FAILED(gnomevfs->GetAppForMimeType(aMIMEType, getter_AddRefs(gnomeHandlerApp))) ||
a8a561
+        !gnomeHandlerApp) {
a8a561
+      return nullptr;
a8a561
+    }
a8a561
+    gnomeHandlerApp->GetName(name);
a8a561
+    gnomevfs->GetDescriptionForMimeType(aMIMEType, description);
a8a561
   }
a8a561
-  gioHandlerApp->GetName(name);
a8a561
-  giovfs->GetDescriptionForMimeType(aMIMEType, description);
a8a561
 
a8a561
   mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUTF16(name));
a8a561
   mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
a8a561
diff -up thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp.moz-694870-backout thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
a8a561
--- thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp.moz-694870-backout	2016-04-07 23:33:34.000000000 +0200
a8a561
+++ thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp	2016-05-11 08:24:13.869018683 +0200
a8a561
@@ -16,6 +16,7 @@
a8a561
 #include "nsIGIOService.h"
a8a561
 #include "nsNetCID.h"
a8a561
 #include "nsIIOService.h"
a8a561
+#include "nsIGnomeVFSService.h"
a8a561
 #include "nsAutoPtr.h"
a8a561
 #ifdef MOZ_ENABLE_DBUS
a8a561
 #include "nsDBusHandlerApp.h"
a8a561
@@ -103,26 +104,51 @@ nsMIMEInfoUnix::LaunchDefaultWithFile(ns
a8a561
 #endif
a8a561
 
a8a561
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
a8a561
-  if (!giovfs) {
a8a561
-    return NS_ERROR_FAILURE;
a8a561
-  }
a8a561
-
a8a561
-  // nsGIOMimeApp->Launch wants a URI string instead of local file
a8a561
-  nsresult rv;
a8a561
-  nsCOMPtr<nsIIOService> ioservice = do_GetService(NS_IOSERVICE_CONTRACTID, &rv;;
a8a561
-  NS_ENSURE_SUCCESS(rv, rv);
a8a561
-  nsCOMPtr<nsIURI> uri;
a8a561
-  rv = ioservice->NewFileURI(aFile, getter_AddRefs(uri));
a8a561
-  NS_ENSURE_SUCCESS(rv, rv);
a8a561
   nsAutoCString uriSpec;
a8a561
-  uri->GetSpec(uriSpec);
a8a561
+  if (giovfs) {
a8a561
+    // nsGIOMimeApp->Launch wants a URI string instead of local file
a8a561
+    nsresult rv;
a8a561
+    nsCOMPtr<nsIIOService> ioservice = do_GetService(NS_IOSERVICE_CONTRACTID, &rv;;
a8a561
+    NS_ENSURE_SUCCESS(rv, rv);
a8a561
+    nsCOMPtr<nsIURI> uri;
a8a561
+    rv = ioservice->NewFileURI(aFile, getter_AddRefs(uri));
a8a561
+    NS_ENSURE_SUCCESS(rv, rv);
a8a561
+    uri->GetSpec(uriSpec);
a8a561
+  }
a8a561
+
a8a561
+  nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
a8a561
+  if (giovfs) {
a8a561
+    nsCOMPtr<nsIGIOMimeApp> app;
a8a561
+    if (NS_SUCCEEDED(giovfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) && app)
a8a561
+      return app->Launch(uriSpec);
a8a561
+  } else if (gnomevfs) {
a8a561
+    /* Fallback to GnomeVFS */
a8a561
+    nsCOMPtr<nsIGnomeVFSMimeApp> app;
a8a561
+    if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) && app)
a8a561
+      return app->Launch(nativePath);
a8a561
+  }
a8a561
+
a8a561
+  // If we haven't got an app we try to get a valid one by searching for the
a8a561
+  // extension mapped type
a8a561
+  RefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromExtension(nativePath);
a8a561
+  if (mimeInfo) {
a8a561
+    nsAutoCString type;
a8a561
+    mimeInfo->GetType(type);
a8a561
+    if (giovfs) {
a8a561
+      nsCOMPtr<nsIGIOMimeApp> app;
a8a561
+      if (NS_SUCCEEDED(giovfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
a8a561
+        return app->Launch(uriSpec);
a8a561
+    } else if (gnomevfs) {
a8a561
+      nsCOMPtr<nsIGnomeVFSMimeApp> app;
a8a561
+      if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
a8a561
+        return app->Launch(nativePath);
a8a561
+    }
a8a561
+  }
a8a561
 
a8a561
-  nsCOMPtr<nsIGIOMimeApp> app;
a8a561
-  if (NS_FAILED(giovfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) || !app) {
a8a561
+  if (!mDefaultApplication)
a8a561
     return NS_ERROR_FILE_NOT_FOUND;
a8a561
-  }
a8a561
 
a8a561
-  return app->Launch(uriSpec);
a8a561
+  return LaunchWithIProcess(mDefaultApplication, nativePath);
a8a561
 }
a8a561
 
a8a561
 #if defined(MOZ_ENABLE_CONTENTACTION)
a8a561
diff -up thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp.moz-694870-backout thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp
a8a561
--- thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp.moz-694870-backout	2016-04-07 23:33:34.000000000 +0200
a8a561
+++ thunderbird-45.0/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp	2016-05-10 15:17:28.974860591 +0200
a8a561
@@ -1150,7 +1150,7 @@ nsresult nsOSHelperAppService::OSProtoco
a8a561
 #endif
a8a561
 
a8a561
 #ifdef MOZ_WIDGET_GTK
a8a561
-  // Check the GNOME registry for a protocol handler
a8a561
+  // Check the GConf registry for a protocol handler
a8a561
   *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme);
a8a561
 #endif
a8a561
 
a8a561
@@ -1369,6 +1369,22 @@ nsOSHelperAppService::GetFromType(const
a8a561
           NS_LossyConvertUTF16toASCII(handler).get(),
a8a561
           NS_LossyConvertUTF16toASCII(mailcap_description).get()));
a8a561
 
a8a561
+#ifdef MOZ_WIDGET_GTK
a8a561
+  RefPtr<nsMIMEInfoBase> gnomeInfo;
a8a561
+  if (handler.IsEmpty()) {
a8a561
+    // No useful data yet.  Check the GNOME registry.  Unfortunately, newer
a8a561
+    // GNOME versions no longer have type-to-extension mappings, so we might
a8a561
+    // get back a MIMEInfo without any extensions set.  In that case we'll have
a8a561
+    // to look in our mime.types files for the extensions.
a8a561
+    LOG(("Looking in GNOME registry\n"));
a8a561
+    gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType);
a8a561
+    if (gnomeInfo && gnomeInfo->HasExtensions()) {
a8a561
+      LOG(("Got MIMEInfo from GNOME registry, and it has extensions set\n"));
a8a561
+      return gnomeInfo.forget();
a8a561
+    }
a8a561
+  }
a8a561
+#endif
a8a561
+
a8a561
   // Now look up our extensions
a8a561
   nsAutoString extensions, mime_types_description;
a8a561
   LookUpExtensionsAndDescription(majorType,
a8a561
@@ -1377,16 +1393,13 @@ nsOSHelperAppService::GetFromType(const
a8a561
                                  mime_types_description);
a8a561
 
a8a561
 #ifdef MOZ_WIDGET_GTK
a8a561
-  if (handler.IsEmpty()) {
a8a561
-    RefPtr<nsMIMEInfoBase> gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType);
a8a561
-    if (gnomeInfo) {
a8a561
-      LOG(("Got MIMEInfo from GNOME registry without extensions; setting them "
a8a561
-           "to %s\n", NS_LossyConvertUTF16toASCII(extensions).get()));
a8a561
-
a8a561
-      NS_ASSERTION(!gnomeInfo->HasExtensions(), "How'd that happen?");
a8a561
-      gnomeInfo->SetFileExtensions(NS_ConvertUTF16toUTF8(extensions));
a8a561
-      return gnomeInfo.forget();
a8a561
-    }
a8a561
+  if (gnomeInfo) {
a8a561
+    LOG(("Got MIMEInfo from GNOME registry without extensions; setting them "
a8a561
+         "to %s\n", NS_LossyConvertUTF16toASCII(extensions).get()));
a8a561
+
a8a561
+    NS_ASSERTION(!gnomeInfo->HasExtensions(), "How'd that happen?");
a8a561
+    gnomeInfo->SetFileExtensions(NS_ConvertUTF16toUTF8(extensions));
a8a561
+    return gnomeInfo.forget();
a8a561
   }
a8a561
 #endif
a8a561
 
a8a561
@@ -1513,6 +1526,9 @@ nsOSHelperAppService::GetProtocolHandler
a8a561
 {
a8a561
   NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");
a8a561
 
a8a561
+  // We must check that a registered handler exists so that gnome_url_show
a8a561
+  // doesn't fallback to gnomevfs.
a8a561
+  // See nsGNOMERegistry::LoadURL and bug 389632.
a8a561
   nsresult rv = OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(),
a8a561
                                         found);
a8a561
   if (NS_FAILED(rv))