LayoutTests/imported/w3c:
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Apr 2016 18:04:20 +0000 (18:04 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Apr 2016 18:04:20 +0000 (18:04 +0000)
commit4da25c2f0847b953a37b3bb850b24efdecf848ab
tree3dc677dbd74e462618f814102a231ee9f7d44a1b
parent63611095b2ff55b891272705bf0216a20bad9b16
LayoutTests/imported/w3c:
[Fetch API] Consume HTTP data as a ReadableStream
https://bugs.webkit.org/show_bug.cgi?id=138968

Reviewed by Alex Christensen.

* web-platform-tests/fetch/api/basic/stream-response-expected.txt:
* web-platform-tests/fetch/api/basic/stream-response-worker-expected.txt:
* web-platform-tests/fetch/api/request/request-consume.html:
* web-platform-tests/fetch/api/resources/data.json: Added.
* web-platform-tests/fetch/api/resources/utils.js:
(validateStreamFromString):
* web-platform-tests/fetch/api/response/response-cancel-stream-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-cancel-stream.html: Added.
* web-platform-tests/fetch/api/response/response-clone-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-stream-expected.txt: Added.
* web-platform-tests/fetch/api/response/response-consume-stream.html: Added.
* web-platform-tests/fetch/api/response/response-init-002-expected.txt:
* web-platform-tests/fetch/api/response/response-stream-disturbed-expected-1.txt: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-1.html: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-expected-2.txt: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-2.html: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-expected-3.txt: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-3.html: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-expected-4.txt: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-4.html: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-expected-5.txt: Added.
* web-platform-tests/fetch/api/response/response-stream-disturbed-5.html: Added.

Source/WebCore:
[Fetch API] Consume HTTP data as a ReadableStream
https://bugs.webkit.org/show_bug.cgi?id=138968

Reviewed by Alex Christensen.

This patch introduces ReadableStreamSource and ReadableStreamController which allow feeding a ReadableStream from DOM classes.
ReadableStreamSource is a base class for all DOM ReadableStream sources.
ReadableStreamController is a wrapper around JSReadableStreamController that can be invoked by DOM code to enqueue/close/error a ReadableStream.
A createReadableStream function is introduced to allow DOM classes creating ReadableStream.

Added support for a FetchResponse ReadableStream source.
Both synthetic FetchResponse and loading FetchResponse are supported.
A new "Stream" FetchLoader::Type is introduced to allow receiving data as chunks and feeding them to a ReadableStream through ReadableStreamSource.

Currently, FetchResponse is consumed and marked as disturbed as soon as a ReadableStreamSource is created.
This should be changed so that consumption happens on the first read call to the ReadableStreamReader, i.e. when stream gets disturbed.

FetchResponseSource never fulfills the start promise, which allows to enqueue, error or close the stream at any time.
FetchResponseSource must therefore always ensure to close or error the stream.
Added support for locked check in FetchResponse.

Tests: imported/w3c/web-platform-tests/fetch/api/response/response-cancel-stream.html
       imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html
       imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1.html
       imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-2.html
       imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-3.html
       imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-4.html
       imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-5.html
Also covered by rebased tests.

* CMakeLists.txt:
* DerivedSources.make:
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeAsStream): Fill stream with body data.
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::type): Added accessor to body type, used for assertions.
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::isDisturbed): Adding stream isLocked check.
(WebCore::FetchBodyOwner::blobLoadingSucceeded): Added assertion that body type is blob. Closing stream if created.
(WebCore::FetchBodyOwner::blobLoadingFailed): Erroring the stream if created and not cancelled.
(WebCore::FetchBodyOwner::blobChunk): Filling stream with chunk.
(WebCore::FetchBodyOwner::stop): Rmoved call to finishBlobLoading as it should be called as part of FetchLoaderCLient::didFail callbacki.
* Modules/fetch/FetchBodyOwner.h:
* Modules/fetch/FetchLoader.cpp: Fixing the case of cancel being called when creating the ThreadableLoader by introducing FetchLoader::m_isStarted.
(WebCore::FetchLoader::start): Setting m_isStarted at the end of the start method.
(WebCore::FetchLoader::stop): Fixing the case that FetchLoader can be destroyed when cancelling its loader.
(WebCore::FetchLoader::startStreaming): Introduced to switch the loading type from ArayBuffer to Stream. Already buffered data is returned.
(WebCore::FetchLoader::didReceiveData): Handling of the new Stream type.
(WebCore::FetchLoader::didFinishLoading):
* Modules/fetch/FetchLoader.h:
* Modules/fetch/FetchLoaderClient.h:
(WebCore::FetchLoaderClient::didReceiveData): Callback to get data as chunks if loader is of type Stream.
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::clone): Removed m_isLocked as it is handled within isDisturbed().
(WebCore::FetchResponse::isDisturbed): Checking whether related ReadableStream is locked.
(WebCore::FetchResponse::BodyLoader::didSucceed): Introduced to handle ReadableStream case.
(WebCore::FetchResponse::BodyLoader::didFail): Ditto.
(WebCore::FetchResponse::BodyLoader::didReceiveData): Ditto.
(WebCore::FetchResponse::BodyLoader::startStreaming): Ditto.
(WebCore::FetchResponse::consumeBodyAsStream): Start filling the ReadableStream with data. Changing loader to Stream if there is one.
(WebCore::FetchResponse::createReadableStreamSource): Called by custom binding to create the source.
(WebCore::FetchResponse::stop): Fixing potential crash in case of cancelling the ibody stream.
(WebCore::FetchResponse::startFetching):
(WebCore::FetchResponse::BodyLoader::didFinishLoadingAsArrayBuffer):
* Modules/fetch/FetchResponse.h:
* Modules/fetch/FetchResponse.idl:
* Modules/fetch/FetchResponseSource.cpp: Specialization of ReadableStreamSource for FetchResponse. It is a push source that never resolves the start promise.
(WebCore::FetchResponseSource::FetchResponseSource):
(WebCore::FetchResponseSource::isReadableStreamLocked):
(WebCore::FetchResponseSource::setActive):
(WebCore::FetchResponseSource::setInactive):
(WebCore::FetchResponseSource::doStart):
(WebCore::FetchResponseSource::doCancel):
(WebCore::FetchResponseSource::close):
(WebCore::FetchResponseSource::error):
* Modules/fetch/FetchResponseSource.h: Added.
* Modules/streams/ReadableStreamController.js:
(error):
* Modules/streams/ReadableStreamSource.h: Added (base class for ReadableStream DOM sources).
(WebCore::ReadableStreamSource::~ReadableStreamSource):
(WebCore::ReadableStreamSource::isStarting):
(WebCore::ReadableStreamSource::isPulling):
(WebCore::ReadableStreamSource::isCancelling):
(WebCore::ReadableStreamSource::controller):
(WebCore::ReadableStreamSource::doStart):
(WebCore::ReadableStreamSource::doCancel):
(WebCore::ReadableStreamSource::start):
(WebCore::ReadableStreamSource::cancel):
(WebCore::ReadableStreamSource::startFinished):
(WebCore::ReadableStreamSource::clean):
* Modules/streams/ReadableStreamSource.idl: Added.
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMGlobalObject.h:
* bindings/js/JSFetchResponseCustom.cpp: In case body is not created, call createReadableStreamSource.
(WebCore::JSFetchResponse::body):
* bindings/js/JSReadableStreamSourceCustom.cpp: Added.
(WebCore::JSReadableStreamSource::start):
(WebCore::JSReadableStreamSource::pull):
(WebCore::JSReadableStreamSource::controller):
* bindings/js/ReadableStreamController.cpp: Added.
(WebCore::callFunction):
(WebCore::ReadableStreamController::invoke):
(WebCore::ReadableStreamController::isControlledReadableStreamLocked):
(WebCore::createReadableStream):
* bindings/js/ReadableStreamController.h: The DOM wrapper for JSReadableStreamController.
(WebCore::ReadableStreamController::ReadableStreamController):
(WebCore::ReadableStreamController::close):
(WebCore::ReadableStreamController::error):
(WebCore::ReadableStreamController::enqueue):
(WebCore::ReadableStreamController::globalObject):
(WebCore::ReadableStreamController::enqueue<RefPtr<JSC::ArrayBuffer>>):
(WebCore::ReadableStreamController::error<String>):

LayoutTests:
[Streams] Consume HTTP data as a ReadableStream
https://bugs.webkit.org/show_bug.cgi?id=138968

Reviewed by Alex Christensen.

* fast/xmlhttprequest/xmlhttprequest-responsetype-stream-expected.txt: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-stream.html: Added.
* http/tests/xmlhttprequest/streams/streams-read-api-cancelled-expected.txt: Added.
* http/tests/xmlhttprequest/streams/streams-read-api-cancelled.html: Added.
* http/tests/xmlhttprequest/streams/streams-read-api-closed-expected.txt: Added.
* http/tests/xmlhttprequest/streams/streams-read-api-closed.html: Added.
* http/tests/xmlhttprequest/streams/streams-read-api-expected.txt: Added.
* http/tests/xmlhttprequest/streams/streams-read-api.html: Added.
* http/tests/xmlhttprequest/streams/streams-read-expected.txt: Added.
* http/tests/xmlhttprequest/streams/streams-read.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
47 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/stream-response-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/stream-response-worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html
LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/data.json [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/utils.js
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-cancel-stream-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-cancel-stream.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-1.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-2-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-2.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-3-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-3.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-4-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-4.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-5-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-5.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Source/WebCore/Modules/fetch/FetchBodyOwner.h
Source/WebCore/Modules/fetch/FetchLoader.cpp
Source/WebCore/Modules/fetch/FetchLoader.h
Source/WebCore/Modules/fetch/FetchLoaderClient.h
Source/WebCore/Modules/fetch/FetchResponse.cpp
Source/WebCore/Modules/fetch/FetchResponse.h
Source/WebCore/Modules/fetch/FetchResponse.idl
Source/WebCore/Modules/fetch/FetchResponseSource.cpp [new file with mode: 0644]
Source/WebCore/Modules/fetch/FetchResponseSource.h [new file with mode: 0644]
Source/WebCore/Modules/streams/ReadableStreamController.js
Source/WebCore/Modules/streams/ReadableStreamSource.h [new file with mode: 0644]
Source/WebCore/Modules/streams/ReadableStreamSource.idl [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMGlobalObject.h
Source/WebCore/bindings/js/JSFetchResponseCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSReadableStreamSourceCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/ReadableStreamController.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/ReadableStreamController.h [new file with mode: 0644]