Chromium Code Reviews| 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..c53e311d986a385e059f88835f600224ec4ae897 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/V8BindingMacros.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; |
| + v8::Local<v8::String> string; |
| + if (!v8Call(body->ToString(scriptState->context()), string)) |
| + return nullptr; |
| + bodyHandle = FetchFormDataConsumerHandle::create(toCoreString(string)); |
| + contentType = "text/plain;charset=UTF-8"; |
|
tyoshino (SeeGerritForStatus)
2015/12/10 10:49:51
no need to call replaceUnmatchedSurrogates()? I'm
yhirano
2015/12/10 11:18:10
You're right. Let's use it.
|
| } |
| - 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) |