1334bf1
Index: uriloader/exthandler/Makefile.in
1334bf1
===================================================================
1334bf1
RCS file: /cvsroot/mozilla/uriloader/exthandler/Makefile.in,v
1334bf1
retrieving revision 1.60
1334bf1
diff -d -u -p -r1.60 Makefile.in
1334bf1
--- uriloader/exthandler/Makefile.in	2 May 2005 16:30:03 -0000	1.60
1334bf1
+++ uriloader/exthandler/Makefile.in	21 Jul 2005 03:07:39 -0000
1334bf1
@@ -102,7 +102,7 @@ endif
1334bf1
 LOCAL_INCLUDES = -I$(srcdir)
1334bf1
 
1334bf1
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
1334bf1
-OSHELPER	+= nsGNOMERegistry.cpp
1334bf1
+OSHELPER	+= nsMIMEInfoUnix.cpp nsGNOMERegistry.cpp
1334bf1
 endif
1334bf1
 
1334bf1
 ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
fa0cf49
Index: uriloader/exthandler/unix/nsGNOMERegistry.cpp
fa0cf49
===================================================================
fa0cf49
RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.cpp,v
fa0cf49
retrieving revision 1.10
fa0cf49
diff -d -u -p -r1.10 nsGNOMERegistry.cpp
fa0cf49
--- uriloader/exthandler/unix/nsGNOMERegistry.cpp	16 Oct 2004 13:46:17 -0000	1.10
1334bf1
+++ uriloader/exthandler/unix/nsGNOMERegistry.cpp	21 Jul 2005 03:07:40 -0000
fa0cf49
@@ -42,7 +42,7 @@
fa0cf49
 #include "nsString.h"
fa0cf49
 #include "nsIComponentManager.h"
fa0cf49
 #include "nsILocalFile.h"
fa0cf49
-#include "nsMIMEInfoImpl.h"
fa0cf49
+#include "nsMIMEInfoUnix.h"
fa0cf49
 #include "nsAutoPtr.h"
fa0cf49
 
fa0cf49
 #include <glib.h>
fa0cf49
@@ -56,12 +56,12 @@ typedef struct _GConfClient GConfClient;
fa0cf49
 typedef struct _GnomeProgram GnomeProgram;
fa0cf49
 typedef struct _GnomeModuleInfo GnomeModuleInfo;
fa0cf49
 
fa0cf49
-typedef struct {
fa0cf49
+struct GnomeVFSMimeApplication {
fa0cf49
   char *id;
fa0cf49
   char *name;
fa0cf49
   char *command;
fa0cf49
   /* there is more here, but we don't need it */
fa0cf49
-} GnomeVFSMimeApplication;
fa0cf49
+};
fa0cf49
 
fa0cf49
 typedef GConfClient * (*_gconf_client_get_default_fn)();
fa0cf49
 typedef gchar * (*_gconf_client_get_string_fn)(GConfClient *,
fa0cf49
@@ -264,7 +264,7 @@ nsGNOMERegistry::GetAppDescForScheme(con
fa0cf49
 }
fa0cf49
 
fa0cf49
 
fa0cf49
-/* static */ already_AddRefed<nsMIMEInfoBase>
fa0cf49
+/* static */ already_AddRefed<nsMIMEInfoUnix>
fa0cf49
 nsGNOMERegistry::GetFromExtension(const char *aFileExt)
fa0cf49
 {
fa0cf49
   if (!gconfLib)
fa0cf49
@@ -286,7 +286,7 @@ nsGNOMERegistry::GetFromExtension(const 
fa0cf49
   return GetFromType(mimeType);
fa0cf49
 }
fa0cf49
 
fa0cf49
-/* static */ already_AddRefed<nsMIMEInfoBase>
fa0cf49
+/* static */ already_AddRefed<nsMIMEInfoUnix>
fa0cf49
 nsGNOMERegistry::GetFromType(const char *aMIMEType)
fa0cf49
 {
fa0cf49
   if (!gconfLib)
1334bf1
@@ -296,9 +296,11 @@ nsGNOMERegistry::GetFromType(const char 
fa0cf49
   if (!handlerApp)
fa0cf49
     return nsnull;
fa0cf49
 
fa0cf49
-  nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(aMIMEType);
fa0cf49
+  nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType);
fa0cf49
   NS_ENSURE_TRUE(mimeInfo, nsnull);
fa0cf49
 
1334bf1
+  mimeInfo->SetDefaultGnomeVFSMimeApplication(handlerApp);
1334bf1
+
fa0cf49
   // Get the list of extensions and append then to the mimeInfo.
1334bf1
   GList *extensions = _gnome_vfs_mime_get_extensions_list(aMIMEType);
1334bf1
   for (GList *extension = extensions; extension; extension = extension->next)
1334bf1
@@ -320,11 +322,21 @@ nsGNOMERegistry::GetFromType(const char 
fa0cf49
     return nsnull;
fa0cf49
   }
fa0cf49
 
fa0cf49
-  gchar *commandPath = g_find_program_in_path(nativeCommand);
fa0cf49
+  gchar **argv;
fa0cf49
+  gboolean res = g_shell_parse_argv(nativeCommand, NULL, &argv, NULL);
fa0cf49
+  if (!res) {
fa0cf49
+    NS_ERROR("Could not convert helper app command to filesystem encoding");
fa0cf49
+    _gnome_vfs_mime_application_free(handlerApp);
fa0cf49
+    return nsnull;
fa0cf49
+  }
fa0cf49
+
fa0cf49
+  gchar *commandPath = g_find_program_in_path(argv[0]);
fa0cf49
 
fa0cf49
   g_free(nativeCommand);
fa0cf49
+  g_strfreev(argv);
fa0cf49
 
fa0cf49
   if (!commandPath) {
fa0cf49
+    NS_WARNING("could not find command in path");
fa0cf49
     _gnome_vfs_mime_application_free(handlerApp);
fa0cf49
     return nsnull;
fa0cf49
   }
1334bf1
@@ -342,7 +354,7 @@ nsGNOMERegistry::GetFromType(const char 
fa0cf49
 
fa0cf49
   _gnome_vfs_mime_application_free(handlerApp);
fa0cf49
 
fa0cf49
-  nsMIMEInfoBase* retval;
fa0cf49
+  nsMIMEInfoUnix* retval;
fa0cf49
   NS_ADDREF((retval = mimeInfo));
fa0cf49
   return retval;
fa0cf49
 }
fa0cf49
Index: uriloader/exthandler/unix/nsGNOMERegistry.h
fa0cf49
===================================================================
fa0cf49
RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsGNOMERegistry.h,v
fa0cf49
retrieving revision 1.3
fa0cf49
diff -d -u -p -r1.3 nsGNOMERegistry.h
fa0cf49
--- uriloader/exthandler/unix/nsGNOMERegistry.h	16 Oct 2004 13:46:17 -0000	1.3
1334bf1
+++ uriloader/exthandler/unix/nsGNOMERegistry.h	21 Jul 2005 03:07:40 -0000
fa0cf49
@@ -35,10 +35,13 @@
fa0cf49
  *
fa0cf49
  * ***** END LICENSE BLOCK ***** */
fa0cf49
 
fa0cf49
+#ifndef nsGNOMERegistry_h__
fa0cf49
+#define nsGNOMERegistry_h__
fa0cf49
+
fa0cf49
 #include "nsIURI.h"
fa0cf49
 #include "nsCOMPtr.h"
fa0cf49
 
fa0cf49
-class nsMIMEInfoBase;
fa0cf49
+class nsMIMEInfoUnix;
fa0cf49
 
fa0cf49
 class nsGNOMERegistry
fa0cf49
 {
fa0cf49
@@ -52,7 +55,9 @@ class nsGNOMERegistry
fa0cf49
   static void GetAppDescForScheme(const nsACString& aScheme,
fa0cf49
                                   nsAString& aDesc);
fa0cf49
 
fa0cf49
-  static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
fa0cf49
+  static already_AddRefed<nsMIMEInfoUnix> GetFromExtension(const char *aFileExt);
fa0cf49
 
fa0cf49
-  static already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMIMEType);
fa0cf49
+  static already_AddRefed<nsMIMEInfoUnix> GetFromType(const char *aMIMEType);
fa0cf49
 };
fa0cf49
+
fa0cf49
+#endif // nsGNOMERegistry_h__
fa0cf49
Index: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
fa0cf49
===================================================================
fa0cf49
RCS file: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
fa0cf49
diff -N uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
fa0cf49
--- /dev/null	1 Jan 1970 00:00:00 -0000
1334bf1
+++ uriloader/exthandler/unix/nsMIMEInfoUnix.cpp	21 Jul 2005 03:07:40 -0000
fa0cf49
@@ -0,0 +1,196 @@
fa0cf49
+/* ***** BEGIN LICENSE BLOCK *****
fa0cf49
+ * Version: MPL 1.1
fa0cf49
+ *
fa0cf49
+ * The contents of this file are subject to the Mozilla Public License Version
fa0cf49
+ * 1.1 (the "License"); you may not use this file except in compliance with
fa0cf49
+ * the License. You may obtain a copy of the License at
fa0cf49
+ * http://www.mozilla.org/MPL/
fa0cf49
+ *
fa0cf49
+ * Software distributed under the License is distributed on an "AS IS" basis,
fa0cf49
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
fa0cf49
+ * for the specific language governing rights and limitations under the
fa0cf49
+ * License.
fa0cf49
+ *
fa0cf49
+ * The Original Code is mozilla.org Code.
fa0cf49
+ *
fa0cf49
+ * The Initial Developer of the Original Code is
fa0cf49
+ * Red Hat, Inc.
fa0cf49
+ * Portions created by the Initial Developer are Copyright (C) 2005
fa0cf49
+ * the Initial Developer. All Rights Reserved.
fa0cf49
+ *
fa0cf49
+ * Contributor(s):
fa0cf49
+ *   Christopher Aillon <caillon@redhat.com> (Original author)
fa0cf49
+ *
fa0cf49
+ *
fa0cf49
+ * ***** END LICENSE BLOCK ***** */
fa0cf49
+
fa0cf49
+#include "nsMIMEInfoUnix.h"
fa0cf49
+#include "prlink.h"
fa0cf49
+#include "prmem.h"
fa0cf49
+#include <glib.h>
fa0cf49
+#include <glib-object.h>
fa0cf49
+
fa0cf49
+static PRLibrary *gnomeLib;
fa0cf49
+static PRLibrary *vfsLib;
fa0cf49
+
fa0cf49
+typedef struct _GnomeProgram GnomeProgram;
fa0cf49
+typedef struct _GnomeModuleInfo GnomeModuleInfo;
fa0cf49
+
fa0cf49
+typedef enum {
fa0cf49
+  GNOME_VFS_OK // there's more but we don't care about them.
fa0cf49
+} GnomeVFSResult;
fa0cf49
+
fa0cf49
+typedef GnomeVFSResult (*_gnome_vfs_mime_application_launch_fn)
fa0cf49
+                              (GnomeVFSMimeApplication *app,
fa0cf49
+                               GList *uris);
fa0cf49
+typedef void (*_gnome_vfs_mime_application_free_fn)(GnomeVFSMimeApplication *);
fa0cf49
+typedef GnomeVFSMimeApplication * (*_gnome_vfs_mime_application_copy_fn)(GnomeVFSMimeApplication *);
fa0cf49
+typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *,
fa0cf49
+						 const GnomeModuleInfo *, int,
fa0cf49
+						 char **, const char *, ...);
fa0cf49
+typedef const char * (*_gnome_vfs_mime_application_get_name_fn)(GnomeVFSMimeApplication *);
fa0cf49
+typedef const GnomeModuleInfo * (*_libgnome_module_info_get_fn)();
fa0cf49
+typedef GnomeProgram * (*_gnome_program_get_fn)();
fa0cf49
+typedef char * (*_gnome_vfs_make_uri_from_input_fn)(const char *);
fa0cf49
+
fa0cf49
+#define DECL_FUNC_PTR(func) static _##func##_fn _##func
fa0cf49
+
fa0cf49
+DECL_FUNC_PTR(gnome_vfs_mime_application_launch);
fa0cf49
+DECL_FUNC_PTR(gnome_vfs_mime_application_free);
fa0cf49
+DECL_FUNC_PTR(gnome_vfs_mime_application_copy);
fa0cf49
+DECL_FUNC_PTR(gnome_vfs_mime_application_get_name);
fa0cf49
+DECL_FUNC_PTR(gnome_program_init);
fa0cf49
+DECL_FUNC_PTR(gnome_program_get);
fa0cf49
+DECL_FUNC_PTR(libgnome_module_info_get);
fa0cf49
+DECL_FUNC_PTR(gnome_vfs_make_uri_from_input);
fa0cf49
+
fa0cf49
+static PRLibrary *
fa0cf49
+LoadVersionedLibrary(const char* libName, const char* libVersion)
fa0cf49
+{
fa0cf49
+  char *platformLibName = PR_GetLibraryName(nsnull, libName);
fa0cf49
+  nsCAutoString versionLibName(platformLibName);
fa0cf49
+  versionLibName.Append(libVersion);
fa0cf49
+  PR_Free(platformLibName);
fa0cf49
+  return PR_LoadLibrary(versionLibName.get());
fa0cf49
+}
fa0cf49
+
fa0cf49
+static void
fa0cf49
+Cleanup()
fa0cf49
+{
fa0cf49
+  // Unload all libraries
fa0cf49
+  if (gnomeLib)
fa0cf49
+    PR_UnloadLibrary(gnomeLib);
fa0cf49
+  if (vfsLib)
fa0cf49
+    PR_UnloadLibrary(vfsLib);
fa0cf49
+
fa0cf49
+  gnomeLib = vfsLib = nsnull;
fa0cf49
+}
fa0cf49
+
fa0cf49
+static void
fa0cf49
+InitGnomeVFS()
fa0cf49
+{
fa0cf49
+  static PRBool initialized = PR_FALSE;
fa0cf49
+
fa0cf49
+  if (initialized)
fa0cf49
+    return;
fa0cf49
+
fa0cf49
+  #define ENSURE_LIB(lib) \
fa0cf49
+    PR_BEGIN_MACRO \
fa0cf49
+    if (!lib) { \
fa0cf49
+      Cleanup(); \
fa0cf49
+      return; \
fa0cf49
+    } \
fa0cf49
+    PR_END_MACRO
fa0cf49
+
fa0cf49
+  #define GET_LIB_FUNCTION(lib, func, failure) \
fa0cf49
+    PR_BEGIN_MACRO \
fa0cf49
+    _##func = (_##func##_fn) PR_FindFunctionSymbol(lib##Lib, #func); \
fa0cf49
+    if (!_##func) { \
fa0cf49
+      failure; \
fa0cf49
+    } \
fa0cf49
+    PR_END_MACRO
fa0cf49
+
fa0cf49
+  // Attempt to open libgnome
fa0cf49
+  gnomeLib = LoadVersionedLibrary("gnome-2", ".0");
fa0cf49
+  ENSURE_LIB(gnomeLib);
fa0cf49
+
fa0cf49
+  GET_LIB_FUNCTION(gnome, gnome_program_init, return Cleanup());
fa0cf49
+  GET_LIB_FUNCTION(gnome, libgnome_module_info_get, return Cleanup());
fa0cf49
+  GET_LIB_FUNCTION(gnome, gnome_program_get, return Cleanup());
fa0cf49
+
fa0cf49
+  // Attempt to open libgnomevfs
fa0cf49
+  vfsLib = LoadVersionedLibrary("gnomevfs-2", ".0");
fa0cf49
+  ENSURE_LIB(vfsLib);
fa0cf49
+
fa0cf49
+  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_launch, /* do nothing */);
fa0cf49
+  GET_LIB_FUNCTION(vfs, gnome_vfs_make_uri_from_input, return Cleanup());
fa0cf49
+  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_get_name, return Cleanup());
fa0cf49
+  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_free, return Cleanup());
fa0cf49
+  GET_LIB_FUNCTION(vfs, gnome_vfs_mime_application_copy, return Cleanup());
fa0cf49
+
fa0cf49
+  // Initialize GNOME, if it's not already initialized.  It's not
fa0cf49
+  // necessary to tell GNOME about our actual command line arguments.
fa0cf49
+
fa0cf49
+  if (!_gnome_program_get()) {
fa0cf49
+    char *argv[1] = { "gecko" };
fa0cf49
+    _gnome_program_init("Gecko", "1.0", _libgnome_module_info_get(),
fa0cf49
+                        1, argv, NULL);
fa0cf49
+  }
fa0cf49
+
fa0cf49
+  // Note: after GNOME has been initialized, do not ever unload these
fa0cf49
+  // libraries.  They register atexit handlers, so if they are unloaded, we'll
fa0cf49
+  // crash on exit.  
fa0cf49
+}
fa0cf49
+
fa0cf49
+void
fa0cf49
+nsMIMEInfoUnix::SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication* app)
fa0cf49
+{
fa0cf49
+  if (_gnome_vfs_mime_application_copy && _gnome_vfs_mime_application_free) {
fa0cf49
+    mDefaultVFSApplication = _gnome_vfs_mime_application_copy(app);
fa0cf49
+
fa0cf49
+    mPreferredAction = nsIMIMEInfo::useSystemDefault;
fa0cf49
+
fa0cf49
+    const gchar * name = _gnome_vfs_mime_application_get_name(mDefaultVFSApplication);
fa0cf49
+    if (name) 
fa0cf49
+      mDefaultAppDescription = NS_ConvertUTF8toUCS2(name);
fa0cf49
+  }
fa0cf49
+}
fa0cf49
+
fa0cf49
+nsMIMEInfoUnix::~nsMIMEInfoUnix()
fa0cf49
+{
fa0cf49
+  if (mDefaultVFSApplication)
fa0cf49
+    _gnome_vfs_mime_application_free(mDefaultVFSApplication);
fa0cf49
+}
fa0cf49
+
fa0cf49
+nsresult
fa0cf49
+nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile* aFile)
fa0cf49
+{
fa0cf49
+  NS_ENSURE_ARG_POINTER(aFile);
fa0cf49
+
fa0cf49
+  InitGnomeVFS();
fa0cf49
+
fa0cf49
+  if (_gnome_vfs_mime_application_launch && mDefaultVFSApplication) {
fa0cf49
+    nsCAutoString nativePath;
fa0cf49
+    aFile->GetNativePath(nativePath);
fa0cf49
+
fa0cf49
+    gchar *uri = _gnome_vfs_make_uri_from_input(nativePath.get());
fa0cf49
+
fa0cf49
+    GList *uris = NULL;
fa0cf49
+    uris = g_list_append(uris, uri);
fa0cf49
+
fa0cf49
+    GnomeVFSResult result = _gnome_vfs_mime_application_launch(mDefaultVFSApplication, uris);
fa0cf49
+
fa0cf49
+    g_free(uri);
fa0cf49
+    g_list_free(uris);
fa0cf49
+
fa0cf49
+    if (result != GNOME_VFS_OK)
fa0cf49
+      return NS_ERROR_FAILURE;
fa0cf49
+
fa0cf49
+    return NS_OK;
fa0cf49
+  }
fa0cf49
+
fa0cf49
+  if (!mDefaultApplication)
fa0cf49
+    return NS_ERROR_FILE_NOT_FOUND;
fa0cf49
+
fa0cf49
+  return LaunchWithIProcess(mDefaultApplication, aFile);
fa0cf49
+}
fa0cf49
Index: uriloader/exthandler/unix/nsMIMEInfoUnix.h
fa0cf49
===================================================================
fa0cf49
RCS file: uriloader/exthandler/unix/nsMIMEInfoUnix.h
fa0cf49
diff -N uriloader/exthandler/unix/nsMIMEInfoUnix.h
fa0cf49
--- /dev/null	1 Jan 1970 00:00:00 -0000
1334bf1
+++ uriloader/exthandler/unix/nsMIMEInfoUnix.h	21 Jul 2005 03:07:40 -0000
1334bf1
@@ -0,0 +1,50 @@
fa0cf49
+/* ***** BEGIN LICENSE BLOCK *****
fa0cf49
+ * Version: MPL 1.1
fa0cf49
+ *
fa0cf49
+ * The contents of this file are subject to the Mozilla Public License Version
fa0cf49
+ * 1.1 (the "License"); you may not use this file except in compliance with
fa0cf49
+ * the License. You may obtain a copy of the License at
fa0cf49
+ * http://www.mozilla.org/MPL/
fa0cf49
+ *
fa0cf49
+ * Software distributed under the License is distributed on an "AS IS" basis,
fa0cf49
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
fa0cf49
+ * for the specific language governing rights and limitations under the
fa0cf49
+ * License.
fa0cf49
+ *
fa0cf49
+ * The Original Code is mozilla.org Code.
fa0cf49
+ *
fa0cf49
+ * The Initial Developer of the Original Code is
fa0cf49
+ * Red Hat, Inc.
fa0cf49
+ * Portions created by the Initial Developer are Copyright (C) 2005
fa0cf49
+ * the Initial Developer. All Rights Reserved.
fa0cf49
+ *
fa0cf49
+ * Contributor(s):
fa0cf49
+ *   Christopher Aillon <caillon@redhat.com> (Original author)
fa0cf49
+ *
fa0cf49
+ *
fa0cf49
+ * ***** END LICENSE BLOCK ***** */
fa0cf49
+
fa0cf49
+#ifndef nsMimeInfoUnix_h__
fa0cf49
+#define nsMimeInfoUnix_h__
fa0cf49
+
fa0cf49
+#include "nsMIMEInfoImpl.h"
fa0cf49
+
fa0cf49
+struct GnomeVFSMimeApplication;
fa0cf49
+
fa0cf49
+class nsMIMEInfoUnix : public nsMIMEInfoImpl
fa0cf49
+{
fa0cf49
+public:
fa0cf49
+  nsMIMEInfoUnix(const char* aType = "") : nsMIMEInfoImpl(aType), mDefaultVFSApplication(nsnull) {}
fa0cf49
+  nsMIMEInfoUnix(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {};
fa0cf49
+
1334bf1
+  virtual ~nsMIMEInfoUnix();
1334bf1
+
fa0cf49
+  void SetDefaultGnomeVFSMimeApplication(GnomeVFSMimeApplication *app);
fa0cf49
+
fa0cf49
+protected:
fa0cf49
+  virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
fa0cf49
+
fa0cf49
+  GnomeVFSMimeApplication *mDefaultVFSApplication;
fa0cf49
+};
fa0cf49
+ 
fa0cf49
+#endif // nsMimeInfoUnix_h__
fa0cf49
Index: uriloader/exthandler/unix/nsOSHelperAppService.cpp
fa0cf49
===================================================================
fa0cf49
RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp,v
fa0cf49
retrieving revision 1.58
fa0cf49
diff -d -u -p -r1.58 nsOSHelperAppService.cpp
fa0cf49
--- uriloader/exthandler/unix/nsOSHelperAppService.cpp	25 Oct 2004 07:46:01 -0000	1.58
1334bf1
+++ uriloader/exthandler/unix/nsOSHelperAppService.cpp	21 Jul 2005 03:07:40 -0000
fa0cf49
@@ -44,6 +44,7 @@
fa0cf49
 #include "nsOSHelperAppService.h"
fa0cf49
 #ifdef MOZ_WIDGET_GTK2
fa0cf49
 #include "nsGNOMERegistry.h"
fa0cf49
+#include "nsMIMEInfoUnix.h"
fa0cf49
 #endif
fa0cf49
 #include "nsISupports.h"
fa0cf49
 #include "nsString.h"
fa0cf49
@@ -1486,6 +1487,17 @@ nsOSHelperAppService::GetFromType(const 
fa0cf49
   
fa0cf49
   LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType.get()));
fa0cf49
 
fa0cf49
+#ifdef MOZ_WIDGET_GTK2
fa0cf49
+  // Look in GNOME registry first since it is the preferred method in GNOME,
fa0cf49
+  // should trump the mailcap entry
fa0cf49
+  LOG(("Looking in GNOME registry\n"));
fa0cf49
+  nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
fa0cf49
+  if (gnomeInfo) {
fa0cf49
+    LOG(("Got MIMEInfo from GNOME registry\n"));
fa0cf49
+    return gnomeInfo;
fa0cf49
+  }
fa0cf49
+#endif
fa0cf49
+
fa0cf49
   // extract the major and minor types
fa0cf49
   NS_ConvertASCIItoUTF16 mimeType(aMIMEType);
fa0cf49
   nsAString::const_iterator start_iter, end_iter,
fa0cf49
@@ -1522,21 +1534,6 @@ nsOSHelperAppService::GetFromType(const 
fa0cf49
                                 mozillaFlags,
fa0cf49
                                 PR_TRUE);
fa0cf49
 
fa0cf49
-  
fa0cf49
-  if (handler.IsEmpty() && extensions.IsEmpty() &&
fa0cf49
-      mailcap_description.IsEmpty() && mime_types_description.IsEmpty()) {
fa0cf49
-    // No useful data yet
fa0cf49
-    
fa0cf49
-#ifdef MOZ_WIDGET_GTK2
fa0cf49
-    LOG(("Looking in GNOME registry\n"));
fa0cf49
-    nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
fa0cf49
-    if (gnomeInfo) {
fa0cf49
-      LOG(("Got MIMEInfo from GNOME registry\n"));
fa0cf49
-      return gnomeInfo;
fa0cf49
-    }
fa0cf49
-#endif
fa0cf49
-  }
fa0cf49
-
fa0cf49
   if (handler.IsEmpty() && mailcap_description.IsEmpty()) {
fa0cf49
     DoLookUpHandlerAndDescription(majorType,
fa0cf49
                                   minorType,