| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 m_loader->setDefersLoading(defersLoading); | 86 m_loader->setDefersLoading(defersLoading); |
| 87 ASSERT(m_loader); | 87 ASSERT(m_loader); |
| 88 m_loader->setLoadingTaskRunner(loadingTaskRunner); | 88 m_loader->setLoadingTaskRunner(loadingTaskRunner); |
| 89 | 89 |
| 90 if (m_resource->options().synchronousPolicy == RequestSynchronously) | 90 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
| 91 requestSynchronously(request); | 91 requestSynchronously(request); |
| 92 else | 92 else |
| 93 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 93 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ResourceLoader::restartForServiceWorkerFallback(const ResourceRequest& requ
est) |
| 97 { |
| 98 m_loader.reset(); |
| 99 m_loader = wrapUnique(Platform::current()->createURLLoader()); |
| 100 DCHECK(m_loader); |
| 101 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 102 } |
| 103 |
| 96 void ResourceLoader::setDefersLoading(bool defers) | 104 void ResourceLoader::setDefersLoading(bool defers) |
| 97 { | 105 { |
| 98 ASSERT(m_loader); | 106 ASSERT(m_loader); |
| 99 m_loader->setDefersLoading(defers); | 107 m_loader->setDefersLoading(defers); |
| 100 } | 108 } |
| 101 | 109 |
| 102 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL
ength) | 110 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL
ength) |
| 103 { | 111 { |
| 104 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); | 112 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); |
| 105 m_resource->didDownloadData(length); | 113 m_resource->didDownloadData(length); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i
nt length) | 145 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i
nt length) |
| 138 { | 146 { |
| 139 m_resource->setSerializedCachedMetadata(data, length); | 147 m_resource->setSerializedCachedMetadata(data, length); |
| 140 } | 148 } |
| 141 | 149 |
| 142 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un
signed long long totalBytesToBeSent) | 150 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un
signed long long totalBytesToBeSent) |
| 143 { | 151 { |
| 144 m_resource->didSendData(bytesSent, totalBytesToBeSent); | 152 m_resource->didSendData(bytesSent, totalBytesToBeSent); |
| 145 } | 153 } |
| 146 | 154 |
| 147 bool ResourceLoader::responseNeedsAccessControlCheck() const | 155 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res
ponse, WebDataConsumerHandle* handle) |
| 148 { | |
| 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; | |
| 151 } | |
| 152 | |
| 153 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res
ponse, WebDataConsumerHandle* rawHandle) | |
| 154 { | 156 { |
| 155 DCHECK(!response.isNull()); | 157 DCHECK(!response.isNull()); |
| 156 // |rawHandle|'s ownership is transferred to the callee. | 158 m_fetcher->didReceiveResponse(m_resource.get(), response.toResourceResponse(
), handle); |
| 157 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); | |
| 158 const ResourceResponse& resourceResponse = response.toResourceResponse(); | |
| 159 | |
| 160 if (responseNeedsAccessControlCheck()) { | |
| 161 if (response.wasFetchedViaServiceWorker()) { | |
| 162 if (response.wasFallbackRequiredByServiceWorker()) { | |
| 163 m_loader.reset(); | |
| 164 m_loader = wrapUnique(Platform::current()->createURLLoader()); | |
| 165 DCHECK(m_loader); | |
| 166 ResourceRequest request = m_resource->lastResourceRequest(); | |
| 167 DCHECK_EQ(request.skipServiceWorker(), WebURLRequest::SkipServic
eWorker::None); | |
| 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); | |
| 176 m_loader->loadAsynchronously(WrappedResourceRequest(request), th
is); | |
| 177 return; | |
| 178 } | |
| 179 } else { | |
| 180 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo
de() != 304) | |
| 181 m_resource->setResponse(resourceResponse); | |
| 182 if (!m_fetcher->canAccessResource(m_resource.get(), m_resource->opti
ons().securityOrigin.get(), response.url())) { | |
| 183 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse
); | |
| 184 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(K
URL(response.url()))); | |
| 185 return; | |
| 186 } | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 m_resource->responseReceived(resourceResponse, std::move(handle)); | |
| 191 if (!m_loader) | |
| 192 return; | |
| 193 | |
| 194 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); | |
| 195 if (!m_loader) | |
| 196 return; | |
| 197 | |
| 198 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) | |
| 199 return; | |
| 200 didFail(nullptr, ResourceError::cancelledError(resourceResponse.url())); | |
| 201 } | 159 } |
| 202 | 160 |
| 203 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon
se& response) | 161 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon
se& response) |
| 204 { | 162 { |
| 205 didReceiveResponse(loader, response, nullptr); | 163 didReceiveResponse(loader, response, nullptr); |
| 206 } | 164 } |
| 207 | 165 |
| 208 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length,
int encodedDataLength, int encodedBodyLength) | 166 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length,
int encodedDataLength, int encodedBodyLength) |
| 209 { | 167 { |
| 210 RELEASE_ASSERT(length >= 0); | 168 RELEASE_ASSERT(length >= 0); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // empty buffer is a noop in most cases, but is destructive in the case of | 221 // empty buffer is a noop in most cases, but is destructive in the case of |
| 264 // a 304, where it will overwrite the cached data we should be reusing. | 222 // a 304, where it will overwrite the cached data we should be reusing. |
| 265 if (dataOut.size()) { | 223 if (dataOut.size()) { |
| 266 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); | 224 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
| 267 m_resource->setResourceBuffer(dataOut); | 225 m_resource->setResourceBuffer(dataOut); |
| 268 } | 226 } |
| 269 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 227 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 270 } | 228 } |
| 271 | 229 |
| 272 } // namespace blink | 230 } // namespace blink |
| OLD | NEW |