[iOS 13] Safari crashes when closing a tab with a focused element if the unified...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Jul 2019 14:41:16 +0000 (14:41 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Jul 2019 14:41:16 +0000 (14:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200291
<rdar://problem/53717946>

Reviewed by Megan Gardner.

Source/WebKit:

Makes -requestAutocorrectionContextWithCompletionHandler: robust in the case where the web page has been closed,
and there is no Connection object to use when waiting for a sync IPC response.

Test: AutocorrectionTests.RequestAutocorrectionContextAfterClosingPage

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):

Tools:

Add an API test to exercise the scenario of synchronously requesting the autocorrection context immediately
after closing the web view, while the web view's content view isn't the first responder.

* TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm:
* TestWebKitAPI/ios/UIKitSPI.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248039 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm
Tools/TestWebKitAPI/ios/UIKitSPI.h

index 5ca4e28..4c2c4da 100644 (file)
@@ -1,3 +1,19 @@
+2019-07-31  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS 13] Safari crashes when closing a tab with a focused element if the unified field has focus
+        https://bugs.webkit.org/show_bug.cgi?id=200291
+        <rdar://problem/53717946>
+
+        Reviewed by Megan Gardner.
+
+        Makes -requestAutocorrectionContextWithCompletionHandler: robust in the case where the web page has been closed,
+        and there is no Connection object to use when waiting for a sync IPC response.
+
+        Test: AutocorrectionTests.RequestAutocorrectionContextAfterClosingPage
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
+
 2019-07-31  Chris Fleizach  <cfleizach@apple.com>
 
         AX: com.apple.WebKit.WebContent at com.apple.WebKit: -[WKAccessibilityWebPageObject accessibilityParameterizedAttributeNames]
index 48d17a5..ed42cec 100644 (file)
@@ -3890,6 +3890,11 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
     }
 #endif
 
+    if (!_page->hasRunningProcess()) {
+        completionHandler(WKAutocorrectionContext.emptyAutocorrectionContext);
+        return;
+    }
+
     // FIXME: Remove the synchronous call when <rdar://problem/16207002> is fixed.
     const bool useSyncRequest = true;
 
@@ -3904,7 +3909,6 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
     if (useSyncRequest) {
         _page->process().connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::HandleAutocorrectionContext>(_page->pageID(), 1_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives);
         [self _cancelPendingAutocorrectionContextHandler];
-        return;
     }
 }
 
index cd16f8e..4be756c 100644 (file)
@@ -1,3 +1,17 @@
+2019-07-31  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS 13] Safari crashes when closing a tab with a focused element if the unified field has focus
+        https://bugs.webkit.org/show_bug.cgi?id=200291
+        <rdar://problem/53717946>
+
+        Reviewed by Megan Gardner.
+
+        Add an API test to exercise the scenario of synchronously requesting the autocorrection context immediately
+        after closing the web view, while the web view's content view isn't the first responder.
+
+        * TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm:
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2019-07-31  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Datalist element support for TextFieldInputType
index 697203a..f0929f8 100644 (file)
@@ -94,4 +94,20 @@ TEST(AutocorrectionTests, FontAtCaretWhenUsingUICTFontTextStyle)
     EXPECT_EQ(32, fontAfterScaling.pointSize);
 }
 
+TEST(AutocorrectionTests, RequestAutocorrectionContextAfterClosingPage)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] init]);
+    [webView synchronouslyLoadTestPageNamed:@"autofocused-text-input"];
+
+    auto contentView = [webView textInputContentView];
+    [contentView resignFirstResponder];
+    [webView _close];
+
+    bool done = false;
+    [contentView requestAutocorrectionContextWithCompletionHandler:[&] (UIWKAutocorrectionContext *) {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+}
+
 #endif // PLATFORM(IOS_FAMILY)
index 56125c2..999349f 100644 (file)
@@ -156,8 +156,12 @@ typedef NS_OPTIONS(NSInteger, UIWKDocumentRequestFlags) {
 @property (nonatomic) CGRect lastRect;
 @end
 
+@interface UIWKAutocorrectionContext : NSObject
+@end
+
 @protocol UIWKInteractionViewProtocol
 - (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
+- (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler;
 @end
 
 IGNORE_WARNINGS_BEGIN("deprecated-implementations")