Title: [214495] trunk
Revision
214495
Author
timothy_hor...@apple.com
Date
2017-03-28 14:43:49 -0700 (Tue, 28 Mar 2017)

Log Message

Safari crashes when attempting to close tab that is displaying PDF
https://bugs.webkit.org/show_bug.cgi?id=170201
<rdar://problem/31242019>

Reviewed by Wenson Hsieh.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _doAfterNextStablePresentationUpdate:]):
Adopt BlockPtr to fix a leak.

(-[WKWebView _firePresentationUpdateForPendingStableStatePresentationCallbacks]):
dispatch_async in the doAfterNextPresentationUpdate callback; since this
recursively calls itself, in cases where doAfterNextPresentationUpdate
returns synchronously (e.g. if the Web Process is missing), we would
recurse infinitely.

* TestWebKitAPI/Tests/WebKit2Cocoa/DoAfterNextPresentationUpdateAfterCrash.mm:
(TEST):
Add a test for doAfterNextStablePresentationUpdate just like the existing
non-stable one.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (214494 => 214495)


--- trunk/Source/WebKit2/ChangeLog	2017-03-28 21:41:24 UTC (rev 214494)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-28 21:43:49 UTC (rev 214495)
@@ -1,3 +1,21 @@
+2017-03-28  Timothy Horton  <timothy_hor...@apple.com>
+
+        Safari crashes when attempting to close tab that is displaying PDF
+        https://bugs.webkit.org/show_bug.cgi?id=170201
+        <rdar://problem/31242019>
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _doAfterNextStablePresentationUpdate:]):
+        Adopt BlockPtr to fix a leak.
+
+        (-[WKWebView _firePresentationUpdateForPendingStableStatePresentationCallbacks]):
+        dispatch_async in the doAfterNextPresentationUpdate callback; since this
+        recursively calls itself, in cases where doAfterNextPresentationUpdate
+        returns synchronously (e.g. if the Web Process is missing), we would
+        recurse infinitely.
+
 2017-03-27  Youenn Fablet  <you...@apple.com>
 
         Remove WebPage::m_shouldDoICECandidateFiltering

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (214494 => 214495)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-03-28 21:41:24 UTC (rev 214494)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-03-28 21:43:49 UTC (rev 214495)
@@ -5160,22 +5160,24 @@
 
 - (void)_doAfterNextStablePresentationUpdate:(dispatch_block_t)updateBlock
 {
-    updateBlock = Block_copy(updateBlock);
+    auto updateBlockCopy = makeBlockPtr(updateBlock);
+
     if (_stableStatePresentationUpdateCallbacks)
-        [_stableStatePresentationUpdateCallbacks addObject:updateBlock];
+        [_stableStatePresentationUpdateCallbacks addObject:updateBlockCopy.get()];
     else {
-        _stableStatePresentationUpdateCallbacks = adoptNS([[NSMutableArray alloc] initWithObjects:Block_copy(updateBlock), nil]);
+        _stableStatePresentationUpdateCallbacks = adoptNS([[NSMutableArray alloc] initWithObjects:updateBlockCopy.get(), nil]);
         [self _firePresentationUpdateForPendingStableStatePresentationCallbacks];
     }
-    Block_release(updateBlock);
 }
 
 - (void)_firePresentationUpdateForPendingStableStatePresentationCallbacks
 {
     RetainPtr<WKWebView> strongSelf = self;
-    [self _doAfterNextPresentationUpdate:^() {
-        if ([strongSelf->_stableStatePresentationUpdateCallbacks count])
-            [strongSelf _firePresentationUpdateForPendingStableStatePresentationCallbacks];
+    [self _doAfterNextPresentationUpdate:[strongSelf] {
+        dispatch_async(dispatch_get_main_queue(), [strongSelf] {
+            if ([strongSelf->_stableStatePresentationUpdateCallbacks count])
+                [strongSelf _firePresentationUpdateForPendingStableStatePresentationCallbacks];
+        });
     }];
 }
 

Modified: trunk/Tools/ChangeLog (214494 => 214495)


--- trunk/Tools/ChangeLog	2017-03-28 21:41:24 UTC (rev 214494)
+++ trunk/Tools/ChangeLog	2017-03-28 21:43:49 UTC (rev 214495)
@@ -1,3 +1,16 @@
+2017-03-28  Timothy Horton  <timothy_hor...@apple.com>
+
+        Safari crashes when attempting to close tab that is displaying PDF
+        https://bugs.webkit.org/show_bug.cgi?id=170201
+        <rdar://problem/31242019>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/DoAfterNextPresentationUpdateAfterCrash.mm:
+        (TEST):
+        Add a test for doAfterNextStablePresentationUpdate just like the existing
+        non-stable one.
+
 2017-03-28  Jonathan Bedard  <jbed...@apple.com>
 
         webkitpy: Use host pattern for devices

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DoAfterNextPresentationUpdateAfterCrash.mm (214494 => 214495)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DoAfterNextPresentationUpdateAfterCrash.mm	2017-03-28 21:41:24 UTC (rev 214494)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DoAfterNextPresentationUpdateAfterCrash.mm	2017-03-28 21:43:49 UTC (rev 214495)
@@ -53,4 +53,24 @@
     TestWebKitAPI::Util::run(&gotCallback);
 }
 
+TEST(WebKit2, DoAfterNextStablePresentationUpdateAfterCrash)
+{
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+    
+    [webView loadHTMLString:@"test" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+    
+    [webView _killWebContentProcessAndResetState];
+    
+    __block bool gotCallback = false;
+    [webView _doAfterNextStablePresentationUpdate:^ {
+        gotCallback = true;
+    }];
+    
+    [webView loadHTMLString:@"test" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+    
+    TestWebKitAPI::Util::run(&gotCallback);
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to