Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser/GeckoDragDropHooks.cpp
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-04-18 12:21:49 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-04-18 12:21:49 (GMT)
commitf26ee4056b4d804a5a841d3d0f1fb959fdaa9bea (patch)
tree1499bdd91d63d66c78a8c9cc7764e642850aa74a /browser/GeckoDragDropHooks.cpp
parent0bade58c23e53ec87385d88e5cb5b0b8add32d6d (diff)
Assure dragged images have the right file extension.
Diffstat (limited to 'browser/GeckoDragDropHooks.cpp')
-rw-r--r--browser/GeckoDragDropHooks.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/browser/GeckoDragDropHooks.cpp b/browser/GeckoDragDropHooks.cpp
index d8b0a84..6439f42 100644
--- a/browser/GeckoDragDropHooks.cpp
+++ b/browser/GeckoDragDropHooks.cpp
@@ -15,6 +15,7 @@
#include <nsServiceManagerUtils.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsIDOMMouseEvent.h>
+#include <nsIMIMEService.h>
#include "GeckoDragDropHooks.h"
#include "GeckoDocumentObject.h"
@@ -66,6 +67,9 @@ UriListDataProvider::GetFlavorData(nsITransferable *aTransferable,
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
char *image_name;
+ char *mime_type;
+ char *file_ext;
+ nsCString mime_ext;
timeval timestamp;
*aData = nsnull;
@@ -83,7 +87,31 @@ UriListDataProvider::GetFlavorData(nsITransferable *aTransferable,
mFilePath.AppendInt(timestamp.tv_usec);
image_name = mDocumentObject->GetImageName();
- mFilePath.Append(image_name);
+ file_ext = strrchr(image_name, '.');
+ mime_type = mDocumentObject->GetImageMimeType();
+
+ nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1",
+ &rv));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = mimeService->GetPrimaryExtension(nsCString(mime_type),
+ EmptyCString(),
+ mime_ext);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ if(!file_ext) {
+ mFilePath.Append(image_name);
+ mFilePath.Append(".");
+ mFilePath.Append(mime_ext);
+ } else if(strcmp(file_ext, mime_ext.get())) {
+ image_name[strlen(file_ext)] = 0;
+ mFilePath.Append(image_name);
+ mFilePath.Append(".");
+ mFilePath.Append(mime_ext);
+ } else {
+ mFilePath.Append(image_name);
+ }
+
+ g_free(mime_type);
g_free(image_name);
if(!mDocumentObject->SaveImage(mFilePath.get())) {