Add initial support for navigator.sendBeacon
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Aug 2017 04:44:23 +0000 (04:44 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Aug 2017 04:44:23 +0000 (04:44 +0000)
commit4b33dc34749d0f1f88ed69ade950bf1463bae932
tree379f8b29414aca5c6665db036904e3117115e66f
parent5b66743cee13f68e6ba76fee606c5d619bdba2ca
Add initial support for navigator.sendBeacon
https://bugs.webkit.org/show_bug.cgi?id=175007
<rdar://problem/33547728>

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

Import more beacon web-platform-tests and rebaseline the one we had
already imported now that navigator.sendBeacon is exposed.

* resources/import-expectations.json:
* resources/resource-files.json:
* web-platform-tests/beacon/beacon-basic-blob-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-blob.html: Added.
* web-platform-tests/beacon/beacon-basic-blobMax-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-blobMax.html: Added.
* web-platform-tests/beacon/beacon-basic-buffersource-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-buffersource.html: Added.
* web-platform-tests/beacon/beacon-basic-buffersourceMax-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-buffersourceMax.html: Added.
* web-platform-tests/beacon/beacon-basic-formdata-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-formdata.html: Added.
* web-platform-tests/beacon/beacon-basic-formdataMax-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-formdataMax.html: Added.
* web-platform-tests/beacon/beacon-basic-string-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-string.html: Added.
* web-platform-tests/beacon/beacon-basic-stringMax-expected.txt: Added.
* web-platform-tests/beacon/beacon-basic-stringMax.html: Added.
* web-platform-tests/beacon/beacon-common.js: Added.
(allTests.forEach):
(CreateArrayBufferFromPayload):
(CreateEmptyFormDataPayload):
(CreateFormDataFromPayload):
(initSession.return.add):
(initSession):
(runTests.):
(runTests):
(continueAfterSendingBeacon):
(waitForResults.):
(waitForResults):
(runSendInIframeAndNavigateTests.self.buildId):
(runSendInIframeAndNavigateTests.window.onmessage):
(runSendInIframeAndNavigateTests.self.sendFunc):
(runSendInIframeAndNavigateTests.iframe.onload):
* web-platform-tests/beacon/beacon-cors.window.js: Added.
(false.forEach.self.buildId):
(false.forEach.self.buildBaseUrl):
(false.forEach.self.buildTargetUrl):
(false.forEach):
* web-platform-tests/beacon/beacon-error.window.js: Added.
(test):
* web-platform-tests/beacon/beacon-redirect.window.js: Added.
(308.forEach.self.buildId):
(308.forEach.self.buildTargetUrl):
(308.forEach):
* web-platform-tests/beacon/fetch-keepalive-navigate.iFrame.html: Added.
* web-platform-tests/beacon/headers/header-content-type-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-no-referrer-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-origin-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-origin-when-cross-origin-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-same-origin-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-strict-origin-when-cross-origin.https-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-strict-origin.https-expected.txt:
* web-platform-tests/beacon/headers/header-referrer-unsafe-url.https-expected.txt:
* web-platform-tests/beacon/resources/beacon.py: Added.
(build_stash_key):
(main):
(main.wrap_key):
* web-platform-tests/beacon/resources/w3c-import.log:
* web-platform-tests/beacon/w3c-import.log: Added.
* web-platform-tests/url/failure-expected.txt:

Source/WebCore:

Add initial support for navigator.sendBeacon behind an experimental
feature runtime flag. The specification is available at:
- https://w3c.github.io/beacon/

The current implementation supports sending beacons with all types of
payloads except for ReadableStream. Some functionality is incomplete
and will be taken care of in follow-up patches:
- Support for CORS preflight for the cases where it is required. We currently
  return false and do not send the beacon in such cases.
- Better support for redirects.
- Use a more power-friendly network priority for beacon requests.

Tests: http/tests/blink/sendbeacon/*
       http/tests/security/mixedContent/beacon/insecure-beacon-in-iframe.html
       http/wpt/beacon/*
       imported/blink/fast/beacon/*
       imported/w3c/web-platform-tests/beacon/*

* CMakeLists.txt:
* DerivedSources.make:
* Modules/beacon/NavigatorBeacon.cpp: Added.
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/beacon/NavigatorBeacon.h: Added.
* Modules/beacon/NavigatorBeacon.idl: Added.
* WebCore.xcodeproj/project.pbxproj:
* loader/PingLoader.cpp:
(WebCore::PingLoader::sendBeacon):
* loader/PingLoader.h:

Source/WebKit:

Add experimental feature flag for the Beacon API, disabled by default.

* Shared/WebPreferencesDefinitions.h:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

Source/WebKitLegacy/mac:

Add setting to toggle support for the Beacon API (it is disabled by default).

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences beaconAPIEnabled]):
(-[WebPreferences setBeaconAPIEnabled:]):
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

Tools:

Enable the Beacon API at runtime in the context of layout tests since the
feature is currently disabled by default.

* DumpRenderTree/mac/DumpRenderTree.mm:
(enableExperimentalFeatures):
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::beginTesting):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setModernMediaControlsEnabled):
(WTR::TestRunner::setBeaconAPIEnabled):
* WebKitTestRunner/InjectedBundle/TestRunner.h:

LayoutTests:

* fast/dom/navigator-detached-no-crash-expected.txt:
Rebaseline test now that sendBeacon is exposed on navigator.

* http/tests/blink/sendbeacon/beacon-cookie-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-cookie.html: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin-redirect-blob-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin-redirect-blob.html: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin-redirect-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin-redirect.html: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin.html: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin.https-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-cross-origin.https.html: Added.
* http/tests/blink/sendbeacon/beacon-detached-no-crash-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-detached-no-crash.html: Added.
* http/tests/blink/sendbeacon/beacon-same-origin-expected.txt: Added.
* http/tests/blink/sendbeacon/beacon-same-origin.html: Added.
* http/tests/blink/sendbeacon/connect-src-beacon-allowed-expected.txt: Added.
* http/tests/blink/sendbeacon/connect-src-beacon-allowed.html: Added.
* http/tests/blink/sendbeacon/resources/check-beacon.php: Added.
* http/tests/blink/sendbeacon/resources/save-beacon.php: Added.
Import more beacon test coverage from Blink.

* http/wpt/beacon/connect-src-beacon-blocked.sub-expected.txt: Added.
* http/wpt/beacon/connect-src-beacon-blocked.sub.html: Added.
Improve test coverage for sendBeacon and CSP.

* http/wpt/beacon/headers/header-content-type-same-origin-expected.txt: Added.
* http/wpt/beacon/headers/header-content-type-same-origin.html: Added.
Improve test coverage for sendBeacon with various types of payload. The test is done
using same origin as we do not currently support sending some of those payloads cross
origin yet.

* imported/blink/fast/beacon/beacon-basic-expected.txt: Added.
* imported/blink/fast/beacon/beacon-basic.html: Added.
Import basic Beacon test coverage from Blink.

* resources/window-postmessage-open-close.html: Added.
* tests-options.json:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
92 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/http/tests/blink/sendbeacon/beacon-cookie-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cookie.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-redirect-blob-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-redirect-blob.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-redirect-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-redirect.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin.https.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-detached-no-crash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-detached-no-crash.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-same-origin-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/beacon-same-origin.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/connect-src-beacon-allowed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/connect-src-beacon-allowed.html [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/resources/check-beacon.php [new file with mode: 0644]
LayoutTests/http/tests/blink/sendbeacon/resources/save-beacon.php [new file with mode: 0644]
LayoutTests/http/wpt/beacon/connect-src-beacon-blocked.sub-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/connect-src-beacon-blocked.sub.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/headers/header-content-type-same-origin-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/headers/header-content-type-same-origin.html [new file with mode: 0644]
LayoutTests/imported/blink/fast/beacon/beacon-basic-expected.txt [new file with mode: 0644]
LayoutTests/imported/blink/fast/beacon/beacon-basic.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/resources/import-expectations.json
LayoutTests/imported/w3c/resources/resource-files.json
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-blob-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-blob.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-blobMax-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-blobMax.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-buffersource-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-buffersource.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-buffersourceMax-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-buffersourceMax.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-formdata-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-formdata.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-formdataMax-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-formdataMax.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-string-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-string.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-stringMax-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-basic-stringMax.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-common.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-cors.window.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-error.window.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/beacon-redirect.window.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/fetch-keepalive-navigate.iFrame.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-no-referrer-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-origin-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-origin-when-cross-origin-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-same-origin-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-strict-origin-when-cross-origin.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-strict-origin.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-referrer-unsafe-url.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/beacon/resources/beacon.py [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/beacon/resources/w3c-import.log
LayoutTests/imported/w3c/web-platform-tests/beacon/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/url/failure-expected.txt
LayoutTests/resources/window-postmessage-open-close.html [new file with mode: 0644]
LayoutTests/tests-options.json
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/beacon/NavigatorBeacon.cpp [new file with mode: 0644]
Source/WebCore/Modules/beacon/NavigatorBeacon.h [new file with mode: 0644]
Source/WebCore/Modules/beacon/NavigatorBeacon.idl [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/loader/PingLoader.cpp
Source/WebCore/loader/PingLoader.h
Source/WebCore/page/Settings.in
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferencesDefinitions.h
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h
Source/WebKitLegacy/mac/WebView/WebView.mm
Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/WebKitTestRunner/TestController.cpp