| 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
rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
| 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 , m_allowStaleResources(false) | 224 , m_allowStaleResources(false) |
| 225 , m_imageFetched(false) | 225 , m_imageFetched(false) |
| 226 { | 226 { |
| 227 ThreadState::current()->registerPreFinalizer(this); | 227 ThreadState::current()->registerPreFinalizer(this); |
| 228 } | 228 } |
| 229 | 229 |
| 230 ResourceFetcher::~ResourceFetcher() | 230 ResourceFetcher::~ResourceFetcher() |
| 231 { | 231 { |
| 232 } | 232 } |
| 233 | 233 |
| 234 WebTaskRunner* ResourceFetcher::loadingTaskRunner() | |
| 235 { | |
| 236 if (!m_context) | |
| 237 return nullptr; | |
| 238 | |
| 239 return m_context->loadingTaskRunner(); | |
| 240 } | |
| 241 | |
| 242 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const | 234 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const |
| 243 { | 235 { |
| 244 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); | 236 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); |
| 245 const WeakMember<Resource>& resource = m_documentResources.get(url); | 237 const WeakMember<Resource>& resource = m_documentResources.get(url); |
| 246 return resource.get(); | 238 return resource.get(); |
| 247 } | 239 } |
| 248 | 240 |
| 249 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const | 241 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const |
| 250 { | 242 { |
| 251 // Redirects can change the response URL different from one of request. | 243 // Redirects can change the response URL different from one of request. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 return false; | 275 return false; |
| 284 if (resource->isImage() && shouldDeferImageLoad(resource->url())) | 276 if (resource->isImage() && shouldDeferImageLoad(resource->url())) |
| 285 return false; | 277 return false; |
| 286 return policy != Use || resource->stillNeedsLoad(); | 278 return policy != Use || resource->stillNeedsLoad(); |
| 287 } | 279 } |
| 288 | 280 |
| 289 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. | 281 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. |
| 290 // http://crbug.com/52411 | 282 // http://crbug.com/52411 |
| 291 static const int kMaxValidatedURLsSize = 10000; | 283 static const int kMaxValidatedURLsSize = 10000; |
| 292 | 284 |
| 293 void ResourceFetcher::requestLoadStarted(Resource* resource, const FetchRequest&
request, ResourceLoadStartType type, bool isStaticData) | 285 void ResourceFetcher::requestLoadStarted(unsigned long identifier, Resource* res
ource, const FetchRequest& request, ResourceLoadStartType type, bool isStaticDat
a) |
| 294 { | 286 { |
| 295 if (type == ResourceLoadingFromCache && resource->getStatus() == Resource::C
ached && !m_validatedURLs.contains(resource->url())) | 287 if (type == ResourceLoadingFromCache && resource->getStatus() == Resource::C
ached && !m_validatedURLs.contains(resource->url())) |
| 296 context().dispatchDidLoadResourceFromMemoryCache(resource, request.resou
rceRequest().frameType(), request.resourceRequest().requestContext()); | 288 context().dispatchDidLoadResourceFromMemoryCache(identifier, resource, r
equest.resourceRequest().frameType(), request.resourceRequest().requestContext()
); |
| 297 | 289 |
| 298 if (isStaticData) | 290 if (isStaticData) |
| 299 return; | 291 return; |
| 300 | 292 |
| 301 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && !m_va
lidatedURLs.contains(request.resourceRequest().url())) { | 293 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && !m_va
lidatedURLs.contains(request.resourceRequest().url())) { |
| 302 // Resources loaded from memory cache should be reported the first time
they're used. | 294 // Resources loaded from memory cache should be reported the first time
they're used. |
| 303 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(request.opt
ions().initiatorInfo.name, monotonicallyIncreasingTime(), resource->getType() ==
Resource::MainResource); | 295 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(request.opt
ions().initiatorInfo.name, monotonicallyIncreasingTime(), resource->getType() ==
Resource::MainResource); |
| 304 populateResourceTiming(info.get(), resource); | 296 populateResourceTiming(info.get(), resource); |
| 305 info->clearLoadTimings(); | 297 info->clearLoadTimings(); |
| 306 info->setLoadFinishTime(info->initialTime()); | 298 info->setLoadFinishTime(info->initialTime()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 406 } |
| 415 | 407 |
| 416 Resource* ResourceFetcher::requestResource(FetchRequest& request, const Resource
Factory& factory, const SubstituteData& substituteData) | 408 Resource* ResourceFetcher::requestResource(FetchRequest& request, const Resource
Factory& factory, const SubstituteData& substituteData) |
| 417 { | 409 { |
| 418 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); | 410 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); |
| 419 | 411 |
| 420 context().upgradeInsecureRequest(request); | 412 context().upgradeInsecureRequest(request); |
| 421 context().addClientHintsIfNecessary(request); | 413 context().addClientHintsIfNecessary(request); |
| 422 context().addCSPHeaderIfNecessary(factory.type(), request); | 414 context().addCSPHeaderIfNecessary(factory.type(), request); |
| 423 | 415 |
| 424 KURL url = request.resourceRequest().url(); | 416 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(request.url())); |
| 425 KURL urlWithoutFragment = MemoryCache::removeFragmentIdentifierIfNeeded(url)
; | |
| 426 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); | |
| 427 | 417 |
| 428 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource '%s', charset '%s
', priority=%d, forPreload=%u, type=%s", url.elidedString().latin1().data(), req
uest.charset().latin1().data(), request.priority(), request.forPreload(), Resour
ce::resourceTypeName(factory.type())); | 418 if (!request.url().isValid()) |
| 429 | |
| 430 if (!url.isValid()) | |
| 431 return nullptr; | 419 return nullptr; |
| 432 | 420 |
| 433 if (!context().canRequest(factory.type(), request.resourceRequest(), urlWith
outFragment, request.options(), request.forPreload(), request.getOriginRestricti
on())) | 421 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC
ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques
t.forPreload(), request.getOriginRestriction())) |
| 422 return nullptr; |
| 423 |
| 424 unsigned long identifier = createUniqueIdentifier(); |
| 425 request.setPriority(loadPriority(factory.type(), request, ResourcePriority::
NotVisible)); |
| 426 request.mutableResourceRequest().setPriority(request.priority()); |
| 427 initializeResourceRequest(request.mutableResourceRequest(), factory.type(),
request.defer()); |
| 428 context().willStartLoadingResource(identifier, request.mutableResourceReques
t(), factory.type()); |
| 429 if (!request.url().isValid()) |
| 434 return nullptr; | 430 return nullptr; |
| 435 | 431 |
| 436 if (!request.forPreload()) { | 432 if (!request.forPreload()) { |
| 437 V8DOMActivityLogger* activityLogger = nullptr; | 433 V8DOMActivityLogger* activityLogger = nullptr; |
| 438 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml
httprequest) | 434 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml
httprequest) |
| 439 activityLogger = V8DOMActivityLogger::currentActivityLogger(); | 435 activityLogger = V8DOMActivityLogger::currentActivityLogger(); |
| 440 else | 436 else |
| 441 activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolate
dWorld(); | 437 activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolate
dWorld(); |
| 442 | 438 |
| 443 if (activityLogger) { | 439 if (activityLogger) { |
| 444 Vector<String> argv; | 440 Vector<String> argv; |
| 445 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); | 441 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); |
| 446 argv.append(url); | 442 argv.append(request.url()); |
| 447 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 443 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
| 448 } | 444 } |
| 449 } | 445 } |
| 450 | 446 |
| 451 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid() || m_archive; | 447 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid() || m_archive; |
| 452 Resource* resource(nullptr); | 448 Resource* resource(nullptr); |
| 453 if (isStaticData) { | 449 if (isStaticData) { |
| 454 resource = resourceForStaticData(request, factory, substituteData); | 450 resource = resourceForStaticData(request, factory, substituteData); |
| 455 // Abort the request if the archive doesn't contain the resource. | 451 // Abort the request if the archive doesn't contain the resource. |
| 456 if (!resource && m_archive) | 452 if (!resource && m_archive) |
| 457 return nullptr; | 453 return nullptr; |
| 458 } | 454 } |
| 459 if (!resource) | 455 if (!resource) |
| 460 resource = memoryCache()->resourceForURL(url, getCacheIdentifier()); | 456 resource = memoryCache()->resourceForURL(request.url(), getCacheIdentifi
er()); |
| 461 | 457 |
| 462 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. | 458 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. |
| 463 moveCachedNonBlockingResourceToBlocking(resource, request); | 459 moveCachedNonBlockingResourceToBlocking(resource, request); |
| 464 | 460 |
| 465 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource, isStaticData); | 461 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource, isStaticData); |
| 466 | 462 |
| 467 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); | 463 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); |
| 468 | 464 |
| 469 initializeResourceRequest(request.mutableResourceRequest(), factory.type(),
request.defer()); | 465 if (policy != Use) |
| 466 willSendRequest(identifier, request.mutableResourceRequest(), ResourceRe
sponse(), request.options()); |
| 467 |
| 470 switch (policy) { | 468 switch (policy) { |
| 471 case Reload: | 469 case Reload: |
| 472 memoryCache()->remove(resource); | 470 memoryCache()->remove(resource); |
| 473 // Fall through | 471 // Fall through |
| 474 case Load: | 472 case Load: |
| 475 resource = createResourceForLoading(request, request.charset(), factory)
; | 473 resource = createResourceForLoading(request, request.charset(), factory)
; |
| 476 break; | 474 break; |
| 477 case Revalidate: | 475 case Revalidate: |
| 478 initializeRevalidation(request, resource); | 476 initializeRevalidation(request.mutableResourceRequest(), resource); |
| 479 break; | 477 break; |
| 480 case Use: | 478 case Use: |
| 481 memoryCache()->updateForAccess(resource); | 479 memoryCache()->updateForAccess(resource); |
| 482 break; | 480 break; |
| 483 } | 481 } |
| 484 | 482 |
| 485 if (!resource) | 483 if (!resource) |
| 486 return nullptr; | 484 return nullptr; |
| 487 if (resource->getType() != factory.type()) { | 485 if (resource->getType() != factory.type()) { |
| 488 ASSERT(request.forPreload()); | 486 ASSERT(request.forPreload()); |
| 489 return nullptr; | 487 return nullptr; |
| 490 } | 488 } |
| 491 | 489 |
| 492 if (!resource->hasClientsOrObservers()) | 490 if (!resource->hasClientsOrObservers()) |
| 493 m_deadStatsRecorder.update(policy); | 491 m_deadStatsRecorder.update(policy); |
| 494 | 492 |
| 495 if (policy != Use) | 493 if (policy != Use) |
| 496 resource->setIdentifier(createUniqueIdentifier()); | 494 resource->setIdentifier(identifier); |
| 497 | 495 |
| 498 if (!request.forPreload() || policy != Use) { | 496 if (!request.forPreload() || policy != Use) { |
| 499 ResourceLoadPriority priority = loadPriority(factory.type(), request, Re
sourcePriority::NotVisible); | |
| 500 // When issuing another request for a resource that is already in-flight
make | 497 // When issuing another request for a resource that is already in-flight
make |
| 501 // sure to not demote the priority of the in-flight request. If the new
request | 498 // sure to not demote the priority of the in-flight request. If the new
request |
| 502 // isn't at the same priority as the in-flight request, only allow promo
tions. | 499 // isn't at the same priority as the in-flight request, only allow promo
tions. |
| 503 // This can happen when a visible image's priority is increased and then
another | 500 // This can happen when a visible image's priority is increased and then
another |
| 504 // reference to the image is parsed (which would be at a lower priority)
. | 501 // reference to the image is parsed (which would be at a lower priority)
. |
| 505 if (priority > resource->resourceRequest().priority()) | 502 if (request.priority() > resource->resourceRequest().priority()) |
| 506 resource->didChangePriority(priority, 0); | 503 resource->didChangePriority(request.priority(), 0); |
| 507 } | 504 } |
| 508 | 505 |
| 509 // If only the fragment identifiers differ, it is the same resource. | 506 // If only the fragment identifiers differ, it is the same resource. |
| 510 ASSERT(equalIgnoringFragmentIdentifier(resource->url(), url)); | 507 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
| 511 requestLoadStarted(resource, request, policy == Use ? ResourceLoadingFromCac
he : ResourceLoadingFromNetwork, isStaticData); | 508 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo
adingFromCache : ResourceLoadingFromNetwork, isStaticData); |
| 512 m_documentResources.set(urlWithoutFragment, resource); | 509 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques
t.url()), resource); |
| 513 | 510 |
| 514 // Returns with an existing resource if the resource does not need to start | 511 // Returns with an existing resource if the resource does not need to start |
| 515 // loading immediately. | 512 // loading immediately. |
| 516 // If revalidation policy was determined as |Revalidate|, the resource was | 513 // If revalidation policy was determined as |Revalidate|, the resource was |
| 517 // already initialized for the revalidation here, but won't start loading. | 514 // already initialized for the revalidation here, but won't start loading. |
| 518 if (!resourceNeedsLoad(resource, request, policy)) | 515 if (!resourceNeedsLoad(resource, request, policy)) |
| 519 return resource; | 516 return resource; |
| 520 | 517 |
| 521 if (!context().shouldLoadNewResource(factory.type())) { | 518 if (!startLoad(resource)) |
| 522 if (memoryCache()->contains(resource)) | |
| 523 memoryCache()->remove(resource); | |
| 524 return nullptr; | 519 return nullptr; |
| 525 } | |
| 526 | |
| 527 resource->load(this); | |
| 528 ASSERT(!resource->errorOccurred() || request.options().synchronousPolicy ==
RequestSynchronously); | 520 ASSERT(!resource->errorOccurred() || request.options().synchronousPolicy ==
RequestSynchronously); |
| 529 return resource; | 521 return resource; |
| 530 } | 522 } |
| 531 | 523 |
| 532 void ResourceFetcher::resourceTimingReportTimerFired(Timer<ResourceFetcher>* tim
er) | 524 void ResourceFetcher::resourceTimingReportTimerFired(Timer<ResourceFetcher>* tim
er) |
| 533 { | 525 { |
| 534 ASSERT_UNUSED(timer, timer == &m_resourceTimingReportTimer); | 526 ASSERT_UNUSED(timer, timer == &m_resourceTimingReportTimer); |
| 535 Vector<OwnPtr<ResourceTimingInfo>> timingReports; | 527 Vector<OwnPtr<ResourceTimingInfo>> timingReports; |
| 536 timingReports.swap(m_scheduledResourceTimingReports); | 528 timingReports.swap(m_scheduledResourceTimingReports); |
| 537 for (const auto& timingInfo : timingReports) | 529 for (const auto& timingInfo : timingReports) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 554 if (request.getCachePolicy() == WebCachePolicy::UseProtocolCachePolicy) | 546 if (request.getCachePolicy() == WebCachePolicy::UseProtocolCachePolicy) |
| 555 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ
e, defer)); | 547 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ
e, defer)); |
| 556 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) | 548 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) |
| 557 determineRequestContext(request, type); | 549 determineRequestContext(request, type); |
| 558 if (type == Resource::LinkPrefetch) | 550 if (type == Resource::LinkPrefetch) |
| 559 request.setHTTPHeaderField(HTTPNames::Purpose, "prefetch"); | 551 request.setHTTPHeaderField(HTTPNames::Purpose, "prefetch"); |
| 560 | 552 |
| 561 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour
ce) ? FetchMainResource : FetchSubresource); | 553 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour
ce) ? FetchMainResource : FetchSubresource); |
| 562 } | 554 } |
| 563 | 555 |
| 564 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour
ce* resource) | 556 void ResourceFetcher::initializeRevalidation(ResourceRequest& revalidatingReques
t, Resource* resource) |
| 565 { | 557 { |
| 566 ASSERT(resource); | 558 ASSERT(resource); |
| 567 ASSERT(memoryCache()->contains(resource)); | 559 ASSERT(memoryCache()->contains(resource)); |
| 568 ASSERT(resource->isLoaded()); | 560 ASSERT(resource->isLoaded()); |
| 569 ASSERT(resource->canUseCacheValidator()); | 561 ASSERT(resource->canUseCacheValidator()); |
| 570 ASSERT(!resource->isCacheValidator()); | 562 ASSERT(!resource->isCacheValidator()); |
| 571 ASSERT(!context().isControlledByServiceWorker()); | 563 ASSERT(!context().isControlledByServiceWorker()); |
| 572 | 564 |
| 573 ResourceRequest revalidatingRequest(resource->resourceRequest()); | |
| 574 revalidatingRequest.clearHTTPReferrer(); | |
| 575 initializeResourceRequest(revalidatingRequest, resource->getType(), request.
defer()); | |
| 576 | |
| 577 const AtomicString& lastModified = resource->response().httpHeaderField(HTTP
Names::Last_Modified); | 565 const AtomicString& lastModified = resource->response().httpHeaderField(HTTP
Names::Last_Modified); |
| 578 const AtomicString& eTag = resource->response().httpHeaderField(HTTPNames::E
Tag); | 566 const AtomicString& eTag = resource->response().httpHeaderField(HTTPNames::E
Tag); |
| 579 if (!lastModified.isEmpty() || !eTag.isEmpty()) { | 567 if (!lastModified.isEmpty() || !eTag.isEmpty()) { |
| 580 ASSERT(context().getCachePolicy() != CachePolicyReload); | 568 ASSERT(context().getCachePolicy() != CachePolicyReload); |
| 581 if (context().getCachePolicy() == CachePolicyRevalidate) | 569 if (context().getCachePolicy() == CachePolicyRevalidate) |
| 582 revalidatingRequest.setHTTPHeaderField(HTTPNames::Cache_Control, "ma
x-age=0"); | 570 revalidatingRequest.setHTTPHeaderField(HTTPNames::Cache_Control, "ma
x-age=0"); |
| 583 } | 571 } |
| 584 if (!lastModified.isEmpty()) | 572 if (!lastModified.isEmpty()) |
| 585 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_Modified_Since, las
tModified); | 573 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_Modified_Since, las
tModified); |
| 586 if (!eTag.isEmpty()) | 574 if (!eTag.isEmpty()) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 return Reload; | 704 return Reload; |
| 717 | 705 |
| 718 // Don't try to reuse an in-progress async request for a new sync request. | 706 // Don't try to reuse an in-progress async request for a new sync request. |
| 719 if (fetchRequest.options().synchronousPolicy == RequestSynchronously && exis
tingResource->isLoading()) | 707 if (fetchRequest.options().synchronousPolicy == RequestSynchronously && exis
tingResource->isLoading()) |
| 720 return Reload; | 708 return Reload; |
| 721 | 709 |
| 722 // Don't reload resources while pasting. | 710 // Don't reload resources while pasting. |
| 723 if (m_allowStaleResources) | 711 if (m_allowStaleResources) |
| 724 return Use; | 712 return Use; |
| 725 | 713 |
| 726 if (request.getCachePolicy() == WebCachePolicy::BypassingCache) | |
| 727 return Reload; | |
| 728 | |
| 729 if (!fetchRequest.options().canReuseRequest(existingResource->options())) | 714 if (!fetchRequest.options().canReuseRequest(existingResource->options())) |
| 730 return Reload; | 715 return Reload; |
| 731 | 716 |
| 732 // Always use preloads. | 717 // Always use preloads. |
| 733 if (existingResource->isPreloaded()) | 718 if (existingResource->isPreloaded()) |
| 734 return Use; | 719 return Use; |
| 735 | 720 |
| 736 // CachePolicyHistoryBuffer uses the cache no matter what. | 721 // CachePolicyHistoryBuffer uses the cache no matter what. |
| 737 CachePolicy cachePolicy = context().getCachePolicy(); | 722 CachePolicy cachePolicy = context().getCachePolicy(); |
| 738 if (cachePolicy == CachePolicyHistoryBuffer) | 723 if (cachePolicy == CachePolicyHistoryBuffer) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 760 // We also group loads of the same resource together. | 745 // We also group loads of the same resource together. |
| 761 // Raw resources are exempted, as XHRs fall into this category and may have
user-set Cache-Control: | 746 // Raw resources are exempted, as XHRs fall into this category and may have
user-set Cache-Control: |
| 762 // headers or other factors that require separate requests. | 747 // headers or other factors that require separate requests. |
| 763 if (type != Resource::Raw) { | 748 if (type != Resource::Raw) { |
| 764 if (!context().isLoadComplete() && m_validatedURLs.contains(existingReso
urce->url())) | 749 if (!context().isLoadComplete() && m_validatedURLs.contains(existingReso
urce->url())) |
| 765 return Use; | 750 return Use; |
| 766 if (existingResource->isLoading()) | 751 if (existingResource->isLoading()) |
| 767 return Use; | 752 return Use; |
| 768 } | 753 } |
| 769 | 754 |
| 755 if (request.getCachePolicy() == WebCachePolicy::BypassingCache) |
| 756 return Reload; |
| 757 |
| 770 // CachePolicyReload always reloads | 758 // CachePolicyReload always reloads |
| 771 if (cachePolicy == CachePolicyReload) { | 759 if (cachePolicy == CachePolicyReload) { |
| 772 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r
eloading due to CachePolicyReload."); | 760 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r
eloading due to CachePolicyReload."); |
| 773 return Reload; | 761 return Reload; |
| 774 } | 762 } |
| 775 | 763 |
| 776 // We'll try to reload the resource if it failed last time. | 764 // We'll try to reload the resource if it failed last time. |
| 777 if (existingResource->errorOccurred()) { | 765 if (existingResource->errorOccurred()) { |
| 778 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicye
reloading due to resource being in the error state"); | 766 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicye
reloading due to resource being in the error state"); |
| 779 return Reload; | 767 return Reload; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 | 833 |
| 846 bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const | 834 bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const |
| 847 { | 835 { |
| 848 return !context().allowImage(m_imagesEnabled, url) || !m_autoLoadImages; | 836 return !context().allowImage(m_imagesEnabled, url) || !m_autoLoadImages; |
| 849 } | 837 } |
| 850 | 838 |
| 851 void ResourceFetcher::reloadImagesIfNotDeferred() | 839 void ResourceFetcher::reloadImagesIfNotDeferred() |
| 852 { | 840 { |
| 853 for (Resource* resource : m_documentResources.values()) { | 841 for (Resource* resource : m_documentResources.values()) { |
| 854 if (resource->getType() == Resource::Image && resource->stillNeedsLoad()
&& !shouldDeferImageLoad(resource->url())) | 842 if (resource->getType() == Resource::Image && resource->stillNeedsLoad()
&& !shouldDeferImageLoad(resource->url())) |
| 855 const_cast<Resource*>(resource)->load(this); | 843 startLoad(resource); |
| 856 } | 844 } |
| 857 } | 845 } |
| 858 | 846 |
| 859 int ResourceFetcher::requestCount() const | 847 int ResourceFetcher::requestCount() const |
| 860 { | 848 { |
| 861 return m_loaders.size(); | 849 return m_loaders.size(); |
| 862 } | 850 } |
| 863 | 851 |
| 864 void ResourceFetcher::preloadStarted(Resource* resource) | 852 void ResourceFetcher::preloadStarted(Resource* resource) |
| 865 { | 853 { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 { | 968 { |
| 981 context().dispatchDidReceiveData(identifier, data, dataLength, encodedDataLe
ngth); | 969 context().dispatchDidReceiveData(identifier, data, dataLength, encodedDataLe
ngth); |
| 982 } | 970 } |
| 983 | 971 |
| 984 void ResourceFetcher::moveResourceLoaderToNonBlocking(ResourceLoader* loader) | 972 void ResourceFetcher::moveResourceLoaderToNonBlocking(ResourceLoader* loader) |
| 985 { | 973 { |
| 986 m_nonBlockingLoaders.add(loader); | 974 m_nonBlockingLoaders.add(loader); |
| 987 m_loaders.remove(loader); | 975 m_loaders.remove(loader); |
| 988 } | 976 } |
| 989 | 977 |
| 990 void ResourceFetcher::willStartLoadingResource(Resource* resource, ResourceLoade
r* loader, ResourceRequest& request) | 978 bool ResourceFetcher::startLoad(Resource* resource) |
| 991 { | 979 { |
| 980 DCHECK(resource && resource->stillNeedsLoad()); |
| 981 if (!context().shouldLoadNewResource(resource->getType())) { |
| 982 memoryCache()->remove(resource); |
| 983 return false; |
| 984 } |
| 985 |
| 986 ResourceLoader* loader = ResourceLoader::create(this, resource); |
| 992 if (resource->shouldBlockLoadEvent()) | 987 if (resource->shouldBlockLoadEvent()) |
| 993 m_loaders.add(loader); | 988 m_loaders.add(loader); |
| 994 else | 989 else |
| 995 m_nonBlockingLoaders.add(loader); | 990 m_nonBlockingLoaders.add(loader); |
| 996 | 991 |
| 997 context().willStartLoadingResource(resource, request); | |
| 998 storeResourceTimingInitiatorInformation(resource); | 992 storeResourceTimingInitiatorInformation(resource); |
| 999 | 993 resource->setFetcherSecurityOrigin(context().getSecurityOrigin()); |
| 1000 context().dispatchWillSendRequest(resource->identifier(), request, ResourceR
esponse(), resource->options().initiatorInfo); | 994 loader->start(resource->resourceRequest(), context().loadingTaskRunner(), co
ntext().defersLoading()); |
| 995 return true; |
| 1001 } | 996 } |
| 1002 | 997 |
| 1003 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) | 998 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) |
| 1004 { | 999 { |
| 1005 if (m_loaders.contains(loader)) | 1000 if (m_loaders.contains(loader)) |
| 1006 m_loaders.remove(loader); | 1001 m_loaders.remove(loader); |
| 1007 else if (m_nonBlockingLoaders.contains(loader)) | 1002 else if (m_nonBlockingLoaders.contains(loader)) |
| 1008 m_nonBlockingLoaders.remove(loader); | 1003 m_nonBlockingLoaders.remove(loader); |
| 1009 else | 1004 else |
| 1010 ASSERT_NOT_REACHED(); | 1005 ASSERT_NOT_REACHED(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 return false; | 1050 return false; |
| 1056 } | 1051 } |
| 1057 } | 1052 } |
| 1058 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe
quest.url())) | 1053 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe
quest.url())) |
| 1059 return false; | 1054 return false; |
| 1060 } | 1055 } |
| 1061 | 1056 |
| 1062 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1057 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
| 1063 if (it != m_resourceTimingInfoMap.end()) | 1058 if (it != m_resourceTimingInfoMap.end()) |
| 1064 it->value->addRedirect(redirectResponse); | 1059 it->value->addRedirect(redirectResponse); |
| 1065 context().dispatchWillSendRequest(resource->identifier(), newRequest, redire
ctResponse, resource->options().initiatorInfo); | 1060 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour
ce->options()); |
| 1066 return true; | 1061 return true; |
| 1067 } | 1062 } |
| 1068 | 1063 |
| 1064 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio
ns& options) |
| 1065 { |
| 1066 newRequest.setAllowStoredCredentials(options.allowCredentials == AllowStored
Credentials); |
| 1067 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse,
options.initiatorInfo); |
| 1068 } |
| 1069 |
| 1069 void ResourceFetcher::updateAllImageResourcePriorities() | 1070 void ResourceFetcher::updateAllImageResourcePriorities() |
| 1070 { | 1071 { |
| 1071 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); | 1072 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); |
| 1072 for (const auto& documentResource : m_documentResources) { | 1073 for (const auto& documentResource : m_documentResources) { |
| 1073 Resource* resource = documentResource.value.get(); | 1074 Resource* resource = documentResource.value.get(); |
| 1074 if (!resource || !resource->isImage() || !resource->isLoading()) | 1075 if (!resource || !resource->isImage() || !resource->isLoading()) |
| 1075 continue; | 1076 continue; |
| 1076 | 1077 |
| 1077 ResourcePriority resourcePriority = resource->priorityFromObservers(); | 1078 ResourcePriority resourcePriority = resource->priorityFromObservers(); |
| 1078 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image
, FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior
ity.visibility); | 1079 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image
, FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior
ity.visibility); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 visitor->trace(m_context); | 1260 visitor->trace(m_context); |
| 1260 visitor->trace(m_archive); | 1261 visitor->trace(m_archive); |
| 1261 visitor->trace(m_loaders); | 1262 visitor->trace(m_loaders); |
| 1262 visitor->trace(m_nonBlockingLoaders); | 1263 visitor->trace(m_nonBlockingLoaders); |
| 1263 visitor->trace(m_documentResources); | 1264 visitor->trace(m_documentResources); |
| 1264 visitor->trace(m_preloads); | 1265 visitor->trace(m_preloads); |
| 1265 visitor->trace(m_resourceTimingInfoMap); | 1266 visitor->trace(m_resourceTimingInfoMap); |
| 1266 } | 1267 } |
| 1267 | 1268 |
| 1268 } // namespace blink | 1269 } // namespace blink |
| OLD | NEW |