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

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

Issue 478693005: Oilpan: Ship Oilpan for serviceworkers/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | Annotate | Revision Log
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 "core/fileapi/Blob.h" 9 #include "core/fileapi/Blob.h"
10 #include "modules/serviceworkers/FetchBodyStream.h" 10 #include "modules/serviceworkers/FetchBodyStream.h"
11 #include "modules/serviceworkers/ResponseInit.h" 11 #include "modules/serviceworkers/ResponseInit.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Response); 15 Response* Response::create(Blob* body, const Dictionary& responseInit, Exception State& exceptionState)
16
17 PassRefPtrWillBeRawPtr<Response> Response::create(Blob* body, const Dictionary& responseInit, ExceptionState& exceptionState)
18 { 16 {
19 return create(body, ResponseInit(responseInit), exceptionState); 17 return create(body, ResponseInit(responseInit), exceptionState);
20 } 18 }
21 19
22 PassRefPtrWillBeRawPtr<Response> Response::create(const String& body, const Dict ionary& responseInit, ExceptionState& exceptionState) 20 Response* Response::create(const String& body, const Dictionary& responseInit, E xceptionState& exceptionState)
23 { 21 {
24 OwnPtr<BlobData> blobData = BlobData::create(); 22 OwnPtr<BlobData> blobData = BlobData::create();
25 blobData->appendText(body, false); 23 blobData->appendText(body, false);
26 // "Set |Content-Type| to `text/plain;charset=UTF-8`." 24 // "Set |Content-Type| to `text/plain;charset=UTF-8`."
27 blobData->setContentType("text/plain;charset=UTF-8"); 25 blobData->setContentType("text/plain;charset=UTF-8");
28 const long long length = blobData->length(); 26 const long long length = blobData->length();
29 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData .release(), length)); 27 RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData .release(), length));
30 return create(blob.get(), ResponseInit(responseInit), exceptionState); 28 return create(blob.get(), ResponseInit(responseInit), exceptionState);
31 } 29 }
32 30
33 PassRefPtrWillBeRawPtr<Response> Response::create(Blob* body, const ResponseInit & responseInit, ExceptionState& exceptionState) 31 Response* Response::create(Blob* body, const ResponseInit& responseInit, Excepti onState& exceptionState)
34 { 32 {
35 // "1. If |init|'s status member is not in the range 200 to 599, throw a 33 // "1. If |init|'s status member is not in the range 200 to 599, throw a
36 // RangeError." 34 // RangeError."
37 if (responseInit.status < 200 || 599 < responseInit.status) { 35 if (responseInit.status < 200 || 599 < responseInit.status) {
38 exceptionState.throwRangeError("Invalid status"); 36 exceptionState.throwRangeError("Invalid status");
39 return nullptr; 37 return 0;
40 } 38 }
41 39
42 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase 40 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase
43 // token production, throw a TypeError." 41 // token production, throw a TypeError."
44 42
45 // "3. Let |r| be a new Response object, associated with a new response, 43 // "3. Let |r| be a new Response object, associated with a new response,
46 // Headers object, and FetchBodyStream object." 44 // Headers object, and FetchBodyStream object."
47 RefPtrWillBeRawPtr<Response> r = adoptRefWillBeNoop(new Response()); 45 Response* r = new Response();
48 46
49 // "4. Set |r|'s response's status to |init|'s status member." 47 // "4. Set |r|'s response's status to |init|'s status member."
50 r->m_response->setStatus(responseInit.status); 48 r->m_response->setStatus(responseInit.status);
51 49
52 // "5. Set |r|'s response's status message to |init|'s statusText member." 50 // "5. Set |r|'s response's status message to |init|'s statusText member."
53 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); 51 r->m_response->setStatusMessage(AtomicString(responseInit.statusText));
54 52
55 // "6. If |init|'s headers member is present, run these substeps:" 53 // "6. If |init|'s headers member is present, run these substeps:"
56 if (responseInit.headers) { 54 if (responseInit.headers) {
57 // "1. Empty |r|'s response's header list." 55 // "1. Empty |r|'s response's header list."
58 r->m_response->headerList()->clearList(); 56 r->m_response->headerList()->clearList();
59 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow 57 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow
60 // any exceptions." 58 // any exceptions."
61 r->m_headers->fillWith(responseInit.headers.get(), exceptionState); 59 r->m_headers->fillWith(responseInit.headers.get(), exceptionState);
62 if (exceptionState.hadException()) 60 if (exceptionState.hadException())
63 return nullptr; 61 return 0;
64 } else if (!responseInit.headersDictionary.isUndefinedOrNull()) { 62 } else if (!responseInit.headersDictionary.isUndefinedOrNull()) {
65 // "1. Empty |r|'s response's header list." 63 // "1. Empty |r|'s response's header list."
66 r->m_response->headerList()->clearList(); 64 r->m_response->headerList()->clearList();
67 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow 65 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow
68 // any exceptions." 66 // any exceptions."
69 r->m_headers->fillWith(responseInit.headersDictionary, exceptionState); 67 r->m_headers->fillWith(responseInit.headersDictionary, exceptionState);
70 if (exceptionState.hadException()) 68 if (exceptionState.hadException())
71 return nullptr; 69 return 0;
72 } 70 }
73 // "7. If body is given, run these substeps:" 71 // "7. If body is given, run these substeps:"
74 if (body) { 72 if (body) {
75 // "1. Let |stream| and |Content-Type| be the result of extracting body. " 73 // "1. Let |stream| and |Content-Type| be the result of extracting body. "
76 // "2. Set |r|'s response's body to |stream|." 74 // "2. Set |r|'s response's body to |stream|."
77 // "3. If |Content-Type| is non-null and |r|'s response's header list 75 // "3. If |Content-Type| is non-null and |r|'s response's header list
78 // contains no header named `Content-Type`, append `Content-Type`/ 76 // contains no header named `Content-Type`, append `Content-Type`/
79 // |Content-Type| to |r|'s response's header list." 77 // |Content-Type| to |r|'s response's header list."
80 r->m_response->setBlobDataHandle(body->blobDataHandle()); 78 r->m_response->setBlobDataHandle(body->blobDataHandle());
81 if (!body->type().isNull() && !r->m_response->headerList()->has("Content -Type")) 79 if (!body->type().isNull() && !r->m_response->headerList()->has("Content -Type"))
82 r->m_response->headerList()->append("Content-Type", body->type()); 80 r->m_response->headerList()->append("Content-Type", body->type());
83 } 81 }
84 82
85 // FIXME: "8. Set |r|'s FetchBodyStream object's MIME type to the result of 83 // FIXME: "8. Set |r|'s FetchBodyStream object's MIME type to the result of
86 // extracting a MIME type from |r|'s response's header list." 84 // extracting a MIME type from |r|'s response's header list."
87 85
88 // "9. Return |r|." 86 // "9. Return |r|."
89 return r.release(); 87 return r;
90 } 88 }
91 89
92 PassRefPtrWillBeRawPtr<Response> Response::create(PassRefPtrWillBeRawPtr<FetchRe sponseData> response) 90 Response* Response::create(FetchResponseData* response)
93 { 91 {
94 return adoptRefWillBeNoop(new Response(response)); 92 return new Response(response);
95 } 93 }
96 94
97 String Response::type() const 95 String Response::type() const
98 { 96 {
99 // "The type attribute's getter must return response's type." 97 // "The type attribute's getter must return response's type."
100 switch (m_response->type()) { 98 switch (m_response->type()) {
101 case FetchResponseData::BasicType: 99 case FetchResponseData::BasicType:
102 return "basic"; 100 return "basic";
103 case FetchResponseData::CORSType: 101 case FetchResponseData::CORSType:
104 return "cors"; 102 return "cors";
(...skipping 25 matching lines...) Expand all
130 // "The status attribute's getter must return response's status." 128 // "The status attribute's getter must return response's status."
131 return m_response->status(); 129 return m_response->status();
132 } 130 }
133 131
134 String Response::statusText() const 132 String Response::statusText() const
135 { 133 {
136 // "The statusText attribute's getter must return response's status message. " 134 // "The statusText attribute's getter must return response's status message. "
137 return m_response->statusMessage(); 135 return m_response->statusMessage();
138 } 136 }
139 137
140 PassRefPtrWillBeRawPtr<Headers> Response::headers() const 138 Headers* Response::headers() const
141 { 139 {
142 // "The headers attribute's getter must return the associated Headers object ." 140 // "The headers attribute's getter must return the associated Headers object ."
143 return m_headers; 141 return m_headers;
144 } 142 }
145 143
146 PassRefPtrWillBeRawPtr<FetchBodyStream> Response::body(ExecutionContext* context ) 144 FetchBodyStream* Response::body(ExecutionContext* context)
147 { 145 {
148 if (!m_response->blobDataHandle()) 146 if (!m_response->blobDataHandle())
149 return nullptr; 147 return 0;
150 if (!m_fetchBodyStream) 148 if (!m_fetchBodyStream)
151 m_fetchBodyStream = FetchBodyStream::create(context, m_response->blobDat aHandle()); 149 m_fetchBodyStream = FetchBodyStream::create(context, m_response->blobDat aHandle());
152 return m_fetchBodyStream; 150 return m_fetchBodyStream;
153 } 151 }
154 152
155 void Response::populateWebServiceWorkerResponse(WebServiceWorkerResponse& respon se) 153 void Response::populateWebServiceWorkerResponse(WebServiceWorkerResponse& respon se)
156 { 154 {
157 m_response->populateWebServiceWorkerResponse(response); 155 m_response->populateWebServiceWorkerResponse(response);
158 } 156 }
159 157
160 Response::Response() 158 Response::Response()
161 : m_response(FetchResponseData::create()) 159 : m_response(FetchResponseData::create())
162 , m_headers(Headers::create(m_response->headerList())) 160 , m_headers(Headers::create(m_response->headerList()))
163 { 161 {
164 m_headers->setGuard(Headers::ResponseGuard); 162 m_headers->setGuard(Headers::ResponseGuard);
165 ScriptWrappable::init(this); 163 ScriptWrappable::init(this);
166 } 164 }
167 165
168 Response::Response(PassRefPtrWillBeRawPtr<FetchResponseData> response) 166 Response::Response(FetchResponseData* response)
169 : m_response(response) 167 : m_response(response)
170 , m_headers(Headers::create(m_response->headerList())) 168 , m_headers(Headers::create(m_response->headerList()))
171 { 169 {
172 m_headers->setGuard(Headers::ResponseGuard); 170 m_headers->setGuard(Headers::ResponseGuard);
173 ScriptWrappable::init(this); 171 ScriptWrappable::init(this);
174 } 172 }
175 173
176 void Response::trace(Visitor* visitor) 174 void Response::trace(Visitor* visitor)
177 { 175 {
178 visitor->trace(m_response); 176 visitor->trace(m_response);
179 visitor->trace(m_headers); 177 visitor->trace(m_headers);
180 visitor->trace(m_fetchBodyStream); 178 visitor->trace(m_fetchBodyStream);
181 } 179 }
182 180
183 } // namespace blink 181 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698