<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[192113] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/192113">192113</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2015-11-06 11:48:27 -0800 (Fri, 06 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add preliminary (SPI) support for NSTextFinder on WKWebView
https://bugs.webkit.org/show_bug.cgi?id=150907
&lt;rdar://problem/19171624&gt;

Reviewed by Darin Adler.

New API test: WebKit2.FindInPage

* Platform/spi/mac/AppKitSPI.h:
Add some SPI.

* UIProcess/API/APIFindClient.h:
(API::FindClient::didFindString):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageFindClient):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didFindString):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/Cocoa/FindClient.h:
* UIProcess/Cocoa/FindClient.mm:
(WebKit::FindClient::didFindString):
Make didFindString return the match rects like didFindStringMatches does.

* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::updateFindUIAfterPageScroll):
(WebKit::FindController::findString):
Keep the most recent find match around for incremental find just like we do
for the non-incremental version. This way, getImageForFindMatch and selectFindMatch
will work for incremental find too!

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _ensureTextFinderClient]):
(-[WKWebView findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
(-[WKWebView documentContainerView]):
(-[WKWebView getSelectedText:]):
(-[WKWebView selectFindMatch:completionHandler:]):
Implement NSTextFinder's async client protocol and forward to the new WKTextFinderClient.

* UIProcess/API/Cocoa/WKWebViewPrivate.h:
Privately note our conformance to the aformentioned protocol.

* UIProcess/mac/WKTextFinderClient.h: Added.
* UIProcess/mac/WKTextFinderClient.mm: Added.
(WebKit::TextFinderFindClient::TextFinderFindClient):
(-[WKTextFinderMatch initWithClient:view:index:rects:]):
(-[WKTextFinderMatch containingView]):
(-[WKTextFinderMatch textRects]):
(-[WKTextFinderMatch generateTextImage:]):
(-[WKTextFinderMatch index]):
(-[WKTextFinderClient initWithPage:view:]):
(-[WKTextFinderClient willDestroyView:]):
(-[WKTextFinderClient findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
(-[WKTextFinderClient getSelectedText:]):
(-[WKTextFinderClient selectFindMatch:completionHandler:]):
(-[WKTextFinderClient didFindStringMatches:rects:index:]):
(-[WKTextFinderClient didGetImageForMatchResult:index:]):
(-[WKTextFinderClient didFindString:rects:index:]):
(-[WKTextFinderClient didFailToFindString:]):
(-[WKTextFinderClient getImageForMatchResult:completionHandler:]):
* WebKit2.xcodeproj/project.pbxproj:
Add WKTextFinderClient. It installs itself as the FindClient and FindMatchesClient,
so you can only use one mechanism or the other.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm: Added.
(-[FindInPageNavigationDelegate webView:didFinishNavigation:]):
(TEST):
Add an API test.

* WebEditingTester/WK1WebDocumentController.m:
* WebEditingTester/WK2WebDocumentController.m:
(-[WK2WebDocumentController awakeFromNib]):
(-[WK2WebDocumentController contentView]):
Use incremental find, and show the overlay/indicator.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformspimacAppKitSPIh">trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIAPIFindClienth">trunk/Source/WebKit2/UIProcess/API/APIFindClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagecpp">trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaFindClienth">trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaFindClientmm">trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewmm">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageFindControllercpp">trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsWebEditingTesterWK1WebDocumentControllerm">trunk/Tools/WebEditingTester/WK1WebDocumentController.m</a></li>
<li><a href="#trunkToolsWebEditingTesterWK2WebDocumentControllerm">trunk/Tools/WebEditingTester/WK2WebDocumentController.m</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessmacWKTextFinderClienth">trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWKTextFinderClientmm">trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaFindInPagemm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/ChangeLog        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -1,3 +1,69 @@
</span><ins>+2015-11-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        Add preliminary (SPI) support for NSTextFinder on WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=150907
+        &lt;rdar://problem/19171624&gt;
+
+        Reviewed by Darin Adler.
+
+        New API test: WebKit2.FindInPage
+
+        * Platform/spi/mac/AppKitSPI.h:
+        Add some SPI.
+
+        * UIProcess/API/APIFindClient.h:
+        (API::FindClient::didFindString):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageFindClient):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didFindString):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/Cocoa/FindClient.h:
+        * UIProcess/Cocoa/FindClient.mm:
+        (WebKit::FindClient::didFindString):
+        Make didFindString return the match rects like didFindStringMatches does.
+
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::FindController::updateFindUIAfterPageScroll):
+        (WebKit::FindController::findString):
+        Keep the most recent find match around for incremental find just like we do
+        for the non-incremental version. This way, getImageForFindMatch and selectFindMatch
+        will work for incremental find too!
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _ensureTextFinderClient]):
+        (-[WKWebView findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
+        (-[WKWebView documentContainerView]):
+        (-[WKWebView getSelectedText:]):
+        (-[WKWebView selectFindMatch:completionHandler:]):
+        Implement NSTextFinder's async client protocol and forward to the new WKTextFinderClient.
+
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        Privately note our conformance to the aformentioned protocol.
+
+        * UIProcess/mac/WKTextFinderClient.h: Added.
+        * UIProcess/mac/WKTextFinderClient.mm: Added.
+        (WebKit::TextFinderFindClient::TextFinderFindClient):
+        (-[WKTextFinderMatch initWithClient:view:index:rects:]):
+        (-[WKTextFinderMatch containingView]):
+        (-[WKTextFinderMatch textRects]):
+        (-[WKTextFinderMatch generateTextImage:]):
+        (-[WKTextFinderMatch index]):
+        (-[WKTextFinderClient initWithPage:view:]):
+        (-[WKTextFinderClient willDestroyView:]):
+        (-[WKTextFinderClient findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
+        (-[WKTextFinderClient getSelectedText:]):
+        (-[WKTextFinderClient selectFindMatch:completionHandler:]):
+        (-[WKTextFinderClient didFindStringMatches:rects:index:]):
+        (-[WKTextFinderClient didGetImageForMatchResult:index:]):
+        (-[WKTextFinderClient didFindString:rects:index:]):
+        (-[WKTextFinderClient didFailToFindString:]):
+        (-[WKTextFinderClient getImageForMatchResult:completionHandler:]):
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add WKTextFinderClient. It installs itself as the FindClient and FindMatchesClient,
+        so you can only use one mechanism or the other.
+
</ins><span class="cx"> 2015-11-06  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2][SpeculativeRevalidation] Save to disk cache relationship between resources
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformspimacAppKitSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -23,9 +23,12 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><ins>+#if USE(APPKIT)
+
</ins><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><span class="cx"> #import &lt;AppKit/NSAccessibilityRemoteUIElement.h&gt;
</span><ins>+#import &lt;AppKit/NSTextFinder_Private.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #else
</span><span class="cx"> 
</span><span class="lines">@@ -35,6 +38,29 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+typedef enum : NSUInteger {
+    NSTextFinderAsynchronousDocumentFindOptionsBackwards = 1 &lt;&lt; 0,
+    NSTextFinderAsynchronousDocumentFindOptionsWrap = 1 &lt;&lt; 1,
+    NSTextFinderAsynchronousDocumentFindOptionsCaseInsensitive = 1 &lt;&lt; 2,
+    NSTextFinderAsynchronousDocumentFindOptionsStartsWith = 1 &lt;&lt; 3,
+} NSTextFinderAsynchronousDocumentFindOptions;
+
+@protocol NSTextFinderAsynchronousDocumentFindMatch &lt;NSObject&gt;
+@required
+@property (retain, nonatomic, readonly) NSView *containingView;
+@property (retain, nonatomic, readonly) NSArray *textRects;
+- (void)generateTextImage:(void (^)(NSImage *))completionHandler;
+@end
+
+@interface NSObject ()
+
+- (void)findMatchesForString:(NSString *)targetString relativeToMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)relativeMatch findOptions:(NSTextFinderAsynchronousDocumentFindOptions)findOptions maxResults:(NSUInteger)maxResults resultCollector:(void (^)(NSArray *matches, BOOL didWrap))resultCollector;
+- (NSView *)documentContainerView;
+- (void)getSelectedText:(void (^)(NSString *selectedTextString))completionHandler;
+- (void)selectFindMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)findMatch completionHandler:(void (^)(void))completionHandler;
+
+@end
+
</ins><span class="cx"> #endif // USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><span class="cx"> @interface NSApplication ()
</span><span class="lines">@@ -43,3 +69,5 @@
</span><span class="cx"> - (void)_setCurrentEvent:(NSEvent *)event;
</span><span class="cx"> 
</span><span class="cx"> @end
</span><ins>+
+#endif // PLATFORM(MAC)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIAPIFindClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/APIFindClient.h (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/APIFindClient.h        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/API/APIFindClient.h        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -28,6 +28,10 @@
</span><span class="cx"> 
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><ins>+namespace WebCore {
+class IntRect;
+}
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> class WebPageProxy;
</span><span class="cx"> }
</span><span class="lines">@@ -39,7 +43,7 @@
</span><span class="cx">     virtual ~FindClient() { }
</span><span class="cx"> 
</span><span class="cx">     virtual void didCountStringMatches(WebKit::WebPageProxy*, const WTF::String&amp;, uint32_t) { }
</span><del>-    virtual void didFindString(WebKit::WebPageProxy*, const WTF::String&amp;, uint32_t, int32_t) { }
</del><ins>+    virtual void didFindString(WebKit::WebPageProxy*, const WTF::String&amp;, const Vector&lt;WebCore::IntRect&gt;&amp; matchRects, uint32_t, int32_t) { }
</ins><span class="cx">     virtual void didFailToFindString(WebKit::WebPageProxy*, const WTF::String&amp;) { }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -887,7 +887,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">     private:
</span><del>-        virtual void didFindString(WebPageProxy* page, const String&amp; string, uint32_t matchCount, int32_t) override
</del><ins>+        virtual void didFindString(WebPageProxy* page, const String&amp; string, const Vector&lt;WebCore::IntRect&gt;&amp;, uint32_t matchCount, int32_t) override
</ins><span class="cx">         {
</span><span class="cx">             if (!m_client.didFindString)
</span><span class="cx">                 return;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #import &quot;APIFormClient.h&quot;
</span><span class="cx"> #import &quot;APIPageConfiguration.h&quot;
</span><span class="cx"> #import &quot;APISerializedScriptValue.h&quot;
</span><ins>+#import &quot;AppKitSPI.h&quot;
</ins><span class="cx"> #import &quot;CompletionHandlerCallChecker.h&quot;
</span><span class="cx"> #import &quot;DiagnosticLoggingClient.h&quot;
</span><span class="cx"> #import &quot;FindClient.h&quot;
</span><span class="lines">@@ -144,6 +145,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><ins>+#import &quot;WKTextFinderClient.h&quot;
</ins><span class="cx"> #import &quot;WKViewInternal.h&quot;
</span><span class="cx"> #import &lt;WebCore/ColorMac.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -235,6 +237,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     std::unique_ptr&lt;WebKit::WebViewImpl&gt; _impl;
</span><ins>+    RetainPtr&lt;WKTextFinderClient&gt; _textFinderClient;
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -419,6 +422,10 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)dealloc
</span><span class="cx"> {
</span><ins>+#if PLATFORM(MAC)
+    [_textFinderClient willDestroyView:self];
+#endif
+
</ins><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     if (_remoteObjectRegistry)
</span><span class="cx">         _page-&gt;process().processPool().removeMessageReceiver(Messages::RemoteObjectRegistry::messageReceiverName(), _page-&gt;pageID());
</span><span class="lines">@@ -2644,6 +2651,33 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+- (WKTextFinderClient *)_ensureTextFinderClient
+{
+    if (!_textFinderClient)
+        _textFinderClient = adoptNS([[WKTextFinderClient alloc] initWithPage:*_page view:self]);
+    return _textFinderClient.get();
+}
+
+- (void)findMatchesForString:(NSString *)targetString relativeToMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)relativeMatch findOptions:(NSTextFinderAsynchronousDocumentFindOptions)findOptions maxResults:(NSUInteger)maxResults resultCollector:(void (^)(NSArray *matches, BOOL didWrap))resultCollector
+{
+    [[self _ensureTextFinderClient] findMatchesForString:targetString relativeToMatch:relativeMatch findOptions:findOptions maxResults:maxResults resultCollector:resultCollector];
+}
+
+- (NSView *)documentContainerView
+{
+    return self;
+}
+
+- (void)getSelectedText:(void (^)(NSString *selectedTextString))completionHandler
+{
+    [[self _ensureTextFinderClient] getSelectedText:completionHandler];
+}
+
+- (void)selectFindMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)findMatch completionHandler:(void (^)(void))completionHandler
+{
+    [[self _ensureTextFinderClient] selectFindMatch:findMatch completionHandler:completionHandler];
+}
+
</ins><span class="cx"> - (NSTextInputContext *)_web_superInputContext
</span><span class="cx"> {
</span><span class="cx">     return [super inputContext];
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -232,6 +232,10 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+#if !TARGET_OS_IPHONE
+@interface WKWebView (WKNSTextFinderClient) &lt;NSTextFinderClient&gt;
+@end
+#endif
</ins><span class="cx"> 
</span><span class="cx"> @interface WKWebView (WKTesting)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaFindClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.h        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx"> private:
</span><span class="cx">     // From API::FindClient
</span><span class="cx">     virtual void didCountStringMatches(WebPageProxy*, const String&amp;, uint32_t matchCount);
</span><del>-    virtual void didFindString(WebPageProxy*, const String&amp;, uint32_t matchCount, int32_t matchIndex);
</del><ins>+    virtual void didFindString(WebPageProxy*, const String&amp;, const Vector&lt;WebCore::IntRect&gt;&amp;, uint32_t matchCount, int32_t matchIndex);
</ins><span class="cx">     virtual void didFailToFindString(WebPageProxy*, const String&amp;);
</span><span class="cx">     
</span><span class="cx">     WKWebView *m_webView;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaFindClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/FindClient.mm        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx">         [m_delegate.get() _webView:m_webView didCountMatches:matchCount forString:string];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FindClient::didFindString(WebPageProxy*, const String&amp; string, uint32_t matchCount, int32_t matchIndex)
</del><ins>+void FindClient::didFindString(WebPageProxy*, const String&amp; string, const Vector&lt;WebCore::IntRect&gt;&amp;, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx"> {
</span><span class="cx">     if (m_delegateMethods.webviewDidFindString)
</span><span class="cx">         [m_delegate.get() _webView:m_webView didFindMatches:matchCount forString:string withMatchIndex:matchIndex];
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -4079,9 +4079,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPageProxy::didFindString(const String&amp; string, uint32_t matchCount, int32_t matchIndex)
</del><ins>+void WebPageProxy::didFindString(const String&amp; string, const Vector&lt;WebCore::IntRect&gt;&amp; matchRects, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx"> {
</span><del>-    m_findClient-&gt;didFindString(this, string, matchCount, matchIndex);
</del><ins>+    m_findClient-&gt;didFindString(this, string, matchRects, matchCount, matchIndex);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::didFindStringMatches(const String&amp; string, const Vector&lt;Vector&lt;WebCore::IntRect&gt;&gt;&amp; matchRects, int32_t firstIndexAfterSelection)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -751,7 +751,7 @@
</span><span class="cx">     void setTextIndicator(const WebCore::TextIndicatorData&amp;, uint64_t /* WebCore::TextIndicatorWindowLifetime */ lifetime = 0 /* Permanent */);
</span><span class="cx">     void setTextIndicatorAnimationProgress(float);
</span><span class="cx">     void clearTextIndicator();
</span><del>-    void didFindString(const String&amp;, uint32_t matchCount, int32_t matchIndex);
</del><ins>+    void didFindString(const String&amp;, const Vector&lt;WebCore::IntRect&gt;&amp;, uint32_t matchCount, int32_t matchIndex);
</ins><span class="cx">     void didFailToFindString(const String&amp;);
</span><span class="cx">     void didFindStringMatches(const String&amp;, const Vector&lt;Vector&lt;WebCore::IntRect&gt;&gt;&amp; matchRects, int32_t firstIndexAfterSelection);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -233,7 +233,7 @@
</span><span class="cx">     DidCountStringMatches(String string, uint32_t matchCount)
</span><span class="cx">     SetTextIndicator(struct WebCore::TextIndicatorData indicator, uint64_t lifetime)
</span><span class="cx">     ClearTextIndicator()
</span><del>-    DidFindString(String string, uint32_t matchCount, int32_t matchIndex)
</del><ins>+    DidFindString(String string, Vector&lt;WebCore::IntRect&gt; matchRect, uint32_t matchCount, int32_t matchIndex)
</ins><span class="cx">     DidFailToFindString(String string)
</span><span class="cx">     DidFindStringMatches(String string, Vector&lt;Vector&lt;WebCore::IntRect&gt;&gt; matches, int32_t firstIndexAfterSelection)
</span><span class="cx">     DidGetImageForFindMatch(WebKit::ShareableBitmap::Handle contentImageHandle, uint32_t matchIndex)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -607,7 +607,7 @@
</span><span class="cx">                 _currentFindMatchIndex = 0;
</span><span class="cx">                 for (const auto&amp; knownMatch : _cachedFindMatches) {
</span><span class="cx">                     if (match.stringRange.location == [knownMatch stringRange].location &amp;&amp; match.stringRange.length == [knownMatch stringRange].length) {
</span><del>-                        page-&gt;findClient().didFindString(page.get(), string, _cachedFindMatches.size(), _currentFindMatchIndex);
</del><ins>+                        page-&gt;findClient().didFindString(page.get(), string, { }, _cachedFindMatches.size(), _currentFindMatchIndex);
</ins><span class="cx">                         break;
</span><span class="cx">                     }
</span><span class="cx">                     _currentFindMatchIndex++;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWKTextFinderClienth"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.h (0 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.h                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.h        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WKTextFinderClient_h
+#define WKTextFinderClient_h
+
+#import &lt;WebKit/WKFoundation.h&gt;
+
+#if PLATFORM(MAC) &amp;&amp; WK_API_ENABLED
+
+OBJC_CLASS NSView;
+
+namespace WebKit {
+class WebPageProxy;
+}
+
+@interface WKTextFinderClient : NSObject
+
+- (instancetype)initWithPage:(WebKit::WebPageProxy&amp;)page view:(NSView *)view;
+- (void)willDestroyView:(NSView *)view;
+
+@end
+
+#endif // PLATFORM(MAC)
+
+#endif // WKTextFinderClient_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWKTextFinderClientmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm (0 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -0,0 +1,275 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;WKTextFinderClient.h&quot;
+
+#if PLATFORM(MAC) &amp;&amp; WK_API_ENABLED
+
+#import &quot;APIFindClient.h&quot;
+#import &quot;APIFindMatchesClient.h&quot;
+#import &quot;AppKitSPI.h&quot;
+#import &quot;WebImage.h&quot;
+#import &quot;WebPageProxy.h&quot;
+#import &lt;wtf/Deque.h&gt;
+
+// FIXME: Implement support for replace.
+// FIXME: Implement scrollFindMatchToVisible.
+// FIXME: The NSTextFinder overlay doesn't move with scrolling; we should have a mode where we manage the overlay.
+
+using namespace WebCore;
+using namespace WebKit;
+
+@interface WKTextFinderClient ()
+
+- (void)didFindStringMatchesWithRects:(const Vector&lt;Vector&lt;IntRect&gt;&gt;&amp;)rects;
+
+- (void)getImageForMatchResult:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)findMatch completionHandler:(void (^)(NSImage *generatedImage))completionHandler;
+- (void)didGetImageForMatchResult:(WebImage *)string;
+
+@end
+
+namespace WebKit {
+
+class TextFinderFindClient : public API::FindMatchesClient, public API::FindClient {
+public:
+    explicit TextFinderFindClient(WKTextFinderClient *textFinderClient)
+        : m_textFinderClient(textFinderClient)
+    {
+    }
+
+private:
+    virtual void didFindStringMatches(WebPageProxy* page, const String&amp;, const Vector&lt;Vector&lt;IntRect&gt;&gt;&amp; matchRects, int32_t) override
+    {
+        [m_textFinderClient didFindStringMatchesWithRects:matchRects];
+    }
+
+    virtual void didGetImageForMatchResult(WebPageProxy* page, WebImage* image, int32_t index) override
+    {
+        [m_textFinderClient didGetImageForMatchResult:image];
+    }
+
+    virtual void didFindString(WebPageProxy*, const String&amp;, const Vector&lt;IntRect&gt;&amp; matchRects, uint32_t, int32_t) override
+    {
+        [m_textFinderClient didFindStringMatchesWithRects:{ matchRects }];
+    }
+
+    virtual void didFailToFindString(WebPageProxy*, const String&amp; string) override
+    {
+        [m_textFinderClient didFindStringMatchesWithRects:{ }];
+    }
+
+    RetainPtr&lt;WKTextFinderClient&gt; m_textFinderClient;
+};
+    
+}
+
+@interface WKTextFinderMatch : NSObject &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;
+
+@property (nonatomic, readonly) unsigned index;
+
+@end
+
+@implementation WKTextFinderMatch {
+    WKTextFinderClient *_client;
+    NSView *_view;
+    RetainPtr&lt;NSArray&gt; _rects;
+    unsigned _index;
+}
+
+- (instancetype)initWithClient:(WKTextFinderClient *)client view:(NSView *)view index:(unsigned)index rects:(NSArray *)rects
+{
+    self = [super init];
+
+    if (!self)
+        return nil;
+
+    _client = client;
+    _view = view;
+    _rects = rects;
+    _index = index;
+
+    return self;
+}
+
+- (NSView *)containingView
+{
+    return _view;
+}
+
+- (NSArray *)textRects
+{
+    return _rects.get();
+}
+
+- (void)generateTextImage:(void (^)(NSImage *generatedImage))completionHandler
+{
+    [_client getImageForMatchResult:self completionHandler:completionHandler];
+}
+
+- (unsigned)index
+{
+    return _index;
+}
+
+@end
+
+@implementation WKTextFinderClient {
+    WebPageProxy *_page;
+    NSView *_view;
+    Deque&lt;std::function&lt;void(NSArray *, bool didWrap)&gt;&gt; _findReplyCallbacks;
+    Deque&lt;std::function&lt;void(NSImage *)&gt;&gt; _imageReplyCallbacks;
+}
+
+- (instancetype)initWithPage:(WebPageProxy&amp;)page view:(NSView *)view
+{
+    self = [super init];
+
+    if (!self)
+        return nil;
+
+    _page = &amp;page;
+    _view = view;
+    
+    _page-&gt;setFindMatchesClient(std::make_unique&lt;TextFinderFindClient&gt;(self));
+    _page-&gt;setFindClient(std::make_unique&lt;TextFinderFindClient&gt;(self));
+
+    return self;
+}
+
+- (void)willDestroyView:(NSView *)view
+{
+    _page-&gt;setFindMatchesClient(nullptr);
+    _page-&gt;setFindClient(nullptr);
+
+    _page = nullptr;
+    _view = nil;
+}
+
+#pragma mark - NSTextFinderClient SPI
+
+- (void)findMatchesForString:(NSString *)targetString relativeToMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)relativeMatch findOptions:(NSTextFinderAsynchronousDocumentFindOptions)findOptions maxResults:(NSUInteger)maxResults resultCollector:(void (^)(NSArray *matches, BOOL didWrap))resultCollector
+{
+    unsigned kitFindOptions = 0;
+
+    if (findOptions &amp; NSTextFinderAsynchronousDocumentFindOptionsBackwards)
+        kitFindOptions |= FindOptionsBackwards;
+    if (findOptions &amp; NSTextFinderAsynchronousDocumentFindOptionsWrap)
+        kitFindOptions |= FindOptionsWrapAround;
+    if (findOptions &amp; NSTextFinderAsynchronousDocumentFindOptionsCaseInsensitive)
+        kitFindOptions |= FindOptionsCaseInsensitive;
+    if (findOptions &amp; NSTextFinderAsynchronousDocumentFindOptionsStartsWith)
+        kitFindOptions |= FindOptionsAtWordStarts;
+
+    RetainPtr&lt;NSProgress&gt; progress = [NSProgress progressWithTotalUnitCount:1];
+    auto copiedResultCollector = Block_copy(resultCollector);
+    _findReplyCallbacks.append([progress, copiedResultCollector] (NSArray *matches, bool didWrap) {
+        copiedResultCollector(matches, didWrap);
+        Block_release(copiedResultCollector);
+
+        [progress setCompletedUnitCount:1];
+    });
+
+    if (maxResults == 1)
+        _page-&gt;findString(targetString, static_cast&lt;WebKit::FindOptions&gt;(kitFindOptions), maxResults);
+    else
+        _page-&gt;findStringMatches(targetString, static_cast&lt;WebKit::FindOptions&gt;(kitFindOptions), maxResults);
+}
+
+- (void)getSelectedText:(void (^)(NSString *selectedTextString))completionHandler
+{
+    void (^copiedCompletionHandler)(NSString *) = Block_copy(completionHandler);
+
+    _page-&gt;getSelectionOrContentsAsString([copiedCompletionHandler] (const String&amp; string, CallbackBase::Error) {
+        copiedCompletionHandler(string);
+        Block_release(copiedCompletionHandler);
+    });
+}
+
+- (void)selectFindMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)findMatch completionHandler:(void (^)(void))completionHandler
+{
+    ASSERT([findMatch isKindOfClass:[WKTextFinderMatch class]]);
+    ASSERT(!completionHandler);
+
+    WKTextFinderMatch *textFinderMatch = static_cast&lt;WKTextFinderMatch *&gt;(findMatch);
+    _page-&gt;selectFindMatch(textFinderMatch.index);
+}
+
+#pragma mark - FindMatchesClient
+
+static RetainPtr&lt;NSArray&gt; arrayFromRects(const Vector&lt;IntRect&gt;&amp; matchRects)
+{
+    RetainPtr&lt;NSMutableArray&gt; nsMatchRects = adoptNS([[NSMutableArray alloc] initWithCapacity:matchRects.size()]);
+    for (auto&amp; rect : matchRects)
+        [nsMatchRects addObject:[NSValue valueWithRect:rect]];
+    return nsMatchRects;
+}
+
+- (void)didFindStringMatchesWithRects:(const Vector&lt;Vector&lt;IntRect&gt;&gt;&amp;)rectsForMatches
+{
+    if (_findReplyCallbacks.isEmpty())
+        return;
+
+    auto replyCallback = _findReplyCallbacks.takeFirst();
+    unsigned matchCount = rectsForMatches.size();
+    RetainPtr&lt;NSMutableArray&gt; matchObjects = adoptNS([[NSMutableArray alloc] initWithCapacity:matchCount]);
+    for (unsigned i = 0; i &lt; matchCount; i++) {
+        RetainPtr&lt;NSArray&gt; nsMatchRects = arrayFromRects(rectsForMatches[i]);
+        RetainPtr&lt;WKTextFinderMatch&gt; match = adoptNS([[WKTextFinderMatch alloc] initWithClient:self view:_view index:i rects:nsMatchRects.get()]);
+        [matchObjects addObject:match.get()];
+    }
+
+    replyCallback(matchObjects.get(), NO);
+}
+
+- (void)didGetImageForMatchResult:(WebImage *)image
+{
+    if (_imageReplyCallbacks.isEmpty())
+        return;
+
+    auto imageCallback = _imageReplyCallbacks.takeFirst();
+    imageCallback([[[NSImage alloc] initWithCGImage:image-&gt;bitmap()-&gt;makeCGImage().get() size:NSZeroSize] autorelease]);
+}
+
+#pragma mark - WKTextFinderMatch callbacks
+
+- (void)getImageForMatchResult:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)findMatch completionHandler:(void (^)(NSImage *generatedImage))completionHandler
+{
+    ASSERT([findMatch isKindOfClass:[WKTextFinderMatch class]]);
+
+    WKTextFinderMatch *textFinderMatch = static_cast&lt;WKTextFinderMatch *&gt;(findMatch);
+
+    auto copiedImageCallback = Block_copy(completionHandler);
+    _imageReplyCallbacks.append([copiedImageCallback] (NSImage *image) {
+        copiedImageCallback(image);
+        Block_release(copiedImageCallback);
+    });
+
+    _page-&gt;getImageForFindMatch(textFinderMatch.index);
+}
+
+@end
+
+#endif // PLATFORM(MAC)
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -692,6 +692,8 @@
</span><span class="cx">                 2DD12A081A8177F3002C74E6 /* WKPageRenderingProgressEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD12A071A8177F3002C74E6 /* WKPageRenderingProgressEvents.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 2DD13BD518F7DADD00E130A1 /* FindControllerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DD13BD318F7DADD00E130A1 /* FindControllerIOS.mm */; };
</span><span class="cx">                 2DD67A2E1BD819730053B251 /* APIFindMatchesClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD67A2D1BD819730053B251 /* APIFindMatchesClient.h */; };
</span><ins>+                2DD67A351BD861060053B251 /* WKTextFinderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD67A331BD861060053B251 /* WKTextFinderClient.h */; };
+                2DD67A361BD861060053B251 /* WKTextFinderClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DD67A341BD861060053B251 /* WKTextFinderClient.mm */; };
</ins><span class="cx">                 2DD9EB2D1A6F012500BB1267 /* APINavigationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD9EB2C1A6F012500BB1267 /* APINavigationClient.h */; };
</span><span class="cx">                 2DDE0AFA18298CC900F97EAA /* RemoteLayerTreePropertyApplier.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DDE0AF818298CC900F97EAA /* RemoteLayerTreePropertyApplier.h */; };
</span><span class="cx">                 2DDE0AFB18298CC900F97EAA /* RemoteLayerTreePropertyApplier.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DDE0AF918298CC900F97EAA /* RemoteLayerTreePropertyApplier.mm */; };
</span><span class="lines">@@ -2885,6 +2887,8 @@
</span><span class="cx">                 2DD12A071A8177F3002C74E6 /* WKPageRenderingProgressEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPageRenderingProgressEvents.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DD13BD318F7DADD00E130A1 /* FindControllerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FindControllerIOS.mm; path = ios/FindControllerIOS.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DD67A2D1BD819730053B251 /* APIFindMatchesClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIFindMatchesClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2DD67A331BD861060053B251 /* WKTextFinderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKTextFinderClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                2DD67A341BD861060053B251 /* WKTextFinderClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKTextFinderClient.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2DD9EB2C1A6F012500BB1267 /* APINavigationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APINavigationClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DDE0AF818298CC900F97EAA /* RemoteLayerTreePropertyApplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteLayerTreePropertyApplier.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DDE0AF918298CC900F97EAA /* RemoteLayerTreePropertyApplier.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreePropertyApplier.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -7133,6 +7137,8 @@
</span><span class="cx">                                 0FCB4E5D18BBE3D9000FCFC9 /* WKPrintingView.mm */,
</span><span class="cx">                                 513E462B1AD837560016234A /* WKSharingServicePickerDelegate.h */,
</span><span class="cx">                                 513E462C1AD837560016234A /* WKSharingServicePickerDelegate.mm */,
</span><ins>+                                2DD67A331BD861060053B251 /* WKTextFinderClient.h */,
+                                2DD67A341BD861060053B251 /* WKTextFinderClient.mm */,
</ins><span class="cx">                                 0FCB4E5E18BBE3D9000FCFC9 /* WKTextInputWindowController.h */,
</span><span class="cx">                                 0FCB4E5F18BBE3D9000FCFC9 /* WKTextInputWindowController.mm */,
</span><span class="cx">                                 2D28A4951AF965A100F190C9 /* WKViewLayoutStrategy.h */,
</span><span class="lines">@@ -8212,6 +8218,7 @@
</span><span class="cx">                                 D3B9484911FF4B6500032B39 /* WebSearchPopupMenu.h in Headers */,
</span><span class="cx">                                 1A4832D71A9CDF96008B4DFE /* WebsiteData.h in Headers */,
</span><span class="cx">                                 1A4832D11A9BDC2F008B4DFE /* WebsiteDataRecord.h in Headers */,
</span><ins>+                                2DD67A351BD861060053B251 /* WKTextFinderClient.h in Headers */,
</ins><span class="cx">                                 1A53C2AA1A325730004E8C70 /* WebsiteDataStore.h in Headers */,
</span><span class="cx">                                 836034A01ACB34D600626549 /* WebSQLiteDatabaseTracker.h in Headers */,
</span><span class="cx">                                 1A52C0F81A38CDC70016160A /* WebStorageNamespaceProvider.h in Headers */,
</span><span class="lines">@@ -9564,6 +9571,7 @@
</span><span class="cx">                                 E179FD9F134D38250015B883 /* ArgumentCodersMac.mm in Sources */,
</span><span class="cx">                                 BC032DA510F437D10058C15A /* ArgumentDecoder.cpp in Sources */,
</span><span class="cx">                                 BC032DA710F437D10058C15A /* ArgumentEncoder.cpp in Sources */,
</span><ins>+                                2DD67A361BD861060053B251 /* WKTextFinderClient.mm in Sources */,
</ins><span class="cx">                                 C59C4A5818B81174007BDCB6 /* AssistedNodeInformation.cpp in Sources */,
</span><span class="cx">                                 839902021BE9A02B000F3653 /* NetworkLoad.cpp in Sources */,
</span><span class="cx">                                 515E7727183DD6F60007203F /* AsyncRequest.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageFindControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -180,8 +180,15 @@
</span><span class="cx">                 m_foundStringMatchIndex -= matchCount;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        m_webPage-&gt;send(Messages::WebPageProxy::DidFindString(string, matchCount, m_foundStringMatchIndex));
</del><ins>+        m_findMatches.clear();
+        Vector&lt;IntRect&gt; matchRects;
+        if (auto range = m_webPage-&gt;corePage()-&gt;selection().firstRange()) {
+            range-&gt;absoluteTextRects(matchRects);
+            m_findMatches.append(range);
+        }
</ins><span class="cx"> 
</span><ins>+        m_webPage-&gt;send(Messages::WebPageProxy::DidFindString(string, matchRects, matchCount, m_foundStringMatchIndex));
+
</ins><span class="cx">         if (!(options &amp; FindOptionsShowFindIndicator) || !selectedFrame || !updateFindIndicator(*selectedFrame, shouldShowOverlay))
</span><span class="cx">             hideFindIndicator();
</span><span class="cx">     }
</span><span class="lines">@@ -221,13 +228,15 @@
</span><span class="cx">             if (fs.selectionBounds().isEmpty()) {
</span><span class="cx">                 m_findMatches.clear();
</span><span class="cx">                 int indexForSelection;
</span><del>-                m_webPage-&gt;corePage()-&gt;findStringMatchingRanges(string, core(options), maxMatchCount, m_findMatches, indexForSelection);
</del><ins>+                m_webPage-&gt;corePage()-&gt;findStringMatchingRanges(string, coreOptions, maxMatchCount, m_findMatches, indexForSelection);
</ins><span class="cx">                 m_foundStringMatchIndex = indexForSelection;
</span><span class="cx">                 foundStringStartsAfterSelection = true;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    m_findMatches.clear();
+
</ins><span class="cx">     bool found;
</span><span class="cx">     if (pluginView)
</span><span class="cx">         found = pluginView-&gt;findString(string, coreOptions, maxMatchCount);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Tools/ChangeLog        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2015-11-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        Add preliminary (SPI) support for NSTextFinder on WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=150907
+        &lt;rdar://problem/19171624&gt;
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm: Added.
+        (-[FindInPageNavigationDelegate webView:didFinishNavigation:]):
+        (TEST):
+        Add an API test.
+
+        * WebEditingTester/WK1WebDocumentController.m:
+        * WebEditingTester/WK2WebDocumentController.m:
+        (-[WK2WebDocumentController awakeFromNib]):
+        (-[WK2WebDocumentController contentView]):
+        Use incremental find, and show the overlay/indicator.
+
</ins><span class="cx"> 2015-11-06  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         iOS test results are not visible on the flakiness dashboard
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx">                 290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; };
</span><span class="cx">                 297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
</span><span class="cx">                 2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */; };
</span><ins>+                2D8104CC1BEC13E70020DA46 /* FindInPage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D8104CB1BEC13E70020DA46 /* FindInPage.mm */; };
</ins><span class="cx">                 2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */; };
</span><span class="cx">                 2DD355361BD08378005DF4A7 /* AutoLayoutIntegration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DD355351BD08378005DF4A7 /* AutoLayoutIntegration.mm */; };
</span><span class="cx">                 2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
</span><span class="lines">@@ -519,6 +520,7 @@
</span><span class="cx">                 29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollPinningBehaviors.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindInPage.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShrinkToFit.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DD355351BD08378005DF4A7 /* AutoLayoutIntegration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoLayoutIntegration.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DD7D3A9178205D00026E1E3 /* ResizeReversePaginatedWebView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeReversePaginatedWebView.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -929,6 +931,7 @@
</span><span class="cx">                                 A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
</span><span class="cx">                                 A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */,
</span><span class="cx">                                 A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
</span><ins>+                                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */,
</ins><span class="cx">                                 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
</span><span class="cx">                                 37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
</span><span class="cx">                                 51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */,
</span><span class="lines">@@ -1799,6 +1802,7 @@
</span><span class="cx">                                 2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */,
</span><span class="cx">                                 1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
</span><span class="cx">                                 2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
</span><ins>+                                2D8104CC1BEC13E70020DA46 /* FindInPage.mm in Sources */,
</ins><span class="cx">                                 41973B5D1AF22875006C7B36 /* SharedBuffer.cpp in Sources */,
</span><span class="cx">                                 2DD355361BD08378005DF4A7 /* AutoLayoutIntegration.mm in Sources */,
</span><span class="cx">                                 7AA6A1521AAC0B31002B2ED3 /* WorkQueue.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaFindInPagemm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm (0 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -0,0 +1,124 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+
+#import &quot;PlatformUtilities.h&quot;
+#import &lt;WebKit/WKWebViewPrivate.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+#if WK_API_ENABLED &amp;&amp; !PLATFORM(IOS)
+
+typedef enum : NSUInteger {
+    NSTextFinderAsynchronousDocumentFindOptionsBackwards = 1 &lt;&lt; 0,
+} NSTextFinderAsynchronousDocumentFindOptions;
+
+@protocol NSTextFinderAsynchronousDocumentFindMatch &lt;NSObject&gt;
+@property (retain, nonatomic, readonly) NSArray *textRects;
+@end
+
+@interface WKWebView (NSTextFinderSupport)
+
+- (void)findMatchesForString:(NSString *)targetString relativeToMatch:(id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt;)relativeMatch findOptions:(NSTextFinderAsynchronousDocumentFindOptions)findOptions maxResults:(NSUInteger)maxResults resultCollector:(void (^)(NSArray *matches, BOOL didWrap))resultCollector;
+
+@end
+
+static bool navigationDone;
+static bool findMatchesDone;
+
+@interface FindInPageNavigationDelegate : NSObject &lt;WKNavigationDelegate&gt;
+@end
+
+@implementation FindInPageNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    navigationDone = true;
+}
+
+@end
+
+TEST(WebKit2, FindInPage)
+{
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+
+    RetainPtr&lt;FindInPageNavigationDelegate&gt; delegate = adoptNS([[FindInPageNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;lots-of-text&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&amp;navigationDone);
+
+    NSTextFinderAsynchronousDocumentFindOptions noFindOptions = (NSTextFinderAsynchronousDocumentFindOptions)0;
+
+    // Find all matches.
+    [webView findMatchesForString:@&quot;Birthday&quot; relativeToMatch:nil findOptions:noFindOptions maxResults:NSUIntegerMax resultCollector:^(NSArray *matches, BOOL didWrap) {
+        EXPECT_EQ((NSUInteger)360, matches.count);
+
+        id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt; firstMatch = [matches objectAtIndex:0];
+        EXPECT_EQ((NSUInteger)1, firstMatch.textRects.count);
+
+        findMatchesDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;findMatchesDone);
+    findMatchesDone = false;
+
+    // Find one match, doing an incremental search.
+    [webView findMatchesForString:@&quot;Birthday&quot; relativeToMatch:nil findOptions:noFindOptions maxResults:1 resultCollector:^(NSArray *matches, BOOL didWrap) {
+        EXPECT_EQ((NSUInteger)1, matches.count);
+
+        id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt; firstMatch = [matches objectAtIndex:0];
+        EXPECT_EQ((NSUInteger)1, firstMatch.textRects.count);
+
+        // Find the next match in incremental mode.
+        [webView findMatchesForString:@&quot;Birthday&quot; relativeToMatch:nil findOptions:noFindOptions maxResults:1 resultCollector:^(NSArray *matches, BOOL didWrap) {
+            EXPECT_EQ((NSUInteger)1, matches.count);
+
+            id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt; secondMatch = [matches objectAtIndex:0];
+            EXPECT_EQ((NSUInteger)1, secondMatch.textRects.count);
+
+            EXPECT_FALSE(NSEqualRects([firstMatch.textRects.lastObject rectValue], [secondMatch.textRects.lastObject rectValue]));
+
+            // Find the previous match in incremental mode.
+            [webView findMatchesForString:@&quot;Birthday&quot; relativeToMatch:nil findOptions:NSTextFinderAsynchronousDocumentFindOptionsBackwards maxResults:1 resultCollector:^(NSArray *matches, BOOL didWrap) {
+                EXPECT_EQ((NSUInteger)1, matches.count);
+
+                id &lt;NSTextFinderAsynchronousDocumentFindMatch&gt; firstMatchAgain = [matches objectAtIndex:0];
+                EXPECT_EQ((NSUInteger)1, firstMatchAgain.textRects.count);
+
+                EXPECT_TRUE(NSEqualRects([firstMatch.textRects.lastObject rectValue], [firstMatchAgain.textRects.lastObject rectValue]));
+                
+                findMatchesDone = true;
+            }];
+        }];
+
+    }];
+
+    TestWebKitAPI::Util::run(&amp;findMatchesDone);
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkToolsWebEditingTesterWK1WebDocumentControllerm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebEditingTester/WK1WebDocumentController.m (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebEditingTester/WK1WebDocumentController.m        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Tools/WebEditingTester/WK1WebDocumentController.m        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx"> #import &lt;WebKit/WebPreferenceKeysPrivate.h&gt;
</span><span class="cx"> #import &lt;WebKit/WebViewPrivate.h&gt;
</span><span class="cx"> 
</span><del>-@interface WK1WebDocumentController()
</del><ins>+@interface WK1WebDocumentController () &lt;WebUIDelegate&gt;
</ins><span class="cx"> @property (nonatomic, strong) WebView *webView;
</span><span class="cx"> @end
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsWebEditingTesterWK2WebDocumentControllerm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebEditingTester/WK2WebDocumentController.m (192112 => 192113)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebEditingTester/WK2WebDocumentController.m        2015-11-06 19:41:50 UTC (rev 192112)
+++ trunk/Tools/WebEditingTester/WK2WebDocumentController.m        2015-11-06 19:48:27 UTC (rev 192113)
</span><span class="lines">@@ -73,7 +73,9 @@
</span><span class="cx">     self.window.title = @&quot;WebEditor [WK2]&quot;;
</span><span class="cx"> 
</span><span class="cx">     _textFinder = [[NSTextFinder alloc] init];
</span><del>-    _textFinder.client = (id&lt;NSTextFinderClient&gt;)_webView;
</del><ins>+    _textFinder.incrementalSearchingEnabled = YES;
+    _textFinder.incrementalSearchingShouldDimContentView = YES;
+    _textFinder.client = _webView;
</ins><span class="cx">     _textFinder.findBarContainer = self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -102,6 +104,11 @@
</span><span class="cx">     [self layout];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (NSView *)contentView
+{
+    return _webView;
+}
+
</ins><span class="cx"> - (BOOL)isFindBarVisible
</span><span class="cx"> {
</span><span class="cx">     return _findBarVisible;
</span></span></pre>
</div>
</div>

</body>
</html>