Bug 327323 - Can't "Open with" files that are send as application/octet-stream (Linux). r=bzbarsky

This commit is contained in:
Wolfgang Rosenauer 2009-10-17 09:53:12 +02:00
parent 31f455b520
commit 522e07958d
2 changed files with 31 additions and 12 deletions

View File

@ -48,6 +48,7 @@
#include "nsGNOMERegistry.h"
#include "nsIGIOService.h"
#include "nsIGnomeVFSService.h"
#include "nsAutoPtr.h"
#ifdef MOZ_ENABLE_DBUS
#include "nsDBusHandlerApp.h"
#endif
@ -75,18 +76,14 @@ NS_IMETHODIMP
nsMIMEInfoUnix::GetHasDefaultHandler(PRBool *_retval)
{
*_retval = PR_FALSE;
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
if (giovfs) {
nsCOMPtr<nsIGIOMimeApp> app;
if (NS_SUCCEEDED(giovfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app)
*_retval = PR_TRUE;
} else if (gnomevfs) {
/* Fallback to GnomeVFS*/
nsCOMPtr<nsIGnomeVFSMimeApp> app;
if (NS_SUCCEEDED(gnomevfs->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;
@ -128,6 +125,23 @@ nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile)
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 (giovfs) {
nsCOMPtr<nsIGIOMimeApp> app;
if (NS_SUCCEEDED(giovfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
return app->Launch(nativePath);
} else if (gnomevfs) {
nsCOMPtr<nsIGnomeVFSMimeApp> app;
if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
return app->Launch(nativePath);
}
}
if (!mDefaultApplication)
return NS_ERROR_FILE_NOT_FOUND;

View File

@ -1580,7 +1580,12 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aType,
return retval;
}
// Copy the attributes of retval onto miByExt, to return it
// Copy the attributes of retval (mimeinfo from type) onto miByExt, to
// return it
// but reset to just collected mDefaultAppDescription (from ext)
nsAutoString byExtDefault;
miByExt->GetDefaultDescription(byExtDefault);
retval->SetDefaultDescription(byExtDefault);
retval->CopyBasicDataTo(miByExt);
miByExt.swap(retval);