Title: [294657] branches/safari-7614.1.14.0-branch
Revision
294657
Author
[email protected]
Date
2022-05-23 11:05:24 -0700 (Mon, 23 May 2022)

Log Message

Cherry-pick r294589. rdar://problem/92006847

    [MacCatalyst] REGRESSION(r290091): sometimes can hang if `WKWebView` is unparented before the next visible content rect update
    https://bugs.webkit.org/show_bug.cgi?id=240691
    <rdar://problem/92006847>

    Reviewed by Wenson Hsieh.

    Test: WKWebViewResize.RemovesAssertionsAfterMovingToWindow

    * Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
    (-[WKWebView _processWillSwapOrDidExit]):
    (-[WKWebView didMoveToWindow]):
    (-[WKWebView _acquireResizeAssertionForReason:]):
    Drive-by: WebProcess crashes should also clear the resize assertions.
    Drive-by: Add a 1s timeout in case the next visible content rect update takes too long.

    * Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:
    * Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm:
    (-[WKWebView _hasResizeAssertion]): Added.
    * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm:
    (TEST.WKWebViewResize.RemovesAssertionsAfterMovingToWindow): Added.

    Canonical link: https://commits.webkit.org/250822@main

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

Modified Paths

Diff

Modified: branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (294656 => 294657)


--- branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-05-23 18:02:42 UTC (rev 294656)
+++ branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-05-23 18:05:24 UTC (rev 294657)
@@ -64,6 +64,7 @@
 #import <pal/spi/cocoa/QuartzCoreSPI.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
 #import <wtf/BlockPtr.h>
+#import <wtf/Box.h>
 #import <wtf/FixedVector.h>
 #import <wtf/SystemTracing.h>
 #import <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
@@ -706,6 +707,10 @@
     [self _hidePasswordView];
     [self _cancelAnimatedResize];
 
+#if HAVE(MAC_CATALYST_LIVE_RESIZE)
+    [self _invalidateResizeAssertions];
+#endif
+
     if (_gestureController)
         _gestureController->disconnectFromProcess();
 
@@ -1562,6 +1567,9 @@
     if (_page->hasRunningProcess() && self.window)
         _page->setIsInMultitaskingMode(self._isInMultitaskingMode);
 #endif
+#if HAVE(MAC_CATALYST_LIVE_RESIZE)
+    [self _invalidateResizeAssertions];
+#endif
 }
 
 - (void)_setOpaqueInternal:(BOOL)opaque
@@ -2014,13 +2022,34 @@
         return;
 
     if (_resizeAssertions.isEmpty()) {
-        [self _doAfterNextVisibleContentRectUpdate:makeBlockPtr([weakSelf = WeakObjCPtr<WKWebView>(self)] {
+        auto didInvalidateResizeAssertions = Box<bool>::create(false);
+
+        [self _doAfterNextVisibleContentRectUpdate:makeBlockPtr([weakSelf = WeakObjCPtr<WKWebView>(self), didInvalidateResizeAssertions] {
             auto strongSelf = weakSelf.get();
             if (!strongSelf)
                 return;
 
+            if (*didInvalidateResizeAssertions)
+                return;
+
             [strongSelf _invalidateResizeAssertions];
+
+            *didInvalidateResizeAssertions = true;
         }).get()];
+
+        RunLoop::main().dispatchAfter(1_s, [weakSelf = WeakObjCPtr<WKWebView>(self), didInvalidateResizeAssertions] {
+            auto strongSelf = weakSelf.get();
+            WKWEBVIEW_RELEASE_LOG("WKWebview %p next visible content rect update took too long; clearing resize assertions", strongSelf.get());
+            if (!strongSelf)
+                return;
+
+            if (*didInvalidateResizeAssertions)
+                return;
+
+            [strongSelf _invalidateResizeAssertions];
+
+            *didInvalidateResizeAssertions = true;
+        });
     }
 
     _resizeAssertions.append(retainPtr([windowScene _holdLiveResizeSnapshotForReason:reason]));

Modified: branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h (294656 => 294657)


--- branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h	2022-05-23 18:02:42 UTC (rev 294656)
+++ branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h	2022-05-23 18:05:24 UTC (rev 294657)
@@ -90,6 +90,8 @@
 
 - (NSString *)_serializedSelectionCaretBackgroundColorForTesting;
 
+- (BOOL)_hasResizeAssertion;
+
 @end
 
 #endif // TARGET_OS_IPHONE

Modified: branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm (294656 => 294657)


--- branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm	2022-05-23 18:02:42 UTC (rev 294656)
+++ branches/safari-7614.1.14.0-branch/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm	2022-05-23 18:05:24 UTC (rev 294657)
@@ -481,6 +481,15 @@
     return serializationForCSS(WebCore::colorFromCocoaColor(backgroundColor));
 }
 
+- (BOOL)_hasResizeAssertion
+{
+#if HAVE(MAC_CATALYST_LIVE_RESIZE)
+    if (!_resizeAssertions.isEmpty())
+        return YES;
+#endif
+    return NO;
+}
+
 @end
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: branches/safari-7614.1.14.0-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm (294656 => 294657)


--- branches/safari-7614.1.14.0-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm	2022-05-23 18:02:42 UTC (rev 294656)
+++ branches/safari-7614.1.14.0-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm	2022-05-23 18:05:24 UTC (rev 294657)
@@ -27,6 +27,7 @@
 
 #import "TestCocoa.h"
 #import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivateForTesting.h>
 #import <wtf/RetainPtr.h>
 
 #if HAVE(MAC_CATALYST_LIVE_RESIZE)
@@ -34,8 +35,10 @@
 TEST(WKWebViewResize, DoesNotAssertInDeallocAfterChangingFrame)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    EXPECT_FALSE([webView _hasResizeAssertion]);
 
     [webView setFrame:NSMakeRect(0, 0, 400, 300)];
+    EXPECT_TRUE([webView _hasResizeAssertion]);
 
     bool didThrow = false;
     @try {
@@ -49,8 +52,10 @@
 TEST(WKWebViewResize, DoesNotAssertInDeallocAfterChangingBounds)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    EXPECT_FALSE([webView _hasResizeAssertion]);
 
     [webView setBounds:NSMakeRect(0, 0, 400, 300)];
+    EXPECT_TRUE([webView _hasResizeAssertion]);
 
     bool didThrow = false;
     @try {
@@ -61,4 +66,24 @@
     EXPECT_FALSE(didThrow);
 }
 
+TEST(WKWebViewResize, RemovesAssertionsAfterMovingToWindow)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    EXPECT_FALSE([webView _hasResizeAssertion]);
+
+    [webView setFrame:NSMakeRect(0, 0, 400, 300)];
+    EXPECT_TRUE([webView _hasResizeAssertion]);
+
+    auto window = adoptNS([[UIWindow alloc] initWithFrame:NSMakeRect(0, 0, 320, 568)]);
+
+    [window addSubview:webView.get()];
+    EXPECT_FALSE([webView _hasResizeAssertion]);
+
+    [webView setFrame:NSMakeRect(0, 0, 200, 150)];
+    EXPECT_TRUE([webView _hasResizeAssertion]);
+
+    [webView removeFromSuperview];
+    EXPECT_FALSE([webView _hasResizeAssertion]);
+}
+
 #endif // HAVE(MAC_CATALYST_LIVE_RESIZE)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to