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