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 "core/fileapi/Blob.h" | 9 #include "core/fileapi/Blob.h" |
10 #include "modules/serviceworkers/ResponseInit.h" | 10 #include "modules/serviceworkers/ResponseInit.h" |
11 | 11 |
12 namespace WebCore { | 12 namespace WebCore { |
13 | 13 |
14 PassRefPtr<Response> Response::create(Blob* body, const Dictionary& responseInit
, ExceptionState& exceptionState) | 14 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Response); |
| 15 |
| 16 PassRefPtrWillBeRawPtr<Response> Response::create(Blob* body, const Dictionary&
responseInit, ExceptionState& exceptionState) |
15 { | 17 { |
16 return create(body, ResponseInit(responseInit), exceptionState); | 18 return create(body, ResponseInit(responseInit), exceptionState); |
17 } | 19 } |
18 | 20 |
19 PassRefPtr<Response> Response::create(Blob* body, const ResponseInit& responseIn
it, ExceptionState& exceptionState) | 21 PassRefPtrWillBeRawPtr<Response> Response::create(Blob* body, const ResponseInit
& responseInit, ExceptionState& exceptionState) |
20 { | 22 { |
21 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 23 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
22 // RangeError." | 24 // RangeError." |
23 if (responseInit.status < 200 || 599 < responseInit.status) { | 25 if (responseInit.status < 200 || 599 < responseInit.status) { |
24 exceptionState.throwRangeError("Invalid status"); | 26 exceptionState.throwRangeError("Invalid status"); |
25 return nullptr; | 27 return nullptr; |
26 } | 28 } |
27 | 29 |
28 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase | 30 // FIXME: "2. If |init|'s statusText member does not match the Reason-Phrase |
29 // token production, throw a TypeError." | 31 // token production, throw a TypeError." |
30 | 32 |
31 // "3. Let |r| be a new Response object, associated with a new response, | 33 // "3. Let |r| be a new Response object, associated with a new response, |
32 // Headers object, and FetchBodyStream object." | 34 // Headers object, and FetchBodyStream object." |
33 RefPtr<Response> r = adoptRef(new Response()); | 35 RefPtrWillBeRawPtr<Response> r = adoptRefWillBeNoop(new Response()); |
34 | 36 |
35 // "4. Set |r|'s response's status to |init|'s status member." | 37 // "4. Set |r|'s response's status to |init|'s status member." |
36 r->m_response->setStatus(responseInit.status); | 38 r->m_response->setStatus(responseInit.status); |
37 | 39 |
38 // "5. Set |r|'s response's status message to |init|'s statusText member." | 40 // "5. Set |r|'s response's status message to |init|'s statusText member." |
39 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); | 41 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); |
40 | 42 |
41 // "6. If |init|'s headers member is present, run these substeps:" | 43 // "6. If |init|'s headers member is present, run these substeps:" |
42 if (responseInit.headers) { | 44 if (responseInit.headers) { |
43 // "1. Empty |r|'s response's header list." | 45 // "1. Empty |r|'s response's header list." |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // extracting a MIME type from |r|'s response's header list." | 78 // extracting a MIME type from |r|'s response's header list." |
77 | 79 |
78 // FIXME: "9. Set |r|'s FetchBodyStream object's codings to the result of | 80 // FIXME: "9. Set |r|'s FetchBodyStream object's codings to the result of |
79 // parsing `Content-Encoding` in |r|'s response's header list if that | 81 // parsing `Content-Encoding` in |r|'s response's header list if that |
80 // result is not failure." | 82 // result is not failure." |
81 | 83 |
82 // "10. Return r." | 84 // "10. Return r." |
83 return r.release(); | 85 return r.release(); |
84 } | 86 } |
85 | 87 |
86 PassRefPtr<Response> Response::create(PassRefPtr<FetchResponseData> response) | 88 PassRefPtrWillBeRawPtr<Response> Response::create(PassRefPtrWillBeRawPtr<FetchRe
sponseData> response) |
87 { | 89 { |
88 return adoptRef(new Response(response)); | 90 return adoptRefWillBeNoop(new Response(response)); |
89 } | 91 } |
90 | 92 |
91 String Response::type() const | 93 String Response::type() const |
92 { | 94 { |
93 // "The type attribute's getter must return response's type." | 95 // "The type attribute's getter must return response's type." |
94 switch (m_response->type()) { | 96 switch (m_response->type()) { |
95 case FetchResponseData::BasicType: | 97 case FetchResponseData::BasicType: |
96 return "basic"; | 98 return "basic"; |
97 case FetchResponseData::CORSType: | 99 case FetchResponseData::CORSType: |
98 return "cors"; | 100 return "cors"; |
(...skipping 25 matching lines...) Expand all Loading... |
124 // "The status attribute's getter must return response's status." | 126 // "The status attribute's getter must return response's status." |
125 return m_response->status(); | 127 return m_response->status(); |
126 } | 128 } |
127 | 129 |
128 String Response::statusText() const | 130 String Response::statusText() const |
129 { | 131 { |
130 // "The statusText attribute's getter must return response's status message.
" | 132 // "The statusText attribute's getter must return response's status message.
" |
131 return m_response->statusMessage(); | 133 return m_response->statusMessage(); |
132 } | 134 } |
133 | 135 |
134 PassRefPtr<Headers> Response::headers() const | 136 PassRefPtrWillBeRawPtr<Headers> Response::headers() const |
135 { | 137 { |
136 // "The headers attribute's getter must return the associated Headers object
." | 138 // "The headers attribute's getter must return the associated Headers object
." |
137 return m_headers; | 139 return m_headers; |
138 } | 140 } |
139 | 141 |
140 void Response::populateWebServiceWorkerResponse(blink::WebServiceWorkerResponse&
response) | 142 void Response::populateWebServiceWorkerResponse(blink::WebServiceWorkerResponse&
response) |
141 { | 143 { |
142 m_response->populateWebServiceWorkerResponse(response); | 144 m_response->populateWebServiceWorkerResponse(response); |
143 } | 145 } |
144 | 146 |
145 Response::Response() | 147 Response::Response() |
146 : m_response(FetchResponseData::create()) | 148 : m_response(FetchResponseData::create()) |
147 , m_headers(Headers::create(m_response->headerList())) | 149 , m_headers(Headers::create(m_response->headerList())) |
148 { | 150 { |
149 m_headers->setGuard(Headers::ResponseGuard); | 151 m_headers->setGuard(Headers::ResponseGuard); |
150 ScriptWrappable::init(this); | 152 ScriptWrappable::init(this); |
151 } | 153 } |
152 | 154 |
153 Response::Response(PassRefPtr<FetchResponseData> response) | 155 Response::Response(PassRefPtrWillBeRawPtr<FetchResponseData> response) |
154 : m_response(response) | 156 : m_response(response) |
155 , m_headers(Headers::create(m_response->headerList())) | 157 , m_headers(Headers::create(m_response->headerList())) |
156 { | 158 { |
157 m_headers->setGuard(Headers::ResponseGuard); | 159 m_headers->setGuard(Headers::ResponseGuard); |
158 ScriptWrappable::init(this); | 160 ScriptWrappable::init(this); |
159 } | 161 } |
160 | 162 |
| 163 void Response::trace(Visitor* visitor) |
| 164 { |
| 165 visitor->trace(m_response); |
| 166 visitor->trace(m_headers); |
| 167 } |
| 168 |
161 } // namespace WebCore | 169 } // namespace WebCore |
OLD | NEW |