| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include <memory> | 47 #include <memory> |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, | 51 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, |
| 52 Resource* resource) { | 52 Resource* resource) { |
| 53 return new ResourceLoader(fetcher, resource); | 53 return new ResourceLoader(fetcher, resource); |
| 54 } | 54 } |
| 55 | 55 |
| 56 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) | 56 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
| 57 : m_fetcher(fetcher), m_resource(resource) { | 57 : m_fetcher(fetcher), |
| 58 m_resource(resource), |
| 59 m_isCacheAwareLoadingActivated(false) { |
| 58 DCHECK(m_resource); | 60 DCHECK(m_resource); |
| 59 DCHECK(m_fetcher); | 61 DCHECK(m_fetcher); |
| 60 m_resource->setLoader(this); | 62 m_resource->setLoader(this); |
| 61 } | 63 } |
| 62 | 64 |
| 63 ResourceLoader::~ResourceLoader() { | 65 ResourceLoader::~ResourceLoader() { |
| 64 DCHECK(!m_loader); | 66 DCHECK(!m_loader); |
| 65 } | 67 } |
| 66 | 68 |
| 67 DEFINE_TRACE(ResourceLoader) { | 69 DEFINE_TRACE(ResourceLoader) { |
| 68 visitor->trace(m_fetcher); | 70 visitor->trace(m_fetcher); |
| 69 visitor->trace(m_resource); | 71 visitor->trace(m_resource); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void ResourceLoader::start(const ResourceRequest& request, | 74 void ResourceLoader::start(const ResourceRequest& originalRequest, |
| 73 WebTaskRunner* loadingTaskRunner, | 75 WebTaskRunner* loadingTaskRunner, |
| 74 bool defersLoading) { | 76 bool defersLoading) { |
| 75 DCHECK(!m_loader); | 77 DCHECK(!m_loader); |
| 76 if (m_resource->options().synchronousPolicy == RequestSynchronously && | 78 if (m_resource->options().synchronousPolicy == RequestSynchronously && |
| 77 defersLoading) { | 79 defersLoading) { |
| 78 cancel(); | 80 cancel(); |
| 79 return; | 81 return; |
| 80 } | 82 } |
| 81 | 83 |
| 84 // This is only for overriding cache policy if cache-aware loading is |
| 85 // activated. |
| 86 ResourceRequest request(originalRequest); |
| 87 |
| 88 if (m_isCacheAwareLoadingActivated) { |
| 89 // TODO(shaochuan): Use new flag |
| 90 request.setCachePolicy(WebCachePolicy::ReturnCacheDataDontLoad); |
| 91 } |
| 92 |
| 82 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 93 m_loader = wrapUnique(Platform::current()->createURLLoader()); |
| 83 DCHECK(m_loader); | 94 DCHECK(m_loader); |
| 84 m_loader->setDefersLoading(defersLoading); | 95 m_loader->setDefersLoading(defersLoading); |
| 85 m_loader->setLoadingTaskRunner(loadingTaskRunner); | 96 m_loader->setLoadingTaskRunner(loadingTaskRunner); |
| 86 | 97 |
| 87 if (m_resource->options().synchronousPolicy == RequestSynchronously) | 98 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
| 88 requestSynchronously(request); | 99 requestSynchronously(request); |
| 89 else | 100 else |
| 90 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 101 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 91 } | 102 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 didFail(ResourceError::cancelledDueToAccessCheckError(newURL)); | 141 didFail(ResourceError::cancelledDueToAccessCheckError(newURL)); |
| 131 } | 142 } |
| 132 | 143 |
| 133 bool ResourceLoader::willFollowRedirect( | 144 bool ResourceLoader::willFollowRedirect( |
| 134 WebURLLoader*, | 145 WebURLLoader*, |
| 135 WebURLRequest& passedNewRequest, | 146 WebURLRequest& passedNewRequest, |
| 136 const WebURLResponse& passedRedirectResponse) { | 147 const WebURLResponse& passedRedirectResponse) { |
| 137 DCHECK(!passedNewRequest.isNull()); | 148 DCHECK(!passedNewRequest.isNull()); |
| 138 DCHECK(!passedRedirectResponse.isNull()); | 149 DCHECK(!passedRedirectResponse.isNull()); |
| 139 | 150 |
| 151 if (m_isCacheAwareLoadingActivated) { |
| 152 // Fail as cache miss if cached response is a redirect. |
| 153 didFail( |
| 154 ResourceError::cacheMissError(m_resource->lastResourceRequest().url())); |
| 155 return false; |
| 156 } |
| 157 |
| 140 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); | 158 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); |
| 141 const ResourceResponse& redirectResponse( | 159 const ResourceResponse& redirectResponse( |
| 142 passedRedirectResponse.toResourceResponse()); | 160 passedRedirectResponse.toResourceResponse()); |
| 143 newRequest.setRedirectStatus( | 161 newRequest.setRedirectStatus( |
| 144 ResourceRequest::RedirectStatus::FollowedRedirect); | 162 ResourceRequest::RedirectStatus::FollowedRedirect); |
| 145 | 163 |
| 146 const KURL originalURL = newRequest.url(); | 164 const KURL originalURL = newRequest.url(); |
| 147 | 165 |
| 148 if (!m_fetcher->willFollowRedirect(m_resource.get(), newRequest, | 166 if (!m_fetcher->willFollowRedirect(m_resource.get(), newRequest, |
| 149 redirectResponse)) { | 167 redirectResponse)) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 // empty buffer is a noop in most cases, but is destructive in the case of | 280 // empty buffer is a noop in most cases, but is destructive in the case of |
| 263 // a 304, where it will overwrite the cached data we should be reusing. | 281 // a 304, where it will overwrite the cached data we should be reusing. |
| 264 if (dataOut.size()) { | 282 if (dataOut.size()) { |
| 265 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(), | 283 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(), |
| 266 encodedDataLength); | 284 encodedDataLength); |
| 267 m_resource->setResourceBuffer(dataOut); | 285 m_resource->setResourceBuffer(dataOut); |
| 268 } | 286 } |
| 269 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 287 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 270 } | 288 } |
| 271 | 289 |
| 290 bool ResourceLoader::willActivateCacheAwareLoading( |
| 291 const ResourceRequest& request) { |
| 292 // Don't activate on Resource revalidation. |
| 293 if (m_resource->isCacheValidator()) |
| 294 return false; |
| 295 // Don't activate if cache policy is explicitly set. |
| 296 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) |
| 297 return false; |
| 298 |
| 299 m_isCacheAwareLoadingActivated = true; |
| 300 return true; |
| 301 } |
| 302 |
| 303 void ResourceLoader::deactivateCacheAwareLoading() { |
| 304 DCHECK(m_isCacheAwareLoadingActivated); |
| 305 m_isCacheAwareLoadingActivated = false; |
| 306 } |
| 307 |
| 272 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |