From: Wolfgang Rosenauer <wr@rosenauer.org>
Subject: no helper app for application/octet-stream but recognized extensions
References:
https://bugzilla.novell.com/show_bug.cgi?id=406979
https://bugzilla.mozilla.org/show_bug.cgi?id=327323

Index: uriloader/exthandler/nsMIMEInfoImpl.cpp
===================================================================
RCS file: /cvsroot/mozilla/uriloader/exthandler/nsMIMEInfoImpl.cpp,v
retrieving revision 1.69
diff -u -p -6 -r1.69 nsMIMEInfoImpl.cpp
--- uriloader/exthandler/nsMIMEInfoImpl.cpp	19 Oct 2007 04:15:43 -0000	1.69
+++ uriloader/exthandler/nsMIMEInfoImpl.cpp	20 Aug 2008 15:45:32 -0000
@@ -408,13 +408,13 @@ nsMIMEInfoBase::LaunchWithURI(nsIURI* aU
 }
 
 void
 nsMIMEInfoBase::CopyBasicDataTo(nsMIMEInfoBase* aOther)
 {
   aOther->mType = mType;
-  aOther->mDefaultAppDescription = mDefaultAppDescription;
+  //aOther->mDefaultAppDescription = mDefaultAppDescription;
   aOther->mExtensions = mExtensions;
 
   aOther->mMacType = mMacType;
   aOther->mMacCreator = mMacCreator;
 }
 
Index: uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
===================================================================
RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp,v
retrieving revision 1.5
diff -u -p -6 -r1.5 nsMIMEInfoUnix.cpp
--- uriloader/exthandler/unix/nsMIMEInfoUnix.cpp	8 Apr 2008 23:18:16 -0000	1.5
+++ uriloader/exthandler/unix/nsMIMEInfoUnix.cpp	20 Aug 2008 15:45:32 -0000
@@ -37,49 +37,63 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMIMEInfoUnix.h"
 #include "nsGNOMERegistry.h"
 #include "nsIGnomeVFSService.h"
+#include "nsAutoPtr.h"
 
 nsresult
 nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI)
 {
   return nsGNOMERegistry::LoadURL(aURI);
 }
 
 NS_IMETHODIMP
 nsMIMEInfoUnix::GetHasDefaultHandler(PRBool *_retval)
 {
   *_retval = PR_FALSE;
-  nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
-  if (vfs) {
-    nsCOMPtr<nsIGnomeVFSMimeApp> app;
-    if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app)
-      *_retval = PR_TRUE;
+  nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromType(mType);
+  if (!mimeInfo) {
+     nsCAutoString ext;
+     GetPrimaryExtension(ext);
+     mimeInfo = nsGNOMERegistry::GetFromExtension(ext);
   }
 
+  if (mimeInfo)
+    *_retval = PR_TRUE;
+
   if (*_retval)
     return NS_OK;
 
   // If we didn't find a VFS handler, fallback.
   return nsMIMEInfoImpl::GetHasDefaultHandler(_retval);
 }
 
 nsresult
 nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile)
 {
   nsCAutoString nativePath;
   aFile->GetNativePath(nativePath);
-
+  
   nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
 
   if (vfs) {
     nsCOMPtr<nsIGnomeVFSMimeApp> app;
     if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app)
       return app->Launch(nativePath);
+
+    // If we haven't got an app we try to get a valid one by searching for the
+    // extension mapped type
+    nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromExtension(nativePath);
+    if (mimeInfo) {
+      nsCAutoString type;
+      mimeInfo->GetType(type);
+      if (NS_SUCCEEDED(vfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
+        return app->Launch(nativePath);
+    }
   }
 
   if (!mDefaultApplication)
     return NS_ERROR_FILE_NOT_FOUND;
 
   return LaunchWithIProcess(mDefaultApplication, nativePath);
Index: uriloader/exthandler/unix/nsOSHelperAppService.cpp
===================================================================
RCS file: /cvsroot/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp,v
retrieving revision 1.74
diff -u -p -6 -r1.74 nsOSHelperAppService.cpp
--- uriloader/exthandler/unix/nsOSHelperAppService.cpp	20 Feb 2008 06:10:33 -0000	1.74
+++ uriloader/exthandler/unix/nsOSHelperAppService.cpp	20 Aug 2008 15:45:33 -0000
@@ -1621,12 +1621,16 @@ nsOSHelperAppService::GetMIMEInfoFromOS(
       
       return retval;
     }
 
     // Copy the attributes of retval onto miByExt, to return it
     retval->CopyBasicDataTo(miByExt);
+    // But set the extensions primary since CopyBasicDataTo overwrites the
+    // list
+    if (!aFileExt.IsEmpty())
+      retval->SetPrimaryExtension(aFileExt);
 
     miByExt.swap(retval);
   }
   return retval;
 }
 
