Title: [249514] trunk
Revision
249514
Author
[email protected]
Date
2019-09-04 19:36:28 -0700 (Wed, 04 Sep 2019)

Log Message

MobileSafari may crash when invoking the C++ lambda in -[WKContentView _shareForWebView:]
https://bugs.webkit.org/show_bug.cgi?id=201479
<rdar://problem/51511834>

Reviewed by Tim Horton.

Source/WebKit:

Fix the crash by making -_shareForWebView: robust in the case where there are no selection rects
known in the UI process when -[WKContentView _share:] is invoked.

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

Tools:

Add a test to verify that the UI process doesn't crash when invoking `_share:` while there's no selection.

* TestWebKitAPI/Tests/WebKitCocoa/WKContentViewEditingActions.mm:
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (249513 => 249514)


--- trunk/Source/WebKit/ChangeLog	2019-09-05 02:15:48 UTC (rev 249513)
+++ trunk/Source/WebKit/ChangeLog	2019-09-05 02:36:28 UTC (rev 249514)
@@ -1,3 +1,17 @@
+2019-09-04  Wenson Hsieh  <[email protected]>
+
+        MobileSafari may crash when invoking the C++ lambda in -[WKContentView _shareForWebView:]
+        https://bugs.webkit.org/show_bug.cgi?id=201479
+        <rdar://problem/51511834>
+
+        Reviewed by Tim Horton.
+
+        Fix the crash by making -_shareForWebView: robust in the case where there are no selection rects
+        known in the UI process when -[WKContentView _share:] is invoked.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _shareForWebView:]):
+
 2019-09-04  Ryosuke Niwa  <[email protected]>
 
         Replace defaultCustomPasteboardDataEnabled by an equivalent macro

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (249513 => 249514)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-09-05 02:15:48 UTC (rev 249513)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-09-05 02:36:28 UTC (rev 249514)
@@ -2800,13 +2800,15 @@
     _page->getSelectionOrContentsAsString([view](const String& string, WebKit::CallbackBase::Error error) {
         if (error != WebKit::CallbackBase::Error::None)
             return;
-        if (!string)
+
+        if (!view->_textSelectionAssistant || !string || view->_page->editorState().isMissingPostLayoutData)
             return;
 
-        CGRect presentationRect = view->_page->editorState().postLayoutData().selectionRects[0].rect();
+        auto& selectionRects = view->_page->editorState().postLayoutData().selectionRects;
+        if (selectionRects.isEmpty())
+            return;
 
-        if (view->_textSelectionAssistant)
-            [view->_textSelectionAssistant showShareSheetFor:string fromRect:presentationRect];
+        [view->_textSelectionAssistant showShareSheetFor:string fromRect:selectionRects.first().rect()];
     });
 }
 

Modified: trunk/Tools/ChangeLog (249513 => 249514)


--- trunk/Tools/ChangeLog	2019-09-05 02:15:48 UTC (rev 249513)
+++ trunk/Tools/ChangeLog	2019-09-05 02:36:28 UTC (rev 249514)
@@ -1,5 +1,18 @@
 2019-09-04  Wenson Hsieh  <[email protected]>
 
+        MobileSafari may crash when invoking the C++ lambda in -[WKContentView _shareForWebView:]
+        https://bugs.webkit.org/show_bug.cgi?id=201479
+        <rdar://problem/51511834>
+
+        Reviewed by Tim Horton.
+
+        Add a test to verify that the UI process doesn't crash when invoking `_share:` while there's no selection.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKContentViewEditingActions.mm:
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
+2019-09-04  Wenson Hsieh  <[email protected]>
+
         -[WKContentView selectedText] returns an empty string when selecting more than 200 characters
         https://bugs.webkit.org/show_bug.cgi?id=201471
         <rdar://problem/55039227>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentViewEditingActions.mm (249513 => 249514)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentViewEditingActions.mm	2019-09-05 02:15:48 UTC (rev 249513)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentViewEditingActions.mm	2019-09-05 02:36:28 UTC (rev 249514)
@@ -31,6 +31,7 @@
 #import "Test.h"
 #import "TestNavigationDelegate.h"
 #import "TestWKWebView.h"
+#import "UIKitSPI.h"
 #import <WebKit/WebKit.h>
 #import <wtf/RetainPtr.h>
 
@@ -62,4 +63,12 @@
     EXPECT_WK_STREQ("Hello world", [[UIPasteboard generalPasteboard] string]);
 }
 
+TEST(WebKit, InvokeShareWithoutSelection)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)]);
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [[webView textInputContentView] _share:nil];
+    [webView waitForNextPresentationUpdate];
+}
+
 #endif

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (249513 => 249514)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-09-05 02:15:48 UTC (rev 249513)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-09-05 02:36:28 UTC (rev 249514)
@@ -255,4 +255,8 @@
 - (CGRect)_selectionClipRect;
 @end
 
+@interface UIResponder (Internal)
+- (void)_share:(id)sender;
+@end
+
 #endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to