Crash under -[WKWebView _updateVisibleContentRects]
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 00:46:38 +0000 (00:46 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 00:46:38 +0000 (00:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173123
rdar://problem/32650112

Reviewed by Tim Horton.

Make sure the WKWebView is valid in places where we dispatch_async or use
a pre-commit handler.

Speculative fix for a rare crasher.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _isValid]):
(-[WKWebView _addUpdateVisibleContentRectPreCommitHandler]):
(-[WKWebView _scheduleVisibleContentRectUpdateAfterScrollInView:]):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

index b71bba0..02a68da 100644 (file)
@@ -1,3 +1,21 @@
+2017-06-08  Simon Fraser  <simon.fraser@apple.com>
+
+        Crash under -[WKWebView _updateVisibleContentRects]
+        https://bugs.webkit.org/show_bug.cgi?id=173123
+        rdar://problem/32650112
+
+        Reviewed by Tim Horton.
+
+        Make sure the WKWebView is valid in places where we dispatch_async or use
+        a pre-commit handler.
+
+        Speculative fix for a rare crasher.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _isValid]):
+        (-[WKWebView _addUpdateVisibleContentRectPreCommitHandler]):
+        (-[WKWebView _scheduleVisibleContentRectUpdateAfterScrollInView:]):
+
 2017-06-07  Simon Fraser  <simon.fraser@apple.com>
 
         Use initializers in WebPageProxy
index 7c5c3e2..17405ee 100644 (file)
@@ -316,6 +316,11 @@ WKWebView* fromWebPageProxy(WebKit::WebPageProxy& page)
     return [self initWithFrame:frame configuration:adoptNS([[WKWebViewConfiguration alloc] init]).get()];
 }
 
+- (BOOL)_isValid
+{
+    return _page && _page->isValid();
+}
+
 #if PLATFORM(IOS)
 static int32_t deviceOrientationForUIInterfaceOrientation(UIInterfaceOrientation orientation)
 {
@@ -2353,6 +2358,8 @@ static WebCore::FloatSize activeMinimumLayoutSize(WKWebView *webView, const CGRe
     auto retainedSelf = retainPtr(self);
     [CATransaction addCommitHandler:[retainedSelf] {
         WKWebView *webView = retainedSelf.get();
+        if (![webView _isValid])
+            return;
         [webView _updateVisibleContentRects];
         webView->_hasScheduledVisibleRectUpdate = NO;
     } forPhase:kCATransactionPhasePreCommit];
@@ -2377,6 +2384,8 @@ static WebCore::FloatSize activeMinimumLayoutSize(WKWebView *webView, const CGRe
 
     dispatch_async(dispatch_get_main_queue(), [retainedSelf = retainPtr(self)] {
         WKWebView *webView = retainedSelf.get();
+        if (![webView _isValid])
+            return;
         [webView _addUpdateVisibleContentRectPreCommitHandler];
     });
 }
@@ -3788,12 +3797,15 @@ WEBCORE_COMMAND(yankAndSelect)
 
 - (pid_t)_webProcessIdentifier
 {
-    return _page->isValid() ? _page->processIdentifier() : 0;
+    if (![self _isValid])
+        return 0;
+
+    return _page->processIdentifier();
 }
 
 - (void)_killWebContentProcess
 {
-    if (!_page->isValid())
+    if (![self _isValid])
         return;
 
     _page->process().terminate();