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)