Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: Source/modules/serviceworkers/Response.cpp

Issue 556563002: Adding ArrayBuffer support to ServiceWorker Response and tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Uncommented assert Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698