| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  109   CHECK_EQ(m_resource->options().synchronousPolicy, RequestAsynchronously); |  109   CHECK_EQ(m_resource->options().synchronousPolicy, RequestAsynchronously); | 
|  110   m_loader.reset(); |  110   m_loader.reset(); | 
|  111   start(request, loadingTaskRunner, defersLoading); |  111   start(request, loadingTaskRunner, defersLoading); | 
|  112 } |  112 } | 
|  113  |  113  | 
|  114 void ResourceLoader::setDefersLoading(bool defers) { |  114 void ResourceLoader::setDefersLoading(bool defers) { | 
|  115   DCHECK(m_loader); |  115   DCHECK(m_loader); | 
|  116   m_loader->setDefersLoading(defers); |  116   m_loader->setDefersLoading(defers); | 
|  117 } |  117 } | 
|  118  |  118  | 
|  119 void ResourceLoader::didDownloadData(WebURLLoader*, |  119 void ResourceLoader::didDownloadData(int length, int encodedDataLength) { | 
|  120                                      int length, |  | 
|  121                                      int encodedDataLength) { |  | 
|  122   m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); |  120   m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); | 
|  123   m_resource->didDownloadData(length); |  121   m_resource->didDownloadData(length); | 
|  124 } |  122 } | 
|  125  |  123  | 
|  126 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, |  124 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, | 
|  127                                        int intraPriorityValue) { |  125                                        int intraPriorityValue) { | 
|  128   if (m_loader) { |  126   if (m_loader) { | 
|  129     m_loader->didChangePriority( |  127     m_loader->didChangePriority( | 
|  130         static_cast<WebURLRequest::Priority>(loadPriority), intraPriorityValue); |  128         static_cast<WebURLRequest::Priority>(loadPriority), intraPriorityValue); | 
|  131   } |  129   } | 
|  132 } |  130 } | 
|  133  |  131  | 
|  134 void ResourceLoader::cancel() { |  132 void ResourceLoader::cancel() { | 
|  135   didFail( |  133   didFail( | 
|  136       ResourceError::cancelledError(m_resource->lastResourceRequest().url())); |  134       ResourceError::cancelledError(m_resource->lastResourceRequest().url())); | 
|  137 } |  135 } | 
|  138  |  136  | 
|  139 void ResourceLoader::cancelForRedirectAccessCheckError(const KURL& newURL) { |  137 void ResourceLoader::cancelForRedirectAccessCheckError(const KURL& newURL) { | 
|  140   m_resource->willNotFollowRedirect(); |  138   m_resource->willNotFollowRedirect(); | 
|  141  |  139  | 
|  142   if (m_loader) |  140   if (m_loader) | 
|  143     didFail(ResourceError::cancelledDueToAccessCheckError(newURL)); |  141     didFail(ResourceError::cancelledDueToAccessCheckError(newURL)); | 
|  144 } |  142 } | 
|  145  |  143  | 
|  146 bool ResourceLoader::willFollowRedirect( |  144 bool ResourceLoader::willFollowRedirect( | 
|  147     WebURLLoader*, |  | 
|  148     WebURLRequest& passedNewRequest, |  145     WebURLRequest& passedNewRequest, | 
|  149     const WebURLResponse& passedRedirectResponse) { |  146     const WebURLResponse& passedRedirectResponse) { | 
|  150   DCHECK(!passedNewRequest.isNull()); |  147   DCHECK(!passedNewRequest.isNull()); | 
|  151   DCHECK(!passedRedirectResponse.isNull()); |  148   DCHECK(!passedRedirectResponse.isNull()); | 
|  152  |  149  | 
|  153   if (m_isCacheAwareLoadingActivated) { |  150   if (m_isCacheAwareLoadingActivated) { | 
|  154     // Fail as cache miss if cached response is a redirect. |  151     // Fail as cache miss if cached response is a redirect. | 
|  155     didFail( |  152     didFail( | 
|  156         ResourceError::cacheMissError(m_resource->lastResourceRequest().url())); |  153         ResourceError::cacheMissError(m_resource->lastResourceRequest().url())); | 
|  157     return false; |  154     return false; | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  183   } |  180   } | 
|  184  |  181  | 
|  185   if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) { |  182   if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) { | 
|  186     cancelForRedirectAccessCheckError(newRequest.url()); |  183     cancelForRedirectAccessCheckError(newRequest.url()); | 
|  187     return false; |  184     return false; | 
|  188   } |  185   } | 
|  189  |  186  | 
|  190   return true; |  187   return true; | 
|  191 } |  188 } | 
|  192  |  189  | 
|  193 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, |  190 void ResourceLoader::didReceiveCachedMetadata(const char* data, int length) { | 
|  194                                               const char* data, |  | 
|  195                                               int length) { |  | 
|  196   m_resource->setSerializedCachedMetadata(data, length); |  191   m_resource->setSerializedCachedMetadata(data, length); | 
|  197 } |  192 } | 
|  198  |  193  | 
|  199 void ResourceLoader::didSendData(WebURLLoader*, |  194 void ResourceLoader::didSendData(unsigned long long bytesSent, | 
|  200                                  unsigned long long bytesSent, |  | 
|  201                                  unsigned long long totalBytesToBeSent) { |  195                                  unsigned long long totalBytesToBeSent) { | 
|  202   m_resource->didSendData(bytesSent, totalBytesToBeSent); |  196   m_resource->didSendData(bytesSent, totalBytesToBeSent); | 
|  203 } |  197 } | 
|  204  |  198  | 
|  205 void ResourceLoader::didReceiveResponse( |  199 void ResourceLoader::didReceiveResponse( | 
|  206     WebURLLoader*, |  | 
|  207     const WebURLResponse& response, |  200     const WebURLResponse& response, | 
|  208     std::unique_ptr<WebDataConsumerHandle> handle) { |  201     std::unique_ptr<WebDataConsumerHandle> handle) { | 
|  209   DCHECK(!response.isNull()); |  202   DCHECK(!response.isNull()); | 
|  210   m_fetcher->didReceiveResponse(m_resource.get(), response.toResourceResponse(), |  203   m_fetcher->didReceiveResponse(m_resource.get(), response.toResourceResponse(), | 
|  211                                 std::move(handle)); |  204                                 std::move(handle)); | 
|  212 } |  205 } | 
|  213  |  206  | 
|  214 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, |  207 void ResourceLoader::didReceiveResponse(const WebURLResponse& response) { | 
|  215                                         const WebURLResponse& response) { |  208   didReceiveResponse(response, nullptr); | 
|  216   didReceiveResponse(loader, response, nullptr); |  | 
|  217 } |  209 } | 
|  218  |  210  | 
|  219 void ResourceLoader::didReceiveData(WebURLLoader*, |  211 void ResourceLoader::didReceiveData(const char* data, | 
|  220                                     const char* data, |  | 
|  221                                     int length, |  212                                     int length, | 
|  222                                     int encodedDataLength) { |  213                                     int encodedDataLength) { | 
|  223   CHECK_GE(length, 0); |  214   CHECK_GE(length, 0); | 
|  224   m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength); |  215   m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength); | 
|  225   m_resource->addToDecodedBodyLength(length); |  216   m_resource->addToDecodedBodyLength(length); | 
|  226   m_resource->appendData(data, length); |  217   m_resource->appendData(data, length); | 
|  227 } |  218 } | 
|  228  |  219  | 
|  229 void ResourceLoader::didFinishLoadingFirstPartInMultipart() { |  220 void ResourceLoader::didFinishLoadingFirstPartInMultipart() { | 
|  230   m_fetcher->didFinishLoading(m_resource.get(), 0, |  221   m_fetcher->didFinishLoading(m_resource.get(), 0, | 
|  231                               ResourceFetcher::DidFinishFirstPartInMultipart); |  222                               ResourceFetcher::DidFinishFirstPartInMultipart); | 
|  232 } |  223 } | 
|  233  |  224  | 
|  234 void ResourceLoader::didFinishLoading(WebURLLoader*, |  225 void ResourceLoader::didFinishLoading(double finishTime, | 
|  235                                       double finishTime, |  | 
|  236                                       int64_t encodedDataLength, |  226                                       int64_t encodedDataLength, | 
|  237                                       int64_t encodedBodyLength) { |  227                                       int64_t encodedBodyLength) { | 
|  238   m_resource->setEncodedDataLength(encodedDataLength); |  228   m_resource->setEncodedDataLength(encodedDataLength); | 
|  239   m_resource->addToEncodedBodyLength(encodedBodyLength); |  229   m_resource->addToEncodedBodyLength(encodedBodyLength); | 
|  240   m_loader.reset(); |  230   m_loader.reset(); | 
|  241   m_fetcher->didFinishLoading(m_resource.get(), finishTime, |  231   m_fetcher->didFinishLoading(m_resource.get(), finishTime, | 
|  242                               ResourceFetcher::DidFinishLoading); |  232                               ResourceFetcher::DidFinishLoading); | 
|  243 } |  233 } | 
|  244  |  234  | 
|  245 void ResourceLoader::didFail(WebURLLoader*, |  235 void ResourceLoader::didFail(const WebURLError& error, | 
|  246                              const WebURLError& error, |  | 
|  247                              int64_t encodedDataLength, |  236                              int64_t encodedDataLength, | 
|  248                              int64_t encodedBodyLength) { |  237                              int64_t encodedBodyLength) { | 
|  249   m_resource->setEncodedDataLength(encodedDataLength); |  238   m_resource->setEncodedDataLength(encodedDataLength); | 
|  250   m_resource->addToEncodedBodyLength(encodedBodyLength); |  239   m_resource->addToEncodedBodyLength(encodedBodyLength); | 
|  251   didFail(error); |  240   didFail(error); | 
|  252 } |  241 } | 
|  253  |  242  | 
|  254 void ResourceLoader::didFail(const ResourceError& error) { |  243 void ResourceLoader::didFail(const ResourceError& error) { | 
|  255   if (m_isCacheAwareLoadingActivated && error.isCacheMiss() && |  244   if (m_isCacheAwareLoadingActivated && error.isCacheMiss() && | 
|  256       m_fetcher->context().shouldLoadNewResource(m_resource->getType())) { |  245       m_fetcher->context().shouldLoadNewResource(m_resource->getType())) { | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  279   int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength; |  268   int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength; | 
|  280   int64_t encodedBodyLength = 0; |  269   int64_t encodedBodyLength = 0; | 
|  281   m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut, |  270   m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut, | 
|  282                               encodedDataLength, encodedBodyLength); |  271                               encodedDataLength, encodedBodyLength); | 
|  283  |  272  | 
|  284   // A message dispatched while synchronously fetching the resource |  273   // A message dispatched while synchronously fetching the resource | 
|  285   // can bring about the cancellation of this load. |  274   // can bring about the cancellation of this load. | 
|  286   if (!m_loader) |  275   if (!m_loader) | 
|  287     return; |  276     return; | 
|  288   if (errorOut.reason) { |  277   if (errorOut.reason) { | 
|  289     didFail(0, errorOut, encodedDataLength, encodedBodyLength); |  278     didFail(errorOut, encodedDataLength, encodedBodyLength); | 
|  290     return; |  279     return; | 
|  291   } |  280   } | 
|  292   didReceiveResponse(0, responseOut); |  281   didReceiveResponse(responseOut); | 
|  293   if (!m_loader) |  282   if (!m_loader) | 
|  294     return; |  283     return; | 
|  295   DCHECK_GE(responseOut.toResourceResponse().encodedBodyLength(), 0); |  284   DCHECK_GE(responseOut.toResourceResponse().encodedBodyLength(), 0); | 
|  296  |  285  | 
|  297   // Follow the async case convention of not calling didReceiveData or |  286   // Follow the async case convention of not calling didReceiveData or | 
|  298   // appending data to m_resource if the response body is empty. Copying the |  287   // appending data to m_resource if the response body is empty. Copying the | 
|  299   // empty buffer is a noop in most cases, but is destructive in the case of |  288   // empty buffer is a noop in most cases, but is destructive in the case of | 
|  300   // a 304, where it will overwrite the cached data we should be reusing. |  289   // a 304, where it will overwrite the cached data we should be reusing. | 
|  301   if (dataOut.size()) { |  290   if (dataOut.size()) { | 
|  302     m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(), |  291     m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(), | 
|  303                               encodedDataLength); |  292                               encodedDataLength); | 
|  304     m_resource->setResourceBuffer(dataOut); |  293     m_resource->setResourceBuffer(dataOut); | 
|  305   } |  294   } | 
|  306   didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength, |  295   didFinishLoading(monotonicallyIncreasingTime(), encodedDataLength, | 
|  307                    encodedBodyLength); |  296                    encodedBodyLength); | 
|  308 } |  297 } | 
|  309  |  298  | 
|  310 void ResourceLoader::activateCacheAwareLoadingIfNeeded( |  299 void ResourceLoader::activateCacheAwareLoadingIfNeeded( | 
|  311     const ResourceRequest& request) { |  300     const ResourceRequest& request) { | 
|  312   DCHECK(!m_isCacheAwareLoadingActivated); |  301   DCHECK(!m_isCacheAwareLoadingActivated); | 
|  313  |  302  | 
|  314   if (m_resource->options().cacheAwareLoadingEnabled != |  303   if (m_resource->options().cacheAwareLoadingEnabled != | 
|  315       IsCacheAwareLoadingEnabled) |  304       IsCacheAwareLoadingEnabled) | 
|  316     return; |  305     return; | 
|  317  |  306  | 
|  318   // Synchronous requests are not supported. |  307   // Synchronous requests are not supported. | 
|  319   if (m_resource->options().synchronousPolicy == RequestSynchronously) |  308   if (m_resource->options().synchronousPolicy == RequestSynchronously) | 
|  320     return; |  309     return; | 
|  321  |  310  | 
|  322   // Don't activate on Resource revalidation. |  311   // Don't activate on Resource revalidation. | 
|  323   if (m_resource->isCacheValidator()) |  312   if (m_resource->isCacheValidator()) | 
|  324     return; |  313     return; | 
|  325  |  314  | 
|  326   // Don't activate if cache policy is explicitly set. |  315   // Don't activate if cache policy is explicitly set. | 
|  327   if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) |  316   if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) | 
|  328     return; |  317     return; | 
|  329  |  318  | 
|  330   m_isCacheAwareLoadingActivated = true; |  319   m_isCacheAwareLoadingActivated = true; | 
|  331 } |  320 } | 
|  332  |  321  | 
|  333 }  // namespace blink |  322 }  // namespace blink | 
| OLD | NEW |