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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 { | 68 { |
69 OwnPtr<BlobData> blobData = BlobData::create(); | 69 OwnPtr<BlobData> blobData = BlobData::create(); |
70 blobData->appendText(body, false); | 70 blobData->appendText(body, false); |
71 // "Set |Content-Type| to `text/plain;charset=UTF-8`." | 71 // "Set |Content-Type| to `text/plain;charset=UTF-8`." |
72 blobData->setContentType("text/plain;charset=UTF-8"); | 72 blobData->setContentType("text/plain;charset=UTF-8"); |
73 const long long length = blobData->length(); | 73 const long long length = blobData->length(); |
74 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); | 74 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); |
75 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); | 75 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); |
76 } | 76 } |
77 | 77 |
78 Response* Response::create(ExecutionContext* context, const ArrayBuffer* body, c
onst Dictionary& responseInit, ExceptionState& exceptionState) | 78 Response* Response::create(ExecutionContext* context, const DOMArrayBuffer* body
, const Dictionary& responseInit, ExceptionState& exceptionState) |
79 { | 79 { |
80 OwnPtr<BlobData> blobData = BlobData::create(); | 80 OwnPtr<BlobData> blobData = BlobData::create(); |
81 blobData->appendArrayBuffer(body); | 81 blobData->appendArrayBuffer(body->buffer()); |
82 const long long length = blobData->length(); | 82 const long long length = blobData->length(); |
83 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); | 83 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); |
84 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); | 84 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); |
85 } | 85 } |
86 | 86 |
87 Response* Response::create(ExecutionContext* context, const ArrayBufferView* bod
y, const Dictionary& responseInit, ExceptionState& exceptionState) | 87 Response* Response::create(ExecutionContext* context, const DOMArrayBufferView*
body, const Dictionary& responseInit, ExceptionState& exceptionState) |
88 { | 88 { |
89 OwnPtr<BlobData> blobData = BlobData::create(); | 89 OwnPtr<BlobData> blobData = BlobData::create(); |
90 blobData->appendArrayBufferView(body); | 90 blobData->appendArrayBufferView(body->view()); |
91 const long long length = blobData->length(); | 91 const long long length = blobData->length(); |
92 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); | 92 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), length)
); |
93 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); | 93 return create(context, blob, ResponseInit(responseInit, exceptionState), exc
eptionState); |
94 } | 94 } |
95 | 95 |
96 Response* Response::create(ExecutionContext* context, Blob* body, const Response
Init& responseInit, ExceptionState& exceptionState) | 96 Response* Response::create(ExecutionContext* context, Blob* body, const Response
Init& responseInit, ExceptionState& exceptionState) |
97 { | 97 { |
98 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 98 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
99 // RangeError." | 99 // RangeError." |
100 if (responseInit.status < 200 || 599 < responseInit.status) { | 100 if (responseInit.status < 200 || 599 < responseInit.status) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 264 } |
265 | 265 |
266 void Response::trace(Visitor* visitor) | 266 void Response::trace(Visitor* visitor) |
267 { | 267 { |
268 Body::trace(visitor); | 268 Body::trace(visitor); |
269 visitor->trace(m_response); | 269 visitor->trace(m_response); |
270 visitor->trace(m_headers); | 270 visitor->trace(m_headers); |
271 } | 271 } |
272 | 272 |
273 } // namespace blink | 273 } // namespace blink |
OLD | NEW |