Title: [264698] trunk
Revision
264698
Author
you...@apple.com
Date
2020-07-22 08:59:56 -0700 (Wed, 22 Jul 2020)

Log Message

KeepAlive fetch should not be blocked in pagehide event handlers
https://bugs.webkit.org/show_bug.cgi?id=214630
<rdar://problem/65564772>

Reviewed by Chris Dumez.

Source/WebCore:

Test: http/wpt/fetch/fetch-in-pagehide.html

* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::load):
Allow keep alive fetches to proceed similarly to ping loads.

LayoutTests:

* http/wpt/fetch/fetch-in-pagehide-expected.txt: Added.
* http/wpt/fetch/fetch-in-pagehide.html: Added.
* http/wpt/fetch/resources/fetch-in-pagehide-window.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (264697 => 264698)


--- trunk/LayoutTests/ChangeLog	2020-07-22 15:23:00 UTC (rev 264697)
+++ trunk/LayoutTests/ChangeLog	2020-07-22 15:59:56 UTC (rev 264698)
@@ -1,3 +1,15 @@
+2020-07-22  Youenn Fablet  <you...@apple.com>
+
+        KeepAlive fetch should not be blocked in pagehide event handlers
+        https://bugs.webkit.org/show_bug.cgi?id=214630
+        <rdar://problem/65564772>
+
+        Reviewed by Chris Dumez.
+
+        * http/wpt/fetch/fetch-in-pagehide-expected.txt: Added.
+        * http/wpt/fetch/fetch-in-pagehide.html: Added.
+        * http/wpt/fetch/resources/fetch-in-pagehide-window.html: Added.
+
 2020-07-22  Diego Pino Garcia  <dp...@igalia.com>
 
         [GTK] Unreviewed test gardening. Update test expectations after r264694.

Added: trunk/LayoutTests/http/wpt/fetch/fetch-in-pagehide-expected.txt (0 => 264698)


--- trunk/LayoutTests/http/wpt/fetch/fetch-in-pagehide-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/fetch-in-pagehide-expected.txt	2020-07-22 15:59:56 UTC (rev 264698)
@@ -0,0 +1,4 @@
+
+PASS Test that fetch sent from pagehide event handler is properly received with keepalive 
+PASS Test that fetch sent from pagehide event handler is not received with no keepalive 
+

Added: trunk/LayoutTests/http/wpt/fetch/fetch-in-pagehide.html (0 => 264698)


--- trunk/LayoutTests/http/wpt/fetch/fetch-in-pagehide.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/fetch-in-pagehide.html	2020-07-22 15:59:56 UTC (rev 264698)
@@ -0,0 +1,53 @@
+<!doctype html><!-- webkit-test-runner [ dumpJSConsoleLogInStdErr=true ] -->
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Fetch in pagehide</title>
+    <script src=""
+    <script src=""
+  </head>
+  <body>
+    <script src=""
+    <script src=""
+    <script>
+const RESOURCES_DIR = "/beacon/resources/";
+
+function checkUrl(id)
+{
+    return RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;
+}
+
+promise_test(async (test) => {
+    const w1 = open("resources/fetch-in-pagehide-window.html#keepalive");
+    await new Promise(resolve => w1._onload_ = resolve);
+
+    let id = w1.id;
+    step_timeout(function() {
+        w1.location = "/";
+    }, 0);
+
+    await new Promise(resolve => step_timeout(resolve, 1000));
+
+    const response = await fetch(checkUrl(id));
+    assert_equals(response.status, 200);
+    const result = await response.text();
+    assert_equals(result, "text/plain;charset=UTF-8", "Correct content-type header result");
+}, "Test that fetch sent from pagehide event handler is properly received with keepalive");
+
+promise_test(async (test) => {
+    const w2 = open("resources/fetch-in-pagehide-window.html#nokeepalive");
+    await new Promise(resolve => w2._onload_ = resolve);
+
+    let id = w2.id;
+    step_timeout(function() {
+      w2.location = "/";
+    }, 0);
+
+    await new Promise(resolve => test.step_timeout(resolve, 50));
+
+    const response = await fetch(checkUrl(id));
+    assert_equals(response.status, 400);
+}, "Test that fetch sent from pagehide event handler is not received with no keepalive");
+    </script>
+  </body>
+</html>

Added: trunk/LayoutTests/http/wpt/fetch/resources/fetch-in-pagehide-window.html (0 => 264698)


--- trunk/LayoutTests/http/wpt/fetch/resources/fetch-in-pagehide-window.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/fetch-in-pagehide-window.html	2020-07-22 15:59:56 UTC (rev 264698)
@@ -0,0 +1,20 @@
+<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+const RESOURCES_DIR = "/beacon/resources/";
+var id = self.token();
+</script>
+</head>
+<body>
+<script>
+_onpagehide_ = function() {
+    const testUrl = RESOURCES_DIR + "content-type.py?cmd=put&id=" + id;
+    fetch(testUrl, { method : 'POST', headers : [["Content-Type", "text/plain;charset=UTF-8"]], body: 'test', keepalive : location.hash === "#keepalive" });    
+}
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (264697 => 264698)


--- trunk/Source/WebCore/ChangeLog	2020-07-22 15:23:00 UTC (rev 264697)
+++ trunk/Source/WebCore/ChangeLog	2020-07-22 15:59:56 UTC (rev 264698)
@@ -1,3 +1,17 @@
+2020-07-22  Youenn Fablet  <you...@apple.com>
+
+        KeepAlive fetch should not be blocked in pagehide event handlers
+        https://bugs.webkit.org/show_bug.cgi?id=214630
+        <rdar://problem/65564772>
+
+        Reviewed by Chris Dumez.
+
+        Test: http/wpt/fetch/fetch-in-pagehide.html
+
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::load):
+        Allow keep alive fetches to proceed similarly to ping loads.
+
 2020-07-22  Geoffrey Garen  <gga...@apple.com>
 
         JSRunLoopTimer should use WTF::RunLoop rather than custom CF code

Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (264697 => 264698)


--- trunk/Source/WebCore/loader/cache/CachedResource.cpp	2020-07-22 15:23:00 UTC (rev 264697)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp	2020-07-22 15:59:56 UTC (rev 264698)
@@ -230,7 +230,7 @@
             break;
         case Document::AboutToEnterBackForwardCache:
             // Beacons are allowed to go through in 'pagehide' event handlers.
-            if (shouldUsePingLoad(type()))
+            if (m_options.keepAlive || shouldUsePingLoad(type()))
                 break;
             RELEASE_LOG_IF_ALLOWED_WITH_FRAME("load: About to enter back/forward cache", frame);
             failBeforeStarting();
@@ -243,7 +243,7 @@
     }
 
     FrameLoader& frameLoader = frame.loader();
-    if (m_options.securityCheck == SecurityCheckPolicy::DoSecurityCheck && !shouldUsePingLoad(type())) {
+    if (m_options.securityCheck == SecurityCheckPolicy::DoSecurityCheck && !m_options.keepAlive && !shouldUsePingLoad(type())) {
         while (true) {
             if (frameLoader.state() == FrameStateProvisional)
                 RELEASE_LOG_IF_ALLOWED_WITH_FRAME("load: Failed security check -- state is provisional", frame);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to