Changeset 221329 in webkit


Ignore:
Timestamp:
Aug 29, 2017, 5:39:26 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add support for FetchRequest.body
https://bugs.webkit.org/show_bug.cgi?id=176066

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-29
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
  • web-platform-tests/fetch/api/request/request-idl-expected.txt:

Source/WebCore:

Covered by existing tests.

Adding support for body attribute getter for FetchRequest.
To do so, FetchRequest will need to create a ReadableStream.
Adding support for DOM based creation of ReadableStream and conversion to JS values.
Small refactoring to make names more consistent.

  • CMakeLists.txt:
  • Modules/beacon/NavigatorBeacon.cpp:

(WebCore::NavigatorBeacon::sendBeacon):

  • Modules/cache/Cache.cpp:

(WebCore::Cache::put):

  • Modules/fetch/FetchBody.cpp:

(WebCore::FetchBody::extract):

  • Modules/fetch/FetchBody.h:

(WebCore::FetchBody::hasReadableStream const):
(WebCore::FetchBody::readableStream):
(WebCore::FetchBody::setReadableStream):
(WebCore::FetchBody::FetchBody):
(WebCore::FetchBody::isReadableStream const): Deleted.
(WebCore::FetchBody::setAsReadableStream): Deleted.

  • Modules/fetch/FetchBody.idl:
  • Modules/fetch/FetchBodyOwner.cpp:

(WebCore::FetchBodyOwner::readableStream):

  • Modules/fetch/FetchBodyOwner.h:

(WebCore::FetchBodyOwner::hasReadableStreamBody const):
(WebCore::FetchBodyOwner::isReadableStreamBody const): Deleted.

  • Modules/fetch/FetchRequest.cpp:

(WebCore::FetchRequest::setBody):

  • Modules/fetch/FetchRequest.h:
  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::setBodyAsReadableStream):
(WebCore::FetchResponse::fetch):

  • Modules/fetch/FetchResponse.h:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/ReadableStream.h:

(WebCore::JSConverter<IDLInterface<ReadableStream>>::convert):

Location:
trunk
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r221214 r221329  
     12017-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for FetchRequest.body
     4        https://bugs.webkit.org/show_bug.cgi?id=176066
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
     9        * web-platform-tests/fetch/api/request/request-idl-expected.txt:
     10
    1112017-08-25  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt

    r212202 r221329  
    11
    2 FAIL Request's body: initial state assert_equals: body's default value is null expected (object) null but got (undefined) undefined
     2PASS Request's body: initial state
    33PASS Request without body cannot be disturbed
    44PASS Check cloning a disturbed request
    55PASS Check creating a new request from a disturbed request
    6 FAIL Input request used for creating new request became disturbed assert_not_equals: body should not be undefined got disallowed value undefined
     6FAIL Input request used for creating new request became disturbed assert_equals: body should not change expected object "[object ReadableStream]" but got object "[object ReadableStream]"
    77FAIL Input request used for creating new request became disturbed even if body is not used assert_true: bodyUsed is true when request is disturbed expected true got false
    88PASS Check consuming a disturbed request
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl-expected.txt

    r220244 r221329  
    1919PASS Request interface: attribute keepalive
    2020PASS Request interface: operation clone()
    21 FAIL Request interface: attribute body assert_true: The prototype object must have a property "body" expected true got false
     21PASS Request interface: attribute body
    2222PASS Request interface: attribute bodyUsed
    2323PASS Request interface: operation arrayBuffer()
     
    4040PASS Request interface: new Request("") must inherit property "keepalive" with the proper type (12)
    4141PASS Request interface: new Request("") must inherit property "clone" with the proper type (13)
    42 FAIL Request interface: new Request("") must inherit property "body" with the proper type (14) assert_inherits: property "body" not found in prototype chain
     42PASS Request interface: new Request("") must inherit property "body" with the proper type (14)
    4343PASS Request interface: new Request("") must inherit property "bodyUsed" with the proper type (15)
    4444PASS Request interface: new Request("") must inherit property "arrayBuffer" with the proper type (16)
  • trunk/Source/WebCore/CMakeLists.txt

    r221309 r221329  
    12861286    bindings/js/JSXPathNSResolverCustom.cpp
    12871287    bindings/js/JSXPathResultCustom.cpp
     1288    bindings/js/ReadableStream.cpp
    12881289    bindings/js/ReadableStreamDefaultController.cpp
    12891290    bindings/js/ScheduledAction.cpp
  • trunk/Source/WebCore/ChangeLog

    r221327 r221329  
     12017-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for FetchRequest.body
     4        https://bugs.webkit.org/show_bug.cgi?id=176066
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by existing tests.
     9
     10        Adding support for body attribute getter for FetchRequest.
     11        To do so, FetchRequest will need to create a ReadableStream.
     12        Adding support for DOM based creation of ReadableStream and conversion to JS values.
     13        Small refactoring to make names more consistent.
     14
     15        * CMakeLists.txt:
     16        * Modules/beacon/NavigatorBeacon.cpp:
     17        (WebCore::NavigatorBeacon::sendBeacon):
     18        * Modules/cache/Cache.cpp:
     19        (WebCore::Cache::put):
     20        * Modules/fetch/FetchBody.cpp:
     21        (WebCore::FetchBody::extract):
     22        * Modules/fetch/FetchBody.h:
     23        (WebCore::FetchBody::hasReadableStream const):
     24        (WebCore::FetchBody::readableStream):
     25        (WebCore::FetchBody::setReadableStream):
     26        (WebCore::FetchBody::FetchBody):
     27        (WebCore::FetchBody::isReadableStream const): Deleted.
     28        (WebCore::FetchBody::setAsReadableStream): Deleted.
     29        * Modules/fetch/FetchBody.idl:
     30        * Modules/fetch/FetchBodyOwner.cpp:
     31        (WebCore::FetchBodyOwner::readableStream):
     32        * Modules/fetch/FetchBodyOwner.h:
     33        (WebCore::FetchBodyOwner::hasReadableStreamBody const):
     34        (WebCore::FetchBodyOwner::isReadableStreamBody const): Deleted.
     35        * Modules/fetch/FetchRequest.cpp:
     36        (WebCore::FetchRequest::setBody):
     37        * Modules/fetch/FetchRequest.h:
     38        * Modules/fetch/FetchResponse.cpp:
     39        (WebCore::FetchResponse::setBodyAsReadableStream):
     40        (WebCore::FetchResponse::fetch):
     41        * Modules/fetch/FetchResponse.h:
     42        * WebCore.xcodeproj/project.pbxproj:
     43        * bindings/js/ReadableStream.h:
     44        (WebCore::JSConverter<IDLInterface<ReadableStream>>::convert):
     45
    1462017-08-29  Yusuke Suzuki  <utatane.tea@gmail.com>
    247
  • trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp

    r221201 r221329  
    131131        auto fetchBody = FetchBody::extract(document, WTFMove(body.value()), mimeType);
    132132
    133         if (fetchBody.isReadableStream())
     133        if (fetchBody.hasReadableStream())
    134134            return Exception { TypeError, ASCIILiteral("Beacons cannot send ReadableStream body") };
    135135
  • trunk/Source/WebCore/Modules/cache/Cache.cpp

    r221112 r221329  
    297297
    298298    // FIXME: Add support for ReadableStream.
    299     if (response->isReadableStreamBody()) {
     299    if (response->hasReadableStreamBody()) {
    300300        promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
    301301        return;
  • trunk/Source/WebCore/Modules/fetch/FetchBody.cpp

    r221201 r221329  
    6262        Ref<const ArrayBufferView> buffer = value.releaseNonNull();
    6363        return FetchBody(WTFMove(buffer));
    64     }, [&](RefPtr<ReadableStream>&) mutable {
    65         FetchBody body;
    66         body.m_isReadableStream = true;
    67         return body;
     64    }, [&](RefPtr<ReadableStream>& stream) mutable {
     65        return FetchBody(stream.releaseNonNull());
    6866    }, [&](String& value) {
    6967        contentType = HTTPHeaderValues::textPlainContentType();
  • trunk/Source/WebCore/Modules/fetch/FetchBody.h

    r221201 r221329  
    6161    bool isURLSearchParams() const { return WTF::holds_alternative<Ref<const URLSearchParams>>(m_data); }
    6262    bool isText() const { return WTF::holds_alternative<String>(m_data); }
    63     bool isReadableStream() const { return m_isReadableStream; }
     63    bool hasReadableStream() const { return !!m_readableStream; }
    6464
    6565    using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, RefPtr<ReadableStream>, String>;
     
    6767    static FetchBody loadingBody() { return { }; }
    6868
    69     void setAsReadableStream() { m_isReadableStream = true; }
    7069    void loadingFailed();
    7170    void loadingSucceeded();
     
    8382
    8483    FetchBody clone() const;
     84    ReadableStream* readableStream() { return m_readableStream.get(); }
     85    void setReadableStream(Ref<ReadableStream>&& stream)
     86    {
     87        ASSERT(!m_readableStream);
     88        m_readableStream = WTFMove(stream);
     89    }
    8590
    8691private:
     
    9297    explicit FetchBody(Ref<const URLSearchParams>&& data) : m_data(WTFMove(data)) { }
    9398    explicit FetchBody(const FetchBodyConsumer& consumer) : m_consumer(consumer) { }
     99    explicit FetchBody(Ref<ReadableStream>&& stream) : m_readableStream(WTFMove(stream)) { }
    94100    FetchBody() = default;
    95101
     
    115121    FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
    116122    RefPtr<DeferredPromise> m_consumePromise;
    117 
    118     // FIXME: We probably want to keep the stream as a specific field in m_data when we will support stream data upload.
    119     bool m_isReadableStream { false };
     123    RefPtr<ReadableStream> m_readableStream;
    120124};
    121125
  • trunk/Source/WebCore/Modules/fetch/FetchBody.idl

    r220241 r221329  
    3434] interface FetchBody {
    3535    // FIMXE: Add missing body attribute.
    36     // readonly attribute ReadableStream? body;
     36    [ImplementedAs=readableStream, CallWith=ScriptState] readonly attribute ReadableStream? body;
    3737    readonly attribute boolean bodyUsed;
    3838    [NewObject] Promise<ArrayBuffer> arrayBuffer();
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp

    r220751 r221329  
    289289}
    290290
     291ReadableStream* FetchBodyOwner::readableStream(JSC::ExecState& state)
     292{
     293    if (isBodyNull())
     294        return nullptr;
     295
     296    if (!m_body->hasReadableStream())
     297        m_body->setReadableStream(ReadableStream::create(state, m_readableStreamSource));
     298
     299    return m_body->readableStream();
     300}
     301
    291302} // namespace WebCore
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h

    r220758 r221329  
    5858    bool isActive() const { return !!m_blobLoader; }
    5959
    60     bool isReadableStreamBody() const { return m_body && m_body->isReadableStream(); }
     60    ReadableStream* readableStream(JSC::ExecState&);
     61    virtual bool hasReadableStreamBody() const { return m_body && m_body->hasReadableStream(); }
    6162
    6263protected:
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r220928 r221329  
    226226        if (!methodCanHaveBody(m_internalRequest))
    227227            return Exception { TypeError };
     228        // FIXME: If body has a readable stream, we should pipe it to this new body stream.
    228229        m_body = WTFMove(request.m_body);
    229230        request.setDisturbed();
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.h

    r220758 r221329  
    8686    const String& internalRequestReferrer() const { return m_internalRequest.referrer; }
    8787    const URL& url() const { return m_internalRequest.request.url(); }
    88     bool isBodyReadableStream() const { return !isBodyNull() && body().isReadableStream(); }
    8988
    9089    ResourceRequest resourceRequest() const;
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r221152 r221329  
    8484    if (isBodyNull())
    8585        setBody(FetchBody::loadingBody());
    86     body().setAsReadableStream();
     86    m_isReadableStream = true;
    8787    updateContentType();
    8888}
     
    106106void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& request, NotificationCallback&& responseCallback)
    107107{
    108     if (request.isBodyReadableStream()) {
     108    if (request.hasReadableStreamBody()) {
    109109        if (responseCallback)
    110110            responseCallback(Exception { NotSupportedError, "ReadableStream uploading is not supported" });
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r220948 r221329  
    103103    const ResourceResponse& resourceResponse() const { return m_response; }
    104104
     105    // FIXME: Remove this method and use FetchBodyOwner one once we have full support in DOM ReadableStream.
     106    bool hasReadableStreamBody() const final { return m_isReadableStream; }
     107
    105108private:
    106109    FetchResponse(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
     
    145148    mutable String m_responseURL;
    146149    bool m_shouldExposeBody { true };
     150    // FIXME: Remove that flag once we have full support in DOM ReadableStream.
     151    bool m_isReadableStream { false };
    147152
    148153    FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::ArrayBuffer  };
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r221302 r221329  
    17631763                41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41AD75391CEF6BCE00A31486 /* FetchOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17641764                41B2A6261EF1BF6D002B9D7A /* WebAudioSourceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1765                41B459EF1F55EBD10000F6FD /* ReadableStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */; };
    17651766                41BF700C0FE86F49005E8DEC /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17661767                41BF700F0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */; };
     
    94869487                41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAudioSourceProvider.h; sourceTree = "<group>"; };
    94879488                41B459DA1F4CADB90000F6FD /* ReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStream.h; sourceTree = "<group>"; };
     9489                41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStream.cpp; sourceTree = "<group>"; };
    94889490                41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannel.h; sourceTree = "<group>"; };
    94899491                41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformMessagePortChannel.cpp; path = default/PlatformMessagePortChannel.cpp; sourceTree = "<group>"; };
     
    2387823880                                E1C36D330EB0A094007410BC /* JSWorkerGlobalScopeBase.h */,
    2387923881                                709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */,
     23882                                41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */,
    2388023883                                41B459DA1F4CADB90000F6FD /* ReadableStream.h */,
    2388123884                                418C395E1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.cpp */,
     
    3329433297                                F55B3DCD1251F12D003EF269 /* RangeInputType.cpp in Sources */,
    3329533298                                6E84E9E017668BEE00815B68 /* RasterShape.cpp in Sources */,
     33299                                41B459EF1F55EBD10000F6FD /* ReadableStream.cpp in Sources */,
    3329633300                                418C39611C8F0AB10051C8A3 /* ReadableStreamDefaultController.cpp in Sources */,
    3329733301                                FD31603B12B0267600C1A359 /* RealtimeAnalyser.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/ReadableStream.h

    r221201 r221329  
    3333namespace WebCore {
    3434
     35class ReadableStreamSource;
     36
    3537class ReadableStream final : public DOMGuarded<JSReadableStream> {
    3638public:
    3739    static Ref<ReadableStream> create(JSDOMGlobalObject& globalObject, JSReadableStream& readableStream) { return adoptRef(*new ReadableStream(globalObject, readableStream)); }
     40
     41    static Ref<ReadableStream> create(JSC::ExecState&, RefPtr<ReadableStreamSource>&&);
    3842
    3943    JSReadableStream* readableStream() { return guarded(); }
     
    6569};
    6670
     71template<> struct JSConverter<IDLInterface<ReadableStream>> {
     72    static constexpr bool needsState = false;
     73    static constexpr bool needsGlobalObject = false;
     74
     75    static JSC::JSValue convert(ReadableStream* value)
     76    {
     77        if (!value)
     78            return JSC::jsNull();
     79        return value->readableStream();
     80    }
     81};
     82
    6783}
Note: See TracChangeset for help on using the changeset viewer.