Title: [214683] trunk
Revision
214683
Author
[email protected]
Date
2017-03-31 12:56:30 -0700 (Fri, 31 Mar 2017)

Log Message

Mail can get stuck underneath FindController::findStringMatches after searching in a long message
https://bugs.webkit.org/show_bug.cgi?id=170326
<rdar://problem/30330395>

Reviewed by Simon Fraser.

Source/WebKit2:

* UIProcess/mac/WKTextFinderClient.mm:
(-[WKTextFinderClient findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
Cap the number of find matches at 1000, the same maximum that Safari uses.

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (214682 => 214683)


--- trunk/Source/WebKit2/ChangeLog	2017-03-31 19:42:07 UTC (rev 214682)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-31 19:56:30 UTC (rev 214683)
@@ -1,3 +1,15 @@
+2017-03-31  Tim Horton  <[email protected]>
+
+        Mail can get stuck underneath FindController::findStringMatches after searching in a long message
+        https://bugs.webkit.org/show_bug.cgi?id=170326
+        <rdar://problem/30330395>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/mac/WKTextFinderClient.mm:
+        (-[WKTextFinderClient findMatchesForString:relativeToMatch:findOptions:maxResults:resultCollector:]):
+        Cap the number of find matches at 1000, the same maximum that Safari uses.
+
 2017-03-31  Brady Eidson  <[email protected]>
 
         Clean up the "StorageType" enum.

Modified: trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm (214682 => 214683)


--- trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm	2017-03-31 19:42:07 UTC (rev 214682)
+++ trunk/Source/WebKit2/UIProcess/mac/WKTextFinderClient.mm	2017-03-31 19:56:30 UTC (rev 214683)
@@ -33,6 +33,7 @@
 #import "WebImage.h"
 #import "WebPageProxy.h"
 #import <WebCore/NSTextFinderSPI.h>
+#import <algorithm>
 #import <wtf/Deque.h>
 
 // FIXME: Implement support for replace.
@@ -42,6 +43,8 @@
 using namespace WebCore;
 using namespace WebKit;
 
+static const NSUInteger maximumFindMatches = 1000;
+
 @interface WKTextFinderClient ()
 
 - (void)didFindStringMatchesWithRects:(const Vector<Vector<IntRect>>&)rects;
@@ -172,6 +175,11 @@
 
 - (void)findMatchesForString:(NSString *)targetString relativeToMatch:(id <NSTextFinderAsynchronousDocumentFindMatch>)relativeMatch findOptions:(NSTextFinderAsynchronousDocumentFindOptions)findOptions maxResults:(NSUInteger)maxResults resultCollector:(void (^)(NSArray *matches, BOOL didWrap))resultCollector
 {
+    // Limit the number of results, for performance reasons; NSTextFinder always
+    // passes either 1 or NSUIntegerMax, which results in search time being
+    // proportional to document length.
+    maxResults = std::min(maxResults, maximumFindMatches);
+
     unsigned kitFindOptions = 0;
 
     if (findOptions & NSTextFinderAsynchronousDocumentFindOptionsBackwards)

Modified: trunk/Tools/ChangeLog (214682 => 214683)


--- trunk/Tools/ChangeLog	2017-03-31 19:42:07 UTC (rev 214682)
+++ trunk/Tools/ChangeLog	2017-03-31 19:56:30 UTC (rev 214683)
@@ -1,3 +1,14 @@
+2017-03-31  Tim Horton  <[email protected]>
+
+        Mail can get stuck underneath FindController::findStringMatches after searching in a long message
+        https://bugs.webkit.org/show_bug.cgi?id=170326
+        <rdar://problem/30330395>
+
+        Reviewed by Simon Fraser.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm:
+        (TEST):
+
 2017-03-31  Carlos Garcia Campos  <[email protected]>
 
         Unreviewed. Fix WTR crashes in GTK+ port after r214413.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm (214682 => 214683)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm	2017-03-31 19:42:07 UTC (rev 214682)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm	2017-03-31 19:56:30 UTC (rev 214683)
@@ -123,6 +123,15 @@
 
     TestWebKitAPI::Util::run(&findMatchesDone);
     findMatchesDone = false;
+
+    // Ensure that we cap the number of matches. There are actually 1600, but we only get the first 1000.
+    [webView findMatchesForString:@" " relativeToMatch:nil findOptions:noFindOptions maxResults:NSUIntegerMax resultCollector:^(NSArray *matches, BOOL didWrap) {
+        EXPECT_EQ((NSUInteger)1000, matches.count);
+
+        findMatchesDone = true;
+    }];
+    TestWebKitAPI::Util::run(&findMatchesDone);
+    findMatchesDone = false;
 }
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to