2011-04-11 Daniel Cheng <dcheng@chromium.org>
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Apr 2011 21:04:18 +0000 (21:04 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Apr 2011 21:04:18 +0000 (21:04 +0000)
        Reviewed by Dmitry Titov.

        [chromium] Implement image/png support in DataTransferItems
        https://bugs.webkit.org/show_bug.cgi?id=58106

        Add a reftest to verify that the various bits in the pipeline work as expected.

        * editing/pasteboard/data-transfer-items-image-png-expected.html: Added.
        * editing/pasteboard/data-transfer-items-image-png.html: Added.
2011-04-11  Daniel Cheng  <dcheng@chromium.org>

        Reviewed by Dmitry Titov.

        [chromium] Implement image/png support in DataTransferItems
        https://bugs.webkit.org/show_bug.cgi?id=58106

        This patch implements DataTransferItem::getAsFile() using Blobs. In
        addition, plumbing for image/png has been added so image paste will be
        supported as long as the renderer makes that data available.

        Tests: editing/pasteboard/data-transfer-items-image-png.html

        * dom/DataTransferItem.h:
        * dom/DataTransferItem.idl:
        * platform/chromium/ClipboardMimeTypes.cpp:
        * platform/chromium/ClipboardMimeTypes.h:
        * platform/chromium/DataTransferItemChromium.cpp:
        (WebCore::DataTransferItemChromium::getAsString):
        (WebCore::DataTransferItemChromium::getAsFile):
        * platform/chromium/DataTransferItemChromium.h:
        * platform/chromium/PlatformBridge.h:
2011-04-11  Daniel Cheng  <dcheng@chromium.org>

        Reviewed by Dmitry Titov.

        [chromium] Implement image/png support in DataTransferItems
        https://bugs.webkit.org/show_bug.cgi?id=58106

        Add glue for reading image data from clipboard.

        * DEPS:
        * src/PlatformBridge.cpp:
        (WebCore::PlatformBridge::clipboardReadImage):

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/data-transfer-items-image-png-expected.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/data-transfer-items-image-png.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/DataTransferItem.h
Source/WebCore/dom/DataTransferItem.idl
Source/WebCore/platform/chromium/ClipboardMimeTypes.cpp
Source/WebCore/platform/chromium/ClipboardMimeTypes.h
Source/WebCore/platform/chromium/DataTransferItemChromium.cpp
Source/WebCore/platform/chromium/DataTransferItemChromium.h
Source/WebCore/platform/chromium/PlatformBridge.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/DEPS
Source/WebKit/chromium/src/PlatformBridge.cpp

index 5121282..4d7b112 100644 (file)
@@ -1,3 +1,15 @@
+2011-04-11  Daniel Cheng  <dcheng@chromium.org>
+
+        Reviewed by Dmitry Titov.
+
+        [chromium] Implement image/png support in DataTransferItems
+        https://bugs.webkit.org/show_bug.cgi?id=58106
+
+        Add a reftest to verify that the various bits in the pipeline work as expected.
+
+        * editing/pasteboard/data-transfer-items-image-png-expected.html: Added.
+        * editing/pasteboard/data-transfer-items-image-png.html: Added.
+
 2011-04-11  Jia Pu  <jpu@apple.com>
 
         Reviewed by Adele Peterson.
diff --git a/LayoutTests/editing/pasteboard/data-transfer-items-image-png-expected.html b/LayoutTests/editing/pasteboard/data-transfer-items-image-png-expected.html
new file mode 100644 (file)
index 0000000..4fc57ea
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div>This file tests the image pasting functionality of DataTransferItems.
+To try the test manually, right-click on the image &gt; Copy Image, click
+anywhere in the background of the main page and paste.</div>
+<iframe id="src" src="resources/mozilla.gif"></iframe><br>
+<img src="resources/mozilla.gif">
+</body>
+</html>
diff --git a/LayoutTests/editing/pasteboard/data-transfer-items-image-png.html b/LayoutTests/editing/pasteboard/data-transfer-items-image-png.html
new file mode 100644 (file)
index 0000000..c825e1a
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../editing.js"></script>
+<script>
+function paste(event)
+{
+    var items = event.clipboardData.items;
+    for (var i = 0; i < items.length; ++i) {
+        if (items[i].kind == 'file' && items[i].type == 'image/png') {
+            var blob = items[i].getAsFile();
+            var url = window.webkitURL.createObjectURL(blob);
+            document.getElementById('dest').src = url;
+        }
+    }
+    window.setTimeout(function () {
+        if (window.layoutTestController)
+            layoutTestController.notifyDone();
+    }, 0);
+}
+
+function runTest()
+{
+    if (!window.layoutTestController)
+        return;
+    layoutTestController.waitUntilDone();
+    var srcElement = document.getElementById('src');
+    srcElement.contentWindow.document.execCommand('copy');
+    eventSender.mouseMoveTo(1, 1);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+    document.execCommand('paste');
+}
+</script>
+</head>
+<body onload="runTest()" onpaste="paste(event)">
+<div>This file tests the image pasting functionality of DataTransferItems.
+To try the test manually, right-click on the image &gt; Copy Image, click
+anywhere in the background of the main page and paste.</div>
+<iframe id="src" src="resources/mozilla.gif"></iframe><br>
+<img id="dest">
+</body>
+</html>
index 7692e20..7e82046 100644 (file)
@@ -1,3 +1,26 @@
+2011-04-11  Daniel Cheng  <dcheng@chromium.org>
+
+        Reviewed by Dmitry Titov.
+
+        [chromium] Implement image/png support in DataTransferItems
+        https://bugs.webkit.org/show_bug.cgi?id=58106
+
+        This patch implements DataTransferItem::getAsFile() using Blobs. In
+        addition, plumbing for image/png has been added so image paste will be
+        supported as long as the renderer makes that data available.
+
+        Tests: editing/pasteboard/data-transfer-items-image-png.html
+
+        * dom/DataTransferItem.h:
+        * dom/DataTransferItem.idl:
+        * platform/chromium/ClipboardMimeTypes.cpp:
+        * platform/chromium/ClipboardMimeTypes.h:
+        * platform/chromium/DataTransferItemChromium.cpp:
+        (WebCore::DataTransferItemChromium::getAsString):
+        (WebCore::DataTransferItemChromium::getAsFile):
+        * platform/chromium/DataTransferItemChromium.h:
+        * platform/chromium/PlatformBridge.h:
+
 2011-04-11  Mario Sanchez Prada  <msanchez@igalia.com>
 
         Reviewed by Chris Fleizach.
index 7b5886a..d648c56 100644 (file)
@@ -38,6 +38,7 @@
 
 namespace WebCore {
 
+class Blob;
 class StringCallback;
 
 class DataTransferItem : public RefCounted<DataTransferItem> {
@@ -51,6 +52,7 @@ public:
     virtual String type() const = 0;
 
     virtual void getAsString(PassRefPtr<StringCallback>) = 0;
+    virtual PassRefPtr<Blob> getAsFile() = 0;
 };
 
 } // namespace WebCore
index a2c9942..accaf50 100644 (file)
@@ -37,6 +37,7 @@ module core {
         readonly attribute DOMString type;
 
         void getAsString(in [Callback] StringCallback callback);
+        Blob getAsFile();
     };
 
 }
index 27e68ff..94ce27d 100644 (file)
@@ -41,5 +41,6 @@ const char mimeTypeURL[] = "url";
 const char mimeTypeTextURIList[] = "text/uri-list";
 const char mimeTypeDownloadURL[] = "downloadurl";
 const char mimeTypeFiles[] = "Files";
+const char mimeTypeImagePng[] = "image/png";
 
 } // namespace WebCore
index 31e2d3e..3e4ab50 100644 (file)
@@ -41,6 +41,7 @@ extern const char mimeTypeURL[];
 extern const char mimeTypeTextURIList[];
 extern const char mimeTypeDownloadURL[];
 extern const char mimeTypeFiles[];
+extern const char mimeTypeImagePng[];
 
 } // namespace WebCore
 
index 7857336..24b498e 100644 (file)
 
 #if ENABLE(DATA_TRANSFER_ITEMS)
 
+#include "Blob.h"
 #include "Clipboard.h"
 #include "ClipboardMimeTypes.h"
 #include "PlatformBridge.h"
+#include "SharedBuffer.h"
 #include "StringCallback.h"
 
 namespace WebCore {
@@ -88,6 +90,8 @@ void DataTransferItemChromium::getAsString(PassRefPtr<StringCallback> callback)
         callback->scheduleCallback(m_context, m_data);
         return;
     }
+
+    ASSERT(m_source == PasteboardSource);
     // This is ugly but there's no real alternative.
     if (m_type == mimeTypeTextPlain) {
         callback->scheduleCallback(m_context, PlatformBridge::clipboardReadPlainText(PasteboardPrivate::StandardBuffer));
@@ -103,6 +107,33 @@ void DataTransferItemChromium::getAsString(PassRefPtr<StringCallback> callback)
     ASSERT_NOT_REACHED();
 }
 
+PassRefPtr<Blob> DataTransferItemChromium::getAsFile()
+{
+    if (m_source == InternalSource)
+        return 0;
+
+    ASSERT(m_source == PasteboardSource);
+    if (m_type == mimeTypeImagePng) {
+        // FIXME: This is pretty inefficient. We copy the data from the browser
+        // to the renderer. We then place it in a blob in WebKit, which
+        // registers it and copies it *back* to the browser. When a consumer
+        // wants to read the data, we then copy the data back into the renderer.
+        // https://bugs.webkit.org/show_bug.cgi?id=58107 has been filed to track
+        // improvements to this code (in particular, add a registerClipboardBlob
+        // method to the blob registry; that way the data is only copied over
+        // into the renderer when it's actually read, not when the blob is
+        // initially constructed).
+        RefPtr<SharedBuffer> data = PlatformBridge::clipboardReadImage(PasteboardPrivate::StandardBuffer);
+        RefPtr<RawData> rawData = RawData::create();
+        rawData->mutableData()->append(data->data(), data->size());
+        OwnPtr<BlobData> blobData = BlobData::create();
+        blobData->appendData(rawData, 0, -1);
+        blobData->setContentType(mimeTypeImagePng);
+        return Blob::create(blobData.release(), data->size());
+    }
+    return 0;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(DATA_TRANSFER_ITEMS)
index 77f74f2..66be96e 100644 (file)
@@ -51,6 +51,7 @@ public:
     virtual String type() const;
 
     virtual void getAsString(PassRefPtr<StringCallback>);
+    virtual PassRefPtr<Blob> getAsFile();
 
 private:
     enum DataSource {
index 1c3ccbd..3a04617 100644 (file)
@@ -98,6 +98,7 @@ public:
 
     static String clipboardReadPlainText(PasteboardPrivate::ClipboardBuffer);
     static void clipboardReadHTML(PasteboardPrivate::ClipboardBuffer, String*, KURL*);
+    static PassRefPtr<SharedBuffer> clipboardReadImage(PasteboardPrivate::ClipboardBuffer);
 
     // Only the clipboardRead functions take a buffer argument because
     // Chromium currently uses a different technique to write to alternate
index 38ecf74..54444cd 100644 (file)
@@ -1,3 +1,16 @@
+2011-04-11  Daniel Cheng  <dcheng@chromium.org>
+
+        Reviewed by Dmitry Titov.
+
+        [chromium] Implement image/png support in DataTransferItems
+        https://bugs.webkit.org/show_bug.cgi?id=58106
+
+        Add glue for reading image data from clipboard.
+
+        * DEPS:
+        * src/PlatformBridge.cpp:
+        (WebCore::PlatformBridge::clipboardReadImage):
+
 2011-04-05  Hans Wennborg  <hans@chromium.org>
 
         Reviewed by Steve Block.
index 6d90dc7..6477760 100644 (file)
@@ -32,7 +32,7 @@
 
 vars = {
   'chromium_svn': 'http://src.chromium.org/svn/trunk/src',
-  'chromium_rev': '80767'
+  'chromium_rev': '80890'
 }
 
 deps = {
index d825d24..3904b0c 100644 (file)
@@ -178,6 +178,12 @@ void PlatformBridge::clipboardReadHTML(
     *sourceURL = url;
 }
 
+PassRefPtr<SharedBuffer> PlatformBridge::clipboardReadImage(
+    PasteboardPrivate::ClipboardBuffer buffer)
+{
+    return webKitClient()->clipboard()->readImage(static_cast<WebClipboard::Buffer>(buffer));
+}
+
 void PlatformBridge::clipboardWriteSelection(const String& htmlText,
                                              const KURL& sourceURL,
                                              const String& plainText,