| 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 "config.h" | 5 #include "config.h" |
| 6 #include "Response.h" | 6 #include "Response.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "core/dom/DOMArrayBuffer.h" |
| 11 #include "core/dom/DOMArrayBufferView.h" |
| 10 #include "core/fileapi/Blob.h" | 12 #include "core/fileapi/Blob.h" |
| 11 #include "modules/serviceworkers/ResponseInit.h" | 13 #include "modules/serviceworkers/ResponseInit.h" |
| 12 #include "public/platform/WebServiceWorkerResponse.h" | 14 #include "public/platform/WebServiceWorkerResponse.h" |
| 13 #include "wtf/ArrayBuffer.h" | |
| 14 #include "wtf/ArrayBufferView.h" | |
| 15 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
Response& webResponse) | 21 FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
Response& webResponse) |
| 22 { | 22 { |
| 23 FetchResponseData* response = 0; | 23 FetchResponseData* response = 0; |
| 24 if (200 <= webResponse.status() && webResponse.status() < 300) | 24 if (200 <= webResponse.status() && webResponse.status() < 300) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 { | 66 { |
| 67 OwnPtr<BlobData> blobData = BlobData::create(); | 67 OwnPtr<BlobData> blobData = BlobData::create(); |
| 68 blobData->appendText(body, false); | 68 blobData->appendText(body, false); |
| 69 // "Set |Content-Type| to `text/plain;charset=UTF-8`." | 69 // "Set |Content-Type| to `text/plain;charset=UTF-8`." |
| 70 blobData->setContentType("text/plain;charset=UTF-8"); | 70 blobData->setContentType("text/plain;charset=UTF-8"); |
| 71 const long long length = blobData->length(); | 71 const long long length = blobData->length(); |
| 72 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); | 72 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); |
| 73 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); | 73 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); |
| 74 } | 74 } |
| 75 | 75 |
| 76 Response* Response::create(ExecutionContext* context, const ArrayBuffer* body, c
onst Dictionary& responseInit, ExceptionState& exceptionState) | 76 Response* Response::create(ExecutionContext* context, const DOMArrayBuffer* body
, const Dictionary& responseInit, ExceptionState& exceptionState) |
| 77 { | 77 { |
| 78 OwnPtr<BlobData> blobData = BlobData::create(); | 78 OwnPtr<BlobData> blobData = BlobData::create(); |
| 79 blobData->appendArrayBuffer(body); | 79 blobData->appendArrayBuffer(body->buffer()); |
| 80 const long long length = blobData->length(); | 80 const long long length = blobData->length(); |
| 81 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); | 81 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); |
| 82 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); | 82 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); |
| 83 } | 83 } |
| 84 | 84 |
| 85 Response* Response::create(ExecutionContext* context, const ArrayBufferView* bod
y, const Dictionary& responseInit, ExceptionState& exceptionState) | 85 Response* Response::create(ExecutionContext* context, const DOMArrayBufferView*
body, const Dictionary& responseInit, ExceptionState& exceptionState) |
| 86 { | 86 { |
| 87 OwnPtr<BlobData> blobData = BlobData::create(); | 87 OwnPtr<BlobData> blobData = BlobData::create(); |
| 88 blobData->appendArrayBufferView(body); | 88 blobData->appendArrayBufferView(body->view()); |
| 89 const long long length = blobData->length(); | 89 const long long length = blobData->length(); |
| 90 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); | 90 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); |
| 91 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); | 91 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); |
| 92 } | 92 } |
| 93 | 93 |
| 94 Response* Response::create(ExecutionContext* context, Blob* body, const Response
Init& responseInit, ExceptionState& exceptionState) | 94 Response* Response::create(ExecutionContext* context, Blob* body, const Response
Init& responseInit, ExceptionState& exceptionState) |
| 95 { | 95 { |
| 96 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 96 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
| 97 // RangeError." | 97 // RangeError." |
| 98 if (responseInit.status < 200 || 599 < responseInit.status) { | 98 if (responseInit.status < 200 || 599 < responseInit.status) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 void Response::trace(Visitor* visitor) | 265 void Response::trace(Visitor* visitor) |
| 266 { | 266 { |
| 267 Body::trace(visitor); | 267 Body::trace(visitor); |
| 268 visitor->trace(m_response); | 268 visitor->trace(m_response); |
| 269 visitor->trace(m_headers); | 269 visitor->trace(m_headers); |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace blink | 272 } // namespace blink |
| OLD | NEW |