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 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
Response& webResponse) | 20 FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
Response& webResponse) |
20 { | 21 { |
21 FetchResponseData* response = 0; | 22 FetchResponseData* response = 0; |
22 if (200 <= webResponse.status() && webResponse.status() < 300) | 23 if (200 <= webResponse.status() && webResponse.status() < 300) |
23 response = FetchResponseData::create(); | 24 response = FetchResponseData::create(); |
(...skipping 29 matching lines...) Expand all Loading... |
53 { | 54 { |
54 OwnPtr<BlobData> blobData = BlobData::create(); | 55 OwnPtr<BlobData> blobData = BlobData::create(); |
55 blobData->appendText(body, false); | 56 blobData->appendText(body, false); |
56 // "Set |Content-Type| to `text/plain;charset=UTF-8`." | 57 // "Set |Content-Type| to `text/plain;charset=UTF-8`." |
57 blobData->setContentType("text/plain;charset=UTF-8"); | 58 blobData->setContentType("text/plain;charset=UTF-8"); |
58 const long long length = blobData->length(); | 59 const long long length = blobData->length(); |
59 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData
.release(), length)); | 60 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData
.release(), length)); |
60 return create(blob.get(), ResponseInit(responseInit), exceptionState); | 61 return create(blob.get(), ResponseInit(responseInit), exceptionState); |
61 } | 62 } |
62 | 63 |
| 64 Response* Response::create(const ArrayBuffer* body, const Dictionary& responseIn
it, ExceptionState& exceptionState) |
| 65 { |
| 66 OwnPtr<BlobData> blobData = BlobData::create(); |
| 67 blobData->appendArrayBuffer(body); |
| 68 const long long length = blobData->length(); |
| 69 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData
.release(), length)); |
| 70 return create(blob.get(), ResponseInit(responseInit), exceptionState); |
| 71 } |
| 72 |
63 Response* Response::create(Blob* body, const ResponseInit& responseInit, Excepti
onState& exceptionState) | 73 Response* Response::create(Blob* body, const ResponseInit& responseInit, Excepti
onState& exceptionState) |
64 { | 74 { |
65 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 75 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
66 // RangeError." | 76 // RangeError." |
67 if (responseInit.status < 200 || 599 < responseInit.status) { | 77 if (responseInit.status < 200 || 599 < responseInit.status) { |
68 exceptionState.throwRangeError("Invalid status"); | 78 exceptionState.throwRangeError("Invalid status"); |
69 return 0; | 79 return 0; |
70 } | 80 } |
71 | 81 |
72 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase | 82 // 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... |
215 } | 225 } |
216 | 226 |
217 void Response::trace(Visitor* visitor) | 227 void Response::trace(Visitor* visitor) |
218 { | 228 { |
219 visitor->trace(m_response); | 229 visitor->trace(m_response); |
220 visitor->trace(m_headers); | 230 visitor->trace(m_headers); |
221 visitor->trace(m_fetchBodyStream); | 231 visitor->trace(m_fetchBodyStream); |
222 } | 232 } |
223 | 233 |
224 } // namespace blink | 234 } // namespace blink |
OLD | NEW |