Changeset 220782 in webkit


Ignore:
Timestamp:
Aug 15, 2017 7:23:41 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Make DataTransferItemList work with plain text entries
https://bugs.webkit.org/show_bug.cgi?id=175596

Reviewed by Wenson Hsieh.

Source/JavaScriptCore:

Added DataTransferItem as a common identifier since it's a runtime enabled feature.

  • runtime/CommonIdentifiers.h:

Source/WebCore:

Added the basic machinery to get the list of plain text items to DataTransferItemList and DataTransferItem.

Each DataTransferItem now depends on DataTransfer so it does ref-forwarding like DataTransferItemList to make
DataTransfer alive as long as any DataTransferItem is alive.

Specifications: https://html.spec.whatwg.org/multipage/dnd.html#the-datatransferitem-interface

https://html.spec.whatwg.org/multipage/dnd.html#the-datatransferitemlist-interface

Tests: editing/pasteboard/datatransfer-items-drop-plaintext-file.html

editing/pasteboard/datatransfer-items-paste-plaintext.html

  • dom/DataTransferItem.cpp:

(WebCore::DataTransferItem::DataTransferItem): Added two variants one for plain text and another one for a file.
(WebCore::DataTransferItem::kind const): Rewritten.
(WebCore::DataTransferItem::getAsString const): Implemented.
(WebCore::DataTransferItem::getAsFile const): Implemented.

  • dom/DataTransferItem.h:

(WebCore::DataTransferItem::ref): Added.
(WebCore::DataTransferItem::deref): Added.
(WebCore::DataTransferItem::type const): Returns String instead of AtomicString.
(WebCore::DataTransferItem::kind const): Moved to cpp.

  • dom/DataTransferItem.idl: Removed NoInterfaceObject since the interface object should exist on DOMWindow.
  • dom/DataTransferItemList.cpp:

(WebCore::DataTransferItemList::length): Implemented.
(WebCore::DataTransferItemList::item): Ditto.
(WebCore::isSupportedType): Added. For now, we only support text/plain.
(WebCore::DataTransferItemList::ensureItems): Added. Constructs the list of DataTransferItems.

  • dom/DataTransferItemList.h:

(DataTransferItemList): Added m_items. The list is filled lazily by ensureItems.

  • dom/DataTransferItemList.idl: Removed NoInterfaceObject since the interface object should exist on DOMWindow.

LayoutTests:

Rebaselined the tests and added two regression tests for pasting plain text and dropping a plain text file.

Unfortunately, dropping a file is only supported by DumpRenderTree on Mac :( so it's disabled elsewhere.

  • editing/pasteboard/datatransfer-idl-expected.txt: Rebaselined now that NoInterfaceObject has been dropped from

DataTransferItem.idl and DataTransferItemList.idl as expected.

  • editing/pasteboard/datatransfer-idl.html: Fixed the bug that it wasn't testing IDL for DataTransferItem.
  • editing/pasteboard/datatransfer-items-drop-plaintext-file-expected.txt: Added.
  • editing/pasteboard/datatransfer-items-drop-plaintext-file.html: Added.
  • editing/pasteboard/datatransfer-items-paste-plaintext-expected.txt: Added.
  • editing/pasteboard/datatransfer-items-paste-plaintext.html: Added.
  • editing/resources/text-pasteboard-data.txt: Added.
  • platform/gtk/js/dom/global-constructors-attributes-expected.txt:
  • platform/ios/TestExpectations:
  • platform/mac-elcapitan-wk2/js/dom/global-constructors-attributes-expected.txt:
  • platform/mac-elcapitan/js/dom/global-constructors-attributes-expected.txt:
  • platform/mac-highsierra-wk1/js/dom/global-constructors-attributes-expected.txt:
  • platform/mac-highsierra/js/dom/global-constructors-attributes-expected.txt:
  • platform/mac/js/dom/global-constructors-attributes-expected.txt:
  • platform/win/TestExpectations:
  • platform/wk2/TestExpectations:
  • platform/wpe/js/dom/global-constructors-attributes-expected.txt:
Location:
trunk
Files:
5 added
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r220779 r220782  
     12017-08-15  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Make DataTransferItemList work with plain text entries
     4        https://bugs.webkit.org/show_bug.cgi?id=175596
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Rebaselined the tests and added two regression tests for pasting plain text and dropping a plain text file.
     9
     10        Unfortunately, dropping a file is only supported by DumpRenderTree on Mac :( so it's disabled elsewhere.
     11
     12        * editing/pasteboard/datatransfer-idl-expected.txt: Rebaselined now that NoInterfaceObject has been dropped from
     13        DataTransferItem.idl and DataTransferItemList.idl as expected.
     14        * editing/pasteboard/datatransfer-idl.html: Fixed the bug that it wasn't testing IDL for DataTransferItem.
     15        * editing/pasteboard/datatransfer-items-drop-plaintext-file-expected.txt: Added.
     16        * editing/pasteboard/datatransfer-items-drop-plaintext-file.html: Added.
     17        * editing/pasteboard/datatransfer-items-paste-plaintext-expected.txt: Added.
     18        * editing/pasteboard/datatransfer-items-paste-plaintext.html: Added.
     19        * editing/resources/text-pasteboard-data.txt: Added.
     20        * platform/gtk/js/dom/global-constructors-attributes-expected.txt:
     21        * platform/ios/TestExpectations:
     22        * platform/mac-elcapitan-wk2/js/dom/global-constructors-attributes-expected.txt:
     23        * platform/mac-elcapitan/js/dom/global-constructors-attributes-expected.txt:
     24        * platform/mac-highsierra-wk1/js/dom/global-constructors-attributes-expected.txt:
     25        * platform/mac-highsierra/js/dom/global-constructors-attributes-expected.txt:
     26        * platform/mac/js/dom/global-constructors-attributes-expected.txt:
     27        * platform/win/TestExpectations:
     28        * platform/wk2/TestExpectations:
     29        * platform/wpe/js/dom/global-constructors-attributes-expected.txt:
     30
    1312017-08-15  Chris Dumez  <cdumez@apple.com>
    232
  • trunk/LayoutTests/editing/pasteboard/datatransfer-idl-expected.txt

    r220627 r220782  
     1CONSOLE MESSAGE: line 251: callback not yet supported
    12
    23PASS DataTransfer interface: existence and properties of interface object
     
    1415PASS DataTransfer interface: operation clearData(DOMString)
    1516PASS DataTransfer interface: attribute files
    16 FAIL DataTransferItemList interface: existence and properties of interface object assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    17 FAIL DataTransferItemList interface object length assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    18 FAIL DataTransferItemList interface object name assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    19 FAIL DataTransferItemList interface: existence and properties of interface prototype object assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    20 FAIL DataTransferItemList interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    21 FAIL DataTransferItemList interface: attribute length assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    22 FAIL DataTransferItemList interface: operation add(DOMString,DOMString) assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    23 FAIL DataTransferItemList interface: operation add(File) assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    24 FAIL DataTransferItemList interface: operation remove(unsigned long) assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
    25 FAIL DataTransferItemList interface: operation clear() assert_own_property: self does not have own property "DataTransferItemList" expected property "DataTransferItemList" missing
     17PASS DataTransferItemList interface: existence and properties of interface object
     18PASS DataTransferItemList interface object length
     19PASS DataTransferItemList interface object name
     20PASS DataTransferItemList interface: existence and properties of interface prototype object
     21PASS DataTransferItemList interface: existence and properties of interface prototype object's "constructor" property
     22PASS DataTransferItemList interface: attribute length
     23FAIL DataTransferItemList interface: operation add(DOMString,DOMString) assert_equals: property has wrong .length expected 1 but got 0
     24FAIL DataTransferItemList interface: operation add(File) assert_equals: property has wrong .length expected 1 but got 0
     25PASS DataTransferItemList interface: operation remove(unsigned long)
     26PASS DataTransferItemList interface: operation clear()
     27PASS DataTransferItem interface: existence and properties of interface object
     28PASS DataTransferItem interface object length
     29PASS DataTransferItem interface object name
     30PASS DataTransferItem interface: existence and properties of interface prototype object
     31PASS DataTransferItem interface: existence and properties of interface prototype object's "constructor" property
     32PASS DataTransferItem interface: attribute kind
     33PASS DataTransferItem interface: attribute type
     34PASS DataTransferItem interface: operation getAsString(FunctionStringCallback)
     35PASS DataTransferItem interface: operation getAsFile()
    2636
  • trunk/LayoutTests/editing/pasteboard/datatransfer-idl.html

    r220627 r220782  
    4040    readonly attribute DOMString kind;
    4141    readonly attribute DOMString type;
    42     void getAsString(FunctionStringCallback? _callback);
     42    void getAsString(FunctionStringCallback? callback);
    4343    File? getAsFile();
    4444};
     
    4949var idlsArray = new IdlArray();
    5050var idl = document.getElementById("datatransfer-idl").textContent
    51     + document.getElementById("datatransferitemlist-idl").textContent;
     51    + document.getElementById("datatransferitemlist-idl").textContent
    5252    + document.getElementById("datatransferitem-idl").textContent;
    5353
    5454idlsArray.add_idls(idl);
    5555idlsArray.add_untested_idls("interface Element {};");
    56 //idlsArray.add_untested_idls("interface ReadableStream {};");
    57 //idlsArray.add_objects({ Response: ['new Response()'] });
    5856idlsArray.test();
    5957</script>
  • trunk/LayoutTests/platform/gtk/js/dom/global-constructors-attributes-expected.txt

    r220450 r220782  
    399399PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    400400PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     401PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     402PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     403PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     404PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     405PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     406PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     407PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     408PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     409PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     410PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    401411PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    402412PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/ios/TestExpectations

    r220747 r220782  
    236236
    237237# Drag-and-drop is not supported:
     238editing/pasteboard/datatransfer-items-drop-plaintext-file.html
     239editing/pasteboard/datatransfer-items-paste-plaintext.html
    238240editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html
    239241fast/events/bogus-dropEffect-effectAllowed.html
  • trunk/LayoutTests/platform/mac-elcapitan-wk2/js/dom/global-constructors-attributes-expected.txt

    r220409 r220782  
    399399PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    400400PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     401PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     402PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     403PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     404PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     405PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     406PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     407PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     408PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     409PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     410PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    401411PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    402412PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/mac-elcapitan/js/dom/global-constructors-attributes-expected.txt

    r220343 r220782  
    389389PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    390390PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     391PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     392PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     393PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     394PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     395PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     396PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     397PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     398PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     399PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     400PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    391401PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    392402PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/mac-highsierra-wk1/js/dom/global-constructors-attributes-expected.txt

    r219729 r220782  
    394394PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    395395PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     396PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     397PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     398PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     399PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     400PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     401PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     402PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     403PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     404PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     405PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    396406PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    397407PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/mac-highsierra/js/dom/global-constructors-attributes-expected.txt

    r220311 r220782  
    409409PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    410410PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     411PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     412PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     413PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     414PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     415PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     416PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     417PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     418PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     419PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     420PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    411421PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    412422PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt

    r220343 r220782  
    404404PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    405405PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     406PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     407PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     408PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     409PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     410PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     411PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     412PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     413PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     414PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     415PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    406416PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    407417PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/win/TestExpectations

    r220734 r220782  
    122122
    123123# TODO Drag & Drop doesn't work correctly in DRT <rdar://5621244>
     124editing/pasteboard/datatransfer-items-drop-plaintext-file.html
    124125fast/events/drop-handler-should-not-stop-navigate.html [ Skip ]
    125126fast/events/drag-in-frames.html [ Skip ]
  • trunk/LayoutTests/platform/wk2/TestExpectations

    r220767 r220782  
    564564# WebKitTestRunner needs an implementation of eventSender.beginDragWithFiles
    565565# https://bugs.webkit.org/show_bug.cgi?id=64285
     566editing/pasteboard/datatransfer-items-drop-plaintext-file.html
    566567editing/pasteboard/file-drag-to-editable.html [ Skip ]
    567568editing/pasteboard/file-input-files-access.html
  • trunk/LayoutTests/platform/wpe/js/dom/global-constructors-attributes-expected.txt

    r220450 r220782  
    394394PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').enumerable is false
    395395PASS Object.getOwnPropertyDescriptor(global, 'DataTransfer').configurable is true
     396PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').value is DataTransferItem
     397PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('get') is false
     398PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').hasOwnProperty('set') is false
     399PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').enumerable is false
     400PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItem').configurable is true
     401PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').value is DataTransferItemList
     402PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('get') is false
     403PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').hasOwnProperty('set') is false
     404PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').enumerable is false
     405PASS Object.getOwnPropertyDescriptor(global, 'DataTransferItemList').configurable is true
    396406PASS Object.getOwnPropertyDescriptor(global, 'DataView').value is DataView
    397407PASS Object.getOwnPropertyDescriptor(global, 'DataView').hasOwnProperty('get') is false
  • trunk/Source/JavaScriptCore/ChangeLog

    r220778 r220782  
     12017-08-15  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Make DataTransferItemList work with plain text entries
     4        https://bugs.webkit.org/show_bug.cgi?id=175596
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Added DataTransferItem as a common identifier since it's a runtime enabled feature.
     9
     10        * runtime/CommonIdentifiers.h:
     11
    1122017-08-15  Robin Morisset  <rmorisset@apple.com>
    213
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r220627 r220782  
    4444    macro(Date) \
    4545    macro(DateTimeFormat) \
     46    macro(DataTransferItem) \
    4647    macro(DataTransferItemList) \
    4748    macro(DocumentTimeline) \
  • trunk/Source/WebCore/ChangeLog

    r220781 r220782  
     12017-08-15  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Make DataTransferItemList work with plain text entries
     4        https://bugs.webkit.org/show_bug.cgi?id=175596
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Added the basic machinery to get the list of plain text items to DataTransferItemList and DataTransferItem.
     9
     10        Each DataTransferItem now depends on DataTransfer so it does ref-forwarding like DataTransferItemList to make
     11        DataTransfer alive as long as any DataTransferItem is alive.
     12
     13        Specifications: https://html.spec.whatwg.org/multipage/dnd.html#the-datatransferitem-interface
     14                        https://html.spec.whatwg.org/multipage/dnd.html#the-datatransferitemlist-interface
     15
     16        Tests: editing/pasteboard/datatransfer-items-drop-plaintext-file.html
     17               editing/pasteboard/datatransfer-items-paste-plaintext.html
     18
     19        * dom/DataTransferItem.cpp:
     20        (WebCore::DataTransferItem::DataTransferItem): Added two variants one for plain text and another one for a file.
     21        (WebCore::DataTransferItem::kind const): Rewritten.
     22        (WebCore::DataTransferItem::getAsString const): Implemented.
     23        (WebCore::DataTransferItem::getAsFile const): Implemented.
     24        * dom/DataTransferItem.h:
     25        (WebCore::DataTransferItem::ref): Added.
     26        (WebCore::DataTransferItem::deref): Added.
     27        (WebCore::DataTransferItem::type const): Returns String instead of AtomicString.
     28        (WebCore::DataTransferItem::kind const): Moved to cpp.
     29        * dom/DataTransferItem.idl: Removed NoInterfaceObject since the interface object should exist on DOMWindow.
     30        * dom/DataTransferItemList.cpp:
     31        (WebCore::DataTransferItemList::length): Implemented.
     32        (WebCore::DataTransferItemList::item): Ditto.
     33        (WebCore::isSupportedType): Added. For now, we only support text/plain.
     34        (WebCore::DataTransferItemList::ensureItems): Added. Constructs the list of DataTransferItems.
     35        * dom/DataTransferItemList.h:
     36        (DataTransferItemList): Added m_items. The list is filled lazily by ensureItems.
     37        * dom/DataTransferItemList.idl: Removed NoInterfaceObject since the interface object should exist on DOMWindow.
     38
    1392017-08-15  Simon Fraser  <simon.fraser@apple.com>
    240
  • trunk/Source/WebCore/dom/DataTransferItem.cpp

    r220627 r220782  
    3333#include "DataTransferItem.h"
    3434
    35 #include "Blob.h"
     35#include "File.h"
     36#include "ScriptExecutionContext.h"
    3637#include "StringCallback.h"
    3738
    3839namespace WebCore {
    3940
    40 DataTransferItem::DataTransferItem()
     41DataTransferItem::DataTransferItem(DataTransfer& dataTransfer, const String& type)
     42    : m_dataTransfer(dataTransfer)
     43    , m_type(type)
     44{
     45}
     46
     47DataTransferItem::DataTransferItem(DataTransfer& dataTransfer, const String& type, Ref<File>&& file)
     48    : m_dataTransfer(dataTransfer)
     49    , m_type(type)
     50    , m_file(WTFMove(file))
    4151{
    4252}
     
    4656}
    4757
    48 void DataTransferItem::getAsString(RefPtr<StringCallback>&&) const
     58String DataTransferItem::kind() const
    4959{
     60    return m_file ? ASCIILiteral("file") : ASCIILiteral("string");
    5061}
    5162
    52 RefPtr<Blob> DataTransferItem::getAsFile() const
     63void DataTransferItem::getAsString(ScriptExecutionContext& context, RefPtr<StringCallback>&& callback) const
    5364{
    54     return nullptr;
     65    if (!callback || !m_dataTransfer.canReadData() || m_file)
     66        return;
     67
     68    // FIXME: Make this async.
     69    callback->scheduleCallback(context, m_dataTransfer.getData(m_type));
     70}
     71
     72RefPtr<File> DataTransferItem::getAsFile() const
     73{
     74    if (!m_dataTransfer.canReadData())
     75        return nullptr;
     76    return m_file.copyRef();
    5577}
    5678
  • trunk/Source/WebCore/dom/DataTransferItem.h

    r220627 r220782  
    3232#pragma once
    3333
     34#include "DataTransfer.h"
     35#include "ScriptWrappable.h"
    3436#include <wtf/Forward.h>
    3537#include <wtf/RefCounted.h>
     
    3840namespace WebCore {
    3941
    40 class Blob;
     42class File;
     43class ScriptExecutionContext;
    4144class StringCallback;
    4245
    43 class DataTransferItem : public RefCounted<DataTransferItem> {
     46class DataTransferItem : public ScriptWrappable {
     47    WTF_MAKE_NONCOPYABLE(DataTransferItem); WTF_MAKE_FAST_ALLOCATED;
    4448public:
    45     DataTransferItem();
     49    DataTransferItem(DataTransfer&, const String&);
     50    DataTransferItem(DataTransfer&, const String&, Ref<File>&&);
    4651    ~DataTransferItem();
    4752
    48     const AtomicString& kind() const { return m_kind; }
    49     const AtomicString& type() const { return m_type; }
    50     void getAsString(RefPtr<StringCallback>&&) const;
    51     RefPtr<Blob> getAsFile() const;
     53    // DataTransfer owns DataTransferItem, and DataTransfer is kept alive as long as DataTransferItem is alive.
     54    void ref() { m_dataTransfer.ref(); }
     55    void deref() { m_dataTransfer.deref(); }
     56
     57    String kind() const;
     58    const String& type() const { return m_type; }
     59    void getAsString(ScriptExecutionContext&, RefPtr<StringCallback>&&) const;
     60    RefPtr<File> getAsFile() const;
    5261
    5362private:
    54     AtomicString m_kind;
    55     AtomicString m_type;
     63    DataTransfer& m_dataTransfer;
     64    const String m_type;
     65    RefPtr<File> m_file;
    5666};
    5767
  • trunk/Source/WebCore/dom/DataTransferItem.idl

    r220627 r220782  
    3131
    3232[
    33     NoInterfaceObject,
    3433    EnabledAtRuntime=DataTransferItems,
    3534    ImplementationLacksVTable,
     
    3837    readonly attribute DOMString type;
    3938
    40     void getAsString(optional StringCallback? callback);
    41     Blob getAsFile();
     39    [CallWith=ScriptExecutionContext] void getAsString(StringCallback? callback);
     40    File getAsFile();
    4241};
    4342
  • trunk/Source/WebCore/dom/DataTransferItemList.cpp

    r220627 r220782  
    2828
    2929#include "DataTransferItem.h"
     30#include "FileList.h"
    3031
    3132namespace WebCore {
     
    3334unsigned DataTransferItemList::length() const
    3435{
    35     return 0;
     36    return ensureItems().size();
    3637}
    3738
    38 RefPtr<DataTransferItem> DataTransferItemList::item(unsigned)
     39RefPtr<DataTransferItem> DataTransferItemList::item(unsigned index)
    3940{
    40     return nullptr;
     41    auto& items = ensureItems();
     42    if (items.size() <= index)
     43        return nullptr;
     44    return items[index].get();
    4145}
    4246
     
    5862}
    5963
     64// FIXME: DataTransfer should filter types itself.
     65static bool isSupportedType(const String& type)
     66{
     67    return equalIgnoringASCIICase(type, "text/plain");
    6068}
    6169
     70Vector<std::unique_ptr<DataTransferItem>>& DataTransferItemList::ensureItems() const
     71{
     72    if (m_items)
     73        return *m_items;
     74
     75    Vector<std::unique_ptr<DataTransferItem>> items;
     76    for (String& type : m_dataTransfer.types()) {
     77        if (isSupportedType(type))
     78            items.append(std::make_unique<DataTransferItem>(m_dataTransfer, type));
     79    }
     80
     81    FileList& files = m_dataTransfer.files();
     82    for (unsigned i = 0, length = files.length(); i < length; ++i) {
     83        File& file = *files.item(i);
     84        String type = File::contentTypeForFile(file.path());
     85        if (isSupportedType(type))
     86            items.append(std::make_unique<DataTransferItem>(m_dataTransfer, type, file));
     87    }
     88
     89
     90    m_items = WTFMove(items);
     91
     92    return *m_items;
     93}
     94
     95}
     96
  • trunk/Source/WebCore/dom/DataTransferItemList.h

    r220627 r220782  
    3333
    3434#include "DataTransfer.h"
     35#include "DataTransferItem.h"
    3536#include "ExceptionOr.h"
     37#include "ScriptWrappable.h"
    3638#include <wtf/Forward.h>
    3739#include <wtf/RefCounted.h>
     
    3941namespace WebCore {
    4042
    41 class DataTransferItem;
    4243class File;
    4344
    44 class DataTransferItemList {
     45class DataTransferItemList : public ScriptWrappable {
    4546    WTF_MAKE_NONCOPYABLE(DataTransferItemList); WTF_MAKE_FAST_ALLOCATED;
    4647public:
     
    6263
    6364private:
     65    Vector<std::unique_ptr<DataTransferItem>>& ensureItems() const;
     66
    6467    DataTransfer& m_dataTransfer;
     68    mutable std::optional<Vector<std::unique_ptr<DataTransferItem>>> m_items;
    6569};
    6670
  • trunk/Source/WebCore/dom/DataTransferItemList.idl

    r220627 r220782  
    3131
    3232[
    33     NoInterfaceObject,
    3433    EnabledAtRuntime=DataTransferItems,
    3534    JSGenerateToNativeObject,
Note: See TracChangeset for help on using the changeset viewer.