| 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/fileapi/Blob.h" | 10 #include "core/fileapi/Blob.h" |
| 11 #include "modules/serviceworkers/FetchBodyStream.h" | 11 #include "modules/serviceworkers/FetchBodyStream.h" |
| 12 #include "modules/serviceworkers/ResponseInit.h" | 12 #include "modules/serviceworkers/ResponseInit.h" |
| 13 #include "public/platform/WebServiceWorkerResponse.h" | 13 #include "public/platform/WebServiceWorkerResponse.h" |
| 14 #include "wtf/ArrayBuffer.h" | 14 #include "wtf/ArrayBuffer.h" |
| 15 #include "wtf/ArrayBufferView.h" |
| 16 #include "wtf/RefPtr.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
Response& webResponse) | 22 FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
Response& webResponse) |
| 21 { | 23 { |
| 22 FetchResponseData* response = 0; | 24 FetchResponseData* response = 0; |
| 23 if (200 <= webResponse.status() && webResponse.status() < 300) | 25 if (200 <= webResponse.status() && webResponse.status() < 300) |
| 24 response = FetchResponseData::create(); | 26 response = FetchResponseData::create(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 65 |
| 64 Response* Response::create(const ArrayBuffer* body, const Dictionary& responseIn
it, ExceptionState& exceptionState) | 66 Response* Response::create(const ArrayBuffer* body, const Dictionary& responseIn
it, ExceptionState& exceptionState) |
| 65 { | 67 { |
| 66 OwnPtr<BlobData> blobData = BlobData::create(); | 68 OwnPtr<BlobData> blobData = BlobData::create(); |
| 67 blobData->appendArrayBuffer(body); | 69 blobData->appendArrayBuffer(body); |
| 68 const long long length = blobData->length(); | 70 const long long length = blobData->length(); |
| 69 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData
.release(), length)); | 71 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData
.release(), length)); |
| 70 return create(blob.get(), ResponseInit(responseInit), exceptionState); | 72 return create(blob.get(), ResponseInit(responseInit), exceptionState); |
| 71 } | 73 } |
| 72 | 74 |
| 75 Response* Response::create(const ArrayBufferView* body, const Dictionary& respon
seInit, ExceptionState& exceptionState) |
| 76 { |
| 77 OwnPtr<BlobData> blobData = BlobData::create(); |
| 78 blobData->appendArrayBufferView(body); |
| 79 const long long length = blobData->length(); |
| 80 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData
.release(), length)); |
| 81 return create(blob.get(), ResponseInit(responseInit), exceptionState); |
| 82 } |
| 83 |
| 73 Response* Response::create(Blob* body, const ResponseInit& responseInit, Excepti
onState& exceptionState) | 84 Response* Response::create(Blob* body, const ResponseInit& responseInit, Excepti
onState& exceptionState) |
| 74 { | 85 { |
| 75 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 86 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
| 76 // RangeError." | 87 // RangeError." |
| 77 if (responseInit.status < 200 || 599 < responseInit.status) { | 88 if (responseInit.status < 200 || 599 < responseInit.status) { |
| 78 exceptionState.throwRangeError("Invalid status"); | 89 exceptionState.throwRangeError("Invalid status"); |
| 79 return 0; | 90 return 0; |
| 80 } | 91 } |
| 81 | 92 |
| 82 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase | 93 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 236 } |
| 226 | 237 |
| 227 void Response::trace(Visitor* visitor) | 238 void Response::trace(Visitor* visitor) |
| 228 { | 239 { |
| 229 visitor->trace(m_response); | 240 visitor->trace(m_response); |
| 230 visitor->trace(m_headers); | 241 visitor->trace(m_headers); |
| 231 visitor->trace(m_fetchBodyStream); | 242 visitor->trace(m_fetchBodyStream); |
| 232 } | 243 } |
| 233 | 244 |
| 234 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |