If we receive an application/octet-stream, check the mime type by looking at its extension.
This commit is contained in:
parent
e179dbae14
commit
891624888f
@ -3,11 +3,15 @@
|
||||
#include <nsIFactory.h>
|
||||
#include <nsIFile.h>
|
||||
#include <nsIFileURL.h>
|
||||
#include <nsServiceManagerUtils.h>
|
||||
#include <nsIMIMEService.h>
|
||||
|
||||
#include "sugar-download-manager.h"
|
||||
|
||||
#include "GeckoDownload.h"
|
||||
|
||||
#define APPLICATION_OCTET_STREAM "application/octet-stream"
|
||||
|
||||
class GeckoDownload : public nsITransfer
|
||||
{
|
||||
public:
|
||||
@ -62,6 +66,8 @@ GeckoDownload::Init (nsIURI *aSource,
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
|
||||
file->GetNativePath (mTargetFileName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -80,6 +86,26 @@ GeckoDownload::OnStateChange (nsIWebProgress *aWebProgress,
|
||||
mMIMEInfo->GetMIMEType(mimeType);
|
||||
mSource->GetSpec(url);
|
||||
|
||||
/* If the file is application/octet-stream, look up a better mime type
|
||||
from the extension. */
|
||||
if(mimeType.Equals(APPLICATION_OCTET_STREAM)) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMIMEService> mimeService(
|
||||
do_GetService("@mozilla.org/mime;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
const char *fileExt = strrchr(mTargetFileName.get(), '.');
|
||||
if(fileExt) {
|
||||
nsCString contentType;
|
||||
|
||||
mimeService->GetTypeFromExtension(nsCString(fileExt),
|
||||
contentType);
|
||||
if(!contentType.IsEmpty()) {
|
||||
mimeType = contentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sugar_download_manager_download_started(download_manager,
|
||||
url.get(),
|
||||
mimeType.get(),
|
||||
|
Loading…
Reference in New Issue
Block a user