Diff
Modified: trunk/LayoutTests/ChangeLog (221200 => 221201)
--- trunk/LayoutTests/ChangeLog 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/LayoutTests/ChangeLog 2017-08-25 20:09:31 UTC (rev 221201)
@@ -1,3 +1,13 @@
+2017-08-25 Youenn Fablet <[email protected]>
+
+ Add support for ReadableStream storage in FetchBody
+ https://bugs.webkit.org/show_bug.cgi?id=175866
+
+ Reviewed by Sam Weinig.
+
+ * http/wpt/beacon/beacon-readablestream-expected.txt: Added.
+ * http/wpt/beacon/beacon-readablestream.html: Added.
+
2017-08-25 Wenson Hsieh <[email protected]>
Using the touchbar, both align left and align justify send a beforeinput event with the 'formatJustifyLeft' inputType.
Added: trunk/LayoutTests/http/wpt/beacon/beacon-readablestream-expected.txt (0 => 221201)
--- trunk/LayoutTests/http/wpt/beacon/beacon-readablestream-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/beacon/beacon-readablestream-expected.txt 2017-08-25 20:09:31 UTC (rev 221201)
@@ -0,0 +1,3 @@
+
+PASS Beacon with a ReadableStream body should fail.
+
Added: trunk/LayoutTests/http/wpt/beacon/beacon-readablestream.html (0 => 221201)
--- trunk/LayoutTests/http/wpt/beacon/beacon-readablestream.html (rev 0)
+++ trunk/LayoutTests/http/wpt/beacon/beacon-readablestream.html 2017-08-25 20:09:31 UTC (rev 221201)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<script src=""
+<script src=""
+<script>
+ test(function() {
+ assert_throws(new TypeError, () => { navigator.sendBeacon("/", new ReadableStream()) });
+ }, "Beacon with a ReadableStream body should fail.");
+</script>
Modified: trunk/Source/WebCore/ChangeLog (221200 => 221201)
--- trunk/Source/WebCore/ChangeLog 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/ChangeLog 2017-08-25 20:09:31 UTC (rev 221201)
@@ -1,3 +1,35 @@
+2017-08-25 Youenn Fablet <[email protected]>
+
+ Add support for ReadableStream storage in FetchBody
+ https://bugs.webkit.org/show_bug.cgi?id=175866
+
+ Reviewed by Sam Weinig.
+
+ Test: http/wpt/beacon/beacon-readablestream.html
+
+ Add support for IDLInterface<ReadableStream>, in particular to handle union conversions.
+ Adding a ReadableStream that guards JSReadableStream from being collected.
+ With this object, FetchBody will be able to store and manipulate ReadableStream.
+
+ Ensure conversion of BodyInit union with ReadableStream is working by adding support for beacon rejection in case of request body streams.
+
+ * Modules/beacon/NavigatorBeacon.cpp:
+ (WebCore::NavigatorBeacon::sendBeacon):
+ * Modules/beacon/NavigatorBeacon.idl:
+ * Modules/fetch/FetchBody.cpp:
+ (WebCore::FetchBody::extract):
+ * Modules/fetch/FetchBody.h:
+ * Modules/fetch/FetchRequest.idl:
+ * Modules/fetch/FetchRequestInit.idl:
+ * Modules/fetch/FetchResponse.idl:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/JSDOMConvertInterface.h:
+ (WebCore::JSToWrappedOverloader::toWrapped):
+ (WebCore::Converter<IDLInterface<T>>::convert):
+ * bindings/js/JSDOMConvertUnion.h:
+ * bindings/js/ReadableStream.h: Added.
+ (WebCore::JSReadableStreamWrapperConverter::toWrapped):
+
2017-08-25 Wenson Hsieh <[email protected]>
Using the touchbar, both align left and align justify send a beforeinput event with the 'formatJustifyLeft' inputType.
Modified: trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp (221200 => 221201)
--- trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp 2017-08-25 20:09:31 UTC (rev 221201)
@@ -29,7 +29,6 @@
#include "CachedRawResource.h"
#include "CachedResourceLoader.h"
#include "Document.h"
-#include "FetchBody.h"
#include "Frame.h"
#include "HTTPParsers.h"
#include "Navigator.h"
@@ -130,6 +129,10 @@
options.mode = FetchOptions::Mode::Cors;
String mimeType;
auto fetchBody = FetchBody::extract(document, WTFMove(body.value()), mimeType);
+
+ if (fetchBody.isReadableStream())
+ return Exception { TypeError, ASCIILiteral("Beacons cannot send ReadableStream body") };
+
request.setHTTPBody(fetchBody.bodyAsFormData(document));
if (!mimeType.isEmpty()) {
request.setHTTPContentType(mimeType);
Modified: trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.idl (221200 => 221201)
--- trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.idl 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.idl 2017-08-25 20:09:31 UTC (rev 221201)
@@ -23,8 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-// FIXME: Should support ReadableStream too.
-typedef (Blob or BufferSource or DOMFormData or URLSearchParams or USVString) BodyInit;
+typedef (Blob or BufferSource or DOMFormData or URLSearchParams or ReadableStream or USVString) BodyInit;
[
EnabledBySetting=BeaconAPI,
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (221200 => 221201)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2017-08-25 20:09:31 UTC (rev 221201)
@@ -42,36 +42,33 @@
FetchBody FetchBody::extract(ScriptExecutionContext& context, Init&& value, String& contentType)
{
- if (WTF::holds_alternative<RefPtr<Blob>>(value)) {
- Ref<const Blob> blob = WTF::get<RefPtr<Blob>>(value).releaseNonNull();
+ return WTF::switchOn(value, [&](RefPtr<Blob>& value) mutable {
+ Ref<const Blob> blob = value.releaseNonNull();
contentType = blob->type();
return FetchBody(WTFMove(blob));
- }
- if (WTF::holds_alternative<RefPtr<DOMFormData>>(value)) {
- Ref<DOMFormData> domFormData = WTF::get<RefPtr<DOMFormData>>(value).releaseNonNull();
+ }, [&](RefPtr<DOMFormData>& value) mutable {
+ Ref<DOMFormData> domFormData = value.releaseNonNull();
auto formData = FormData::createMultiPart(domFormData.get(), domFormData->encoding(), &static_cast<Document&>(context));
contentType = makeString("multipart/form-data; boundary=", formData->boundary().data());
return FetchBody(WTFMove(formData));
- }
-
- if (WTF::holds_alternative<RefPtr<URLSearchParams>>(value)) {
- Ref<const URLSearchParams> params = WTF::get<RefPtr<URLSearchParams>>(value).releaseNonNull();
+ }, [&](RefPtr<URLSearchParams>& value) mutable {
+ Ref<const URLSearchParams> params = value.releaseNonNull();
contentType = HTTPHeaderValues::formURLEncodedContentType();
return FetchBody(WTFMove(params));
- }
-
- if (WTF::holds_alternative<RefPtr<ArrayBuffer>>(value)) {
- Ref<const ArrayBuffer> buffer = WTF::get<RefPtr<ArrayBuffer>>(value).releaseNonNull();
+ }, [&](RefPtr<ArrayBuffer>& value) mutable {
+ Ref<const ArrayBuffer> buffer = value.releaseNonNull();
return FetchBody(WTFMove(buffer));
- }
- if (WTF::holds_alternative<RefPtr<ArrayBufferView>>(value)) {
- Ref<const ArrayBufferView> buffer = WTF::get<RefPtr<ArrayBufferView>>(value).releaseNonNull();
+ }, [&](RefPtr<ArrayBufferView>& value) mutable {
+ Ref<const ArrayBufferView> buffer = value.releaseNonNull();
return FetchBody(WTFMove(buffer));
- }
-
- ASSERT(WTF::holds_alternative<String>(value));
- contentType = HTTPHeaderValues::textPlainContentType();
- return FetchBody(WTFMove(WTF::get<String>(value)));
+ }, [&](RefPtr<ReadableStream>&) mutable {
+ FetchBody body;
+ body.m_isReadableStream = true;
+ return body;
+ }, [&](String& value) {
+ contentType = HTTPHeaderValues::textPlainContentType();
+ return FetchBody(WTFMove(value));
+ });
}
void FetchBody::arrayBuffer(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (221200 => 221201)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.h 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h 2017-08-25 20:09:31 UTC (rev 221201)
@@ -32,6 +32,7 @@
#include "FetchBodyConsumer.h"
#include "FormData.h"
#include "JSDOMPromiseDeferred.h"
+#include "ReadableStream.h"
#include "URLSearchParams.h"
#include <wtf/Variant.h>
@@ -61,7 +62,7 @@
bool isText() const { return WTF::holds_alternative<String>(m_data); }
bool isReadableStream() const { return m_isReadableStream; }
- using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, String>;
+ using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, RefPtr<ReadableStream>, String>;
static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
static FetchBody loadingBody() { return { }; }
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.idl (221200 => 221201)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2017-08-25 20:09:31 UTC (rev 221201)
@@ -31,8 +31,7 @@
typedef (FetchRequest or USVString) RequestInfo;
-// FIXME: Should include ReadableStream
-typedef (Blob or BufferSource or DOMFormData or URLSearchParams or USVString) BodyInit;
+typedef (Blob or BufferSource or DOMFormData or URLSearchParams or ReadableStream or USVString) BodyInit;
[
ActiveDOMObject,
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequestInit.idl (221200 => 221201)
--- trunk/Source/WebCore/Modules/fetch/FetchRequestInit.idl 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequestInit.idl 2017-08-25 20:09:31 UTC (rev 221201)
@@ -25,8 +25,7 @@
typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;
-// FIXME: Should include ReadableStream
-typedef (Blob or BufferSource or DOMFormData or URLSearchParams or USVString) BodyInit;
+typedef (Blob or BufferSource or DOMFormData or URLSearchParams or ReadableStream or USVString) BodyInit;
dictionary FetchRequestInit {
ByteString method;
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.idl (221200 => 221201)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2017-08-25 20:09:31 UTC (rev 221201)
@@ -26,8 +26,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-// FIXME: Should include ReadableStream
-typedef (Blob or BufferSource or DOMFormData or URLSearchParams or USVString) BodyInit;
+typedef (Blob or BufferSource or DOMFormData or URLSearchParams or ReadableStream or USVString) BodyInit;
typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;
enum FetchResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (221200 => 221201)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-08-25 20:09:31 UTC (rev 221201)
@@ -9447,6 +9447,7 @@
41ABE67A1D0580D5006D862D /* CrossOriginPreflightChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossOriginPreflightChecker.h; sourceTree = "<group>"; };
41AD75391CEF6BCE00A31486 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAudioSourceProvider.h; sourceTree = "<group>"; };
+ 41B459DA1F4CADB90000F6FD /* ReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStream.h; sourceTree = "<group>"; };
41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannel.h; sourceTree = "<group>"; };
41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformMessagePortChannel.cpp; path = default/PlatformMessagePortChannel.cpp; sourceTree = "<group>"; };
41BF700E0FE86F61005E8DEC /* PlatformMessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformMessagePortChannel.h; path = default/PlatformMessagePortChannel.h; sourceTree = "<group>"; };
@@ -23731,6 +23732,7 @@
E1C36D320EB0A094007410BC /* JSWorkerGlobalScopeBase.cpp */,
E1C36D330EB0A094007410BC /* JSWorkerGlobalScopeBase.h */,
709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */,
+ 41B459DA1F4CADB90000F6FD /* ReadableStream.h */,
418C395E1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.cpp */,
418C395F1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.h */,
41F1D21E0EF35C2A00DA8753 /* ScriptCachedFrameData.cpp */,
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertInterface.h (221200 => 221201)
--- trunk/Source/WebCore/bindings/js/JSDOMConvertInterface.h 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertInterface.h 2017-08-25 20:09:31 UTC (rev 221201)
@@ -33,6 +33,28 @@
template<typename ImplementationClass> struct JSDOMWrapperConverterTraits;
+template<typename T, typename Enable = void>
+struct JSToWrappedOverloader {
+ using ReturnType = typename JSDOMWrapperConverterTraits<T>::ToWrappedReturnType;
+ using WrapperType = typename JSDOMWrapperConverterTraits<T>::WrapperClass;
+
+ static ReturnType toWrapped(JSC::ExecState& state, JSC::JSValue value)
+ {
+ return WrapperType::toWrapped(state.vm(), value);
+ }
+};
+
+template<typename T>
+struct JSToWrappedOverloader<T, typename std::enable_if<JSDOMWrapperConverterTraits<T>::needsState>::type> {
+ using ReturnType = typename JSDOMWrapperConverterTraits<T>::ToWrappedReturnType;
+ using WrapperType = typename JSDOMWrapperConverterTraits<T>::WrapperClass;
+
+ static ReturnType toWrapped(JSC::ExecState& state, JSC::JSValue value)
+ {
+ return WrapperType::toWrapped(state, value);
+ }
+};
+
template<typename T> struct Converter<IDLInterface<T>> : DefaultConverter<IDLInterface<T>> {
using ReturnType = typename JSDOMWrapperConverterTraits<T>::ToWrappedReturnType;
using WrapperType = typename JSDOMWrapperConverterTraits<T>::WrapperClass;
@@ -42,7 +64,7 @@
{
auto& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- ReturnType object = WrapperType::toWrapped(vm, value);
+ ReturnType object = JSToWrappedOverloader<T>::toWrapped(state, value);
if (UNLIKELY(!object))
exceptionThrower(state, scope);
return object;
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertUnion.h (221200 => 221201)
--- trunk/Source/WebCore/bindings/js/JSDOMConvertUnion.h 2017-08-25 19:12:37 UTC (rev 221200)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertUnion.h 2017-08-25 20:09:31 UTC (rev 221201)
@@ -29,6 +29,7 @@
#include "JSDOMBinding.h"
#include "JSDOMConvertBase.h"
#include "JSDOMConvertBufferSource.h"
+#include "JSDOMConvertInterface.h"
#include "JSDOMConvertNull.h"
#include <runtime/IteratorOperations.h>
#include <wtf/Variant.h>
@@ -198,9 +199,8 @@
using Type = typename WTF::RemoveCVAndReference<decltype(type)>::type::type;
using ImplementationType = typename Type::ImplementationType;
using RawType = typename Type::RawType;
- using WrapperType = typename JSDOMWrapperConverterTraits<RawType>::WrapperClass;
- auto castedValue = WrapperType::toWrapped(vm, value);
+ auto castedValue = JSToWrappedOverloader<RawType>::toWrapped(state, value);
if (!castedValue)
return;
Added: trunk/Source/WebCore/bindings/js/ReadableStream.h (0 => 221201)
--- trunk/Source/WebCore/bindings/js/ReadableStream.h (rev 0)
+++ trunk/Source/WebCore/bindings/js/ReadableStream.h 2017-08-25 20:09:31 UTC (rev 221201)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CANON INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "JSDOMBinding.h"
+#include "JSDOMConvert.h"
+#include "JSDOMGuardedObject.h"
+#include "JSReadableStream.h"
+
+namespace WebCore {
+
+class ReadableStream final : public DOMGuarded<JSReadableStream> {
+public:
+ static Ref<ReadableStream> create(JSDOMGlobalObject& globalObject, JSReadableStream& readableStream) { return adoptRef(*new ReadableStream(globalObject, readableStream)); }
+
+ JSReadableStream* readableStream() { return guarded(); }
+
+protected:
+ ReadableStream(JSDOMGlobalObject& globalObject, JSReadableStream& readableStream) : DOMGuarded<JSReadableStream>(globalObject, readableStream) { }
+};
+
+struct JSReadableStreamWrapperConverter {
+ static RefPtr<ReadableStream> toWrapped(JSC::ExecState& state, JSC::JSValue value)
+ {
+ JSC::VM& vm = state.vm();
+ auto* globalObject = jsDynamicDowncast<JSDOMGlobalObject*>(vm, state.lexicalGlobalObject());
+ if (!globalObject)
+ return nullptr;
+
+ auto* readableStream = jsDynamicDowncast<JSReadableStream*>(vm, value);
+ if (!readableStream)
+ return nullptr;
+
+ return ReadableStream::create(*globalObject, *readableStream);
+ }
+};
+
+template<> struct JSDOMWrapperConverterTraits<ReadableStream> {
+ using WrapperClass = JSReadableStreamWrapperConverter;
+ using ToWrappedReturnType = RefPtr<ReadableStream>;
+ static constexpr bool needsState = true;
+};
+
+}