Title: [234684] trunk
- Revision
- 234684
- Author
- [email protected]
- Date
- 2018-08-07 18:41:45 -0700 (Tue, 07 Aug 2018)
Log Message
navigator.sendBeacon does not work in pagehide callbacks
https://bugs.webkit.org/show_bug.cgi?id=188329
Reviewed by Alex Christensen.
Source/WebCore:
Add support for sending beacons from pagehide event handlers. We normally do not allow loads because we're
about to enter PageCache. However, in case of Beacon, this is fine since it uses PingLoad and does not
WebCore to do the load.
Test: http/wpt/beacon/sendBeacon-in-pagehide.html
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::load):
- Allow Beacon loads to go through even if the document's pageCacheState is AboutToEnterPageCache (i.e.
we're firing the 'pagehide' event)
- Allow Becon loads to go though even if the FrameLoader's state is provisional (i.e. a load is pending)
LayoutTests:
Add layout test coverage.
* http/wpt/beacon/sendBeacon-in-pagehide-expected.txt: Added.
* http/wpt/beacon/sendBeacon-in-pagehide.html: Added.
* http/wpt/beacon/support/sendBeacon-onpagehide-window.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (234683 => 234684)
--- trunk/LayoutTests/ChangeLog 2018-08-08 00:55:51 UTC (rev 234683)
+++ trunk/LayoutTests/ChangeLog 2018-08-08 01:41:45 UTC (rev 234684)
@@ -1,3 +1,16 @@
+2018-08-07 Chris Dumez <[email protected]>
+
+ navigator.sendBeacon does not work in pagehide callbacks
+ https://bugs.webkit.org/show_bug.cgi?id=188329
+
+ Reviewed by Alex Christensen.
+
+ Add layout test coverage.
+
+ * http/wpt/beacon/sendBeacon-in-pagehide-expected.txt: Added.
+ * http/wpt/beacon/sendBeacon-in-pagehide.html: Added.
+ * http/wpt/beacon/support/sendBeacon-onpagehide-window.html: Added.
+
2018-08-07 Said Abou-Hallawa <[email protected]>
Allow href attribute without xlink on SVG elements
Added: trunk/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide-expected.txt (0 => 234684)
--- trunk/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide-expected.txt 2018-08-08 01:41:45 UTC (rev 234684)
@@ -0,0 +1,3 @@
+
+PASS Test that beacon sent from pagehide event handler is properly received
+
Added: trunk/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide.html (0 => 234684)
--- trunk/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide.html (rev 0)
+++ trunk/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide.html 2018-08-08 01:41:45 UTC (rev 234684)
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon keepalive flag</title>
+ <script src=""
+ <script src=""
+ </head>
+ <body>
+ <script src=""
+ <script src=""
+ <script>
+const RESOURCES_DIR = "/beacon/resources/";
+
+function pollResult(test, id) {
+ var checkUrl = RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;
+
+ return new Promise(resolve => {
+ step_timeout(test.step_func(() => {
+ fetch(checkUrl).then(response => {
+ response.text().then(body => {
+ resolve(body);
+ });
+ });
+ }), 1000);
+ });
+}
+
+_onload_ = function() {
+ w = open("support/sendBeacon-onpagehide-window.html");
+ w._onload_ = function() {
+ promise_test(function(test) {
+ let id = w.id;
+ setTimeout(function() {
+ w.location = "about:blank";
+ }, 0);
+
+ return pollResult(test, id).then(result => {
+ assert_equals(result, "text/plain;charset=UTF-8", "Correct content-type header result");
+ });
+ }, "Test that beacon sent from pagehide event handler is properly received");
+ }
+}
+ </script>
+ </body>
+</html>
Added: trunk/LayoutTests/http/wpt/beacon/support/sendBeacon-onpagehide-window.html (0 => 234684)
--- trunk/LayoutTests/http/wpt/beacon/support/sendBeacon-onpagehide-window.html (rev 0)
+++ trunk/LayoutTests/http/wpt/beacon/support/sendBeacon-onpagehide-window.html 2018-08-08 01:41:45 UTC (rev 234684)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+const RESOURCES_DIR = "/beacon/resources/";
+var id = self.token();
+
+if (window.testRunner)
+ testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+</script>
+</head>
+<body>
+<script>
+_onpagehide_ = function() {
+ const testUrl = RESOURCES_DIR + "content-type.py?cmd=put&id=" + id;
+ navigator.sendBeacon(testUrl, "test");
+}
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (234683 => 234684)
--- trunk/Source/WebCore/ChangeLog 2018-08-08 00:55:51 UTC (rev 234683)
+++ trunk/Source/WebCore/ChangeLog 2018-08-08 01:41:45 UTC (rev 234684)
@@ -1,3 +1,22 @@
+2018-08-07 Chris Dumez <[email protected]>
+
+ navigator.sendBeacon does not work in pagehide callbacks
+ https://bugs.webkit.org/show_bug.cgi?id=188329
+
+ Reviewed by Alex Christensen.
+
+ Add support for sending beacons from pagehide event handlers. We normally do not allow loads because we're
+ about to enter PageCache. However, in case of Beacon, this is fine since it uses PingLoad and does not
+ WebCore to do the load.
+
+ Test: http/wpt/beacon/sendBeacon-in-pagehide.html
+
+ * loader/cache/CachedResource.cpp:
+ (WebCore::CachedResource::load):
+ - Allow Beacon loads to go through even if the document's pageCacheState is AboutToEnterPageCache (i.e.
+ we're firing the 'pagehide' event)
+ - Allow Becon loads to go though even if the FrameLoader's state is provisional (i.e. a load is pending)
+
2018-08-07 Said Abou-Hallawa <[email protected]>
Allow href attribute without xlink on SVG elements
Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (234683 => 234684)
--- trunk/Source/WebCore/loader/cache/CachedResource.cpp 2018-08-08 00:55:51 UTC (rev 234683)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp 2018-08-08 01:41:45 UTC (rev 234684)
@@ -201,7 +201,15 @@
// and their pageCacheState will not reflect the fact that they are about to enter page
// cache.
if (auto* topDocument = frame.mainFrame().document()) {
- if (topDocument->pageCacheState() != Document::NotInPageCache) {
+ switch (topDocument->pageCacheState()) {
+ case Document::NotInPageCache:
+ break;
+ case Document::AboutToEnterPageCache:
+ // Beacons are allowed to go through in 'pagehide' event handlers.
+ if (shouldUsePingLoad(type()))
+ break;
+ FALLTHROUGH;
+ case Document::InPageCache:
RELEASE_LOG_IF_ALLOWED("load: Already in page cache or being added to it (frame = %p)", &frame);
failBeforeStarting();
return;
@@ -209,7 +217,7 @@
}
FrameLoader& frameLoader = frame.loader();
- if (m_options.securityCheck == SecurityCheckPolicy::DoSecurityCheck && (frameLoader.state() == FrameStateProvisional || !frameLoader.activeDocumentLoader() || frameLoader.activeDocumentLoader()->isStopping())) {
+ if (m_options.securityCheck == SecurityCheckPolicy::DoSecurityCheck && !shouldUsePingLoad(type()) && (frameLoader.state() == FrameStateProvisional || !frameLoader.activeDocumentLoader() || frameLoader.activeDocumentLoader()->isStopping())) {
if (frameLoader.state() == FrameStateProvisional)
RELEASE_LOG_IF_ALLOWED("load: Failed security check -- state is provisional (frame = %p)", &frame);
else if (!frameLoader.activeDocumentLoader())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes