[macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Mar 2018 11:33:20 +0000 (11:33 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Mar 2018 11:33:20 +0000 (11:33 +0000)
commit20b9080565b766610e1c3adc723f429d060b00a0
treef50bff269262d8b825a45e756a4fc8ae02b7d41a
parentcdad864bb1882f459547b43f31f461466d84bb96
[macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails
https://bugs.webkit.org/show_bug.cgi?id=183485
<rdar://problem/38041984>

Reviewed by Ryosuke Niwa.

Source/WebCore:

After r222656, WebKit now treats raw image data on the pasteboard as files for the purposes of computing
DataTransfer.files and DataTransfer.types. However, this is combined with existing policies that suppress
DataTransfer.getData and DataTransfer.setData when the pasteboard contains files (generalized to copy/paste in
r222688). This means we now don't allow web pages to access "text/plain" in the case where the user copies part
of a table from the native Numbers app since Numbers additionally writes a snapshot of the table to the platform
pasteboard.

This restriction on getData/setData was intended to prevent web pages from extracting users' file paths when
pasting or dropping, so it doesn't make sense to enforce this restriction even when there is only in-memory
image data on the pasteboard. To fix this bug, we make Pasteboard::fileContentState() differentiate between
cases where there are (real) files on the pasteboard, and cases where we've fallen back to treating image data
as files.

Rebaselined existing LayoutTests to match new behavior.
Also covered by 4 new API tests:
    - PasteMixedContent.ImageDataAndPlainText
    - PasteMixedContent.ImageDataAndPlainTextAndURL
    - PasteMixedContent.ImageDataAndPlainTextAndURLAndHTML
    - UIPasteboardTests.DataTransferGetDataWhenPastingImageAndText

* dom/DataTransfer.cpp:
(WebCore::DataTransfer::shouldSuppressGetAndSetDataToAvoidExposingFilePaths const):

If custom pasteboard data is enabled, suppress getData and setData if and only if we might actually expose file
paths (see Pasteboard::fileContentState).

(WebCore::DataTransfer::types const):

Only allow "text/html" or "text/uri-list" in the case where there are actual files in the pasteboard. If there's
only image data, add all of the DOM-safe types back into the list of types.

* platform/Pasteboard.h:
* platform/StaticPasteboard.h:

Add an enum type to represent the result of Pasteboard::fileContentState.
-   NoFileOrImageData indicates that there was nothing on the pasteboard that could be considered a file
    from the point of view of the page.
-   InMemoryImage indicates that there are no files on the pasteboard, but there is image data that we consider
    to be files, exposed via DataTransfer API.
-   MayContainFilePaths indicates that there might be file paths on the pasteboard. This means that the source
    has either written file paths to the pasteboard (for example, through NSFilenamesPboardType) or the source
    has written image data along with a URL type of some sort that does not match one of the allowed URL schemes
    that are safe to expose (currently, these are http-family, data, or blob).

* platform/cocoa/PasteboardCocoa.mm:
(WebCore::Pasteboard::fileContentState):

Refactor to return one of the three enum types described above.

(WebCore::Pasteboard::containsFiles): Deleted.
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::containsFiles): Deleted.
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::containsFiles): Deleted.
* platform/wpe/PasteboardWPE.cpp:
(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::containsFiles): Deleted.

Adjust for Pasteboard::fileContentState() tweaks.

Tools:

Add new API tests to cover scenarios in which we paste image data alongside text data.

* TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
(TestWebKitAPI::TEST):

LayoutTests:

Rebaseline some pasteboard-related layout tests, in which we now expose text/plain alongside files that were
written to the DataTransfer by the page itself.

* editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt:
* editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt:
* editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229503 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt
LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt
LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/StaticPasteboard.h
Source/WebCore/platform/cocoa/PasteboardCocoa.mm
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/platform/wpe/PasteboardWPE.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm
Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm