[iOS] Paste is missing from callout bar when pasteboard only contains custom data
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2018 22:59:20 +0000 (22:59 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2018 22:59:20 +0000 (22:59 +0000)
commit0ced64494513d41e9e2c30590c5c46804d723edd
tree98ac294d2dac74594ec0cf3e990298c9823c17d1
parentb5d8ea855b1ac040c11371167d9d384f4be03fdf
[iOS] Paste is missing from callout bar when pasteboard only contains custom data
https://bugs.webkit.org/show_bug.cgi?id=184271
<rdar://problem/39256708>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Export a couple of WebCore functions for use in WebKit.

* dom/Document.h:
* platform/Pasteboard.h:

Source/WebKit:

Currently, the "paste:" selector action cannot be performed during editing if the pasteboard only contains
custom pasteboard data. This is because logic in -[WKContentView canPerformActionForWebView:withSender:] only
checks against a list of pasteboard types which does not include the type identifier for custom pasteboard data.
To fix this, we allow pasting only in the case where none of the other type identifiers exist in the pasteboard,
as long as the custom pasteboard data type identifier is present, and the custom pasteboard data's origin
matches the origin of the focused frame's document.

Test: PasteMixedContent.CopyAndPasteWithCustomPasteboardDataOnly

* Shared/EditorState.cpp:
(WebKit::EditorState::encode const):
(WebKit::EditorState::decode):
* Shared/EditorState.h:

Add a originIdentifierForPasteboard field, and add support for encoding it when propagating EditorState via IPC.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView canPerformActionForWebView:withSender:]):

If none of the conventional pasteboard type identifiers for rich or plain text editing are present, check to see
if we have custom pasteboard data; if so, only allow pasting if the custom pasteboard data's origin matches that
of the focused frame's document origin.

Additionally refactor a bit of logic by pulling out `_page->editorState()` into a separate local variable, used
throughout the rest of the method.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):

Send the focused frame's document origin to the UI process via EditorState.

Tools:

Add a new API test to verify that on both iOS and macOS, copied custom pasteboard data can only be pasted in a
matching origin. Additionally verify that on iOS, the web view is capable of performing the "paste:" selector.

* TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm:
(TestWebKitAPI::TEST):
(imagePath): Deleted.
(writeTypesAndDataToPasteboard): Deleted.
(setUpWebView): Deleted.
(markupString): Deleted.

Make this test file no longer exclusive to macOS.

* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebView synchronouslyLoadHTMLString:baseURL:]):

Tweak this helper to also take in a `baseURL`. Defaults to using the TestWebKitAPI bundle resource URL.

(-[TestWKWebView synchronouslyLoadHTMLString:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235011 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.h
Source/WebCore/platform/Pasteboard.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/EditorState.cpp
Source/WebKit/Shared/EditorState.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/cocoa/TestWKWebView.mm