| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 6 rights reserved. | 6 rights reserved. |
| 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 8 | 8 |
| 9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
| 10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // loadingTaskRunner() is null in tests that use the null fetch context. | 255 // loadingTaskRunner() is null in tests that use the null fetch context. |
| 256 m_resourceTimingReportTimer( | 256 m_resourceTimingReportTimer( |
| 257 context().loadingTaskRunner() | 257 context().loadingTaskRunner() |
| 258 ? context().loadingTaskRunner() | 258 ? context().loadingTaskRunner() |
| 259 : Platform::current()->currentThread()->getWebTaskRunner(), | 259 : Platform::current()->currentThread()->getWebTaskRunner(), |
| 260 this, | 260 this, |
| 261 &ResourceFetcher::resourceTimingReportTimerFired), | 261 &ResourceFetcher::resourceTimingReportTimerFired), |
| 262 m_autoLoadImages(true), | 262 m_autoLoadImages(true), |
| 263 m_imagesEnabled(true), | 263 m_imagesEnabled(true), |
| 264 m_allowStaleResources(false), | 264 m_allowStaleResources(false), |
| 265 m_imageFetched(false) {} | 265 m_imageFetched(false), |
| 266 m_onloadDeferredResourcesLoaded(false) {} |
| 266 | 267 |
| 267 ResourceFetcher::~ResourceFetcher() {} | 268 ResourceFetcher::~ResourceFetcher() {} |
| 268 | 269 |
| 269 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const { | 270 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const { |
| 270 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); | 271 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); |
| 271 const WeakMember<Resource>& resource = m_documentResources.at(url); | 272 const WeakMember<Resource>& resource = m_documentResources.at(url); |
| 272 return resource.get(); | 273 return resource.get(); |
| 273 } | 274 } |
| 274 | 275 |
| 275 bool ResourceFetcher::isControlledByServiceWorker() const { | 276 bool ResourceFetcher::isControlledByServiceWorker() const { |
| 276 return context().isControlledByServiceWorker(); | 277 return context().isControlledByServiceWorker(); |
| 277 } | 278 } |
| 278 | 279 |
| 279 bool ResourceFetcher::resourceNeedsLoad(Resource* resource, | 280 bool ResourceFetcher::resourceNeedsLoad(Resource* resource, |
| 280 const FetchRequest& request, | 281 const FetchRequest& request, |
| 281 RevalidationPolicy policy) { | 282 RevalidationPolicy policy) { |
| 282 // Defer a font load until it is actually needed unless this is a link | 283 // Defer a font load until it is actually needed unless this is a link |
| 283 // preload. | 284 // preload. |
| 284 if (resource->getType() == Resource::Font && !request.isLinkPreload()) | 285 if (resource->getType() == Resource::Font && !request.isLinkPreload()) |
| 285 return false; | 286 return false; |
| 286 if (resource->isImage() && shouldDeferImageLoad(resource->url())) | 287 if (resource->isImage() && shouldDeferImageLoad(resource->url())) |
| 287 return false; | 288 return false; |
| 289 if (resource->getType() == Resource::LinkPrefetch && |
| 290 !m_onloadDeferredResourcesLoaded) { |
| 291 if (!m_onloadDeferredResources) |
| 292 m_onloadDeferredResources = new HeapVector<Member<Resource>>; |
| 293 m_onloadDeferredResources->push_back(resource); |
| 294 return false; |
| 295 } |
| 288 return policy != Use || resource->stillNeedsLoad(); | 296 return policy != Use || resource->stillNeedsLoad(); |
| 289 } | 297 } |
| 290 | 298 |
| 291 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. | 299 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. |
| 292 // http://crbug.com/52411 | 300 // http://crbug.com/52411 |
| 293 static const int kMaxValidatedURLsSize = 10000; | 301 static const int kMaxValidatedURLsSize = 10000; |
| 294 | 302 |
| 295 void ResourceFetcher::requestLoadStarted(unsigned long identifier, | 303 void ResourceFetcher::requestLoadStarted(unsigned long identifier, |
| 296 Resource* resource, | 304 Resource* resource, |
| 297 const FetchRequest& request, | 305 const FetchRequest& request, |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 } | 1050 } |
| 1043 | 1051 |
| 1044 void ResourceFetcher::reloadImagesIfNotDeferred() { | 1052 void ResourceFetcher::reloadImagesIfNotDeferred() { |
| 1045 for (Resource* resource : m_documentResources.values()) { | 1053 for (Resource* resource : m_documentResources.values()) { |
| 1046 if (resource->getType() == Resource::Image && resource->stillNeedsLoad() && | 1054 if (resource->getType() == Resource::Image && resource->stillNeedsLoad() && |
| 1047 !shouldDeferImageLoad(resource->url())) | 1055 !shouldDeferImageLoad(resource->url())) |
| 1048 startLoad(resource); | 1056 startLoad(resource); |
| 1049 } | 1057 } |
| 1050 } | 1058 } |
| 1051 | 1059 |
| 1060 void ResourceFetcher::loadOnloadDeferredResources() { |
| 1061 if (!m_onloadDeferredResources) |
| 1062 return; |
| 1063 for (auto& resource : *m_onloadDeferredResources) { |
| 1064 if (resource->stillNeedsLoad()) |
| 1065 startLoad(resource); |
| 1066 } |
| 1067 m_onloadDeferredResources->clear(); |
| 1068 m_onloadDeferredResourcesLoaded = true; |
| 1069 } |
| 1070 |
| 1052 void ResourceFetcher::clearContext() { | 1071 void ResourceFetcher::clearContext() { |
| 1053 clearPreloads(ResourceFetcher::ClearAllPreloads); | 1072 clearPreloads(ResourceFetcher::ClearAllPreloads); |
| 1054 m_context.clear(); | 1073 m_context.clear(); |
| 1055 } | 1074 } |
| 1056 | 1075 |
| 1057 int ResourceFetcher::requestCount() const { | 1076 int ResourceFetcher::requestCount() const { |
| 1058 return m_loaders.size(); | 1077 return m_loaders.size(); |
| 1059 } | 1078 } |
| 1060 | 1079 |
| 1061 bool ResourceFetcher::hasPendingRequest() const { | 1080 bool ResourceFetcher::hasPendingRequest() const { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 } | 1561 } |
| 1543 } | 1562 } |
| 1544 | 1563 |
| 1545 DEFINE_TRACE(ResourceFetcher) { | 1564 DEFINE_TRACE(ResourceFetcher) { |
| 1546 visitor->trace(m_context); | 1565 visitor->trace(m_context); |
| 1547 visitor->trace(m_archive); | 1566 visitor->trace(m_archive); |
| 1548 visitor->trace(m_loaders); | 1567 visitor->trace(m_loaders); |
| 1549 visitor->trace(m_nonBlockingLoaders); | 1568 visitor->trace(m_nonBlockingLoaders); |
| 1550 visitor->trace(m_documentResources); | 1569 visitor->trace(m_documentResources); |
| 1551 visitor->trace(m_preloads); | 1570 visitor->trace(m_preloads); |
| 1571 visitor->trace(m_onloadDeferredResources); |
| 1552 visitor->trace(m_resourceTimingInfoMap); | 1572 visitor->trace(m_resourceTimingInfoMap); |
| 1553 } | 1573 } |
| 1554 | 1574 |
| 1555 } // namespace blink | 1575 } // namespace blink |
| OLD | NEW |