| 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 24 matching lines...) Expand all Loading... |
| 35 #include "platform/Logging.h" | 35 #include "platform/Logging.h" |
| 36 #include "platform/SharedBuffer.h" | 36 #include "platform/SharedBuffer.h" |
| 37 #include "platform/exported/WrappedResourceRequest.h" | 37 #include "platform/exported/WrappedResourceRequest.h" |
| 38 #include "platform/exported/WrappedResourceResponse.h" | 38 #include "platform/exported/WrappedResourceResponse.h" |
| 39 #include "platform/network/ResourceError.h" | 39 #include "platform/network/ResourceError.h" |
| 40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebData.h" | 41 #include "public/platform/WebData.h" |
| 42 #include "public/platform/WebURLError.h" | 42 #include "public/platform/WebURLError.h" |
| 43 #include "public/platform/WebURLRequest.h" | 43 #include "public/platform/WebURLRequest.h" |
| 44 #include "public/platform/WebURLResponse.h" | 44 #include "public/platform/WebURLResponse.h" |
| 45 #include "public/platform/WebViewScheduler.h" |
| 45 #include "wtf/Assertions.h" | 46 #include "wtf/Assertions.h" |
| 46 #include "wtf/CurrentTime.h" | 47 #include "wtf/CurrentTime.h" |
| 47 #include "wtf/PtrUtil.h" | 48 #include "wtf/PtrUtil.h" |
| 48 #include <memory> | 49 #include <memory> |
| 49 | 50 |
| 50 namespace blink { | 51 namespace blink { |
| 51 | 52 |
| 52 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou
rce) | 53 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou
rce) |
| 53 { | 54 { |
| 54 return new ResourceLoader(fetcher, resource); | 55 return new ResourceLoader(fetcher, resource); |
| 55 } | 56 } |
| 56 | 57 |
| 57 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) | 58 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
| 58 : m_fetcher(fetcher) | 59 : m_fetcher(fetcher) |
| 59 , m_resource(resource) | 60 , m_resource(resource), |
| 61 m_webViewScheduler(nullptr) |
| 60 { | 62 { |
| 61 ASSERT(m_resource); | 63 ASSERT(m_resource); |
| 62 ASSERT(m_fetcher); | 64 ASSERT(m_fetcher); |
| 63 m_resource->setLoader(this); | 65 m_resource->setLoader(this); |
| 64 } | 66 } |
| 65 | 67 |
| 66 ResourceLoader::~ResourceLoader() | 68 ResourceLoader::~ResourceLoader() |
| 67 { | 69 { |
| 68 DCHECK(!m_loader); | 70 DCHECK(!m_loader); |
| 69 } | 71 } |
| 70 | 72 |
| 71 DEFINE_TRACE(ResourceLoader) | 73 DEFINE_TRACE(ResourceLoader) |
| 72 { | 74 { |
| 73 visitor->trace(m_fetcher); | 75 visitor->trace(m_fetcher); |
| 74 visitor->trace(m_resource); | 76 visitor->trace(m_resource); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, bool defersLoading) | 79 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, WeakPtr<WebViewScheduler> webViewScheduler, bool defersLoading) |
| 78 { | 80 { |
| 79 ASSERT(!m_loader); | 81 ASSERT(!m_loader); |
| 80 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { | 82 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { |
| 81 cancel(); | 83 cancel(); |
| 82 return; | 84 return; |
| 83 } | 85 } |
| 84 | 86 |
| 87 m_webViewScheduler = std::move(webViewScheduler); |
| 88 |
| 85 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 89 m_loader = wrapUnique(Platform::current()->createURLLoader()); |
| 86 m_loader->setDefersLoading(defersLoading); | 90 m_loader->setDefersLoading(defersLoading); |
| 87 ASSERT(m_loader); | 91 ASSERT(m_loader); |
| 88 m_loader->setLoadingTaskRunner(loadingTaskRunner); | 92 m_loader->setLoadingTaskRunner(loadingTaskRunner); |
| 89 | 93 |
| 94 if (m_webViewScheduler) |
| 95 m_webViewScheduler->incrementPendingResourceLoadCount(); |
| 96 |
| 90 if (m_resource->options().synchronousPolicy == RequestSynchronously) | 97 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
| 91 requestSynchronously(request); | 98 requestSynchronously(request); |
| 92 else | 99 else |
| 93 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 100 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 94 } | 101 } |
| 95 | 102 |
| 96 void ResourceLoader::setDefersLoading(bool defers) | 103 void ResourceLoader::setDefersLoading(bool defers) |
| 97 { | 104 { |
| 98 ASSERT(m_loader); | 105 ASSERT(m_loader); |
| 99 m_loader->setDefersLoading(defers); | 106 m_loader->setDefersLoading(defers); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 214 |
| 208 void ResourceLoader::didFinishLoadingFirstPartInMultipart() | 215 void ResourceLoader::didFinishLoadingFirstPartInMultipart() |
| 209 { | 216 { |
| 210 m_fetcher->didFinishLoading(m_resource.get(), 0, WebURLLoaderClient::kUnknow
nEncodedDataLength, ResourceFetcher::DidFinishFirstPartInMultipart); | 217 m_fetcher->didFinishLoading(m_resource.get(), 0, WebURLLoaderClient::kUnknow
nEncodedDataLength, ResourceFetcher::DidFinishFirstPartInMultipart); |
| 211 } | 218 } |
| 212 | 219 |
| 213 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t
encodedDataLength) | 220 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t
encodedDataLength) |
| 214 { | 221 { |
| 215 m_loader.reset(); | 222 m_loader.reset(); |
| 216 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength,
ResourceFetcher::DidFinishLoading); | 223 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength,
ResourceFetcher::DidFinishLoading); |
| 224 |
| 225 if (m_webViewScheduler) |
| 226 m_webViewScheduler->decrementPendingResourceLoadCount(); |
| 217 } | 227 } |
| 218 | 228 |
| 219 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) | 229 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) |
| 220 { | 230 { |
| 221 m_loader.reset(); | 231 m_loader.reset(); |
| 222 m_fetcher->didFailLoading(m_resource.get(), error); | 232 m_fetcher->didFailLoading(m_resource.get(), error); |
| 233 |
| 234 if (m_webViewScheduler) |
| 235 m_webViewScheduler->decrementPendingResourceLoadCount(); |
| 223 } | 236 } |
| 224 | 237 |
| 225 void ResourceLoader::requestSynchronously(const ResourceRequest& request) | 238 void ResourceLoader::requestSynchronously(const ResourceRequest& request) |
| 226 { | 239 { |
| 227 // downloadToFile is not supported for synchronous requests. | 240 // downloadToFile is not supported for synchronous requests. |
| 228 ASSERT(!request.downloadToFile()); | 241 ASSERT(!request.downloadToFile()); |
| 229 ASSERT(m_loader); | 242 ASSERT(m_loader); |
| 230 DCHECK(request.priority() == ResourceLoadPriorityHighest); | 243 DCHECK(request.priority() == ResourceLoadPriorityHighest); |
| 231 | 244 |
| 232 WrappedResourceRequest requestIn(request); | 245 WrappedResourceRequest requestIn(request); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 255 // empty buffer is a noop in most cases, but is destructive in the case of | 268 // 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. | 269 // a 304, where it will overwrite the cached data we should be reusing. |
| 257 if (dataOut.size()) { | 270 if (dataOut.size()) { |
| 258 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); | 271 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
| 259 m_resource->setResourceBuffer(dataOut); | 272 m_resource->setResourceBuffer(dataOut); |
| 260 } | 273 } |
| 261 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 274 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 262 } | 275 } |
| 263 | 276 |
| 264 } // namespace blink | 277 } // namespace blink |
| OLD | NEW |