Dragging a .jpg to Finder saves it as .jpeg
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Dec 2012 21:28:15 +0000 (21:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Dec 2012 21:28:15 +0000 (21:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=105140
https://code.google.com/p/chromium/issues/detail?id=35811

Patch by Avi Drissman <avi@chromium.org> on 2012-12-17
Reviewed by Tony Chang.

If the filename's extension is already valid for the MIME type, we don't
need to rewrite it to the preferred extension.

No layout tests because it involves dragging items to the desktop.

* platform/chromium/ClipboardChromium.cpp:
(WebCore::writeImageToDataObject):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@137934 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/chromium/ClipboardChromium.cpp

index a2bd046..af26311 100644 (file)
@@ -1,3 +1,19 @@
+2012-12-17  Avi Drissman  <avi@chromium.org>
+
+        Dragging a .jpg to Finder saves it as .jpeg
+        https://bugs.webkit.org/show_bug.cgi?id=105140
+        https://code.google.com/p/chromium/issues/detail?id=35811
+
+        Reviewed by Tony Chang.
+
+        If the filename's extension is already valid for the MIME type, we don't
+        need to rewrite it to the preferred extension.
+
+        No layout tests because it involves dragging items to the desktop.
+
+        * platform/chromium/ClipboardChromium.cpp:
+        (WebCore::writeImageToDataObject):
+
 2012-12-17  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         [CSS Exclusions] shape-outside on floats for rectangle shapes height/width
index f58ebce..fc37278 100644 (file)
@@ -369,6 +369,7 @@ static void writeImageToDataObject(ChromiumDataObject* dataObject, Element* elem
 
     // Determine the filename for the file contents of the image.
     String filename = cachedImage->response().suggestedFilename();
+    String extension;
     if (filename.isEmpty())
         filename = url.lastPathComponent();
     if (filename.isEmpty())
@@ -376,14 +377,19 @@ static void writeImageToDataObject(ChromiumDataObject* dataObject, Element* elem
     else {
         // Strip any existing extension. Assume that alt text is usually not a filename.
         int extensionIndex = filename.reverseFind('.');
-        if (extensionIndex != -1)
+        if (extensionIndex != -1) {
+            extension = filename.substring(extensionIndex + 1);
             filename.truncate(extensionIndex);
+        }
     }
 
-    String extension = MIMETypeRegistry::getPreferredExtensionForMIMEType(
-        cachedImage->response().mimeType());
-    extension = extension.isEmpty() ? emptyString() : "." + extension;
+    String extensionMimeType = MIMETypeRegistry::getMIMETypeForExtension(extension);
+    if (extensionMimeType != cachedImage->response().mimeType()) {
+        extension = MIMETypeRegistry::getPreferredExtensionForMIMEType(
+            cachedImage->response().mimeType());
+    }
 
+    extension = extension.isEmpty() ? emptyString() : "." + extension;
     ClipboardChromium::validateFilename(filename, extension);
 
     dataObject->addSharedBuffer(filename + extension, imageBuffer);