Crash when closing WKWebView during enter fullscreen animation
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2018 23:46:12 +0000 (23:46 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2018 23:46:12 +0000 (23:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190412

Reviewed by Brian Burg.

Source/WebKit:

We need a valid _webView if, during -[NSWindow close], we catch a notification saying we failed to enter
fullscreen and try to replace the placeholder with the actual _webView.

* UIProcess/mac/WKFullScreenWindowController.mm:
(-[WKFullScreenWindowController close]):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/CloseWebViewDuringEnterFullscreen.mm: Added.
(-[CloseWebViewDuringEnterFullscreenUIDelegate _webViewWillEnterFullscreen:]):
(-[CloseWebViewDuringEnterFullscreenUIDelegate _webViewWillExitFullscreen:]):
(TestWebKitAPI::TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/CloseWebViewDuringEnterFullscreen.mm [new file with mode: 0644]

index 3d60192..94abad9 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-09  Jer Noble  <jer.noble@apple.com>
+
+        Crash when closing WKWebView during enter fullscreen animation
+        https://bugs.webkit.org/show_bug.cgi?id=190412
+
+        Reviewed by Brian Burg.
+
+        We need a valid _webView if, during -[NSWindow close], we catch a notification saying we failed to enter
+        fullscreen and try to replace the placeholder with the actual _webView.
+
+        * UIProcess/mac/WKFullScreenWindowController.mm:
+        (-[WKFullScreenWindowController close]):
+
 2018-10-09  Alex Christensen  <achristensen@webkit.org>
 
         REGRESSION(r231663) loading in hidden WKWebViews stalls because WebProcess is suspended
index b60a55c..ca83781 100644 (file)
@@ -529,9 +529,9 @@ static const float minVideoWidth = 480 + 20 + 20; // Note: Keep in sync with med
     if (_fullScreenState == ExitingFullScreen)
         [self finishedExitFullScreenAnimation:YES];
 
-    _webView = nil;
-
     [super close];
+
+    _webView = nil;
 }
 
 - (void)videoControlsManagerDidChange
index a0d9b7b..8a11f46 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-09  Jer Noble  <jer.noble@apple.com>
+
+        Crash when closing WKWebView during enter fullscreen animation
+        https://bugs.webkit.org/show_bug.cgi?id=190412
+
+        Reviewed by Brian Burg.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/CloseWebViewDuringEnterFullscreen.mm: Added.
+        (-[CloseWebViewDuringEnterFullscreenUIDelegate _webViewWillEnterFullscreen:]):
+        (-[CloseWebViewDuringEnterFullscreenUIDelegate _webViewWillExitFullscreen:]):
+        (TestWebKitAPI::TEST):
+
 2018-10-09  Chris Dumez  <cdumez@apple.com>
 
         Anchor target should be ignored on activation when the download attribute is set
index e1eb05f..a44232f 100644 (file)
                CDC9442F1EF205D60059C3C4 /* mediastreamtrack-detached.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDC9442B1EF1FBD20059C3C4 /* mediastreamtrack-detached.html */; };
                CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDCFA7A91E45122F00C2433D /* SampleMap.cpp */; };
                CDE195B51CFE0B880053D256 /* FullscreenTopContentInset.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */; };
+               CDF0B78A216D48DC00421ECC /* CloseWebViewDuringEnterFullscreen.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDF0B789216D484300421ECC /* CloseWebViewDuringEnterFullscreen.mm */; };
                CDF92237216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDF92236216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm */; };
                CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */; };
                CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE0947362063223B003C9BA0 /* SchemeRegistry.mm */; };
                CDCFA7A91E45122F00C2433D /* SampleMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SampleMap.cpp; sourceTree = "<group>"; };
                CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenTopContentInset.html; sourceTree = "<group>"; };
                CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenTopContentInset.mm; sourceTree = "<group>"; };
+               CDF0B789216D484300421ECC /* CloseWebViewDuringEnterFullscreen.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CloseWebViewDuringEnterFullscreen.mm; sourceTree = "<group>"; };
                CDF92236216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CloseWebViewAfterEnterFullscreen.mm; sourceTree = "<group>"; };
                CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityOrigin.cpp; sourceTree = "<group>"; };
                CE0947362063223B003C9BA0 /* SchemeRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SchemeRegistry.mm; sourceTree = "<group>"; };
                                1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */,
                                5CB18BA71F5645B200EE23C4 /* ClickAutoFillButton.mm */,
                                CDF92236216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm */,
+                               CDF0B789216D484300421ECC /* CloseWebViewDuringEnterFullscreen.mm */,
                                1AAD19F51C7CE20300831E47 /* Coding.mm */,
                                7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */,
                                5C4A84941F7EEFD400ACFC54 /* Configuration.mm */,
                                7CCE7EE61A411AE600447C4C /* CloseFromWithinCreatePage.cpp in Sources */,
                                7CCE7EB71A411A7E00447C4C /* CloseNewWindowInNavigationPolicyDelegate.mm in Sources */,
                                7CCE7EE51A411AE600447C4C /* CloseThenTerminate.cpp in Sources */,
+                               CDF92237216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm in Sources */,
+                               CDF0B78A216D48DC00421ECC /* CloseWebViewDuringEnterFullscreen.mm in Sources */,
                                7C83E0BA1D0A64FB00FEBCF3 /* Coding.mm in Sources */,
                                7C3965061CDD74F90094DBB8 /* Color.cpp in Sources */,
                                7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */,
                                5C0BF88D1DD5964D00B00328 /* MemoryPressureHandler.mm in Sources */,
                                7C83E0B71D0A64B800FEBCF3 /* MenuTypesForMouseEvents.cpp in Sources */,
                                5C0BF8941DD599C900B00328 /* MenuTypesForMouseEvents.mm in Sources */,
-                               CDF92237216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm in Sources */,
                                5165FE04201EE620009F7EC3 /* MessagePortProviders.mm in Sources */,
                                A5B149DE1F5A19EA00C6DAFF /* MIMETypeRegistry.cpp in Sources */,
                                51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/CloseWebViewDuringEnterFullscreen.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CloseWebViewDuringEnterFullscreen.mm
new file mode 100644 (file)
index 0000000..af0458b
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+
+#if WK_API_ENABLED && PLATFORM(MAC)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/_WKFullscreenDelegate.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/Seconds.h>
+
+static bool willEnterFullscreen;
+static bool willExitFullscreen;
+
+@interface CloseWebViewDuringEnterFullscreenUIDelegate : NSObject <_WKFullscreenDelegate>
+@end
+
+@implementation CloseWebViewDuringEnterFullscreenUIDelegate
+
+- (void)_webViewWillEnterFullscreen:(WKWebView *)webView
+{
+    willEnterFullscreen = true;
+}
+
+- (void)_webViewWillExitFullscreen:(WKWebView *)webView
+{
+    willExitFullscreen = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(CloseWebViewDuringEnterFullscreen, VideoFullscreen)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration preferences]._fullScreenEnabled = YES;
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+    RetainPtr<CloseWebViewDuringEnterFullscreenUIDelegate> handler = adoptNS([[CloseWebViewDuringEnterFullscreenUIDelegate alloc] init]);
+    [webView _setFullscreenDelegate:handler.get()];
+
+    [webView synchronouslyLoadHTMLString:@"<video src=\"video-with-audio.mp4\" controls></video>"];
+
+    willEnterFullscreen = false;
+    [webView evaluateJavaScript:@"document.querySelector('video').webkitEnterFullscreen()" completionHandler: nil];
+    TestWebKitAPI::Util::run(&willEnterFullscreen);
+    TestWebKitAPI::Util::sleep(0.2);
+
+    // Should not crash:
+    [webView _close];
+}
+
+
+TEST(CloseWebViewDuringEnterFullscreen, ElementFullscreen)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration preferences]._fullScreenEnabled = YES;
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+    RetainPtr<CloseWebViewDuringEnterFullscreenUIDelegate> handler = adoptNS([[CloseWebViewDuringEnterFullscreenUIDelegate alloc] init]);
+    [webView _setFullscreenDelegate:handler.get()];
+
+    [webView synchronouslyLoadHTMLString:@"<div style=\"width:100px;height:100px;background-color:red;\"></div>"];
+
+    willEnterFullscreen = false;
+    [webView evaluateJavaScript:@"document.querySelector('div').webkitRequestFullscreen()" completionHandler: nil];
+    TestWebKitAPI::Util::run(&willEnterFullscreen);
+    TestWebKitAPI::Util::sleep(0.2);
+
+    // Should not crash:
+    [webView _close];
+}
+
+} // namespace TestWebKitAPI
+
+#endif