Modified: trunk/Source/WebCore/ChangeLog (252742 => 252743)
--- trunk/Source/WebCore/ChangeLog 2019-11-21 19:31:40 UTC (rev 252742)
+++ trunk/Source/WebCore/ChangeLog 2019-11-21 19:50:21 UTC (rev 252743)
@@ -1,3 +1,22 @@
+2019-11-21 Wenson Hsieh <[email protected]>
+
+ [iOS] Web process crashes when attempting to request document context in a textarea
+ https://bugs.webkit.org/show_bug.cgi?id=204455
+ <rdar://problem/57383975>
+
+ Reviewed by Tim Horton.
+
+ Make `WebCore::rangesOverlap` robust in the case where the ranges' container nodes are in different tree scopes.
+ Currently, `compareBoundaryPoints` returns an exception in this scenario, which `rangesOverlap` does not expect.
+ As a result, we crash when releasing the return value after boundary point comparison. To fix this, just upgrade
+ the `ownerDocument` check in `rangesOverlap` to check for tree scopes instead, via the
+ `areNodesConnectedInSameTreeScope` helper function.
+
+ Test: WebKit.DocumentEditingContextSpatialRequestInTextField
+
+ * dom/Range.cpp:
+ (WebCore::rangesOverlap):
+
2019-11-21 Antti Koivisto <[email protected]>
Tighten ScrollingTreeNode tree mutations
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm (252742 => 252743)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm 2019-11-21 19:31:40 UTC (rev 252742)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm 2019-11-21 19:50:21 UTC (rev 252743)
@@ -37,6 +37,7 @@
#import <WebKit/WebKit.h>
#import <WebKit/_WKTextInputContext.h>
#import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
#define EXPECT_NSSTRING_EQ(expected, actual) \
EXPECT_TRUE([actual isKindOfClass:[NSString class]]); \
@@ -64,6 +65,7 @@
@interface UIWKDocumentContext (TestRunner)
@property (nonatomic, readonly) NSArray<NSValue *> *markedTextRects;
+@property (nonatomic, readonly) NSArray<NSValue *> *textRects;
@end
@implementation UIWKDocumentContext (TestRunner)
@@ -71,7 +73,7 @@
- (NSArray<NSValue *> *)markedTextRects
{
// This should ideally be equivalent to [self characterRectsForCharacterRange:self.markedTextRange]. However, the implementation
- // of -characterRectsForCharacterRange: in UIKit doesn't guarantee any order to the returned character rects.
+ // of -characterRectsForCharacterRange: in UIKit doesn't guarantee any order to the returned character rects. See: <rdar://57338528>.
NSRange range = self.markedTextRange;
NSMutableArray *rects = [NSMutableArray arrayWithCapacity:range.length];
for (auto location = range.location; location < range.location + range.length; ++location)
@@ -79,6 +81,23 @@
return rects;
}
+- (NSArray<NSValue *> *)textRects
+{
+ Vector<std::pair<NSRange, CGRect>> rangesAndRects;
+ [self enumerateLayoutRects:[&](NSRange characterRange, CGRect layoutRect, BOOL *) {
+ rangesAndRects.append(std::make_pair(characterRange, layoutRect));
+ }];
+
+ std::sort(rangesAndRects.begin(), rangesAndRects.end(), [](auto& a, auto& b) {
+ return a.first.location < b.first.location;
+ });
+
+ auto result = adoptNS([[NSMutableArray alloc] initWithCapacity:rangesAndRects.size()]);
+ for (auto& rangeAndRect : rangesAndRects)
+ [result addObject:[NSValue valueWithCGRect:rangeAndRect.second]];
+ return result.autorelease();
+}
+
@end
@implementation TestWKWebView (SynchronousDocumentContext)
@@ -351,4 +370,29 @@
}
}
+TEST(WebKit, DocumentEditingContextSpatialRequestInTextField)
+{
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+ [webView synchronouslyLoadHTMLString:@"<span style='-webkit-text-size-adjust: none;'>Hello<input type='text' value='foo bar' />world</span>"];
+ [webView stringByEvaluatingJavaScript:@"document.querySelector('input').focus()"];
+
+ auto request = retainPtr(makeRequest(UIWKDocumentRequestRects | UIWKDocumentRequestText | UIWKDocumentRequestSpatial, UITextGranularityCharacter, 0, [webView textInputContentView].bounds));
+ auto context = retainPtr([webView synchronouslyRequestDocumentContext:request.get()]);
+ auto *textRects = [context textRects];
+ EXPECT_EQ(10U, textRects.count);
+ if (textRects.count >= 10) {
+ EXPECT_EQ(CGRectMake(8, 9, 12, 19), textRects[0].CGRectValue);
+ EXPECT_EQ(CGRectMake(19, 9, 8, 19), textRects[1].CGRectValue);
+ EXPECT_EQ(CGRectMake(26, 9, 6, 19), textRects[2].CGRectValue);
+ EXPECT_EQ(CGRectMake(31, 9, 5, 19), textRects[3].CGRectValue);
+ EXPECT_EQ(CGRectMake(35, 9, 9, 19), textRects[4].CGRectValue);
+ EXPECT_EQ(CGRectMake(182, 9, 13, 19), textRects[5].CGRectValue);
+ EXPECT_EQ(CGRectMake(194, 9, 9, 19), textRects[6].CGRectValue);
+ EXPECT_EQ(CGRectMake(202, 9, 6, 19), textRects[7].CGRectValue);
+ EXPECT_EQ(CGRectMake(207, 9, 6, 19), textRects[8].CGRectValue);
+ EXPECT_EQ(CGRectMake(212, 9, 9, 19), textRects[9].CGRectValue);
+ }
+}
+
#endif // PLATFORM(IOS_FAMILY) && HAVE(UI_WK_DOCUMENT_CONTEXT)
Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (252742 => 252743)
--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h 2019-11-21 19:31:40 UTC (rev 252742)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h 2019-11-21 19:50:21 UTC (rev 252743)
@@ -138,6 +138,7 @@
@property (nonatomic, copy) NSAttributedString *annotatedText;
@property (nonatomic, readonly) NSRange markedTextRange;
+- (void)enumerateLayoutRects:(void (^)(NSRange characterRange, CGRect layoutRect, BOOL *stop))block;
- (NSArray<NSValue *> *)characterRectsForCharacterRange:(NSRange)range;
@end