If we have an /etc/mime.types extension for a type, that should NOT make/etc/mailcap override the gnome-vfs handler for that type. Patch partially byMike Hommey <mh+mozilla@glandium.org> and partially by me, r+sr=biesi
authorbzbarsky@mit.edu
Sun, 15 Apr 2007 13:43:49 -0700
changeset 542 b7b5b326331d7550efc0f445249d35b68dfaa56a
parent 541 1819b8d802eb86a443e4269a5bcd46091ae5f0a4
child 543 21e3ecb149698b2bcaeb892a0e76c757f0e61d4c
push idunknown
push userunknown
push dateunknown
milestone1.9a4pre
If we have an /etc/mime.types extension for a type, that should NOT make/etc/mailcap override the gnome-vfs handler for that type. Patch partially byMike Hommey <mh+mozilla@glandium.org> and partially by me, r+sr=biesi
uriloader/exthandler/nsMIMEInfoImpl.cpp
uriloader/exthandler/nsMIMEInfoImpl.h
uriloader/exthandler/unix/nsOSHelperAppService.cpp
--- a/uriloader/exthandler/nsMIMEInfoImpl.cpp
+++ b/uriloader/exthandler/nsMIMEInfoImpl.cpp
@@ -42,30 +42,30 @@
 #include "nsStringEnumerator.h"
 #include "nsIProcess.h"
 
 // nsISupports methods
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoBase, nsIMIMEInfo)
 
 // nsMIMEInfoImpl methods
 nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) :
+    mMacType(0),
+    mMacCreator(0),
     mMIMEType(aMIMEType),
     mPreferredAction(nsIMIMEInfo::saveToDisk),
-    mAlwaysAskBeforeHandling(PR_TRUE),
-    mMacType(0),
-    mMacCreator(0)
+    mAlwaysAskBeforeHandling(PR_TRUE)
 {
 }
 
 nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aMIMEType) :
+    mMacType(0),
+    mMacCreator(0),
     mMIMEType(aMIMEType),
     mPreferredAction(nsIMIMEInfo::saveToDisk),
-    mAlwaysAskBeforeHandling(PR_TRUE),
-    mMacType(0),
-    mMacCreator(0)
+    mAlwaysAskBeforeHandling(PR_TRUE)
 {
 }
 
 nsMIMEInfoBase::~nsMIMEInfoBase()
 {
 }
 
 NS_IMETHODIMP
--- a/uriloader/exthandler/nsMIMEInfoImpl.h
+++ b/uriloader/exthandler/nsMIMEInfoImpl.h
@@ -106,16 +106,21 @@ class nsMIMEInfoBase : public nsIMIMEInf
      * MIME Info. The data consists of the MIME Type, the (default) description,
      * the MacOS type and creator, and the extension list (this object's
      * extension list will replace aOther's list, not append to it). This
      * function also ensures that aOther's primary extension will be the same as
      * the one of this object.
      */
     void CopyBasicDataTo(nsMIMEInfoBase* aOther);
 
+    /**
+     * Return whether this MIMEInfo has any extensions
+     */
+    PRBool HasExtensions() const { return mExtensions.Count() != 0; }
+
   protected:
     /**
      * Launch the default application for the given file.
      * For even more control over the launching, override launchWithFile.
      * Also see the comment about nsIMIMEInfo in general, above.
      *
      * @param aFile The file that should be opened
      */
--- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp
@@ -1501,68 +1501,86 @@ nsOSHelperAppService::GetFromType(const 
                               minorTypeStart, minorTypeEnd, end_iter);
 
   if (NS_FAILED(rv)) {
     return nsnull;
   }
 
   nsDependentSubstring majorType(majorTypeStart, majorTypeEnd);
   nsDependentSubstring minorType(minorTypeStart, minorTypeEnd);
-  nsAutoString extensions, mime_types_description;
-  LookUpExtensionsAndDescription(majorType,
-                                 minorType,
-                                 extensions,
-                                 mime_types_description);
 
-
+  // First check the user's private mailcap file
   nsAutoString mailcap_description, handler, mozillaFlags;
   DoLookUpHandlerAndDescription(majorType,
                                 minorType,
                                 typeOptions,
                                 handler,
                                 mailcap_description,
                                 mozillaFlags,
                                 PR_TRUE);
+  
+  LOG(("Private Handler/Description results:  handler='%s', description='%s'\n",
+          NS_LossyConvertUTF16toASCII(handler).get(),
+          NS_LossyConvertUTF16toASCII(mailcap_description).get()));
 
-  
-  if (handler.IsEmpty() && extensions.IsEmpty() &&
-      mailcap_description.IsEmpty() && mime_types_description.IsEmpty()) {
-    // No useful data yet
-    
 #ifdef MOZ_WIDGET_GTK2
+  nsMIMEInfoBase *gnomeInfo = nsnull;
+  if (handler.IsEmpty()) {
+    // No useful data yet.  Check the GNOME registry.  Unfortunately, newer
+    // GNOME versions no longer have type-to-extension mappings, so we might
+    // get back a MIMEInfo without any extensions set.  In that case we'll have
+    // to look in our mime.types files for the extensions.    
     LOG(("Looking in GNOME registry\n"));
-    nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
-    if (gnomeInfo) {
-      LOG(("Got MIMEInfo from GNOME registry\n"));
+    gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
+    if (gnomeInfo && gnomeInfo->HasExtensions()) {
+      LOG(("Got MIMEInfo from GNOME registry, and it has extensions set\n"));
       return gnomeInfo;
     }
-#endif
   }
+#endif
 
-  if (handler.IsEmpty() && mailcap_description.IsEmpty()) {
+  // Now look up our extensions
+  nsAutoString extensions, mime_types_description;
+  LookUpExtensionsAndDescription(majorType,
+                                 minorType,
+                                 extensions,
+                                 mime_types_description);
+
+#ifdef MOZ_WIDGET_GTK2
+  if (gnomeInfo) {
+    LOG(("Got MIMEInfo from GNOME registry without extensions; setting them "
+         "to %s\n", NS_LossyConvertUTF16toASCII(extensions).get()));
+
+    NS_ASSERTION(!gnomeInfo->HasExtensions(), "How'd that happen?");
+    gnomeInfo->SetFileExtensions(NS_ConvertUTF16toUTF8(extensions));
+    return gnomeInfo;
+  }
+#endif
+
+  if (handler.IsEmpty()) {
     DoLookUpHandlerAndDescription(majorType,
                                   minorType,
                                   typeOptions,
                                   handler,
                                   mailcap_description,
                                   mozillaFlags,
                                   PR_FALSE);
   }
 
-  if (handler.IsEmpty() && mailcap_description.IsEmpty()) {
+  if (handler.IsEmpty()) {
     DoLookUpHandlerAndDescription(majorType,
                                   NS_LITERAL_STRING("*"),
                                   typeOptions,
                                   handler,
                                   mailcap_description,
                                   mozillaFlags,
                                   PR_TRUE);
   }
 
-  if (handler.IsEmpty() && mailcap_description.IsEmpty()) {
+  if (handler.IsEmpty()) {
     DoLookUpHandlerAndDescription(majorType,
                                   NS_LITERAL_STRING("*"),
                                   typeOptions,
                                   handler,
                                   mailcap_description,
                                   mozillaFlags,
                                   PR_FALSE);
   }