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 "modules/fetch/FetchResponseData.h" | 5 #include "modules/fetch/FetchResponseData.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
9 #include "core/fetch/FetchUtils.h" | 9 #include "core/fetch/FetchUtils.h" |
10 #include "modules/fetch/BodyStreamBuffer.h" | 10 #include "modules/fetch/BodyStreamBuffer.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return response; | 74 return response; |
75 } | 75 } |
76 | 76 |
77 FetchResponseData* FetchResponseData::createBasicFilteredResponse() const { | 77 FetchResponseData* FetchResponseData::createBasicFilteredResponse() const { |
78 DCHECK_EQ(m_type, DefaultType); | 78 DCHECK_EQ(m_type, DefaultType); |
79 // "A basic filtered response is a filtered response whose type is |basic|, | 79 // "A basic filtered response is a filtered response whose type is |basic|, |
80 // header list excludes any headers in internal response's header list whose | 80 // header list excludes any headers in internal response's header list whose |
81 // name is `Set-Cookie` or `Set-Cookie2`." | 81 // name is `Set-Cookie` or `Set-Cookie2`." |
82 FetchResponseData* response = | 82 FetchResponseData* response = |
83 new FetchResponseData(BasicType, m_status, m_statusMessage); | 83 new FetchResponseData(BasicType, m_status, m_statusMessage); |
84 response->m_url = m_url; | 84 response->setURLList(m_urlList); |
85 for (size_t i = 0; i < m_headerList->size(); ++i) { | 85 for (size_t i = 0; i < m_headerList->size(); ++i) { |
86 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); | 86 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); |
87 if (FetchUtils::isForbiddenResponseHeaderName(header->first)) | 87 if (FetchUtils::isForbiddenResponseHeaderName(header->first)) |
88 continue; | 88 continue; |
89 response->m_headerList->append(header->first, header->second); | 89 response->m_headerList->append(header->first, header->second); |
90 } | 90 } |
91 response->m_buffer = m_buffer; | 91 response->m_buffer = m_buffer; |
92 response->m_mimeType = m_mimeType; | 92 response->m_mimeType = m_mimeType; |
93 response->m_internalResponse = const_cast<FetchResponseData*>(this); | 93 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
94 return response; | 94 return response; |
(...skipping 15 matching lines...) Expand all Loading... |
110 DCHECK_EQ(m_type, DefaultType); | 110 DCHECK_EQ(m_type, DefaultType); |
111 // "A CORS filtered response is a filtered response whose type is |CORS|, | 111 // "A CORS filtered response is a filtered response whose type is |CORS|, |
112 // header list excludes all headers in internal response's header list, | 112 // header list excludes all headers in internal response's header list, |
113 // except those whose name is either one of `Cache-Control`, | 113 // except those whose name is either one of `Cache-Control`, |
114 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and | 114 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and |
115 // `Pragma`, and except those whose name is one of the values resulting from | 115 // `Pragma`, and except those whose name is one of the values resulting from |
116 // parsing `Access-Control-Expose-Headers` in internal response's header | 116 // parsing `Access-Control-Expose-Headers` in internal response's header |
117 // list." | 117 // list." |
118 FetchResponseData* response = | 118 FetchResponseData* response = |
119 new FetchResponseData(CORSType, m_status, m_statusMessage); | 119 new FetchResponseData(CORSType, m_status, m_statusMessage); |
120 response->m_url = m_url; | 120 response->setURLList(m_urlList); |
121 for (size_t i = 0; i < m_headerList->size(); ++i) { | 121 for (size_t i = 0; i < m_headerList->size(); ++i) { |
122 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); | 122 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); |
123 const String& name = header->first; | 123 const String& name = header->first; |
124 const bool explicitlyExposed = exposedHeaders.contains(name); | 124 const bool explicitlyExposed = exposedHeaders.contains(name); |
125 if (isOnAccessControlResponseHeaderWhitelist(name) || | 125 if (isOnAccessControlResponseHeaderWhitelist(name) || |
126 (explicitlyExposed && | 126 (explicitlyExposed && |
127 !FetchUtils::isForbiddenResponseHeaderName(name))) { | 127 !FetchUtils::isForbiddenResponseHeaderName(name))) { |
128 if (explicitlyExposed) | 128 if (explicitlyExposed) |
129 response->m_corsExposedHeaderNames.add(name); | 129 response->m_corsExposedHeaderNames.add(name); |
130 response->m_headerList->append(name, header->second); | 130 response->m_headerList->append(name, header->second); |
(...skipping 21 matching lines...) Expand all Loading... |
152 FetchResponseData* FetchResponseData::createOpaqueRedirectFilteredResponse() | 152 FetchResponseData* FetchResponseData::createOpaqueRedirectFilteredResponse() |
153 const { | 153 const { |
154 DCHECK_EQ(m_type, DefaultType); | 154 DCHECK_EQ(m_type, DefaultType); |
155 // "An opaque filtered response is a filtered response whose type is | 155 // "An opaque filtered response is a filtered response whose type is |
156 // 'opaqueredirect', status is 0, status message is the empty byte sequence, | 156 // 'opaqueredirect', status is 0, status message is the empty byte sequence, |
157 // header list is the empty list, body is null, and cache state is 'none'." | 157 // header list is the empty list, body is null, and cache state is 'none'." |
158 // | 158 // |
159 // https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect | 159 // https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect |
160 FetchResponseData* response = | 160 FetchResponseData* response = |
161 new FetchResponseData(OpaqueRedirectType, 0, ""); | 161 new FetchResponseData(OpaqueRedirectType, 0, ""); |
162 response->m_url = m_url; | 162 response->setURLList(m_urlList); |
163 response->m_internalResponse = const_cast<FetchResponseData*>(this); | 163 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
164 return response; | 164 return response; |
165 } | 165 } |
166 | 166 |
| 167 const KURL* FetchResponseData::url() const { |
| 168 // "A response has an associated url. It is a pointer to the last response URL |
| 169 // in response’s url list and null if response’s url list is the empty list." |
| 170 if (m_urlList.isEmpty()) |
| 171 return nullptr; |
| 172 return &m_urlList.back(); |
| 173 } |
| 174 |
167 String FetchResponseData::mimeType() const { | 175 String FetchResponseData::mimeType() const { |
168 return m_mimeType; | 176 return m_mimeType; |
169 } | 177 } |
170 | 178 |
171 BodyStreamBuffer* FetchResponseData::internalBuffer() const { | 179 BodyStreamBuffer* FetchResponseData::internalBuffer() const { |
172 if (m_internalResponse) { | 180 if (m_internalResponse) { |
173 return m_internalResponse->m_buffer; | 181 return m_internalResponse->m_buffer; |
174 } | 182 } |
175 return m_buffer; | 183 return m_buffer; |
176 } | 184 } |
177 | 185 |
178 String FetchResponseData::internalMIMEType() const { | 186 String FetchResponseData::internalMIMEType() const { |
179 if (m_internalResponse) { | 187 if (m_internalResponse) { |
180 return m_internalResponse->mimeType(); | 188 return m_internalResponse->mimeType(); |
181 } | 189 } |
182 return m_mimeType; | 190 return m_mimeType; |
183 } | 191 } |
184 | 192 |
| 193 void FetchResponseData::setURLList(const Vector<KURL>& urlList) { |
| 194 m_urlList = urlList; |
| 195 } |
| 196 |
185 FetchResponseData* FetchResponseData::clone(ScriptState* scriptState) { | 197 FetchResponseData* FetchResponseData::clone(ScriptState* scriptState) { |
186 FetchResponseData* newResponse = create(); | 198 FetchResponseData* newResponse = create(); |
187 newResponse->m_type = m_type; | 199 newResponse->m_type = m_type; |
188 if (m_terminationReason) { | 200 if (m_terminationReason) { |
189 newResponse->m_terminationReason = wrapUnique(new TerminationReason); | 201 newResponse->m_terminationReason = wrapUnique(new TerminationReason); |
190 *newResponse->m_terminationReason = *m_terminationReason; | 202 *newResponse->m_terminationReason = *m_terminationReason; |
191 } | 203 } |
192 newResponse->m_url = m_url; | 204 newResponse->setURLList(m_urlList); |
193 newResponse->m_status = m_status; | 205 newResponse->m_status = m_status; |
194 newResponse->m_statusMessage = m_statusMessage; | 206 newResponse->m_statusMessage = m_statusMessage; |
195 newResponse->m_headerList = m_headerList->clone(); | 207 newResponse->m_headerList = m_headerList->clone(); |
196 newResponse->m_mimeType = m_mimeType; | 208 newResponse->m_mimeType = m_mimeType; |
197 newResponse->m_responseTime = m_responseTime; | 209 newResponse->m_responseTime = m_responseTime; |
198 newResponse->m_cacheStorageCacheName = m_cacheStorageCacheName; | 210 newResponse->m_cacheStorageCacheName = m_cacheStorageCacheName; |
199 newResponse->m_corsExposedHeaderNames = m_corsExposedHeaderNames; | 211 newResponse->m_corsExposedHeaderNames = m_corsExposedHeaderNames; |
200 | 212 |
201 switch (m_type) { | 213 switch (m_type) { |
202 case BasicType: | 214 case BasicType: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 248 |
237 void FetchResponseData::populateWebServiceWorkerResponse( | 249 void FetchResponseData::populateWebServiceWorkerResponse( |
238 WebServiceWorkerResponse& response) { | 250 WebServiceWorkerResponse& response) { |
239 if (m_internalResponse) { | 251 if (m_internalResponse) { |
240 m_internalResponse->populateWebServiceWorkerResponse(response); | 252 m_internalResponse->populateWebServiceWorkerResponse(response); |
241 response.setResponseType(fetchTypeToWebType(m_type)); | 253 response.setResponseType(fetchTypeToWebType(m_type)); |
242 response.setCorsExposedHeaderNames( | 254 response.setCorsExposedHeaderNames( |
243 headerSetToWebVector(m_corsExposedHeaderNames)); | 255 headerSetToWebVector(m_corsExposedHeaderNames)); |
244 return; | 256 return; |
245 } | 257 } |
246 | 258 response.setURLList(m_urlList); |
247 response.setURL(url()); | |
248 response.setStatus(status()); | 259 response.setStatus(status()); |
249 response.setStatusText(statusMessage()); | 260 response.setStatusText(statusMessage()); |
250 response.setResponseType(fetchTypeToWebType(m_type)); | 261 response.setResponseType(fetchTypeToWebType(m_type)); |
251 response.setResponseTime(responseTime()); | 262 response.setResponseTime(responseTime()); |
252 response.setCacheStorageCacheName(cacheStorageCacheName()); | 263 response.setCacheStorageCacheName(cacheStorageCacheName()); |
253 response.setCorsExposedHeaderNames( | 264 response.setCorsExposedHeaderNames( |
254 headerSetToWebVector(m_corsExposedHeaderNames)); | 265 headerSetToWebVector(m_corsExposedHeaderNames)); |
255 for (size_t i = 0; i < headerList()->size(); ++i) { | 266 for (size_t i = 0; i < headerList()->size(); ++i) { |
256 const FetchHeaderList::Header* header = headerList()->list()[i].get(); | 267 const FetchHeaderList::Header* header = headerList()->list()[i].get(); |
257 response.appendHeader(header->first, header->second); | 268 response.appendHeader(header->first, header->second); |
(...skipping 20 matching lines...) Expand all Loading... |
278 } | 289 } |
279 } | 290 } |
280 | 291 |
281 DEFINE_TRACE(FetchResponseData) { | 292 DEFINE_TRACE(FetchResponseData) { |
282 visitor->trace(m_headerList); | 293 visitor->trace(m_headerList); |
283 visitor->trace(m_internalResponse); | 294 visitor->trace(m_internalResponse); |
284 visitor->trace(m_buffer); | 295 visitor->trace(m_buffer); |
285 } | 296 } |
286 | 297 |
287 } // namespace blink | 298 } // namespace blink |
OLD | NEW |