dataTransfer.types (HTML5 drag & drop) should return DOMStringList
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 07:26:18 +0000 (07:26 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 07:26:18 +0000 (07:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=30416

Reviewed by Eric Seidel.

Source/WebCore:

This change breaks backwards compatibility; however, since Firefox only supported
event.dataTransfer.types.contains, sites already needed to check whether to use contains or
indexOf. Therefore, the net compatibility effect of this change should be minimal.

Test: fast/events/drag-dataTransfer-live-attributes.html

* bindings/js/JSClipboardCustom.cpp:
(WebCore):
* bindings/v8/custom/V8ClipboardCustom.cpp:
* dom/Clipboard.cpp:
(WebCore::Clipboard::hasStringOfType):
* dom/Clipboard.h:
(WebCore):
(Clipboard):
* dom/Clipboard.idl:
* platform/blackberry/ClipboardBlackBerry.cpp:
(WebCore::ClipboardBlackBerry::types):
* platform/blackberry/ClipboardBlackBerry.h:
(ClipboardBlackBerry):
* platform/chromium/ChromiumDataObject.cpp:
(WebCore::ChromiumDataObject::types):
* platform/chromium/ChromiumDataObject.h:
(ChromiumDataObject):
* platform/chromium/ClipboardChromium.cpp:
(WebCore::ClipboardChromium::types):
(WebCore::ClipboardChromium::mayUpdateItems):
* platform/chromium/ClipboardChromium.h:
(ClipboardChromium):
* platform/chromium/DragDataChromium.cpp:
(WebCore::containsHTML):
(WebCore::DragData::containsURL):
(WebCore::DragData::asURL):
(WebCore::DragData::containsPlainText):
(WebCore::DragData::canSmartReplace):
(WebCore::DragData::asFragment):
* platform/efl/ClipboardEfl.cpp:
(WebCore::ClipboardEfl::types):
* platform/efl/ClipboardEfl.h:
(ClipboardEfl):
* platform/gtk/ClipboardGtk.cpp:
(WebCore::ClipboardGtk::types):
* platform/gtk/ClipboardGtk.h:
(ClipboardGtk):
* platform/mac/ClipboardMac.h:
(ClipboardMac):
* platform/mac/ClipboardMac.mm:
(WebCore::addHTMLClipboardTypesForCocoaType):
(WebCore::ClipboardMac::types):
* platform/qt/ClipboardQt.cpp:
(WebCore::ClipboardQt::types):
* platform/qt/ClipboardQt.h:
(ClipboardQt):
* platform/win/ClipboardWin.cpp:
(WebCore::addMimeTypesForFormat):
(WebCore::ClipboardWin::types):
* platform/win/ClipboardWin.h:
(ClipboardWin):
* platform/wx/ClipboardWx.cpp:
(WebCore::ClipboardWx::types):
* platform/wx/ClipboardWx.h:
(ClipboardWx):

LayoutTests:

Add a test to document the fact that many dataTransfer attributes aren't live and return a
different object each time they're accessed. Also update tests to use contains() instead of
indexOf().

* editing/pasteboard/clipboard-customData.html:
* editing/pasteboard/onpaste-text-html-types.html:
* fast/events/drag-and-drop-dataTransfer-types-nocrash.html:
* fast/events/drag-customData.html:
* fast/events/drag-dataTransfer-live-attributes-expected.txt: Added.
* fast/events/drag-dataTransfer-live-attributes.html: Copied from LayoutTests/fast/events/drag-customData.html.
* http/tests/local/fileapi/resources/setup-file-input-element-for-drag.js:
* http/tests/security/clipboard/script-tests/clipboard-file-access.js:
(checkForEventTransferType):

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

34 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/clipboard-customData.html
LayoutTests/editing/pasteboard/onpaste-text-html-types.html
LayoutTests/fast/events/drag-and-drop-dataTransfer-types-nocrash.html
LayoutTests/fast/events/drag-customData.html
LayoutTests/fast/events/drag-dataTransfer-live-attributes-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/drag-dataTransfer-live-attributes.html [new file with mode: 0644]
LayoutTests/http/tests/local/fileapi/resources/setup-file-input-element-for-drag.js
LayoutTests/http/tests/security/clipboard/script-tests/clipboard-file-access.js
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSClipboardCustom.cpp
Source/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp
Source/WebCore/dom/Clipboard.cpp
Source/WebCore/dom/Clipboard.h
Source/WebCore/dom/Clipboard.idl
Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp
Source/WebCore/platform/blackberry/ClipboardBlackBerry.h
Source/WebCore/platform/chromium/ChromiumDataObject.cpp
Source/WebCore/platform/chromium/ChromiumDataObject.h
Source/WebCore/platform/chromium/ClipboardChromium.cpp
Source/WebCore/platform/chromium/ClipboardChromium.h
Source/WebCore/platform/chromium/DragDataChromium.cpp
Source/WebCore/platform/efl/ClipboardEfl.cpp
Source/WebCore/platform/efl/ClipboardEfl.h
Source/WebCore/platform/gtk/ClipboardGtk.cpp
Source/WebCore/platform/gtk/ClipboardGtk.h
Source/WebCore/platform/mac/ClipboardMac.h
Source/WebCore/platform/mac/ClipboardMac.mm
Source/WebCore/platform/qt/ClipboardQt.cpp
Source/WebCore/platform/qt/ClipboardQt.h
Source/WebCore/platform/win/ClipboardWin.cpp
Source/WebCore/platform/win/ClipboardWin.h
Source/WebCore/platform/wx/ClipboardWx.cpp
Source/WebCore/platform/wx/ClipboardWx.h

index 1b9c307..cdf4699 100644 (file)
@@ -1,3 +1,24 @@
+2012-02-15  Daniel Cheng  <dcheng@chromium.org>
+
+        dataTransfer.types (HTML5 drag & drop) should return DOMStringList
+        https://bugs.webkit.org/show_bug.cgi?id=30416
+
+        Reviewed by Eric Seidel.
+
+        Add a test to document the fact that many dataTransfer attributes aren't live and return a
+        different object each time they're accessed. Also update tests to use contains() instead of
+        indexOf().
+
+        * editing/pasteboard/clipboard-customData.html:
+        * editing/pasteboard/onpaste-text-html-types.html:
+        * fast/events/drag-and-drop-dataTransfer-types-nocrash.html:
+        * fast/events/drag-customData.html:
+        * fast/events/drag-dataTransfer-live-attributes-expected.txt: Added.
+        * fast/events/drag-dataTransfer-live-attributes.html: Copied from LayoutTests/fast/events/drag-customData.html.
+        * http/tests/local/fileapi/resources/setup-file-input-element-for-drag.js:
+        * http/tests/security/clipboard/script-tests/clipboard-file-access.js:
+        (checkForEventTransferType):
+
 2012-02-15  Bear Travis  <betravis@adobe.com>
 
         Repaint issues on changing 'viewBox' of inner SVG
index 31d99bb..0ce4cbb 100644 (file)
@@ -17,8 +17,8 @@ function copy(event) {
 
 function paste(event) {
     var failed = false;
-    if (event.clipboardData.types.indexOf('text/plain') < 0
-        || event.clipboardData.types.indexOf('custom-data') < 0)
+    if (!event.clipboardData.types.contains('text/plain')
+        || !event.clipboardData.types.contains('custom-data'))
         failed = true;
     if (event.clipboardData.getData('text') != 'sample'
         || event.clipboardData.getData('custom-data') != 'hello world')
index 3b74ce4..f87fbe5 100644 (file)
@@ -8,8 +8,7 @@ during an onpaste event.  This test requires DRT.</div>
 function paste(ev)
 {
     var types = ev.clipboardData.types;
-    if (types.indexOf('text/plain') >= 0 &&
-        types.indexOf('text/html') >= 0)
+    if (types.contains('text/plain') && types.contains('text/html'))
         document.getElementById("results").innerHTML = "PASS";
 }
 
index 2128e40..3739655 100644 (file)
@@ -84,7 +84,7 @@
     {
         event = e;
         var formatTypes = e.dataTransfer.types; // This line causes the crash.
-        if (event.dataTransfer.types.indexOf(FORMAT_TYPE) == -1)
+        if (event.dataTransfer.types.contains(FORMAT_TYPE) == -1)
             testFailed('event.dataTransfer.types should contain format "' + FORMAT_TYPE + '", but it does not.');
         else
             testPassed('event.dataTransfer.types contains format "' + FORMAT_TYPE + '"');
index dca57ef..d8ce25c 100644 (file)
@@ -32,8 +32,8 @@ function dragover(event) {
 }
 function drop(event) {
     var failed = false;
-    if (event.dataTransfer.types.indexOf('text/plain') < 0
-        || event.dataTransfer.types.indexOf('custom-data') < 0)
+    if (!event.dataTransfer.types.contains('text/plain')
+        || !event.dataTransfer.types.contains('custom-data'))
         failed = true;
     if (event.dataTransfer.getData('text') != 'sample'
         || event.dataTransfer.getData('custom-data') != 'hello world')
diff --git a/LayoutTests/fast/events/drag-dataTransfer-live-attributes-expected.txt b/LayoutTests/fast/events/drag-dataTransfer-live-attributes-expected.txt
new file mode 100644 (file)
index 0000000..010acc1
--- /dev/null
@@ -0,0 +1,9 @@
+This is a test that various dataTransfer attributes are live and return the same object when accessed multiple times. To manually test, drag 'Drag Me' to 'Drop Here' and drop. The word 'SUCCESS' should appear.
+
+Drag Me
+Drop Here
+types != types
+files != files
+items != items
+FAILURE
+
diff --git a/LayoutTests/fast/events/drag-dataTransfer-live-attributes.html b/LayoutTests/fast/events/drag-dataTransfer-live-attributes.html
new file mode 100644 (file)
index 0000000..13aecdd
--- /dev/null
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+#drag {
+    border: 1px solid black;
+    height: 200px;
+    width: 200px;
+}
+#drop {
+    border: 1px solid black;
+    height: 200px;
+    width: 200px;
+}
+</style>
+<script>
+var failed;
+
+function log(str)
+{
+    var result = document.getElementById('result');
+    result.appendChild(document.createTextNode(str));
+    result.appendChild(document.createElement('br'));
+}
+function dragstart(event)
+{
+    failed = false;
+    event.dataTransfer.setData('text', 'sample');
+    if (event.dataTransfer.types != event.dataTransfer.types) {
+        failed = true;
+        log('types != types');
+    }
+    if (event.dataTransfer.files != event.dataTransfer.files) {
+        failed = true;
+        log('files != files');
+    }
+    if (event.dataTransfer.items != event.dataTransfer.items) {
+        failed = true;
+        log('items != items');
+    }
+}
+function dragenter(event)
+{
+    event.preventDefault();
+}
+function dragover(event)
+{
+    event.preventDefault();
+}
+function drop(event)
+{
+    if (!event.dataTransfer.types.contains('text/plain'))
+        failed = true;
+    if (event.dataTransfer.getData('text') != 'sample')
+        failed = true;
+    log(failed ? 'FAILURE' : 'SUCCESS');
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+window.onload = function()
+{
+    if (!window.layoutTestController)
+        return;
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+
+    var dragElement = document.getElementById('drag');
+    eventSender.mouseMoveTo(dragElement.offsetLeft + dragElement.offsetWidth / 2,
+                            dragElement.offsetTop + dragElement.offsetHeight / 2);
+    eventSender.mouseDown();
+    eventSender.leapForward(100);
+    var dropElement = document.getElementById('drop');
+    eventSender.mouseMoveTo(dropElement.offsetLeft + dropElement.offsetWidth / 2,
+                            dropElement.offsetTop + dropElement.offsetHeight / 2);
+    eventSender.mouseUp();
+}
+</script>
+</head>
+<body>
+<p>This is a test that various dataTransfer attributes are live and return the same object when accessed multiple times. To manually test, drag 'Drag Me' to 'Drop Here' and drop. The word 'SUCCESS' should appear.
+<div draggable="true" id="drag" ondragstart="dragstart(event)">Drag Me</div>
+<div id="drop" ondragenter="dragenter(event)" ondragover="dragover(event)" ondrop="drop(event)">Drop Here</div>
+</div>
+<div id="result"></div>
+</body>
+</html>
index c51c680..378feb8 100644 (file)
@@ -16,7 +16,7 @@ fileInput.addEventListener("dragover", function() {
 
 var fileInputDropCallback = null;
 fileInput.addEventListener("drop", function() {
-    if (event.dataTransfer.types.indexOf("Files") != -1 && event.dataTransfer.files.length == 1)
+    if (event.dataTransfer.types.contains("Files") && event.dataTransfer.files.length == 1)
         testPassed("event.dataTransfer contains a File object on drop.");
     else {
         testFailed("event.dataTransfer does not contain a File object on drop.");
index 4b6368d..9b28a0b 100644 (file)
@@ -75,7 +75,7 @@ function checkForEventTransferType(event, typeString, shouldContainType)
 {
     var passedCheck;
     var message;
-    if (event.dataTransfer.types && event.dataTransfer.types.indexOf(typeString) != -1) {
+    if (event.dataTransfer.types && event.dataTransfer.types.contains(typeString)) {
         passedCheck = shouldContainType;
         message = "event.dataTransfer.types contains " + typeString + ".";
     } else {
index 75ca9c8..cbdbf93 100644 (file)
@@ -1,3 +1,72 @@
+2012-02-15  Daniel Cheng  <dcheng@chromium.org>
+
+        dataTransfer.types (HTML5 drag & drop) should return DOMStringList
+        https://bugs.webkit.org/show_bug.cgi?id=30416
+
+        Reviewed by Eric Seidel.
+
+        This change breaks backwards compatibility; however, since Firefox only supported
+        event.dataTransfer.types.contains, sites already needed to check whether to use contains or
+        indexOf. Therefore, the net compatibility effect of this change should be minimal.
+
+        Test: fast/events/drag-dataTransfer-live-attributes.html
+
+        * bindings/js/JSClipboardCustom.cpp:
+        (WebCore):
+        * bindings/v8/custom/V8ClipboardCustom.cpp:
+        * dom/Clipboard.cpp:
+        (WebCore::Clipboard::hasStringOfType):
+        * dom/Clipboard.h:
+        (WebCore):
+        (Clipboard):
+        * dom/Clipboard.idl:
+        * platform/blackberry/ClipboardBlackBerry.cpp:
+        (WebCore::ClipboardBlackBerry::types):
+        * platform/blackberry/ClipboardBlackBerry.h:
+        (ClipboardBlackBerry):
+        * platform/chromium/ChromiumDataObject.cpp:
+        (WebCore::ChromiumDataObject::types):
+        * platform/chromium/ChromiumDataObject.h:
+        (ChromiumDataObject):
+        * platform/chromium/ClipboardChromium.cpp:
+        (WebCore::ClipboardChromium::types):
+        (WebCore::ClipboardChromium::mayUpdateItems):
+        * platform/chromium/ClipboardChromium.h:
+        (ClipboardChromium):
+        * platform/chromium/DragDataChromium.cpp:
+        (WebCore::containsHTML):
+        (WebCore::DragData::containsURL):
+        (WebCore::DragData::asURL):
+        (WebCore::DragData::containsPlainText):
+        (WebCore::DragData::canSmartReplace):
+        (WebCore::DragData::asFragment):
+        * platform/efl/ClipboardEfl.cpp:
+        (WebCore::ClipboardEfl::types):
+        * platform/efl/ClipboardEfl.h:
+        (ClipboardEfl):
+        * platform/gtk/ClipboardGtk.cpp:
+        (WebCore::ClipboardGtk::types):
+        * platform/gtk/ClipboardGtk.h:
+        (ClipboardGtk):
+        * platform/mac/ClipboardMac.h:
+        (ClipboardMac):
+        * platform/mac/ClipboardMac.mm:
+        (WebCore::addHTMLClipboardTypesForCocoaType):
+        (WebCore::ClipboardMac::types):
+        * platform/qt/ClipboardQt.cpp:
+        (WebCore::ClipboardQt::types):
+        * platform/qt/ClipboardQt.h:
+        (ClipboardQt):
+        * platform/win/ClipboardWin.cpp:
+        (WebCore::addMimeTypesForFormat):
+        (WebCore::ClipboardWin::types):
+        * platform/win/ClipboardWin.h:
+        (ClipboardWin):
+        * platform/wx/ClipboardWx.cpp:
+        (WebCore::ClipboardWx::types):
+        * platform/wx/ClipboardWx.h:
+        (ClipboardWx):
+
 2012-02-15  Bear Travis  <betravis@adobe.com>
 
         Repaint issues on changing 'viewBox' of inner SVG
index efce79b..3532c78 100644 (file)
@@ -48,21 +48,6 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-JSValue JSClipboard::types(ExecState* exec) const
-{
-    Clipboard* clipboard = impl();
-
-    HashSet<String> types = clipboard->types();
-    if (types.isEmpty())
-        return jsNull();
-
-    MarkedArgumentBuffer list;
-    HashSet<String>::const_iterator end = types.end();
-    for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it)
-        list.append(jsString(exec, stringToUString(*it)));
-    return constructArray(exec, globalObject(), list);
-}
-
 JSValue JSClipboard::clearData(ExecState* exec)
 {
     Clipboard* clipboard = impl();
index d85d7a0..51d6f2c 100644 (file)
 
 namespace WebCore {
 
-v8::Handle<v8::Value> V8Clipboard::typesAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
-{
-    INC_STATS("DOM.Clipboard.types()");
-    Clipboard* clipboard = V8Clipboard::toNative(info.Holder());
-
-    HashSet<String> types = clipboard->types();
-    if (types.isEmpty())
-        return v8::Null();
-
-    v8::Local<v8::Array> result = v8::Array::New(types.size());
-    HashSet<String>::const_iterator end = types.end();
-    int index = 0;
-    for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it, ++index)
-        result->Set(v8::Integer::New(index), v8String(*it));
-
-    return result;
-}
-
 v8::Handle<v8::Value> V8Clipboard::clearDataCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.Clipboard.clearData()");
index 0279925..2053292 100644 (file)
@@ -27,6 +27,7 @@
 #include "Clipboard.h"
 
 #include "CachedImage.h"
+#include "DOMStringList.h"
 #include "FileList.h"
 #include "Frame.h"
 #include "FrameLoader.h"
@@ -147,7 +148,7 @@ bool Clipboard::hasStringOfType(const String& type) const
     if (m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)
         return false;
     
-    return types().contains(type); 
+    return types()->contains(type);
 }
     
 void Clipboard::setDropEffect(const String &effect)
index a07ae9f..d33829a 100644 (file)
@@ -33,6 +33,7 @@
 
 namespace WebCore {
 
+    class DOMStringList;
     class DataTransferItemList;
     class DragData;
     class FileList;
@@ -66,7 +67,7 @@ namespace WebCore {
         virtual bool setData(const String& type, const String& data) = 0;
     
         // extensions beyond IE's API
-        virtual HashSet<String> types() const = 0;
+        virtual PassRefPtr<DOMStringList> types() const = 0;
         virtual PassRefPtr<FileList> files() const = 0;
 
         IntPoint dragLocation() const { return m_dragLoc; }
index b005046..c1c5850 100644 (file)
@@ -31,7 +31,7 @@ module core {
     interface Clipboard {
                  attribute [TreatReturnedNullStringAs=Undefined] DOMString dropEffect;
                  attribute [TreatReturnedNullStringAs=Undefined] DOMString effectAllowed;
-        readonly attribute [CustomGetter] Array types;
+        readonly attribute DOMStringList types;
         readonly attribute FileList files;
 
         [Custom] void clearData(in [Optional] DOMString type)
index 1612737..b224d5c 100644 (file)
@@ -19,6 +19,7 @@
 #include "config.h"
 #include "ClipboardBlackBerry.h"
 
+#include "DOMStringList.h"
 #include "FileList.h"
 #include "NotImplemented.h"
 
@@ -72,14 +73,14 @@ bool ClipboardBlackBerry::setData(const String& type, const String& text)
     return true;
 }
 
-HashSet<String> ClipboardBlackBerry::types() const
+PassRefPtr<DOMStringList> ClipboardBlackBerry::types() const
 {
     // We use hardcoded list here since there seems to be no API to get the list.
-    HashSet<String> ret;
-    ret.add("text/plain");
-    ret.add("text/html");
-    ret.add("text/url");
-    return ret;
+    RefPtr<DOMStringList> ret = DOMStringList::create();
+    ret->append("text/plain");
+    ret->append("text/html");
+    ret->append("text/url");
+    return ret.release();
 }
 
 PassRefPtr<FileList> ClipboardBlackBerry::files() const
index 2f39f46..255d6aa 100644 (file)
@@ -36,7 +36,7 @@ public:
     bool setData(const String& type, const String& data);
 
     // extensions beyond IE's API
-    virtual HashSet<String> types() const;
+    virtual PassRefPtr<DOMStringList> types() const;
     virtual PassRefPtr<FileList> files() const;
     virtual DragImageRef createDragImage(IntPoint&) const;
     virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*);
index 6ad10c7..d6b73e5 100644 (file)
@@ -101,33 +101,36 @@ bool ChromiumDataObject::hasData() const
         || m_fileContent;
 }
 
-HashSet<String> ChromiumDataObject::types() const
+PassRefPtr<DOMStringList> ChromiumDataObject::types() const
 {
+    RefPtr<DOMStringList> results = DOMStringList::create();
+
     if (m_storageMode == Pasteboard) {
         bool ignoredContainsFilenames;
-        return PlatformSupport::clipboardReadAvailableTypes(currentPasteboardBuffer(),
-                                                            &ignoredContainsFilenames);
+        HashSet<String> hashedResults = PlatformSupport::clipboardReadAvailableTypes(
+            currentPasteboardBuffer(), &ignoredContainsFilenames);
+        for (HashSet<String>::const_iterator it = hashedResults.begin(); it != hashedResults.end(); ++it)
+          results->append(*it);
+        return results.release();
     }
 
-    HashSet<String> results;
-
     if (!m_plainText.isEmpty()) {
-        results.add(mimeTypeText);
-        results.add(mimeTypeTextPlain);
+        results->append(mimeTypeText);
+        results->append(mimeTypeTextPlain);
     }
 
     if (!m_uriList.isEmpty())
-        results.add(mimeTypeTextURIList);
+        results->append(mimeTypeTextURIList);
 
     if (!m_textHtml.isEmpty())
-        results.add(mimeTypeTextHTML);
+        results->append(mimeTypeTextHTML);
 
     for (HashMap<String, String>::const_iterator::Keys it = m_customData.begin().keys();
          it != m_customData.end().keys(); ++it) {
-        results.add(*it);
+        results->append(*it);
     }
 
-    return results;
+    return results.release();
 }
 
 String ChromiumDataObject::getData(const String& type, bool& success) const
index 7e675bf..9a6f562 100644 (file)
 #ifndef ChromiumDataObject_h
 #define ChromiumDataObject_h
 
+#include "DOMStringList.h"
 #include "KURL.h"
 #include "PlatformString.h"
 #include "SharedBuffer.h"
 #include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 #include <wtf/text/StringHash.h>
@@ -75,7 +75,7 @@ public:
 
     bool hasData() const;
 
-    HashSet<String> types() const;
+    PassRefPtr<DOMStringList> types() const;
     String getData(const String& type, bool& success) const;
     bool setData(const String& type, const String& data);
 
index 75f8f63..1b1536e 100644 (file)
@@ -31,6 +31,7 @@
 #include "ChromiumDataObject.h"
 #include "ClipboardMimeTypes.h"
 #include "ClipboardUtilitiesChromium.h"
+#include "DOMStringList.h"
 #include "DataTransferItemChromium.h"
 #include "DataTransferItemListChromium.h"
 #include "Document.h"
@@ -289,21 +290,20 @@ bool ClipboardChromium::platformClipboardChanged() const
 }
 
 // extensions beyond IE's API
-HashSet<String> ClipboardChromium::types() const
+PassRefPtr<DOMStringList> ClipboardChromium::types() const
 {
-    HashSet<String> results;
     if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
-        return results;
+        return DOMStringList::create();
 
     if (!m_dataObject)
-        return results;
+        return DOMStringList::create();
 
-    results = m_dataObject->types();
+    RefPtr<DOMStringList> results = m_dataObject->types();
 
     if (m_dataObject->containsFilenames())
-        results.add(mimeTypeFiles);
+        results->append(mimeTypeFiles);
 
-    return results;
+    return results.release();
 }
 
 PassRefPtr<FileList> ClipboardChromium::files() const
@@ -518,9 +518,9 @@ void ClipboardChromium::mayUpdateItems(Vector<RefPtr<DataTransferItem> >& items)
 
     if (isForCopyAndPaste() && policy() == ClipboardReadable) {
         // Iterate through the types and add them.
-        HashSet<String> types = m_dataObject->types();
-        for (HashSet<String>::const_iterator it = types.begin(); it != types.end(); ++it)
-            items.append(DataTransferItemChromium::createFromPasteboard(this, scriptExecutionContext, *it));
+        RefPtr<DOMStringList> types = m_dataObject->types();
+        for (size_t i = 0; i < types->length(); ++i)
+            items.append(DataTransferItemChromium::createFromPasteboard(this, scriptExecutionContext, types->item(i)));
         return;
     }
 
index 924226d..ae9eb71 100644 (file)
@@ -63,7 +63,7 @@ namespace WebCore {
         bool platformClipboardChanged() const;
 
         // extensions beyond IE's API
-        virtual HashSet<String> types() const;
+        virtual PassRefPtr<DOMStringList> types() const;
         virtual PassRefPtr<FileList> files() const;
 
         void setDragImage(CachedImage*, const IntPoint&);
index 3d94a19..a7a8535 100644 (file)
@@ -45,19 +45,19 @@ namespace WebCore {
 
 static bool containsHTML(const ChromiumDataObject* dropData)
 {
-    return dropData->types().contains(mimeTypeTextHTML);
+    return dropData->types()->contains(mimeTypeTextHTML);
 }
 
 bool DragData::containsURL(Frame*, FilenameConversionPolicy filenamePolicy) const
 {
-    return m_platformDragData->types().contains(mimeTypeTextURIList)
+    return m_platformDragData->types()->contains(mimeTypeTextURIList)
         || (filenamePolicy == ConvertFilenames && m_platformDragData->containsFilenames());
 }
 
 String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
 {
     String url;
-    if (m_platformDragData->types().contains(mimeTypeTextURIList)) {
+    if (m_platformDragData->types()->contains(mimeTypeTextURIList)) {
         bool ignoredSuccess;
         url = m_platformDragData->getData(mimeTypeURL, ignoredSuccess);
         if (title)
@@ -87,7 +87,7 @@ void DragData::asFilenames(Vector<String>& result) const
 
 bool DragData::containsPlainText() const
 {
-    return m_platformDragData->types().contains(mimeTypeTextPlain);
+    return m_platformDragData->types()->contains(mimeTypeTextPlain);
 }
 
 String DragData::asPlainText(Frame*) const
@@ -108,8 +108,8 @@ bool DragData::canSmartReplace() const
     // This is allowed whenever the drag data contains a 'range' (ie.,
     // ClipboardWin::writeRange is called).  For example, dragging a link
     // should not result in a space being added.
-    return m_platformDragData->types().contains(mimeTypeTextPlain)
-        && !m_platformDragData->types().contains(mimeTypeTextURIList);
+    return m_platformDragData->types()->contains(mimeTypeTextPlain)
+        && !m_platformDragData->types()->contains(mimeTypeTextURIList);
 }
 
 bool DragData::containsCompatibleContent() const
@@ -141,7 +141,7 @@ PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range
         //    return fragment;
     }
 
-    if (m_platformDragData->types().contains(mimeTypeTextHTML)) {
+    if (m_platformDragData->types()->contains(mimeTypeTextHTML)) {
         bool ignoredSuccess;
         RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(),
             m_platformDragData->getData(mimeTypeTextHTML, ignoredSuccess), m_platformDragData->htmlBaseUrl(), FragmentScriptingNotAllowed);
index 8dc95e8..6015272 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "ClipboardEfl.h"
 
+#include "DOMStringList.h"
 #include "DataTransferItemList.h"
 #include "Editor.h"
 #include "FileList.h"
@@ -77,10 +78,10 @@ bool ClipboardEfl::setData(const String&, const String&)
     return false;
 }
 
-HashSet<String> ClipboardEfl::types() const
+PassRefPtr<DOMStringList> ClipboardEfl::types() const
 {
     notImplemented();
-    return HashSet<String>();
+    return DOMStringList::create();
 }
 
 PassRefPtr<FileList> ClipboardEfl::files() const
index 575382f..5645519 100644 (file)
@@ -39,7 +39,7 @@ public:
     String getData(const String&, bool&) const;
     bool setData(const String&, const String&);
 
-    HashSet<String> types() const;
+    PassRefPtr<DOMStringList> types() const;
     virtual PassRefPtr<FileList> files() const;
 
     IntPoint dragLocation() const;
index b1d2b52..b202167 100644 (file)
@@ -18,6 +18,7 @@
 #include "ClipboardGtk.h"
 
 #include "CachedImage.h"
+#include "DOMStringList.h"
 #include "DragData.h"
 #include "Editor.h"
 #include "Element.h"
@@ -189,33 +190,33 @@ bool ClipboardGtk::setData(const String& typeString, const String& data)
     return success;
 }
 
-HashSet<String> ClipboardGtk::types() const
+PassRefPtr<DOMStringList> ClipboardGtk::types() const
 {
     if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
-        return HashSet<String>();
+        return DOMStringList::create();
 
     if (m_clipboard)
         PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_clipboard);
 
-    HashSet<String> types;
+    RefPtr<DOMStringList> types = DOMStringList::create();
     if (m_dataObject->hasText()) {
-        types.add("text/plain");
-        types.add("Text");
-        types.add("text");
+        types->append("text/plain");
+        types->append("Text");
+        types->append("text");
     }
 
     if (m_dataObject->hasMarkup())
-        types.add("text/html");
+        types->append("text/html");
 
     if (m_dataObject->hasURIList()) {
-        types.add("text/uri-list");
-        types.add("URL");
+        types->append("text/uri-list");
+        types->append("URL");
     }
 
     if (m_dataObject->hasFilenames())
-        types.add("Files");
+        types->append("Files");
 
-    return types;
+    return types.release();
 }
 
 PassRefPtr<FileList> ClipboardGtk::files() const
index d8b7518..b72e1c8 100644 (file)
@@ -57,7 +57,7 @@ namespace WebCore {
         String getData(const String&, bool&) const;
         bool setData(const String&, const String&);
 
-        virtual HashSet<String> types() const;
+        virtual PassRefPtr<DOMStringList> types() const;
         virtual PassRefPtr<FileList> files() const;
 
         void setDragImage(CachedImage*, const IntPoint&);
index a4b6796..a84f289 100644 (file)
@@ -56,7 +56,7 @@ public:
     virtual bool hasData();
     
     // extensions beyond IE's API
-    virtual HashSet<String> types() const;
+    virtual PassRefPtr<DOMStringList> types() const;
     virtual PassRefPtr<FileList> files() const;
 
     void setDragImage(CachedImage*, const IntPoint&);
index c48aa49..1b0a5ab 100644 (file)
@@ -27,6 +27,7 @@
 #import "ClipboardMac.h"
 
 #import "DOMElementInternal.h"
+#import "DOMStringList.h"
 #import "DragClient.h"
 #import "DragController.h"
 #import "DragData.h"
@@ -111,15 +112,15 @@ static String utiTypeFromCocoaType(const String& type)
     return String();
 }
 
-static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName)
+static void addHTMLClipboardTypesForCocoaType(DOMStringList* resultTypes, const String& cocoaType, const String& pasteboardName)
 {
     // UTI may not do these right, so make sure we get the right, predictable result
     if (cocoaType == String(NSStringPboardType)) {
-        resultTypes.add("text/plain");
+        resultTypes->append("text/plain");
         return;
     }
     if (cocoaType == String(NSURLPboardType)) {
-        resultTypes.add("text/uri-list");
+        resultTypes->append("text/uri-list");
         return;
     }
     if (cocoaType == String(NSFilenamesPboardType)) {
@@ -131,18 +132,18 @@ static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, cons
         if (!fileList.isEmpty()) {
             // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
             // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
-            resultTypes.add("text/uri-list");
-            resultTypes.add("Files");
+            resultTypes->append("text/uri-list");
+            resultTypes->append("Files");
         }
         return;
     }
     String utiType = utiTypeFromCocoaType(cocoaType);
     if (!utiType.isEmpty()) {
-        resultTypes.add(utiType);
+        resultTypes->append(utiType);
         return;
     }
     // No mapping, just pass the whole string though
-    resultTypes.add(cocoaType);
+    resultTypes->append(cocoaType);
 }
 
 void ClipboardMac::clearData(const String& type)
@@ -283,10 +284,10 @@ bool ClipboardMac::setData(const String &type, const String &data)
     return false;
 }
 
-HashSet<String> ClipboardMac::types() const
+PassRefPtr<DOMStringList> ClipboardMac::types() const
 {
     if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
-        return HashSet<String>();
+        return DOMStringList::create();
 
     Vector<String> types;
     platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName);
@@ -294,19 +295,19 @@ HashSet<String> ClipboardMac::types() const
     // Enforce changeCount ourselves for security.  We check after reading instead of before to be
     // sure it doesn't change between our testing the change count and accessing the data.
     if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
-        return HashSet<String>();
+        return DOMStringList::create();
 
-    HashSet<String> result;
+    RefPtr<DOMStringList> result = DOMStringList::create();
     // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types
     // and a second which adds all the extra types from the cocoa clipboard (which is Mac-only behavior).
     for (size_t i = 0; i < types.size(); i++) {
         if (types[i] == "NeXT plain ascii pasteboard type")
             continue;   // skip this ancient type that gets auto-supplied by some system conversion
 
-        addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName);
+        addHTMLClipboardTypesForCocoaType(result.get(), types[i], m_pasteboardName);
     }
 
-    return result;
+    return result.release();
 }
 
 // FIXME: We could cache the computed fileList if necessary
index 2734952..3d8bab1 100644 (file)
@@ -30,6 +30,7 @@
 #include "ClipboardQt.h"
 
 #include "CachedImage.h"
+#include "DOMStringList.h"
 #include "DataTransferItemListQt.h"
 #include "Document.h"
 #include "DragData.h"
@@ -189,17 +190,17 @@ bool ClipboardQt::setData(const String& type, const String& data)
 }
 
 // extensions beyond IE's API
-HashSet<String> ClipboardQt::types() const
+PassRefPtr<DOMStringList> ClipboardQt::types() const
 {
     if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
-        return HashSet<String>();
+        return DOMStringList::create();
 
     ASSERT(m_readableData);
-    HashSet<String> result;
+    RefPtr<DOMStringList> result = DOMStringList::create();
     QStringList formats = m_readableData->formats();
     for (int i = 0; i < formats.count(); ++i)
-        result.add(formats.at(i));
-    return result;
+        result->append(formats.at(i));
+    return result.release();
 }
 
 PassRefPtr<FileList> ClipboardQt::files() const
index dc6ba41..a840bec 100644 (file)
@@ -57,7 +57,7 @@ public:
     bool setData(const String& type, const String& data);
 
     // extensions beyond IE's API
-    virtual HashSet<String> types() const;
+    virtual PassRefPtr<DOMStringList> types() const;
     virtual PassRefPtr<FileList> files() const;
 
     void setDragImage(CachedImage*, const IntPoint&);
index aa38388..89cacb3 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "CachedImage.h"
 #include "ClipboardUtilitiesWin.h"
+#include "DOMStringList.h"
 #include "Document.h"
 #include "DragData.h"
 #include "Editor.h"
@@ -485,24 +486,24 @@ bool ClipboardWin::setData(const String& type, const String& data)
     return false;
 }
 
-static void addMimeTypesForFormat(HashSet<String>& results, const FORMATETC& format)
+static void addMimeTypesForFormat(DOMStringList* results, const FORMATETC& format)
 {
     // URL and Text are provided for compatibility with IE's model
     if (format.cfFormat == urlFormat()->cfFormat || format.cfFormat == urlWFormat()->cfFormat) {
-        results.add("URL");
-        results.add("text/uri-list");
+        results->append("URL");
+        results->append("text/uri-list");
     }
 
     if (format.cfFormat == plainTextWFormat()->cfFormat || format.cfFormat == plainTextFormat()->cfFormat) {
-        results.add("Text");
-        results.add("text/plain");
+        results->append("Text");
+        results->append("text/plain");
     }
 }
 
 // extensions beyond IE's API
-HashSet<String> ClipboardWin::types() const
+PassRefPtr<DOMStringList> ClipboardWin::types() const
 { 
-    HashSet<String> results; 
+    RefPtr<DOMStringList> results = DOMStringList::create();
     if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
         return results;
 
@@ -522,16 +523,16 @@ HashSet<String> ClipboardWin::types() const
 
         // IEnumFORMATETC::Next returns S_FALSE if there are no more items.
         while (itr->Next(1, &data, 0) == S_OK)
-            addMimeTypesForFormat(results, data);
+            addMimeTypesForFormat(results.get(), data);
     } else {
         for (DragDataMap::const_iterator it = m_dragDataMap.begin(); it != m_dragDataMap.end(); ++it) {
             FORMATETC data;
             data.cfFormat = (*it).first;
-            addMimeTypesForFormat(results, data);
+            addMimeTypesForFormat(results.get(), data);
         }
     }
 
-    return results;
+    return results.release();
 }
 
 PassRefPtr<FileList> ClipboardWin::files() const
index a35d8b4..8c22c0a 100644 (file)
@@ -64,7 +64,7 @@ public:
     bool setData(const String& type, const String& data);
 
     // extensions beyond IE's API
-    virtual HashSet<String> types() const;
+    virtual PassRefPtr<DOMStringList> types() const;
     virtual PassRefPtr<FileList> files() const;
 
     void setDragImage(CachedImage*, const IntPoint&);
index 32216a6..161bce8 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "ClipboardWx.h"
 
+#include "DOMStringList.h"
 #include "FileList.h"
 #include "HashTable.h"
 #include "IntPoint.h"
@@ -70,11 +71,10 @@ bool ClipboardWx::setData(const String& type, const String& data)
 }
 
 // extensions beyond IE's API
-HashSet<String> ClipboardWx::types() const 
+PassRefPtr<DOMStringList> ClipboardWx::types() const 
 {
     notImplemented();
-    HashSet<String> result;
-    return result;
+    return DOMStringList::create();
 }
 
 PassRefPtr<FileList> ClipboardWx::files() const
index 138635a..f92726a 100644 (file)
@@ -46,7 +46,7 @@ namespace WebCore {
         bool setData(const String& type, const String& data);
     
         // extensions beyond IE's API
-        virtual HashSet<String> types() const;
+        virtual PassRefPtr<DOMStringList> types() const;
         virtual PassRefPtr<FileList> files() const;
     
         IntPoint dragLocation() const;