2011-06-01 Daniel Cheng <dcheng@chromium.org>
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Jun 2011 21:13:06 +0000 (21:13 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Jun 2011 21:13:06 +0000 (21:13 +0000)
        Reviewed by Tony Chang.

        [chromium] Use correct file name for dragging out images.
        https://bugs.webkit.org/show_bug.cgi?id=24887

        * fast/events/drag-image-filename-expected.txt: Added.
        * fast/events/drag-image-filename.html: Added.
        * platform/gtk/Skipped:
        * platform/mac/Skipped:
        * platform/qt/Skipped:
        * platform/win/Skipped:
2011-06-01  Daniel Cheng  <dcheng@chromium.org>

        Reviewed by Tony Chang.

        [chromium] Use correct file name for dragging out images.
        https://bugs.webkit.org/show_bug.cgi?id=24887

        We try to guess an appropriate filename when dragging out images. In order, we try to use:
        - The filename suggested in the HTTP header.
        - The last path component of the source URL.
        - The alt text.
        This matches the behavior of the other WebKit ports.

        Test: fast/events/drag-image-filename.html

        * platform/chromium/ClipboardChromium.cpp:
        (WebCore::writeImageToDataObject):
        * platform/chromium/ClipboardChromiumMac.cpp:
        (WebCore::isInvalidFileCharacter):
        (WebCore::ClipboardChromium::validateFileName):
2011-06-01  Daniel Cheng  <dcheng@chromium.org>

        Reviewed by Tony Chang.

        [chromium] Use correct file name for dragging out images.
        https://bugs.webkit.org/show_bug.cgi?id=24887

        * DumpRenderTree/chromium/EventSender.cpp:
        (EventSender::EventSender):
        (EventSender::dumpFilenameBeingDragged):
        * DumpRenderTree/chromium/EventSender.h:

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/drag-image-filename-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/drag-image-filename.html [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
Source/WebCore/ChangeLog
Source/WebCore/platform/chromium/ClipboardChromium.cpp
Source/WebCore/platform/chromium/ClipboardChromiumMac.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/EventSender.cpp
Tools/DumpRenderTree/chromium/EventSender.h

index 781ab3950c063c836ab4ba60a4da332ff7b06b28..93f06a8ceb309fca683788e3d978cedd690fbf41 100644 (file)
@@ -1,3 +1,17 @@
+2011-06-01  Daniel Cheng  <dcheng@chromium.org>
+
+        Reviewed by Tony Chang.
+
+        [chromium] Use correct file name for dragging out images.
+        https://bugs.webkit.org/show_bug.cgi?id=24887
+
+        * fast/events/drag-image-filename-expected.txt: Added.
+        * fast/events/drag-image-filename.html: Added.
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+
 2011-06-01  Levi Weintraub  <leviw@chromium.org>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/fast/events/drag-image-filename-expected.txt b/LayoutTests/fast/events/drag-image-filename-expected.txt
new file mode 100644 (file)
index 0000000..7a224ba
--- /dev/null
@@ -0,0 +1,4 @@
+Filename being dragged: onload-image.png
+This test requires DumpRenderTree. To test manually, drag the image to the desktop. It should receive the name "onload-image.png".
+
+
diff --git a/LayoutTests/fast/events/drag-image-filename.html b/LayoutTests/fast/events/drag-image-filename.html
new file mode 100644 (file)
index 0000000..e78e7d5
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+function runTest() {
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    } else
+        return;
+    
+    e = document.getElementById("source");
+    x = e.offsetLeft + e.offsetWidth / 2;
+    y = e.offsetTop + e.offsetHeight / 2;
+
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown();    
+    e = document.getElementById("target");
+    x = e.offsetLeft + e.offsetWidth / 2;
+    y = e.offsetTop + e.offsetHeight / 2;
+    
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseUp();
+}
+
+function dragEnterOrOver(event) {
+    event.dataTransfer.dropEffect = "copy";
+    event.preventDefault();
+}
+
+function drop(event) {
+    event.preventDefault();
+    eventSender.dumpFilenameBeingDragged();
+    layoutTestController.notifyDone();
+}
+</script>
+<style>
+#target {
+    height: 100px;
+    width: 100px;
+}
+</style>
+</head>
+
+<body onload="runTest()">  
+
+<p>This test requires DumpRenderTree. To test manually, drag the image to the desktop. It should receive the name "onload-image.png".
+
+<div id="target" ondragenter="dragEnterOrOver(event)" ondragover="dragEnterOrOver(event)" ondrop="drop(event)"></div>
+<img id="source" src="resources/onload-image.png" alt="Does it work?">
+
+</body>
+</html>
index bbc851b12d20af6df07392e7ceb889cbd62caf7e..42a32feeccc26e082bbde87120c51e16fee9a66c 100644 (file)
@@ -1148,6 +1148,10 @@ http/tests/xmlhttprequest/remember-bad-password.html
 fast/css/user-drag-none.html
 fast/events/5056619.html
 
+# EventSender::dumpFilenameBeingDragged not implemented.
+# https://bugs.webkit.org/show_bug.cgi?id=61826
+fast/events/drag-image-filename.html
+
 # Tests that fail because they assume a certain number of mouse
 # movements during drags or fail only in Xvfb
 http/tests/local/drag-over-remote-content.html
index 01033c4cc1cc6cc099e190f32476de34b88bdd66..8d88315b98f1a4eab98262450230d8db6640ff42 100644 (file)
@@ -191,6 +191,10 @@ http/tests/misc/prefetch-purpose.html
 # Filenames aren't filtered out from edit drags yet, see https://bugs.wekit.org/show_bug.cgi?id=38826
 editing/pasteboard/file-drag-to-editable.html
 
+# EventSender::dumpFilenameBeingDragged not implemented.
+# https://bugs.webkit.org/show_bug.cgi?id=61827
+fast/events/drag-image-filename.html
+
 # Hits an assert in FrameLoader.cpp. https://bugs.webkit.org/show_bug.cgi?id=31387
 http/tests/multipart/policy-ignore-crash.php
 
index 1213471df0d4bf65f4307c8a4411efb541763d35..a5c97d8562764cfbe7bed9824e7789bc0f25ad78 100644 (file)
@@ -172,6 +172,10 @@ fast/css/user-drag-none.html
 svg/as-image/drag-svg-as-image.html
 fast/forms/slider-delete-while-dragging-thumb.html
 
+# EventSender::dumpFilenameBeingDragged not implemented.
+# https://bugs.webkit.org/show_bug.cgi?id=61828
+fast/events/drag-image-filename.html
+
 # ------- missing drag-and-drop support
 # See bug https://bugs.webkit.org/show_bug.cgi?id=31332
 fast/events/drag-parent-node.html
index e0af214ff5453031f80dbe083569b721cc8455ae..43a1808d3b8d125cecb442ebd2b1ceb9318d2fd2 100644 (file)
@@ -126,6 +126,10 @@ fast/events/drag-in-frames.html
 fast/events/standalone-image-drag-to-editable.html
 http/tests/security/drag-drop-same-unique-origin.html
 
+# EventSender::dumpFilenameBeingDragged not implemented.
+# https://bugs.webkit.org/show_bug.cgi?id=61829
+fast/events/drag-image-filename.html
+
 # <rdar://problem/5643675> window.scrollTo scrolls a window with no scrollbars
 fast/events/attempt-scroll-with-no-scrollbars.html
 
index 3835d245dfa9007179d71b8060df9b2b2434742b..ac3c2b7179da10bcc46d10b9f9dac788cedb8f8f 100644 (file)
@@ -1,3 +1,24 @@
+2011-06-01  Daniel Cheng  <dcheng@chromium.org>
+
+        Reviewed by Tony Chang.
+
+        [chromium] Use correct file name for dragging out images.
+        https://bugs.webkit.org/show_bug.cgi?id=24887
+
+        We try to guess an appropriate filename when dragging out images. In order, we try to use:
+        - The filename suggested in the HTTP header.
+        - The last path component of the source URL.
+        - The alt text.
+        This matches the behavior of the other WebKit ports.
+
+        Test: fast/events/drag-image-filename.html
+
+        * platform/chromium/ClipboardChromium.cpp:
+        (WebCore::writeImageToDataObject):
+        * platform/chromium/ClipboardChromiumMac.cpp:
+        (WebCore::isInvalidFileCharacter):
+        (WebCore::ClipboardChromium::validateFileName):
+
 2011-06-01  Levi Weintraub  <leviw@chromium.org>
 
         Reviewed by Eric Seidel.
         * platform/graphics/gpu/LoopBlinnMathUtils.cpp:
         * platform/graphics/gpu/TilingData.cpp:
 
-<<<<<<< .mine
 2011-05-31  Justin Novosad  <junov@chromium.org>
 
         Reviewed by Stephen White.
         * platform/graphics/gpu/LoopBlinnMathUtils.cpp:
         * platform/graphics/gpu/TilingData.cpp:
 
-=======
 2011-05-31  Rob Buis  <rbuis@rim.com>
 
         Reviewed by Dirk Schulze.
index 5bc26f74d802f9ba804f319a25ad2e9c62e19647..f5675e24e6192feff7f8f4f7313d8e97e7fbc2eb 100644 (file)
@@ -224,19 +224,25 @@ static void writeImageToDataObject(ChromiumDataObject* dataObject, Element* elem
 
     dataObject->setFileContent(imageBuffer);
 
-    // Determine the filename for the file contents of the image.  We try to
-    // use the alt tag if one exists, otherwise we fall back on the suggested
-    // filename in the http header, and finally we resort to using the filename
-    // in the URL.
+    // Determine the filename for the file contents of the image.
+    String filename = cachedImage->response().suggestedFilename();
+    if (filename.isEmpty())
+        filename = url.lastPathComponent();
+    if (filename.isEmpty())
+        filename = element->getAttribute(altAttr);
+    else {
+        // Strip any existing extension. Assume that alt text is usually not a filename.
+        int extensionIndex = filename.reverseFind('.');
+        if (extensionIndex != -1)
+            filename.truncate(extensionIndex);
+    }
+    filename = ClipboardChromium::validateFileName(filename, dataObject);
+
     String extension = MIMETypeRegistry::getPreferredExtensionForMIMEType(
         cachedImage->response().mimeType());
     dataObject->setFileExtension(extension.isEmpty() ? emptyString() : "." + extension);
-    String title = element->getAttribute(altAttr);
-    if (title.isEmpty())
-        title = cachedImage->response().suggestedFilename();
 
-    title = ClipboardChromium::validateFileName(title, dataObject);
-    dataObject->setFileContentFilename(title + dataObject->fileExtension());
+    dataObject->setFileContentFilename(filename + dataObject->fileExtension());
 }
 
 void ClipboardChromium::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
index 2c89f6e8ee999202912b3d8db9bf5bb772577a97..38021402eb929e3cc6e251d223f007466adf2f27 100644 (file)
 #include "ClipboardChromium.h"
 
 #include "ChromiumDataObject.h"
-#include "NotImplemented.h"
 
 namespace WebCore {
+    
+
+// Filename length and character-set limits vary by filesystem, and there's no
+// real way to tell what filesystem is in use. Since HFS+ is by far the most
+// common, we'll abide by its limits, which are 255 Unicode characters (slightly
+// simplified; really it uses Normalization Form D, but the differences aren't
+// really worth dealing with here.)
+static const unsigned MaxHFSFilenameLength = 255;
+
+
+static bool isInvalidFileCharacter(UChar c)
+{
+    // HFS+ basically allows anything but '/'. For sanity's sake we'll disallow
+    // control characters.
+    return c < ' ' || c == 0x7F || c == '/';
+}
 
 String ClipboardChromium::validateFileName(const String& title, ChromiumDataObject* dataObject)
 {
-    notImplemented();
-    return title;
+    // Remove any invalid file system characters, especially "/".
+    String result = title.removeCharacters(isInvalidFileCharacter);
+    String extension = dataObject->fileExtension().removeCharacters(&isInvalidFileCharacter);
+
+    // Remove a ridiculously-long extension.
+    if (extension.length() >= MaxHFSFilenameLength)
+        extension = "";
+    
+    // Truncate an overly-long filename.
+    int overflow = result.length() + extension.length() - MaxHFSFilenameLength;
+    if (overflow > 0) 
+        result.remove(result.length() - overflow, overflow);
+    
+    dataObject->setFileExtension(extension);
+    return result;
 }
 
 }  // namespace WebCore
index bc5e6d73b102b2b9dea89d4473cd929c4da42243..67ada74fb8c0fa241dba1b19db6d05702ceacf2d 100644 (file)
@@ -1,3 +1,15 @@
+2011-06-01  Daniel Cheng  <dcheng@chromium.org>
+
+        Reviewed by Tony Chang.
+
+        [chromium] Use correct file name for dragging out images.
+        https://bugs.webkit.org/show_bug.cgi?id=24887
+
+        * DumpRenderTree/chromium/EventSender.cpp:
+        (EventSender::EventSender):
+        (EventSender::dumpFilenameBeingDragged):
+        * DumpRenderTree/chromium/EventSender.h:
+
 2011-06-01  Dirk Pranke  <dpranke@chromium.org>
 
         Reviewed by Tony Chang.
index 9e555893e98a7a04dd45c55cb029dc175bf8cc05..73bd145c8ce1192d4bfb794371b91f3073a525cd 100644 (file)
@@ -259,6 +259,7 @@ EventSender::EventSender(TestShell* shell)
     bindMethod("contextClick", &EventSender::contextClick);
     bindMethod("continuousMouseScrollBy", &EventSender::continuousMouseScrollBy);
     bindMethod("dispatchMessage", &EventSender::dispatchMessage);
+    bindMethod("dumpFilenameBeingDragged", &EventSender::dumpFilenameBeingDragged);
     bindMethod("enableDOMUIEventLogging", &EventSender::enableDOMUIEventLogging);
     bindMethod("fireKeyboardEventsToElement", &EventSender::fireKeyboardEventsToElement);
     bindMethod("keyDown", &EventSender::keyDown);
@@ -344,6 +345,11 @@ void EventSender::doDragDrop(const WebDragData& dragData, WebDragOperationsMask
     replaySavedEvents();
 }
 
+void EventSender::dumpFilenameBeingDragged(const CppArgumentList&, CppVariant*)
+{
+    printf("Filename being dragged: %s\n", currentDragData.fileContentFilename().utf8().data());
+}
+
 WebMouseEvent::Button EventSender::getButtonTypeFromButtonNumber(int buttonCode)
 {
     if (!buttonCode)
index de1ca054039122577c9d6dbe3c9f6a854a4c8a86..54b065033c68192c377218365539ec4798f91b3b 100644 (file)
@@ -62,6 +62,9 @@ public:
     // Simulate drag&drop system call.
     void doDragDrop(const WebKit::WebDragData&, WebKit::WebDragOperationsMask);
 
+    // Test helper for dragging out images.
+    void dumpFilenameBeingDragged(const CppArgumentList&, CppVariant*);
+
     // JS callback methods.
     void mouseDown(const CppArgumentList&, CppVariant*);
     void mouseUp(const CppArgumentList&, CppVariant*);