[Attachment Support] Remove _WKAttachments and notify the UI client upon mainframe...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2018 03:21:56 +0000 (03:21 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2018 03:21:56 +0000 (03:21 +0000)
commit0bc0edcc499334e97dfbe8587c9017d3ccb74ac5
tree8f4eaeb95ddabb6a73dc853041f74f24bb547114
parentfbbe0e2f946087ea64f68fdfab1aaa8315b497b4
[Attachment Support] Remove _WKAttachments and notify the UI client upon mainframe navigation
https://bugs.webkit.org/show_bug.cgi?id=188715
<rdar://problem/43541790>

Reviewed by Tim Horton.

Source/WebCore:

Rename didInsertAttachment to didInsertAttachmentWithIdentifier. See WebKit ChangeLog for more detail.

Tests:  WKAttachmentTests.InvalidateAttachmentsAfterMainFrameNavigation
        WKAttachmentTests.InvalidateAttachmentsAfterWebProcessTermination

* editing/Editor.cpp:
(WebCore::Editor::notifyClientOfAttachmentUpdates):
* page/EditorClient.h:
(WebCore::EditorClient::didInsertAttachmentWithIdentifier):
(WebCore::EditorClient::didRemoveAttachmentWithIdentifier):
(WebCore::EditorClient::didInsertAttachment): Deleted.
(WebCore::EditorClient::didRemoveAttachment): Deleted.

Source/WebKit:

Adds logic for invalidating Attachment objects upon mainframe navigation, or upon web content process
termination. An invalid Attachment's wrapper may still be retained by a UI client; however, calls to -info and
other SPI methods will either return nil or immediately invoke their completion handlers with a nil result and
an NSError. See changes below for more detail.

This patch also takes some extra measures to avoid sending redundant or unexpected removal updates to the UI
client upon invalidating all Attachments.

See Tools changes for new API tests.

* UIProcess/API/APIAttachment.cpp:
(API::Attachment::invalidate):
* UIProcess/API/APIAttachment.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didInsertAttachment:withSource:]):
(-[WKWebView _didRemoveAttachment:]):

Refactor these methods to take references to the API::Attachment that is being inserted or removed, rather than
take attachment identifiers. This allows us to keep logic for setting the InsertionState of Attachment objects
in WebPageProxy, rather than in platform code.

* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/_WKAttachment.h:
* UIProcess/API/Cocoa/_WKAttachment.mm:
(-[_WKAttachment info]):

If the attachment object is invalid, return nil.

(-[_WKAttachment setDisplayOptions:completion:]):
(-[_WKAttachment setFileWrapper:contentType:completion:]):

If the attachment object is invalid, immediately invoke the completion block with an error.

(-[_WKAttachment isConnected]):

Add a new readonly property for a client to easily determine whether a _WKAttachment is connected to the
document, without having to maintain the current set of connected attachment objects by observing insertion and
removal callbacks.

* UIProcess/Cocoa/PageClientImplCocoa.h:
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::didInsertAttachment):
(WebKit::PageClientImplCocoa::didRemoveAttachment):

Make these take API::Attachment&s rather than identifier strings.

* UIProcess/PageClient.h:
(WebKit::PageClient::didInsertAttachment):
(WebKit::PageClient::didRemoveAttachment):

Also make these take API::Attachment&s rather than identifier strings.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didCommitLoadForFrame):
(WebKit::WebPageProxy::resetStateAfterProcessExited):
(WebKit::WebPageProxy::invalidateAllAttachments):

Introduce a helper function that invalidates all Attachments and notifies the UI client if needed. This is
invoked upon mainframe navigation, and when the web content process terminates.

(WebKit::WebPageProxy::platformRegisterAttachment):
(WebKit::WebPageProxy::didInsertAttachmentWithIdentifier):
(WebKit::WebPageProxy::didRemoveAttachmentWithIdentifier):
(WebKit::WebPageProxy::didInsertAttachment):
(WebKit::WebPageProxy::didRemoveAttachment):

Keep track of whether we've notified the UI client that an Attachment has been inserted into the document. This
allows us to send removal updates to the UI client only for Attachments that are currently in the document, from
the perspective of the UI client, and allows us to avoid sending extra removal updates in
invalidateAllAttachments for Attachments that either have already been removed, or Attachments which we haven't
inserted yet.

* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::didInsertAttachmentWithIdentifier):
(WebKit::WebEditorClient::didRemoveAttachmentWithIdentifier):
(WebKit::WebEditorClient::didInsertAttachment): Deleted.
(WebKit::WebEditorClient::didRemoveAttachment): Deleted.
* WebProcess/WebCoreSupport/WebEditorClient.h:

Rename did{Insert|Remove}Attachment to did{Insert|Remove}AttachmentWithIdentifier.

Tools:

Adds API tests to exercises cases where (1) the UI client is notified of attachment removal upon mainframe
navigation, and (2) the UI client is notified of attachment removal upon web content process termination.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::ObserveAttachmentUpdatesForScope::expectAttachmentUpdates):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235156 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/page/EditorClient.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIAttachment.cpp
Source/WebKit/UIProcess/API/APIAttachment.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.h
Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm
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