Title: [290442] trunk
Revision
290442
Author
drou...@apple.com
Date
2022-02-24 10:29:46 -0800 (Thu, 24 Feb 2022)

Log Message

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

Reviewed by Tim Horton.

Source/WebKit:

Tests: WKWebViewResize.DoesNotAssertInDeallocAfterChangingFrame
       WKWebViewResize.DoesNotAssertInDeallocAfterChangingBounds

* UIProcess/API/ios/WKWebViewIOS.h:
* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _acquireResizeAssertionForReason:]):
(-[WKWebView _invalidateResizeAssertions]): Added.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView dealloc]):
Make sure to `-invalidate` any remaining assertions in `-dealloc` as required by `_UIInvalidatable`.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm: Added.
(TEST.WKWebViewResize.DoesNotAssertInDeallocAfterChangingFrame):
(TEST.WKWebViewResize.DoesNotAssertInDeallocAfterChangingBounds):

* TestWebKitAPI/SourcesCocoa.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290441 => 290442)


--- trunk/Source/WebKit/ChangeLog	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Source/WebKit/ChangeLog	2022-02-24 18:29:46 UTC (rev 290442)
@@ -1,5 +1,24 @@
 2022-02-24  Devin Rousso  <drou...@apple.com>
 
+        [MacCatalyst] REGRESSION(r290091): sometimes can crash if `WKWebView` is deallocated before the next visible content rect update
+        https://bugs.webkit.org/show_bug.cgi?id=237126
+        <rdar://problem/89345853>
+
+        Reviewed by Tim Horton.
+
+        Tests: WKWebViewResize.DoesNotAssertInDeallocAfterChangingFrame
+               WKWebViewResize.DoesNotAssertInDeallocAfterChangingBounds
+
+        * UIProcess/API/ios/WKWebViewIOS.h:
+        * UIProcess/API/ios/WKWebViewIOS.mm:
+        (-[WKWebView _acquireResizeAssertionForReason:]):
+        (-[WKWebView _invalidateResizeAssertions]): Added.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView dealloc]):
+        Make sure to `-invalidate` any remaining assertions in `-dealloc` as required by `_UIInvalidatable`.
+
+2022-02-24  Devin Rousso  <drou...@apple.com>
+
         [Apple Pay] switch from `PassKit/*` to `PassKit[Core,UI]/*`
         https://bugs.webkit.org/show_bug.cgi?id=237091
         <rdar://problem/81085862>

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (290441 => 290442)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2022-02-24 18:29:46 UTC (rev 290442)
@@ -649,6 +649,10 @@
     CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), (__bridge CFStringRef)notificationName.get(), nullptr);
 #endif
 
+#if HAVE(MAC_CATALYST_LIVE_RESIZE)
+    [self _invalidateResizeAssertions];
+#endif
+
     [super dealloc];
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h (290441 => 290442)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h	2022-02-24 18:29:46 UTC (rev 290442)
@@ -49,6 +49,10 @@
 - (void)_accessibilitySettingsDidChange:(NSNotification *)notification;
 
 - (void)_frameOrBoundsChanged;
+#if HAVE(MAC_CATALYST_LIVE_RESIZE)
+- (void)_invalidateResizeAssertions;
+#endif
+
 - (BOOL)usesStandardContentView;
 
 - (void)_processDidExit;

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (290441 => 290442)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-02-24 18:29:46 UTC (rev 290442)
@@ -2013,14 +2013,19 @@
             if (!strongSelf)
                 return;
 
-            for (auto resizeAssertion : std::exchange(strongSelf->_resizeAssertions, { }))
-                [resizeAssertion _invalidate];
+            [strongSelf _invalidateResizeAssertions];
         }).get()];
     }
 
-    _resizeAssertions.append(adoptNS([windowScene _holdLiveResizeSnapshotForReason:reason]));
+    _resizeAssertions.append(retainPtr([windowScene _holdLiveResizeSnapshotForReason:reason]));
 }
 
+- (void)_invalidateResizeAssertions
+{
+    for (auto resizeAssertion : std::exchange(_resizeAssertions, { }))
+        [resizeAssertion _invalidate];
+}
+
 #endif // HAVE(MAC_CATALYST_LIVE_RESIZE)
 
 // Unobscured content rect where the user can interact. When the keyboard is up, this should be the area above or below the keyboard, wherever there is enough space.

Modified: trunk/Tools/ChangeLog (290441 => 290442)


--- trunk/Tools/ChangeLog	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Tools/ChangeLog	2022-02-24 18:29:46 UTC (rev 290442)
@@ -1,3 +1,18 @@
+2022-02-24  Devin Rousso  <drou...@apple.com>
+
+        [MacCatalyst] REGRESSION(r290091): sometimes can crash if `WKWebView` is deallocated before the next visible content rect update
+        https://bugs.webkit.org/show_bug.cgi?id=237126
+        <rdar://problem/89345853>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm: Added.
+        (TEST.WKWebViewResize.DoesNotAssertInDeallocAfterChangingFrame):
+        (TEST.WKWebViewResize.DoesNotAssertInDeallocAfterChangingBounds):
+
+        * TestWebKitAPI/SourcesCocoa.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+
 2022-02-24  J Pascoe  <j_pas...@apple.com>
 
         Add myself (John Pascoe) to watchlist for authentication and WebCrypto

Modified: trunk/Tools/TestWebKitAPI/SourcesCocoa.txt (290441 => 290442)


--- trunk/Tools/TestWebKitAPI/SourcesCocoa.txt	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Tools/TestWebKitAPI/SourcesCocoa.txt	2022-02-24 18:29:46 UTC (rev 290442)
@@ -286,6 +286,7 @@
 Tests/WebKitCocoa/WKWebViewGetContents.mm
 Tests/WebKitCocoa/WKWebViewLoadAPIs.mm
 Tests/WebKitCocoa/WKWebViewPrintFormatter.mm
+Tests/WebKitCocoa/WKWebViewResize.mm
 Tests/WebKitCocoa/WKWebViewServerTrustKVC.mm
 Tests/WebKitCocoa/WKWebViewSnapshot.mm
 Tests/WebKitCocoa/WKWebViewSuspendAllMediaPlayback.mm

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (290441 => 290442)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2022-02-24 18:02:18 UTC (rev 290441)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2022-02-24 18:29:46 UTC (rev 290442)
@@ -2582,6 +2582,7 @@
 		952F7166270BD99700D00DCC /* CSSViewportUnits.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = CSSViewportUnits.html; sourceTree = "<group>"; };
 		952F7166270BD99700D00DCD /* CSSViewportUnits.svg */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = CSSViewportUnits.svg; sourceTree = "<group>"; };
 		953ABB3425C0D681004C8B73 /* WKWebViewUnderPageBackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewUnderPageBackgroundColor.mm; sourceTree = "<group>"; };
+		953DF77B27C6DE5D00FDF3A5 /* WKWebViewResize.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewResize.mm; sourceTree = "<group>"; };
 		958B70E026C46EDC00B2022B /* NSAttributedStringWebKitAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NSAttributedStringWebKitAdditions.mm; sourceTree = "<group>"; };
 		95A524942581A10D00461FE9 /* WKWebViewThemeColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewThemeColor.mm; sourceTree = "<group>"; };
 		95B6B3B6251EBF2F00FC4382 /* MediaDocument.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaDocument.mm; sourceTree = "<group>"; };
@@ -3715,6 +3716,7 @@
 				D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
 				7A42ABD625CCD0F500980BCA /* WKWebViewLoadAPIs.mm */,
 				2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */,
+				953DF77B27C6DE5D00FDF3A5 /* WKWebViewResize.mm */,
 				37A9DBE7213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm */,
 				93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */,
 				CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm (0 => 290442)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewResize.mm	2022-02-24 18:29:46 UTC (rev 290442)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "TestCocoa.h"
+#import "TestWKWebView.h"
+#import <wtf/RetainPtr.h>
+
+#if HAVE(MAC_CATALYST_LIVE_RESIZE)
+
+TEST(WKWebViewResize, DoesNotAssertInDeallocAfterChangingFrame)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView setFrame:NSMakeRect(0, 0, 400, 300)];
+
+    bool didThrow = false;
+    @try {
+        webView = nil;
+    } @catch (NSException *exception) {
+        didThrow = true;
+    }
+    EXPECT_FALSE(didThrow);
+}
+
+TEST(WKWebViewResize, DoesNotAssertInDeallocAfterChangingBounds)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView setBounds:NSMakeRect(0, 0, 400, 300)];
+
+    bool didThrow = false;
+    @try {
+        webView = nil;
+    } @catch (NSException *exception) {
+        didThrow = true;
+    }
+    EXPECT_FALSE(didThrow);
+}
+
+#endif // HAVE(MAC_CATALYST_LIVE_RESIZE)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to