Index: third_party/WebKit/Source/modules/fetch/Response.cpp |
diff --git a/third_party/WebKit/Source/modules/fetch/Response.cpp b/third_party/WebKit/Source/modules/fetch/Response.cpp |
index ac921661d387681b63191d578cb6ea8b3c5ce64f..478426227a827e71def320de9bc3118152d37998 100644 |
--- a/third_party/WebKit/Source/modules/fetch/Response.cpp |
+++ b/third_party/WebKit/Source/modules/fetch/Response.cpp |
@@ -7,6 +7,13 @@ |
#include "bindings/core/v8/Dictionary.h" |
#include "bindings/core/v8/ExceptionState.h" |
+#include "bindings/core/v8/ReadableStreamOperations.h" |
+#include "bindings/core/v8/ScriptState.h" |
+#include "bindings/core/v8/V8ArrayBuffer.h" |
+#include "bindings/core/v8/V8ArrayBufferView.h" |
+#include "bindings/core/v8/V8Binding.h" |
+#include "bindings/core/v8/V8Blob.h" |
+#include "bindings/core/v8/V8FormData.h" |
#include "core/dom/DOMArrayBuffer.h" |
#include "core/dom/DOMArrayBufferView.h" |
#include "core/fileapi/Blob.h" |
@@ -14,7 +21,9 @@ |
#include "modules/fetch/BodyStreamBuffer.h" |
#include "modules/fetch/FetchBlobDataConsumerHandle.h" |
#include "modules/fetch/FetchFormDataConsumerHandle.h" |
+#include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
#include "modules/fetch/ResponseInit.h" |
+#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/network/EncodedFormData.h" |
#include "platform/network/HTTPHeaderMap.h" |
#include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" |
@@ -95,37 +104,44 @@ bool isValidReasonPhrase(const String& statusText) |
} |
-Response* Response::create(ExecutionContext* context, ExceptionState& exceptionState) |
+Response* Response::create(ScriptState* scriptState, ExceptionState& exceptionState) |
{ |
- return create(context, nullptr, String(), ResponseInit(), exceptionState); |
+ return create(scriptState->executionContext(), nullptr, String(), ResponseInit(), exceptionState); |
} |
-Response* Response::create(ExecutionContext* context, const BodyInit& body, const Dictionary& init, ExceptionState& exceptionState) |
+Response* Response::create(ScriptState* scriptState, ScriptValue bodyValue, const Dictionary& init, ExceptionState& exceptionState) |
{ |
- ASSERT(!body.isNull()); |
+ v8::Local<v8::Value> body = bodyValue.v8Value(); |
+ v8::Isolate* isolate = scriptState->isolate(); |
+ ExecutionContext* executionContext = scriptState->executionContext(); |
+ |
OwnPtr<FetchDataConsumerHandle> bodyHandle; |
String contentType; |
- if (body.isBlob()) { |
- bodyHandle = FetchBlobDataConsumerHandle::create(context, body.getAsBlob()->blobDataHandle()); |
- contentType = body.getAsBlob()->type(); |
- } else if (body.isUSVString()) { |
- bodyHandle = FetchFormDataConsumerHandle::create(body.getAsUSVString()); |
- contentType = "text/plain;charset=UTF-8"; |
- } else if (body.isArrayBuffer()) { |
- bodyHandle = FetchFormDataConsumerHandle::create(body.getAsArrayBuffer()); |
- } else if (body.isArrayBufferView()) { |
- bodyHandle = FetchFormDataConsumerHandle::create(body.getAsArrayBufferView()); |
- } else if (body.isFormData()) { |
- RefPtr<EncodedFormData> formData = body.getAsFormData()->encodeMultiPartFormData(); |
+ if (V8Blob::hasInstance(body, isolate)) { |
+ Blob* blob = V8Blob::toImpl(body.As<v8::Object>()); |
+ bodyHandle = FetchBlobDataConsumerHandle::create(executionContext, blob->blobDataHandle()); |
+ contentType = blob->type(); |
+ } else if (V8ArrayBuffer::hasInstance(body, isolate)) { |
+ bodyHandle = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(body.As<v8::Object>())); |
+ } else if (V8ArrayBufferView::hasInstance(body, isolate)) { |
+ bodyHandle = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(body.As<v8::Object>())); |
+ } else if (V8FormData::hasInstance(body, isolate)) { |
+ RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object>())->encodeMultiPartFormData(); |
// Here we handle formData->boundary() as a C-style string. See |
// FormDataEncoder::generateUniqueBoundaryString. |
contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + formData->boundary().data(); |
- bodyHandle = FetchFormDataConsumerHandle::create(context, formData.release()); |
+ bodyHandle = FetchFormDataConsumerHandle::create(executionContext, formData.release()); |
+ } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnabled() && ReadableStreamOperations::isReadableStream(scriptState, body)) { |
+ bodyHandle = ReadableStreamDataConsumerHandle::create(scriptState, body); |
} else { |
- ASSERT_NOT_REACHED(); |
- return nullptr; |
+ String string = toUSVString(isolate, body, exceptionState); |
+ if (exceptionState.hadException()) |
+ return nullptr; |
+ bodyHandle = FetchFormDataConsumerHandle::create(string); |
+ contentType = "text/plain;charset=UTF-8"; |
} |
- return create(context, bodyHandle.release(), contentType, ResponseInit(init, exceptionState), exceptionState); |
+ // TODO(yhirano): Add the URLSearchParams case. |
+ return create(executionContext, bodyHandle.release(), contentType, ResponseInit(init, exceptionState), exceptionState); |
} |
Response* Response::create(ExecutionContext* context, PassOwnPtr<FetchDataConsumerHandle> bodyHandle, const String& contentType, const ResponseInit& init, ExceptionState& exceptionState) |
@@ -327,6 +343,12 @@ bool Response::hasPendingActivity() const |
return Body::hasPendingActivity(); |
} |
+void Response::stop() |
+{ |
+ if (m_response->internalBuffer()) |
+ m_response->internalBuffer()->stop(); |
+} |
+ |
void Response::populateWebServiceWorkerResponse(WebServiceWorkerResponse& response) |
{ |
m_response->populateWebServiceWorkerResponse(response); |