Title: [256390] branches/safari-609-branch
Revision
256390
Author
alanc...@apple.com
Date
2020-02-11 15:55:22 -0800 (Tue, 11 Feb 2020)

Log Message

Cherry-pick r255595. rdar://problem/59298183

    Regression(r253224) WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView
    https://bugs.webkit.org/show_bug.cgi?id=207121
    <rdar://problem/58880177>

    Reviewed by Alex Christensen.

    Source/WebKit:

    WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView, in case we time out
    while waiting for an answer from the WebProcess but the WebProcess eventually responds.

    Change is covered by new API test.

    * UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::tryClose):

    Tools:

    Add API test coverage.

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/WebKit/beforeunload-slow.html: Added.
    * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
    (-[SlowBeforeUnloadHandlerUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
    (-[SlowBeforeUnloadHandlerUIDelegate webViewDidClose:]):
    (TEST):

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-609-branch/Source/WebKit/ChangeLog (256389 => 256390)


--- branches/safari-609-branch/Source/WebKit/ChangeLog	2020-02-11 23:55:19 UTC (rev 256389)
+++ branches/safari-609-branch/Source/WebKit/ChangeLog	2020-02-11 23:55:22 UTC (rev 256390)
@@ -1,5 +1,54 @@
 2020-02-11  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r255595. rdar://problem/59298183
+
+    Regression(r253224) WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView
+    https://bugs.webkit.org/show_bug.cgi?id=207121
+    <rdar://problem/58880177>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebKit:
+    
+    WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView, in case we time out
+    while waiting for an answer from the WebProcess but the WebProcess eventually responds.
+    
+    Change is covered by new API test.
+    
+    * UIProcess/WebPageProxy.cpp:
+    (WebKit::WebPageProxy::tryClose):
+    
+    Tools:
+    
+    Add API test coverage.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKit/beforeunload-slow.html: Added.
+    * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
+    (-[SlowBeforeUnloadHandlerUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
+    (-[SlowBeforeUnloadHandlerUIDelegate webViewDidClose:]):
+    (TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255595 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-02-03  Chris Dumez  <cdu...@apple.com>
+
+            Regression(r253224) WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView
+            https://bugs.webkit.org/show_bug.cgi?id=207121
+            <rdar://problem/58880177>
+
+            Reviewed by Alex Christensen.
+
+            WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView, in case we time out
+            while waiting for an answer from the WebProcess but the WebProcess eventually responds.
+
+            Change is covered by new API test.
+
+            * UIProcess/WebPageProxy.cpp:
+            (WebKit::WebPageProxy::tryClose):
+
+2020-02-11  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r255519. rdar://problem/59298166
 
     Unreviewed macOS build fix after r255518

Modified: branches/safari-609-branch/Source/WebKit/UIProcess/WebPageProxy.cpp (256389 => 256390)


--- branches/safari-609-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-02-11 23:55:19 UTC (rev 256389)
+++ branches/safari-609-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-02-11 23:55:22 UTC (rev 256390)
@@ -1114,6 +1114,10 @@
         if (!weakThis)
             return;
 
+        // If we timed out, don't ask the client to close again.
+        if (!m_tryCloseTimeoutTimer.isActive())
+            return;
+
         m_tryCloseTimeoutTimer.stop();
         if (shouldClose)
             closePage();

Modified: branches/safari-609-branch/Tools/ChangeLog (256389 => 256390)


--- branches/safari-609-branch/Tools/ChangeLog	2020-02-11 23:55:19 UTC (rev 256389)
+++ branches/safari-609-branch/Tools/ChangeLog	2020-02-11 23:55:22 UTC (rev 256390)
@@ -1,5 +1,55 @@
 2020-02-11  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r255595. rdar://problem/59298183
+
+    Regression(r253224) WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView
+    https://bugs.webkit.org/show_bug.cgi?id=207121
+    <rdar://problem/58880177>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebKit:
+    
+    WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView, in case we time out
+    while waiting for an answer from the WebProcess but the WebProcess eventually responds.
+    
+    Change is covered by new API test.
+    
+    * UIProcess/WebPageProxy.cpp:
+    (WebKit::WebPageProxy::tryClose):
+    
+    Tools:
+    
+    Add API test coverage.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKit/beforeunload-slow.html: Added.
+    * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
+    (-[SlowBeforeUnloadHandlerUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
+    (-[SlowBeforeUnloadHandlerUIDelegate webViewDidClose:]):
+    (TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255595 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-02-03  Chris Dumez  <cdu...@apple.com>
+
+            Regression(r253224) WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView
+            https://bugs.webkit.org/show_bug.cgi?id=207121
+            <rdar://problem/58880177>
+
+            Reviewed by Alex Christensen.
+
+            Add API test coverage.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKit/beforeunload-slow.html: Added.
+            * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
+            (-[SlowBeforeUnloadHandlerUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
+            (-[SlowBeforeUnloadHandlerUIDelegate webViewDidClose:]):
+            (TEST):
+
+2020-02-11  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r255158. rdar://problem/59298137
 
     Throttling requestAnimationFrame should be controlled by RenderingUpdateScheduler

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (256389 => 256390)


--- branches/safari-609-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-02-11 23:55:19 UTC (rev 256389)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-02-11 23:55:22 UTC (rev 256390)
@@ -250,6 +250,7 @@
 		46E816F81E79E29C00375ADC /* RestoreStateAfterTermination.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46E816F71E79E29100375ADC /* RestoreStateAfterTermination.mm */; };
 		46EBD8472372320F00223A6E /* RestoreScrollPosition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46EBD846237231E600223A6E /* RestoreScrollPosition.mm */; };
 		46FA2FEE23846CA5000CCB0C /* HTTPHeaderMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */; };
+		46FACF7423E8842300A9EBC6 /* beforeunload-slow.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */; };
 		4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC79F168BE454E579E417B05 /* Markable.cpp */; };
 		4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
 		510477721D298DDD009747EB /* IDBDeleteRecovery.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5104776F1D298D85009747EB /* IDBDeleteRecovery.sqlite3 */; };
@@ -1197,6 +1198,7 @@
 				2E14A5291D3FE96B0010F35B /* autoplaying-video-with-audio.html in Copy Resources */,
 				F41AB9A01EF4696B0083FA08 /* background-image-link-and-input.html in Copy Resources */,
 				464C764D230DF85C00AFB020 /* BadServiceWorkerRegistrations-4.sqlite3 in Copy Resources */,
+				46FACF7423E8842300A9EBC6 /* beforeunload-slow.html in Copy Resources */,
 				2DE71B001D49C3ED00904094 /* blinking-div.html in Copy Resources */,
 				7C486BA11AA12567003F6F9B /* bundle-file.html in Copy Resources */,
 				26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */,
@@ -1792,6 +1794,7 @@
 		46E816F71E79E29100375ADC /* RestoreStateAfterTermination.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RestoreStateAfterTermination.mm; sourceTree = "<group>"; };
 		46EBD846237231E600223A6E /* RestoreScrollPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RestoreScrollPosition.mm; sourceTree = "<group>"; };
 		46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPHeaderMap.cpp; sourceTree = "<group>"; };
+		46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "beforeunload-slow.html"; sourceTree = "<group>"; };
 		4A410F4B19AF7BD6002EBAB5 /* UserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMedia.cpp; sourceTree = "<group>"; };
 		4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = getUserMedia.html; sourceTree = "<group>"; };
 		4A410F4D19AF7BEF002EBAB6 /* ondevicechange.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ondevicechange.html; sourceTree = "<group>"; };
@@ -3840,6 +3843,7 @@
 				C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */,
 				C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */,
 				C99BDF881E8097E300C7170E /* autoplay-zero-volume-check.html */,
+				46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */,
 				46C3AEB223D0E50F001B0680 /* beforeunload.html */,
 				7C486BA01AA1254B003F6F9B /* bundle-file.html */,
 				9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */,

Added: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKit/beforeunload-slow.html (0 => 256390)


--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKit/beforeunload-slow.html	                        (rev 0)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKit/beforeunload-slow.html	2020-02-11 23:55:22 UTC (rev 256390)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+function sleep(millisecondsToWait) {
+    var now = new Date().getTime();
+    while (new Date().getTime() < now + millisecondsToWait) { }
+}
+
+_onbeforeunload_ = (ev) => {
+    sleep(70);
+}
+</script>
+</head>
+</html>

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm (256389 => 256390)


--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm	2020-02-11 23:55:19 UTC (rev 256389)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm	2020-02-11 23:55:22 UTC (rev 256390)
@@ -190,4 +190,51 @@
     EXPECT_FALSE([webView _isClosed]);
 }
 
+static bool webViewDidCloseCalled = false;
+static unsigned viewDidCloseCallCount = 0;
+
+@interface SlowBeforeUnloadHandlerUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation SlowBeforeUnloadHandlerUIDelegate
+
+- (void)_webView:(WKWebView *)webView runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
+{
+    completionHandler(YES);
+}
+
+- (void)webViewDidClose:(WKWebView *)webView
+{
+    ++viewDidCloseCallCount;
+    webViewDidCloseCalled = true;
+}
+
+@end
+
+TEST(WebKit, SlowBeforeUnloadHandlerSingleClosePageCall)
+{
+    auto slowBeforeUnloadHandlerUIDelegate = adoptNS([[SlowBeforeUnloadHandlerUIDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView setUIDelegate:slowBeforeUnloadHandlerUIDelegate.get()];
+    [webView synchronouslyLoadTestPageNamed:@"beforeunload-slow"];
+
+    TestWebKitAPI::Util::spinRunLoop(10);
+
+    // Need a user gesture on the page before being allowed to show the beforeunload prompt.
+    [webView sendClicksAtPoint:NSMakePoint(5, 5) numberOfClicks:1];
+
+    TestWebKitAPI::Util::spinRunLoop(100);
+
+    [webView _tryClose];
+
+    TestWebKitAPI::Util::run(&webViewDidCloseCalled);
+    EXPECT_EQ(1U, viewDidCloseCallCount);
+    EXPECT_FALSE([webView _isClosed]);
+
+    TestWebKitAPI::Util::sleep(0.2);
+
+    EXPECT_EQ(1U, viewDidCloseCallCount);
+    EXPECT_FALSE([webView _isClosed]);
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to