Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTomeu <tomeu@bicho.(none)>2007-03-30 12:32:07 (GMT)
committer Tomeu <tomeu@bicho.(none)>2007-03-30 12:32:07 (GMT)
commit891624888f5812ca407e8bea74549f0909a0de21 (patch)
tree34c3e7f6a9a57def34d0c604f4c0b80324b629b5 /lib
parente179dbae14586c21cd99babbe9c676e9726e2428 (diff)
If we receive an application/octet-stream, check the mime type by looking at its extension.
Diffstat (limited to 'lib')
-rw-r--r--lib/src/GeckoDownload.cpp86
1 files changed, 56 insertions, 30 deletions
diff --git a/lib/src/GeckoDownload.cpp b/lib/src/GeckoDownload.cpp
index 134e1de..cd45bc8 100644
--- a/lib/src/GeckoDownload.cpp
+++ b/lib/src/GeckoDownload.cpp
@@ -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,41 +66,63 @@ GeckoDownload::Init (nsIURI *aSource,
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
file->GetNativePath (mTargetFileName);
+
+ return NS_OK;
}
NS_IMETHODIMP
-GeckoDownload::OnStateChange (nsIWebProgress *aWebProgress,
- nsIRequest *aRequest,
- PRUint32 aStateFlags,
- nsresult aStatus)
+GeckoDownload::OnStateChange(nsIWebProgress *aWebProgress,
+ nsIRequest *aRequest,
+ PRUint32 aStateFlags,
+ nsresult aStatus)
{
- SugarDownloadManager *download_manager = sugar_get_download_manager ();
+ SugarDownloadManager *download_manager = sugar_get_download_manager();
+
+ if(aStateFlags == STATE_START) {
+
+ nsCString url;
+ nsCString mimeType;
+
+ 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(),
+ mTargetFileName.get());
+
+ } else if(aStateFlags == STATE_STOP) {
+
+ if(NS_SUCCEEDED(aStatus)) {
+ sugar_download_manager_download_completed(download_manager,
+ mTargetFileName.get());
+ } else {
+ sugar_download_manager_download_cancelled(download_manager,
+ mTargetFileName.get());
+ }
+ }
- if (aStateFlags == STATE_START) {
-
- nsCString url;
- nsCString mimeType;
-
- mMIMEInfo->GetMIMEType (mimeType);
- mSource->GetSpec (url);
-
- sugar_download_manager_download_started (download_manager,
- url.get (),
- mimeType.get (),
- mTargetFileName.get ());
-
- } else if (aStateFlags == STATE_STOP) {
-
- if (NS_SUCCEEDED (aStatus)) {
- sugar_download_manager_download_completed (download_manager,
- mTargetFileName.get ());
- } else {
- sugar_download_manager_download_cancelled (download_manager,
- mTargetFileName.get ());
- }
- }
-
- return NS_OK;
+ return NS_OK;
}
NS_IMETHODIMP