[Attachment Support] Provide the `src` of an attachment to the UI delegate when an...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 18:46:04 +0000 (18:46 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 18:46:04 +0000 (18:46 +0000)
commitc6edf9105d666bdd84f04b5247459705bc75624a
tree421d8da8ba1d1ec1fc19644c37d3ed155a4c3e4a
parent70d1fed7c301ee5d9c64b80f586abe3659e78403
[Attachment Support] Provide the `src` of an attachment to the UI delegate when an attachment is inserted
https://bugs.webkit.org/show_bug.cgi?id=181638
<rdar://problem/36508702>

Reviewed by Dan Bernstein.

Source/WebCore:

Adjust the `didInsertAttachment` codepath to additionally propagate the attachment element's `src`.
Additionally, fix an issue with insertion and removal client notifications wherein the client can receive
insertion calls without corresponding removal calls, or vice versa. This is an existing issue, but matters more
now because we actually need to access the attachment element for its `src` when propagating changes to the
client. See below for details.

Test: WKAttachmentTests.AttachmentUpdatesWhenInsertingRichMarkup

* dom/Document.h:
(WebCore::Document::attachmentElementsByIdentifier const):
* editing/Editor.cpp:
(WebCore::Editor::notifyClientOfAttachmentUpdates):
* page/EditorClient.h:
(WebCore::EditorClient::didInsertAttachment):
* page/Frame.cpp:
(WebCore::Frame::setDocument):

When a Frame's document changes, inform the client that the attachments in the previous document are going away.
For each attachment currently connected to the document, we have either (1) already informed the client that it
was inserted, or (2) the attachment is pending an insertion call to the client. If (1) is the case, then we'll
tell the client that the attachment is removed, which will balance out the earlier insertion call. If (2) is the
case, then we'll remove the previously inserted attachment identifier from the set of attachment identifiers
pending insertion, and the client won't be informed of insertions or removals.

Source/WebKit:

Add a `source` parameter to the `didInsertAttachment` codepath for notifying WebKit2 clients when attachment
elements are inserted into the document.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didInsertAttachment:withSource:]):
(-[WKWebView _didInsertAttachment:]): Deleted.
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/Cocoa/PageClientImplCocoa.h:
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::didInsertAttachment):
* UIProcess/PageClient.h:
(WebKit::PageClient::didInsertAttachment):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didInsertAttachment):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::didInsertAttachment):
* WebProcess/WebCoreSupport/WebEditorClient.h:

Tools:

Tweak an existing API test to check that the `src` of an attachment element inserted via script matches the
`source` provided to the UI delegate via -[WKUIDelegate _webView:didInsertAttachment:withSource:].

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(-[AttachmentUpdateObserver init]):
(-[AttachmentUpdateObserver sourceForIdentifier:]):
(-[AttachmentUpdateObserver _webView:didInsertAttachment:withSource:]):
(TestWebKitAPI::ObserveAttachmentUpdatesForScope::expectSourceForIdentifier):
(TestWebKitAPI::TEST):
(-[AttachmentUpdateObserver _webView:didInsertAttachment:]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226977 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/page/EditorClient.h
Source/WebCore/page/Frame.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h
Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm