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

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

Issue 307063002: ServiceWorker: Add a Response ctor that accepts the body as a Blob (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: use BlobDataHandle Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/serviceworkers/Response.h ('k') | Source/modules/serviceworkers/Response.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/v8/Dictionary.h" 8 #include "bindings/v8/Dictionary.h"
9 #include "core/fileapi/Blob.h"
9 #include "modules/serviceworkers/ResponseInit.h" 10 #include "modules/serviceworkers/ResponseInit.h"
10 #include "platform/NotImplemented.h" 11 #include "platform/NotImplemented.h"
11 #include "public/platform/WebServiceWorkerResponse.h" 12 #include "public/platform/WebServiceWorkerResponse.h"
12 13
13 namespace WebCore { 14 namespace WebCore {
14 15
15 PassRefPtr<Response> Response::create() 16 // FIXME: Remove this legacy function when the required Chromium-side patch land s.
17 PassRefPtr<Response> Response::create(const Dictionary& responseInit)
16 { 18 {
17 return create(Dictionary()); 19 return adoptRef(new Response(nullptr, ResponseInit(responseInit)));
18 } 20 }
19 21
20 PassRefPtr<Response> Response::create(const Dictionary& responseInit) 22 PassRefPtr<Response> Response::create(Blob* body, const Dictionary& responseInit )
21 { 23 {
22 return adoptRef(new Response(ResponseInit(responseInit))); 24 // FIXME: Maybe append or override content-length and content-type headers u sing the blob. The spec will clarify what to do:
25 // https://github.com/slightlyoff/ServiceWorker/issues/192
26 return adoptRef(new Response(body->blobDataHandle(), ResponseInit(responseIn it)));
tkent 2014/06/03 02:13:41 This will crash if |body| is null.
falken 2014/06/03 08:12:27 Great point. Done. I also added a test for it in t
23 } 27 }
24 28
25 PassRefPtr<HeaderMap> Response::headers() const 29 PassRefPtr<HeaderMap> Response::headers() const
26 { 30 {
27 // FIXME: Implement. Spec will eventually whitelist allowable headers. 31 // FIXME: Implement. Spec will eventually whitelist allowable headers.
28 return m_headers; 32 return m_headers;
29 } 33 }
30 34
31 void Response::populateWebServiceWorkerResponse(blink::WebServiceWorkerResponse& response) 35 void Response::populateWebServiceWorkerResponse(blink::WebServiceWorkerResponse& response)
32 { 36 {
33 response.setStatus(status()); 37 response.setStatus(status());
34 response.setStatusText(statusText()); 38 response.setStatusText(statusText());
35 response.setHeaders(m_headers->headerMap()); 39 response.setHeaders(m_headers->headerMap());
40 response.setBlobDataHandle(m_blobDataHandle);
36 } 41 }
37 42
38 Response::Response(const ResponseInit& responseInit) 43 Response::Response(PassRefPtr<BlobDataHandle> blobDataHandle, const ResponseInit & responseInit)
39 : m_status(responseInit.status) 44 : m_status(responseInit.status)
40 , m_statusText(responseInit.statusText) 45 , m_statusText(responseInit.statusText)
41 , m_headers(responseInit.headers) 46 , m_headers(responseInit.headers)
47 , m_blobDataHandle(blobDataHandle)
42 { 48 {
43 ScriptWrappable::init(this); 49 ScriptWrappable::init(this);
44 50
45 if (!m_headers) 51 if (!m_headers)
46 m_headers = HeaderMap::create(); 52 m_headers = HeaderMap::create();
47 } 53 }
48 54
49 } // namespace WebCore 55 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/Response.h ('k') | Source/modules/serviceworkers/Response.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698