WebKit Bugzilla
Attachment 346740 Details for
Bug 188329
: navigator.sendBeacon does not work in pagehide callbacks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188329-20180807160350.patch (text/plain), 6.92 KB, created by
Chris Dumez
on 2018-08-07 16:03:51 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2018-08-07 16:03:51 PDT
Size:
6.92 KB
patch
obsolete
>Subversion Revision: 234670 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index b500682922f89cc8ffe77c2c367fe360f9af74ec..2944a19889f1dc8bcc21a41a5dbb64740406e103 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,22 @@ >+2018-08-07 Chris Dumez <cdumez@apple.com> >+ >+ navigator.sendBeacon does not work in pagehide callbacks >+ https://bugs.webkit.org/show_bug.cgi?id=188329 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-06 Ryosuke Niwa <rniwa@webkit.org> > > document.open and document.write must throw while the HTML parser is synchronously constructing a custom element >diff --git a/Source/WebCore/loader/cache/CachedResource.cpp b/Source/WebCore/loader/cache/CachedResource.cpp >index beb74f0fb57b48fcd8422f14c4f69b78c4e381b0..b40f130e6b755e7e375005b915f88764d9dc37d2 100644 >--- a/Source/WebCore/loader/cache/CachedResource.cpp >+++ b/Source/WebCore/loader/cache/CachedResource.cpp >@@ -201,7 +201,15 @@ void CachedResource::load(CachedResourceLoader& cachedResourceLoader) > // 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 @@ void CachedResource::load(CachedResourceLoader& cachedResourceLoader) > } > > 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()) >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index d040c486f7571f5743508b3c86c4f89ee5f2c2f1..cb5e6e6f0230fea6801c3a696eefb520768e7bab 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,16 @@ >+2018-08-07 Chris Dumez <cdumez@apple.com> >+ >+ navigator.sendBeacon does not work in pagehide callbacks >+ https://bugs.webkit.org/show_bug.cgi?id=188329 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r234669. >diff --git a/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide-expected.txt b/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..7b0e5a7be3950306d4df48b4405c0ae3ac7c2997 >--- /dev/null >+++ b/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide-expected.txt >@@ -0,0 +1,3 @@ >+ >+PASS Test that beacon sent from pagehide event handler is properly received >+ >diff --git a/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide.html b/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide.html >new file mode 100644 >index 0000000000000000000000000000000000000000..74242ed9e6a52f81c3664c69d9d8d839b29b3a8d >--- /dev/null >+++ b/LayoutTests/http/wpt/beacon/sendBeacon-in-pagehide.html >@@ -0,0 +1,46 @@ >+<!doctype html> >+<html> >+ <head> >+ <meta charset="utf-8"> >+ <title>SendBeacon keepalive flag</title> >+ <script src=/resources/testharness.js></script> >+ <script src=/resources/testharnessreport.js></script> >+ </head> >+ <body> >+ <script src="/common/utils.js"></script> >+ <script src="/common/get-host-info.sub.js"></script> >+ <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> >diff --git a/LayoutTests/http/wpt/beacon/support/sendBeacon-onpagehide-window.html b/LayoutTests/http/wpt/beacon/support/sendBeacon-onpagehide-window.html >new file mode 100644 >index 0000000000000000000000000000000000000000..ba131769d6d19f0eb2aa7fc00fc80d2e41b98470 >--- /dev/null >+++ b/LayoutTests/http/wpt/beacon/support/sendBeacon-onpagehide-window.html >@@ -0,0 +1,22 @@ >+<!DOCTYPE html> >+<html> >+<head> >+<script src="/common/utils.js"></script> >+<script src="/common/get-host-info.sub.js"></script> >+<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>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188329
: 346740