DataTransfer.items does not contain items for custom types supplied via add or setData
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Oct 2017 21:58:28 +0000 (21:58 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Oct 2017 21:58:28 +0000 (21:58 +0000)
commit0e60f236595048fded42d8f89cf076cea93aed84
treea0e9048b4f08c7943f26bc008c912de0599880b8
parenta554d35ec704daae0ea25d11c546aa157e807c58
DataTransfer.items does not contain items for custom types supplied via add or setData
https://bugs.webkit.org/show_bug.cgi?id=178016

Reviewed by Darin Adler.

Source/WebCore:

Minor tweaks to expose pasteboard types and data through DataTransfer's item list. This patch fixes two primary
issues: (1) custom pasteboard data is not exposed through the item list in any way, and (2) the "Files"
compatibility type is exposed as a separate data transfer item of kind 'string' when dropping or pasting files.

Tests: editing/pasteboard/data-transfer-items-add-custom-data.html
       editing/pasteboard/data-transfer-items-drop-file.html

* dom/DataTransfer.cpp:
(WebCore::normalizeType):

Use stripLeadingAndTrailingHTMLSpaces instead of stripWhitespace.

(WebCore::shouldReadOrWriteTypeAsCustomData):
(WebCore::DataTransfer::getDataForItem const):
(WebCore::DataTransfer::getData const):

Add getDataForItem, a version of getData that does not normalize types before reading from the pasteboard. This
normalization step is only needed for backwards compatibility with legacy types (such as "text" and "url")
written to and read from using getData and setData; when using DataTransferItemList.add to set data, adding data
for these types should instead write as custom pasteboard data.

(WebCore::DataTransfer::setDataFromItemList):
(WebCore::DataTransfer::types const):
(WebCore::DataTransfer::typesForItemList const):

Add typesForItemList, which fetches the list of types to expose as items on the DataTransfer. Importantly, this
does not include the "Files" type added for compatibility when accessing DataTransfer.types, instead returning
an empty array. The actual files are added separately, by iterating over DataTransfer's files in ensureItems.

Note that when starting a drag or copying, we will still expose the full list of file and string types to
bindings and not just file-backed items. Since all of this information is supplied by the page in the first
place, we don't have to worry about exposing information, such as file paths, that may exist on the pasteboard.

* dom/DataTransfer.h:
* dom/DataTransferItem.cpp:
(WebCore::DataTransferItem::getAsString const):
* dom/DataTransferItemList.cpp:
(WebCore::shouldExposeTypeInItemList):
(WebCore::DataTransferItemList::add):
(WebCore::DataTransferItemList::ensureItems const):
(WebCore::isSupportedType): Deleted.

LayoutTests:

Adds new layout tests to check DataTransfer.items when dropping a file, and when copying and pasting with custom
pasteboard data types. Tweaks an existing test to adjust for normalizeType stripping HTML whitespace rather than
ASCII whitespace.

* TestExpectations:
* editing/pasteboard/data-transfer-get-data-non-normalized-types-expected.txt:
* editing/pasteboard/data-transfer-get-data-non-normalized-types.html:
* editing/pasteboard/data-transfer-items-add-custom-data-expected.txt: Added.
* editing/pasteboard/data-transfer-items-add-custom-data.html: Added.
* editing/pasteboard/data-transfer-items-drop-file-expected.txt: Added.
* editing/pasteboard/data-transfer-items-drop-file.html: Added.
* platform/ios-simulator-wk1/TestExpectations:
* platform/mac-wk1/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223034 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/editing/pasteboard/data-transfer-get-data-non-normalized-types-expected.txt
LayoutTests/editing/pasteboard/data-transfer-get-data-non-normalized-types.html
LayoutTests/editing/pasteboard/data-transfer-items-add-custom-data-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/data-transfer-items-add-custom-data.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/data-transfer-items-drop-file-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/data-transfer-items-drop-file.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator-wk1/TestExpectations
LayoutTests/platform/mac-wk1/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/dom/DataTransfer.h
Source/WebCore/dom/DataTransferItem.cpp
Source/WebCore/dom/DataTransferItemList.cpp