[Attachment Support] Implement SPI for clients to update a given attachment's data
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Dec 2017 23:36:41 +0000 (23:36 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Dec 2017 23:36:41 +0000 (23:36 +0000)
commit1df80046e282047b3130a2af2f234d244c1ff092
treef98266ac0de180d9a5643d6967807d9a0f3454dc
parent6d8dd13e9926d941c0d3cf50a80516e58d09841f
[Attachment Support] Implement SPI for clients to update a given attachment's data
https://bugs.webkit.org/show_bug.cgi?id=180184
<rdar://problem/35355731>

Reviewed by Tim Horton.

Source/WebCore:

Add native API support for Mail to update the data (and optionally, the name and type) of a given attachment
element. See per-method comments below for more detail.

Test: WKAttachmentTests.ChangeAttachmentDataAndFileInformation
      WKAttachmentTests.ChangeAttachmentDataUpdatesWithInPlaceDisplay

* editing/Editor.cpp:
(WebCore::Editor::insertAttachment):
* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::setFile):
(WebCore::HTMLAttachmentElement::invalidateShadowRootChildrenIfNecessary):

Pull out logic to hide and reset shadow DOM state into a separate helper, and additionally hide both the image
and video child elements if they exist. This prevents us from getting into a state where both image and video
elements may appear side-by-side when changing data from an image to a video or vice versa.

(WebCore::HTMLAttachmentElement::updateFileWithData):

Add a new helper to update the backing File of an attachment element from data, optionally updating the filename
and content type as well.

(WebCore::HTMLAttachmentElement::populateShadowRootIfNecessary):
* html/HTMLAttachmentElement.h:

Source/WebKit:

Add plumbing to the web process for setting the attachment data (and optionally, the content type and/or file
name) of a given attachment. See WebCore ChangeLog for more detail. Changes covered by new API tests.

* UIProcess/API/APIAttachment.cpp:
(API::Attachment::setDataAndContentType):
* UIProcess/API/APIAttachment.h:
* UIProcess/API/Cocoa/_WKAttachment.h:

Add nullability annotations around _WKAttachment SPI methods.

* UIProcess/API/Cocoa/_WKAttachment.mm:
(-[_WKAttachment setData:newContentType:newFilename:completion:]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setAttachmentDataAndContentType):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setAttachmentDataAndContentType):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Adds two new API tests to exercise the attachment data update flow.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::ObserveAttachmentUpdatesForScope::ObserveAttachmentUpdatesForScope):
(-[_WKAttachment synchronouslySetDisplayOptions:error:]):
(-[_WKAttachment synchronouslyRequestData:]):
(-[_WKAttachment synchronouslySetData:newContentType:newFilename:error:]):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/html/HTMLAttachmentElement.cpp
Source/WebCore/html/HTMLAttachmentElement.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIAttachment.cpp
Source/WebKit/UIProcess/API/APIAttachment.h
Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.h
Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm