Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/fetch/Response.h" | 5 #include "modules/fetch/Response.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8ArrayBuffer.h" | 10 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 11 #include "bindings/core/v8/V8ArrayBufferView.h" | 11 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 12 #include "bindings/core/v8/V8Binding.h" | 12 #include "bindings/core/v8/V8Binding.h" |
| 13 #include "bindings/core/v8/V8Blob.h" | 13 #include "bindings/core/v8/V8Blob.h" |
| 14 #include "bindings/core/v8/V8FormData.h" | 14 #include "bindings/core/v8/V8FormData.h" |
| 15 #include "bindings/core/v8/V8HiddenValue.h" | 15 #include "bindings/core/v8/V8HiddenValue.h" |
| 16 #include "bindings/core/v8/V8URLSearchParams.h" | |
| 16 #include "core/dom/DOMArrayBuffer.h" | 17 #include "core/dom/DOMArrayBuffer.h" |
| 17 #include "core/dom/DOMArrayBufferView.h" | 18 #include "core/dom/DOMArrayBufferView.h" |
| 19 #include "core/dom/URLSearchParams.h" | |
| 18 #include "core/fileapi/Blob.h" | 20 #include "core/fileapi/Blob.h" |
| 19 #include "core/html/FormData.h" | 21 #include "core/html/FormData.h" |
| 20 #include "core/streams/ReadableStreamOperations.h" | 22 #include "core/streams/ReadableStreamOperations.h" |
| 21 #include "modules/fetch/BodyStreamBuffer.h" | 23 #include "modules/fetch/BodyStreamBuffer.h" |
| 22 #include "modules/fetch/DataConsumerHandleUtil.h" | 24 #include "modules/fetch/DataConsumerHandleUtil.h" |
| 23 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 25 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 24 #include "modules/fetch/FetchFormDataConsumerHandle.h" | 26 #include "modules/fetch/FetchFormDataConsumerHandle.h" |
| 25 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" | 27 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
| 26 #include "modules/fetch/ResponseInit.h" | 28 #include "modules/fetch/ResponseInit.h" |
| 27 #include "platform/RuntimeEnabledFeatures.h" | 29 #include "platform/RuntimeEnabledFeatures.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 } else if (body->IsArrayBuffer()) { | 138 } else if (body->IsArrayBuffer()) { |
| 137 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBuffer::toImpl(body.As<v8::Object>()))); | 139 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBuffer::toImpl(body.As<v8::Object>()))); |
| 138 } else if (body->IsArrayBufferView()) { | 140 } else if (body->IsArrayBufferView()) { |
| 139 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBufferView::toImpl(body.As<v8::Object>()))); | 141 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(V8ArrayBufferView::toImpl(body.As<v8::Object>()))); |
| 140 } else if (V8FormData::hasInstance(body, isolate)) { | 142 } else if (V8FormData::hasInstance(body, isolate)) { |
| 141 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object >())->encodeMultiPartFormData(); | 143 RefPtr<EncodedFormData> formData = V8FormData::toImpl(body.As<v8::Object >())->encodeMultiPartFormData(); |
| 142 // Here we handle formData->boundary() as a C-style string. See | 144 // Here we handle formData->boundary() as a C-style string. See |
| 143 // FormDataEncoder::generateUniqueBoundaryString. | 145 // FormDataEncoder::generateUniqueBoundaryString. |
| 144 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data(); | 146 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data(); |
| 145 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release())); | 147 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release())); |
| 148 } else if (V8URLSearchParams::hasInstance(body, isolate)) { | |
| 149 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(body.As<v8: :Object>())->toEncodedFormData(); | |
| 150 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(executionContext, formData.release())); | |
| 151 contentType = "application/x-www-form-urlencoded;charset=UTF-8"; | |
| 146 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { | 152 } else if (RuntimeEnabledFeatures::responseConstructedWithReadableStreamEnab led() && ReadableStreamOperations::isReadableStream(scriptState, bodyValue)) { |
| 147 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 153 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
| 148 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue); | 154 bodyBuffer = new BodyStreamBuffer(scriptState, bodyValue); |
| 149 } else { | 155 } else { |
| 150 std::unique_ptr<FetchDataConsumerHandle> bodyHandle; | 156 std::unique_ptr<FetchDataConsumerHandle> bodyHandle; |
| 151 reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState); | 157 reader = ReadableStreamOperations::getReader(scriptState, bodyValue, exceptionState); |
| 152 if (exceptionState.hadException()) { | 158 if (exceptionState.hadException()) { |
| 153 reader = ScriptValue(); | 159 reader = ScriptValue(); |
| 154 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn expectedErrorDataConsumerHandle()); | 160 bodyHandle = createFetchDataConsumerHandleFromWebHandle(createUn expectedErrorDataConsumerHandle()); |
| 155 exceptionState.clearException(); | 161 exceptionState.clearException(); |
| 156 } else { | 162 } else { |
| 157 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat e, reader); | 163 bodyHandle = ReadableStreamDataConsumerHandle::create(scriptStat e, reader); |
| 158 } | 164 } |
| 159 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle) ); | 165 bodyBuffer = new BodyStreamBuffer(scriptState, std::move(bodyHandle) ); |
| 160 } | 166 } |
| 161 } else { | 167 } else { |
| 162 String string = toUSVString(isolate, body, exceptionState); | 168 String string = toUSVString(isolate, body, exceptionState); |
| 163 if (exceptionState.hadException()) | 169 if (exceptionState.hadException()) |
| 164 return nullptr; | 170 return nullptr; |
| 165 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(string)); | 171 bodyBuffer = new BodyStreamBuffer(scriptState, FetchFormDataConsumerHand le::create(string)); |
| 166 contentType = "text/plain;charset=UTF-8"; | 172 contentType = "text/plain;charset=UTF-8"; |
| 167 } | 173 } |
| 168 // TODO(yhirano): Add the URLSearchParams case. | 174 // TODO(yhirano): Add the URLSearchParams case. |
|
tyoshino (SeeGerritForStatus)
2016/07/21 07:30:28
Remove this TODO
e_hakkinen
2016/07/21 12:02:25
Done.
| |
| 169 Response* response = create(scriptState, bodyBuffer, contentType, ResponseIn it(init, exceptionState), exceptionState); | 175 Response* response = create(scriptState, bodyBuffer, contentType, ResponseIn it(init, exceptionState), exceptionState); |
| 170 if (!exceptionState.hadException() && !reader.isEmpty()) { | 176 if (!exceptionState.hadException() && !reader.isEmpty()) { |
| 171 // Add a hidden reference so that the weak persistent in the | 177 // Add a hidden reference so that the weak persistent in the |
| 172 // ReadableStreamDataConsumerHandle will be valid as long as the | 178 // ReadableStreamDataConsumerHandle will be valid as long as the |
| 173 // Response is valid. | 179 // Response is valid. |
| 174 v8::Local<v8::Value> wrapper = toV8(response, scriptState); | 180 v8::Local<v8::Value> wrapper = toV8(response, scriptState); |
| 175 if (wrapper.IsEmpty()) { | 181 if (wrapper.IsEmpty()) { |
| 176 exceptionState.throwTypeError("Cannot create a Response wrapper"); | 182 exceptionState.throwTypeError("Cannot create a Response wrapper"); |
| 177 return nullptr; | 183 return nullptr; |
| 178 } | 184 } |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 } | 453 } |
| 448 | 454 |
| 449 DEFINE_TRACE(Response) | 455 DEFINE_TRACE(Response) |
| 450 { | 456 { |
| 451 Body::trace(visitor); | 457 Body::trace(visitor); |
| 452 visitor->trace(m_response); | 458 visitor->trace(m_response); |
| 453 visitor->trace(m_headers); | 459 visitor->trace(m_headers); |
| 454 } | 460 } |
| 455 | 461 |
| 456 } // namespace blink | 462 } // namespace blink |
| OLD | NEW |