[chromium] Add setter/getter to expose drag data as a list of items
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Feb 2012 23:14:24 +0000 (23:14 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Feb 2012 23:14:24 +0000 (23:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77125

This change supports the unification of the data store backing ChromiumDataObject and
DataTransferItemListChromium. ChromiumDataObject will represent dragging and clipboard data
as a list of data nodes to make it more straightforward to implement the HTML spec for
DataTransferItemList. Thus, we extend the abstraction to the webkit glue layer to
simplify the serialization/deserialization between platform-specific data and WebDragData.
The other setter/getter methods are deprecated and will be removed once the dependencies in
Chromium code are gone.

Reviewed by Darin Fisher.

* public/platform/WebDragData.h:
(WebKit):
(WebDragData):
* src/WebDragData.cpp:
(WebKit::WebDragData::items):
(WebKit):
(WebKit::WebDragData::setItems):
(WebKit::WebDragData::addItem):

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

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/platform/WebDragData.h
Source/WebKit/chromium/src/WebDragData.cpp

index 81aeea6..6f5c948 100644 (file)
@@ -1,3 +1,27 @@
+2012-02-01  Daniel Cheng  <dcheng@chromium.org>
+
+        [chromium] Add setter/getter to expose drag data as a list of items
+        https://bugs.webkit.org/show_bug.cgi?id=77125
+
+        This change supports the unification of the data store backing ChromiumDataObject and
+        DataTransferItemListChromium. ChromiumDataObject will represent dragging and clipboard data
+        as a list of data nodes to make it more straightforward to implement the HTML spec for
+        DataTransferItemList. Thus, we extend the abstraction to the webkit glue layer to
+        simplify the serialization/deserialization between platform-specific data and WebDragData.
+        The other setter/getter methods are deprecated and will be removed once the dependencies in
+        Chromium code are gone.
+
+        Reviewed by Darin Fisher.
+
+        * public/platform/WebDragData.h:
+        (WebKit):
+        (WebDragData):
+        * src/WebDragData.cpp:
+        (WebKit::WebDragData::items):
+        (WebKit):
+        (WebKit::WebDragData::setItems):
+        (WebKit::WebDragData::addItem):
+
 2012-02-15  Sadrul Habib Chowdhury  <sadrul@chromium.org>
 
         Notify ChromeClient when touch-event handlers are installed/removed.
index 171231e..096f33c 100644 (file)
@@ -32,7 +32,9 @@
 #define WebDragData_h
 
 #include "WebCommon.h"
+#include "WebData.h"
 #include "WebString.h"
+#include "WebURL.h"
 
 #if WEBKIT_IMPLEMENTATION
 namespace WebCore { class ChromiumDataObject; }
@@ -41,15 +43,45 @@ namespace WTF { template <typename T> class PassRefPtr; }
 
 namespace WebKit {
 
-class WebData;
 class WebDragDataPrivate;
-class WebURL;
 template <typename T> class WebVector;
 
 // Holds data that may be exchanged through a drag-n-drop operation.  It is
 // inexpensive to copy a WebDragData object.
 class WebDragData {
 public:
+    struct Item {
+        enum StorageType {
+            // String data with an associated MIME type. Depending on the MIME type, there may be
+            // optional metadata attributes as well.
+            StorageTypeString,
+            // Stores the name of one file being dragged into the renderer.
+            StorageTypeFilename,
+            // An image being dragged out of the renderer. Contains a buffer holding the image data
+            // as well as the suggested name for saving the image to.
+            StorageTypeBinaryData,
+        };
+
+        StorageType storageType;
+
+        // Only valid when storageType == StorageTypeString.
+        WebString stringType;
+        WebString stringData;
+
+        // Only valid when storageType == StorageTypeFilename.
+        WebString filenameData;
+
+        // Only valid when storageType == StorageTypeBinaryData.
+        WebData binaryData;
+
+        // Title associated with a link when stringType == "text/uri-list".
+        // Filename when storageType == StorageTypeBinaryData.
+        WebString title;
+
+        // Only valid when stringType == "text/html".
+        WebURL baseURL;
+    };
+
     ~WebDragData() { reset(); }
 
     WebDragData() : m_private(0) { }
@@ -66,6 +98,9 @@ public:
 
     bool isNull() const { return !m_private; }
 
+    WebVector<Item> items() const;
+    void setItems(const WebVector<Item>&);
+
     WEBKIT_EXPORT WebString url() const;
     WEBKIT_EXPORT void setURL(const WebURL&);
 
@@ -104,6 +139,7 @@ public:
     };
     WEBKIT_EXPORT WebVector<CustomData> customData() const;
     WEBKIT_EXPORT void setCustomData(const WebVector<CustomData>&);
+    void addItem(const Item&);
 
 #if WEBKIT_IMPLEMENTATION
     WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>&);
index 5c31239..742de79 100644 (file)
@@ -66,6 +66,88 @@ void WebDragData::assign(const WebDragData& other)
     assign(p);
 }
 
+WebVector<WebDragData::Item> WebDragData::items() const
+{
+    Vector<Item> itemList;
+    const HashSet<String>& types = m_private->types();
+    if (types.contains(mimeTypeTextPlain)) {
+        Item item;
+        item.storageType = Item::StorageTypeString;
+        item.stringType = String(mimeTypeTextPlain);
+        bool ignored;
+        item.stringData = m_private->getData(mimeTypeTextPlain, ignored);
+        itemList.append(item);
+    }
+    if (types.contains(mimeTypeTextURIList)) {
+        Item item;
+        item.storageType = Item::StorageTypeString;
+        item.stringType = String(mimeTypeTextURIList);
+        bool ignored;
+        item.stringData = m_private->getData(mimeTypeURL, ignored);
+        item.title = m_private->urlTitle();
+        itemList.append(item);
+    }
+    if (types.contains(mimeTypeTextHTML)) {
+        Item item;
+        item.storageType = Item::StorageTypeString;
+        item.stringType = String(mimeTypeTextHTML);
+        bool ignored;
+        item.stringData = m_private->getData(mimeTypeTextHTML, ignored);
+        item.baseURL = m_private->htmlBaseUrl();
+        itemList.append(item);
+    }
+    if (types.contains(mimeTypeDownloadURL)) {
+        Item item;
+        item.storageType = Item::StorageTypeString;
+        item.stringType = String(mimeTypeDownloadURL);
+        bool ignored;
+        item.stringData = m_private->getData(mimeTypeDownloadURL, ignored);
+        itemList.append(item);
+    }
+    const HashMap<String, String>& customData = m_private->customData();
+    for (HashMap<String, String>::const_iterator it = customData.begin(); it != customData.end(); ++it) {
+        Item item;
+        item.storageType = Item::StorageTypeString;
+        item.stringType = it->first;
+        item.stringData = it->second;
+        itemList.append(item);
+    }
+    if (m_private->fileContent()) {
+        Item item;
+        item.storageType = Item::StorageTypeBinaryData;
+        item.binaryData = m_private->fileContent();
+        item.title = m_private->fileContentFilename();
+    }
+    // We don't handle filenames here, since they are never used for dragging out.
+    return itemList;
+}
+
+void WebDragData::setItems(const WebVector<Item>& itemList)
+{
+    m_private->clearAll();
+    for (size_t i = 0; i < itemList.size(); ++i)
+        addItem(itemList[i]);
+}
+
+void WebDragData::addItem(const Item& item)
+{
+    switch (item.storageType) {
+    case Item::StorageTypeString:
+        m_private->setData(item.stringType, item.stringData);
+        if (String(item.stringType) == mimeTypeTextURIList)
+            m_private->setUrlTitle(item.title);
+        else if (String(item.stringType) == mimeTypeTextHTML)
+            m_private->setHtmlBaseUrl(item.baseURL);
+        return;
+    case Item::StorageTypeFilename:
+        m_private->addFilename(item.filenameData);
+        return;
+    case Item::StorageTypeBinaryData:
+        // This should never happen when dragging in.
+        ASSERT_NOT_REACHED();
+    }
+}
+
 WebString WebDragData::url() const
 {
     ASSERT(!isNull());