Add the support for mutating clipboard data via DataTransferItemList
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Aug 2017 06:17:09 +0000 (06:17 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Aug 2017 06:17:09 +0000 (06:17 +0000)
commitd75b321bf96a8cdd2651a3fa3c09963182dca940
tree3df874fdab02cdb49de4e8dd90c77f3eae4bf6b9
parentbeb4914c79d470f6ba3749173127fddfe560b06b
Add the support for mutating clipboard data via DataTransferItemList
https://bugs.webkit.org/show_bug.cgi?id=175639

Reviewed by Wenson Hsieh.

Source/WebCore:

Added the support for adding plaintext data via dataTransfer.items.add, clearing data via clear,
and removing an entry via remove. When DataTransferItem is removed from DataTransferItemList,
we must put into the disabled mode.

To support the removal of DataTransferItem, this patch replaces a reference to DataTransfer by
a WeakPtr to DataTransferItemList, and stops forwarding ref from DataTransferItem to DataTransfer.
This means that DataTransfer can now be GC'ed before DataTransferItem is GC'ed.

Because the identify and the order of DataTransferItems need to be preserved, we can't simply
re-popluate m_itemList in DataTransferItemList. Instead, whenever the clipboard content is mutated,
we make the parallel modifications to m_itemList. This includes changes made via DataTransfer
methods such as setData and clearData.

Test: editing/pasteboard/datatransfer-items-copy-plaintext.html

* dom/DataTransfer.cpp:
(WebCore::DataTransfer::clearData): Invoke didClearStringData when m_itemList exists.
(WebCore::DataTransfer::setData): Ditto.
(WebCore::DataTransfer::createForInputEvent):
(WebCore::DataTransfer::createForDrag):
(WebCore::DataTransfer::createForDrop):
* dom/DataTransferItem.cpp:
(WebCore::DataTransferItem::create):
(WebCore::DataTransferItem::DataTransferItem):
(WebCore::DataTransferItem::clearListAndPutIntoDisabledMode): Added.
(WebCore::DataTransferItem::type const): Moved from the header.
(WebCore::DataTransferItem::getAsString const):
(WebCore::DataTransferItem::getAsFile const):
* dom/DataTransferItem.h:
(WebCore::DataTransferItem::ref): Deleted.
(WebCore::DataTransferItem::deref): Deleted.
(WebCore::DataTransferItem::isFile const): Added.
(WebCore::DataTransferItem::type const): Move to the cpp file.
* dom/DataTransferItemList.cpp:
(WebCore::isSupportedType): Moved.
(WebCore::DataTransferItemList::DataTransferItemList): Moved from the header.
(WebCore::DataTransferItemList::~DataTransferItemList): Added.
(WebCore::DataTransferItemList::item):
(WebCore::DataTransferItemList::add): Implemented the variant to add string data.
(WebCore::DataTransferItemList::remove): Implemented. For now, we don't have to deal with removing
a file since a writable dataTransfer never contains a File object.
(WebCore::DataTransferItemList::clear): Implemented.
(WebCore::DataTransferItemList::ensureItems const):
(WebCore::removeStringItemOfLowercasedType): Added.
(WebCore::DataTransferItemList::didClearStringData): Called when dataTransfer.clear is called.
(WebCore::DataTransferItemList::didSetStringData): Ditto for
* dom/DataTransferItemList.h:
(WebCore::DataTransferItemList): Added a WeakPtrFactory. Also use a vector of Ref<DataTransferItem>
instead of unique_ptr<DataTransferItem> since DataTransferItem can outlive DataTransferItemList.
(WebCore::DataTransferItemList::dataTransfer): Added.
* dom/DataTransferItemList.idl:

LayoutTests:

Rebaselined the IDL test which now passes all test cases, and added a regression test for mutating clipboard data
via dataTransfer.items and methods on dataTransfer for plaintext.

* editing/pasteboard/datatransfer-idl-expected.txt:
* editing/pasteboard/datatransfer-items-copy-plaintext-expected.txt: Added.
* editing/pasteboard/datatransfer-items-copy-plaintext.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220829 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/datatransfer-idl-expected.txt
LayoutTests/editing/pasteboard/datatransfer-items-copy-plaintext-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-copy-plaintext.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/dom/DataTransferItem.cpp
Source/WebCore/dom/DataTransferItem.h
Source/WebCore/dom/DataTransferItemList.cpp
Source/WebCore/dom/DataTransferItemList.h
Source/WebCore/dom/DataTransferItemList.idl