[Cocoa] Add WKWebView SPI to trigger and remove data detection
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Nov 2018 21:06:09 +0000 (21:06 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Nov 2018 21:06:09 +0000 (21:06 +0000)
commite6a88e28d99e1af4b755393ecc7c9cfd7d089dfd
treed2ffbfefc44e32ef872dbea0639624abb57c36a8
parentbc7d5e929cea187f6349bc0cf00427d26b7621ce
[Cocoa] Add WKWebView SPI to trigger and remove data detection
https://bugs.webkit.org/show_bug.cgi?id=191918
<rdar://problem/36185051>

Reviewed by Tim Horton.

Source/WebCore:

Add a helper method on DataDetection to remove all data detected links in the given document. See WebKit changes
for more detail.

* editing/cocoa/DataDetection.h:
* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::removeDataDetectedLinksInDocument):

Source/WebKit:

Adds support for two new WKWebView SPI methods, `-_detectDataWithTypes:completionHandler:` and
`-_removeAllDataDetectedLinks:`, to allow internal WebKit clients to run data detection and add links to data
detected content, or remove all data detected links from the document.

Test: WebKit.AddAndRemoveDataDetectors

* Shared/Cocoa/DataDetectionResult.h:
* Shared/Cocoa/DataDetectionResult.mm:
(WebKit::DataDetectionResult::decode):

Modernize DataDetectionResult's IPC decoding, so that it can be used with reply-based async IPC.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _removeDataDetectedLinks:]):
(-[WKWebView _detectDataWithTypes:completionHandler:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::detectDataInAllFrames):
(WebKit::WebPageProxy::removeDataDetectedLinks):

Add or remove data detected links from each frame in the page, and then propagate the new data detector
results of the main frame to the UI process (this matches current behavior, where the results of -[WKWebView
_dataDetectionResults] only reflects data detection results in the main frame of the page).

* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::removeDataDetectedLinks):
(WebKit::WebPage::detectDataInAllFrames):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Add an API test to exercise the new WebKit SPI.

* TestWebKitAPI/DataDetectorsCoreSPI.h: Added.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/DataDetection.mm:
(-[WKWebView synchronouslyDetectDataWithTypes:]):
(-[WKWebView synchronouslyRemoveDataDetectedLinks]):
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):
(-[TestWKWebView tagsInBody]): Deleted.
(-[TestWKWebView expectElementTagsInOrder:]): Deleted.
(-[TestWKWebView expectElementCount:tagName:]): Deleted.
(-[TestWKWebView expectElementTag:toComeBefore:]): Deleted.

Rename this from `-expectElementCount:tagName:` to `-expectElementCount:querySelector:`.

* TestWebKitAPI/Tests/WebKitCocoa/data-detectors.html: Added.

Add a new test page containing some content that can be data detected.

* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[WKWebView tagsInBody]):
(-[WKWebView expectElementTagsInOrder:]):
(-[WKWebView expectElementCount:querySelector:]):
(-[WKWebView expectElementTag:toComeBefore:]):

Move some testing helper functions from WKAttachmentTests to a testing category on WKWebView. This allows us to
use `-expectElementCount:querySelector:` in tests outside of WKAttachmentTests.

(-[WKWebView objectByEvaluatingJavaScript:]):
(-[WKWebView objectByEvaluatingJavaScriptWithUserGesture:]):
(-[WKWebView stringByEvaluatingJavaScript:]):

Move some common helper functions from TestWKWebView to a testing category on WKWebView.

(-[TestWKWebView objectByEvaluatingJavaScript:]): Deleted.
(-[TestWKWebView objectByEvaluatingJavaScriptWithUserGesture:]): Deleted.
(-[TestWKWebView stringByEvaluatingJavaScript:]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238471 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/DataDetection.h
Source/WebCore/editing/cocoa/DataDetection.mm
Source/WebKit/ChangeLog
Source/WebKit/Shared/Cocoa/DataDetectionResult.h
Source/WebKit/Shared/Cocoa/DataDetectionResult.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
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/DataDetectorsCoreSPI.h [new file with mode: 0644]
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/DataDetection.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/data-detectors.html [new file with mode: 0644]
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/cocoa/TestWKWebView.mm