[iOS] Support pasting item-provider-backed data on the pasteboard as attachment elements
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Feb 2019 00:43:40 +0000 (00:43 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Feb 2019 00:43:40 +0000 (00:43 +0000)
commit89a179a3bef1e00370673c9d242dc91ccb9c8c2b
tree007b83f75a4d441e17e65f7ac80a664695f52f1b
parent96a414430718954d40485a8718cbaab6beaea728
[iOS] Support pasting item-provider-backed data on the pasteboard as attachment elements
https://bugs.webkit.org/show_bug.cgi?id=194670
<rdar://problem/39066529>

Reviewed by Tim Horton.

Source/WebCore:

Adds support for pasting files on the pasteboard as attachment elements, if the attachment element runtime
switch is enabled. Currently, the only types of data that can be pasted as attachments are images, which take a
special codepath in WebContentReader::readImage.

This patch adds a readDataBuffer method that converts a given blob of data from the pasteboard into an
attachment-element-backed representation in the DOM (i.e. either an attachment element or image element that
contains an attachment element). In the case where the given pasteboard item has been explicitly marked as an
attachment (via the preferredPresentationStyle hint) and the item has at least one type representation that
conforms to "public.content", we take this codepath instead of first attempting the web content reading types
supported by default in WebKit.

See below for more detail.

Test: WKAttachmentTestsIOS.InsertPastedFilesAsAttachments

* editing/Editor.cpp:
(WebCore::Editor::clientReplacementURLForResource): Deleted.
* editing/Editor.h:
* editing/WebContentReader.h:
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::mimeTypeFromContentType):
(WebCore::contentTypeIsSuitableForInlineImageRepresentation):
(WebCore::createFragmentAndAddResources):
(WebCore::sanitizeMarkupWithArchive):

Remove all logic for handling subresource URL replacement. See WebKit ChangeLog for more details on this.

(WebCore::WebContentReader::readImage):
(WebCore::attachmentForFilePath):
(WebCore::attachmentForData):

Add a helper that creates an attachment element for a given blob of data and content type. The logic here is
quite similar to that of attachmentForFilePath, and we should find a way to either merge them, or pull out more
of their similarities into helper functions.

(WebCore::WebContentReader::readDataBuffer):
(WebCore::replaceSubresourceURLsWithURLsFromClient): Deleted.

Remove more logic for handling subresource URL replacement. See WebKit ChangeLog for more details on this.

* loader/EmptyClients.cpp:
* page/EditorClient.h:
* platform/Pasteboard.h:
* platform/PasteboardItemInfo.h:
(WebCore::PasteboardItemInfo::contentTypeForHighestFidelityItem const):
(WebCore::PasteboardItemInfo::pathForHighestFidelityItem const):
(WebCore::PasteboardItemInfo::encode const):
(WebCore::PasteboardItemInfo::decode):

Add contentTypesByFidelity to PasteboardItemInfo, instead of requesting this information using a separate IPC
message. This means we can also remove getTypesByFidelityForItemAtIndex, and just use the item's types in
fidelity order instead.

* platform/PasteboardStrategy.h:
* platform/PlatformPasteboard.h:
* platform/ios/AbstractPasteboard.h:
* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::read):

Shave off (potentially many) sync IPC messages to the UI process by pulling each call to
informationForItemAtIndex out of the inner loop when reading web content.

(WebCore::Pasteboard::readRespectingUTIFidelities):

Shave off one extraneous sync IPC message by rolling the types in fidelity order into the request for
PasteboardItemInfo, instead of being sent in a separate message.

* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::informationForItemAtIndex):

Populate contentTypesForFileUpload in the case where UIPasteboard is used (i.e. copy and paste).

(WebCore::PlatformPasteboard::getTypesByFidelityForItemAtIndex): Deleted.
* platform/ios/WebItemProviderPasteboard.h:
* platform/ios/WebItemProviderPasteboard.mm:
(-[WebItemProviderPasteboard pasteboardTypesByFidelityForItemAtIndex:]): Deleted.

Source/WebKit:

Remove all IPC plumbing for getTypesByFidelityForItemAtIndex, now that the types in fidelity order have been
rolled into PasteboardItemInfo.

Additionally, remove support for subresource URL replacement. This feature was originally added with the
intention that private clients (i.e. Mail) would intercept pasted or dropped images and replace their URLs.
However, since <rdar://problem/43216836>, our strategy for this scenario has changed, such that WebKit now
handles the drop/paste, and later delivers the image data to the client via NSFileWrappers in the UI process.
At this time, there are no adopters of this SPI, and no adopters of the V2 injected bundle editing client. As
such, we can simply revert all of this to its state prior to the introduction of the replacement URL SPI, with
the exception to changes in WKBundlePageEditorClient.h, wherein there is a nonzero (but likely tiny) chance of
completely breaking binary compatability with any third parties on macOS which may have tried to adopt
subresource URL replacement.

* UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
(WebKit::WebPasteboardProxy::getPasteboardTypesByFidelityForItemAtIndex): Deleted.
* UIProcess/WebPasteboardProxy.h:
* UIProcess/WebPasteboardProxy.messages.in:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView canPerformActionForWebView:withSender:]):

Return YES for -paste: in the case where:
1. The pasteboard contains items that are explicitly marked as attachments.
2. The selection is richly contenteditable.
3. Attachment elements are enabled.

Among other things, this allows the callout bar on iOS to show the "Paste" action.

* WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h:
(API::InjectedBundle::EditorClient::performTwoStepDrop):
(API::InjectedBundle::EditorClient::replacementURLForResource): Deleted.
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h:
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]):
* WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp:
(WebKit::InjectedBundlePageEditorClient::replacementURLForResource): Deleted.
* WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::replacementURLForResource): Deleted.
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::getTypesByFidelityForItemAtIndex): Deleted.
* WebProcess/WebCoreSupport/WebPlatformStrategies.h:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::replacementURLForResource): Deleted.
* WebCoreSupport/WebPlatformStrategies.h:
* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::getTypesByFidelityForItemAtIndex): Deleted.

Source/WebKitLegacy/win:

* WebCoreSupport/WebEditorClient.cpp:
(WebEditorClient::replacementURLForResource): Deleted.
* WebCoreSupport/WebEditorClient.h:

Tools:

Remove code and tests for subresource URL replacement, and also add a new test to verify that copied data can be
pasted in an editable area as attachment elements.

* TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegatePlugIn.mm:
(-[BundleEditingDelegatePlugIn webProcessPlugIn:didCreateBrowserContextController:]):
(-[BundleEditingDelegatePlugIn _webProcessPlugInBrowserContextController:replacementURLForResource:mimeType:]): Deleted.
* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):
* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::InjectedBundlePage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241749 268f45cc-cd09-0410-ab3c-d52691b4dbfc
42 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/WebContentReader.h
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/page/EditorClient.h
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/PasteboardItemInfo.h
Source/WebCore/platform/PasteboardStrategy.h
Source/WebCore/platform/PlatformPasteboard.h
Source/WebCore/platform/ios/AbstractPasteboard.h
Source/WebCore/platform/ios/PasteboardIOS.mm
Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
Source/WebCore/platform/ios/WebItemProviderPasteboard.h
Source/WebCore/platform/ios/WebItemProviderPasteboard.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
Source/WebKit/UIProcess/WebPasteboardProxy.h
Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h
Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h
Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp
Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.h
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebCoreSupport/WebEditorClient.cpp
Source/WebKitLegacy/win/WebCoreSupport/WebEditorClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegatePlugIn.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp