OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 bool ResourceLoader::responseNeedsAccessControlCheck() const | 147 bool ResourceLoader::responseNeedsAccessControlCheck() const |
148 { | 148 { |
149 // If the fetch was (potentially) CORS enabled, an access control check of t
he response is required. | 149 // If the fetch was (potentially) CORS enabled, an access control check of t
he response is required. |
150 return m_resource->options().corsEnabled == IsCORSEnabled; | 150 return m_resource->options().corsEnabled == IsCORSEnabled; |
151 } | 151 } |
152 | 152 |
153 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res
ponse, WebDataConsumerHandle* rawHandle) | 153 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res
ponse, WebDataConsumerHandle* rawHandle) |
154 { | 154 { |
155 ASSERT(!response.isNull()); | 155 DCHECK(!response.isNull()); |
156 // |rawHandle|'s ownership is transferred to the callee. | 156 // |rawHandle|'s ownership is transferred to the callee. |
157 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); | 157 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); |
158 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 158 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
159 | 159 |
160 if (responseNeedsAccessControlCheck()) { | 160 if (responseNeedsAccessControlCheck()) { |
161 if (response.wasFetchedViaServiceWorker()) { | 161 if (response.wasFetchedViaServiceWorker()) { |
162 if (response.wasFallbackRequiredByServiceWorker()) { | 162 if (response.wasFallbackRequiredByServiceWorker()) { |
163 m_loader.reset(); | 163 m_loader.reset(); |
164 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 164 m_loader = wrapUnique(Platform::current()->createURLLoader()); |
165 ASSERT(m_loader); | 165 DCHECK(m_loader); |
166 ResourceRequest request = m_resource->lastResourceRequest(); | 166 ResourceRequest request = m_resource->lastResourceRequest(); |
167 ASSERT(!request.skipServiceWorker()); | 167 DCHECK_EQ(request.skipServiceWorker(), WebURLRequest::SkipServic
eWorker::None); |
168 request.setSkipServiceWorker(true); | 168 // This code handles the case when a regular controlling service
worker |
| 169 // doesn't handle a cross origin request. When this happens we s
till |
| 170 // want to give foreign fetch a chance to handle the request, so |
| 171 // only skip the controlling service worker for the fallback req
uest. |
| 172 // This is currently safe because of http://crbug.com/604084 the |
| 173 // wasFallbackRequiredByServiceWorker flag is never set when for
eign fetch |
| 174 // handled a request. |
| 175 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::C
ontrolling); |
169 m_loader->loadAsynchronously(WrappedResourceRequest(request), th
is); | 176 m_loader->loadAsynchronously(WrappedResourceRequest(request), th
is); |
170 return; | 177 return; |
171 } | 178 } |
172 } else { | 179 } else { |
173 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo
de() != 304) | 180 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo
de() != 304) |
174 m_resource->setResponse(resourceResponse); | 181 m_resource->setResponse(resourceResponse); |
175 if (!m_fetcher->canAccessResource(m_resource.get(), m_resource->opti
ons().securityOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessCont
rolErrors)) { | 182 if (!m_fetcher->canAccessResource(m_resource.get(), m_resource->opti
ons().securityOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessCont
rolErrors)) { |
176 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse
); | 183 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse
); |
177 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(K
URL(response.url()))); | 184 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(K
URL(response.url()))); |
178 return; | 185 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // empty buffer is a noop in most cases, but is destructive in the case of | 262 // empty buffer is a noop in most cases, but is destructive in the case of |
256 // a 304, where it will overwrite the cached data we should be reusing. | 263 // a 304, where it will overwrite the cached data we should be reusing. |
257 if (dataOut.size()) { | 264 if (dataOut.size()) { |
258 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); | 265 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
259 m_resource->setResourceBuffer(dataOut); | 266 m_resource->setResourceBuffer(dataOut); |
260 } | 267 } |
261 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 268 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
262 } | 269 } |
263 | 270 |
264 } // namespace blink | 271 } // namespace blink |
OLD | NEW |