| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 { | 225 { |
| 226 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); | 226 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); |
| 227 const WeakPtrWillBeWeakMember<Resource>& resource = m_documentResources.get(
url); | 227 const WeakPtrWillBeWeakMember<Resource>& resource = m_documentResources.get(
url); |
| 228 return resource.get(); | 228 return resource.get(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const | 231 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const |
| 232 { | 232 { |
| 233 // Redirects can change the response URL different from one of request. | 233 // Redirects can change the response URL different from one of request. |
| 234 bool forPreload = resource->isUnusedPreload(); | 234 bool forPreload = resource->isUnusedPreload(); |
| 235 if (!context().canRequest(resource->type(), resource->resourceRequest(), url
, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionForT
ype)) | 235 if (!context().canRequest(resource->getType(), resource->resourceRequest(),
url, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionF
orType)) |
| 236 return false; | 236 return false; |
| 237 | 237 |
| 238 if (!sourceOrigin) | 238 if (!sourceOrigin) |
| 239 sourceOrigin = context().securityOrigin(); | 239 sourceOrigin = context().securityOrigin(); |
| 240 | 240 |
| 241 if (sourceOrigin->canRequestNoSuborigin(url)) | 241 if (sourceOrigin->canRequestNoSuborigin(url)) |
| 242 return true; | 242 return true; |
| 243 | 243 |
| 244 String errorDescription; | 244 String errorDescription; |
| 245 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) { | 245 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) { |
| 246 resource->setCORSFailed(); | 246 resource->setCORSFailed(); |
| 247 if (!forPreload && (logErrorsDecision == ShouldLogAccessControlErrors))
{ | 247 if (!forPreload && (logErrorsDecision == ShouldLogAccessControlErrors))
{ |
| 248 String resourceType = Resource::resourceTypeToString(resource->type(
), resource->options().initiatorInfo); | 248 String resourceType = Resource::resourceTypeToString(resource->getTy
pe(), resource->options().initiatorInfo); |
| 249 context().addConsoleMessage(resourceType + " from origin '" + Securi
tyOrigin::create(url)->toString() + "' has been blocked from loading by Cross-Or
igin Resource Sharing policy: " + errorDescription); | 249 context().addConsoleMessage(resourceType + " from origin '" + Securi
tyOrigin::create(url)->toString() + "' has been blocked from loading by Cross-Or
igin Resource Sharing policy: " + errorDescription); |
| 250 } | 250 } |
| 251 return false; | 251 return false; |
| 252 } | 252 } |
| 253 return true; | 253 return true; |
| 254 } | 254 } |
| 255 | 255 |
| 256 bool ResourceFetcher::isControlledByServiceWorker() const | 256 bool ResourceFetcher::isControlledByServiceWorker() const |
| 257 { | 257 { |
| 258 return context().isControlledByServiceWorker(); | 258 return context().isControlledByServiceWorker(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool ResourceFetcher::resourceNeedsLoad(Resource* resource, const FetchRequest&
request, RevalidationPolicy policy) | 261 bool ResourceFetcher::resourceNeedsLoad(Resource* resource, const FetchRequest&
request, RevalidationPolicy policy) |
| 262 { | 262 { |
| 263 if (FetchRequest::DeferredByClient == request.defer()) | 263 if (FetchRequest::DeferredByClient == request.defer()) |
| 264 return false; | 264 return false; |
| 265 if (policy != Use) | 265 if (policy != Use) |
| 266 return true; | 266 return true; |
| 267 if (resource->stillNeedsLoad()) | 267 if (resource->stillNeedsLoad()) |
| 268 return true; | 268 return true; |
| 269 return request.options().synchronousPolicy == RequestSynchronously && resour
ce->isLoading(); | 269 return request.options().synchronousPolicy == RequestSynchronously && resour
ce->isLoading(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. | 272 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. |
| 273 // http://crbug.com/52411 | 273 // http://crbug.com/52411 |
| 274 static const int kMaxValidatedURLsSize = 10000; | 274 static const int kMaxValidatedURLsSize = 10000; |
| 275 | 275 |
| 276 void ResourceFetcher::requestLoadStarted(Resource* resource, const FetchRequest&
request, ResourceLoadStartType type, bool isStaticData) | 276 void ResourceFetcher::requestLoadStarted(Resource* resource, const FetchRequest&
request, ResourceLoadStartType type, bool isStaticData) |
| 277 { | 277 { |
| 278 if (type == ResourceLoadingFromCache && resource->status() == Resource::Cach
ed && !m_validatedURLs.contains(resource->url())) | 278 if (type == ResourceLoadingFromCache && resource->getStatus() == Resource::C
ached && !m_validatedURLs.contains(resource->url())) |
| 279 context().dispatchDidLoadResourceFromMemoryCache(resource, request.resou
rceRequest().frameType(), request.resourceRequest().requestContext()); | 279 context().dispatchDidLoadResourceFromMemoryCache(resource, request.resou
rceRequest().frameType(), request.resourceRequest().requestContext()); |
| 280 | 280 |
| 281 if (isStaticData) | 281 if (isStaticData) |
| 282 return; | 282 return; |
| 283 | 283 |
| 284 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && !m_va
lidatedURLs.contains(request.resourceRequest().url())) { | 284 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && !m_va
lidatedURLs.contains(request.resourceRequest().url())) { |
| 285 // Resources loaded from memory cache should be reported the first time
they're used. | 285 // Resources loaded from memory cache should be reported the first time
they're used. |
| 286 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(request.opt
ions().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Re
source::MainResource); | 286 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(request.opt
ions().initiatorInfo.name, monotonicallyIncreasingTime(), resource->getType() ==
Resource::MainResource); |
| 287 populateResourceTiming(info.get(), resource, true); | 287 populateResourceTiming(info.get(), resource, true); |
| 288 m_scheduledResourceTimingReports.append(info.release()); | 288 m_scheduledResourceTimingReports.append(info.release()); |
| 289 if (!m_resourceTimingReportTimer.isActive()) | 289 if (!m_resourceTimingReportTimer.isActive()) |
| 290 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); | 290 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); |
| 291 } | 291 } |
| 292 | 292 |
| 293 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { | 293 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { |
| 294 m_validatedURLs.clear(); | 294 m_validatedURLs.clear(); |
| 295 } | 295 } |
| 296 m_validatedURLs.add(request.resourceRequest().url()); | 296 m_validatedURLs.add(request.resourceRequest().url()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); | 377 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); |
| 378 | 378 |
| 379 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())); | 379 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())); |
| 380 | 380 |
| 381 // If only the fragment identifiers differ, it is the same resource. | 381 // If only the fragment identifiers differ, it is the same resource. |
| 382 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); | 382 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); |
| 383 | 383 |
| 384 if (!url.isValid()) | 384 if (!url.isValid()) |
| 385 return nullptr; | 385 return nullptr; |
| 386 | 386 |
| 387 if (!context().canRequest(factory.type(), request.resourceRequest(), url, re
quest.options(), request.forPreload(), request.originRestriction())) | 387 if (!context().canRequest(factory.type(), request.resourceRequest(), url, re
quest.options(), request.forPreload(), request.getOriginRestriction())) |
| 388 return nullptr; | 388 return nullptr; |
| 389 | 389 |
| 390 if (!request.forPreload()) { | 390 if (!request.forPreload()) { |
| 391 V8DOMActivityLogger* activityLogger = nullptr; | 391 V8DOMActivityLogger* activityLogger = nullptr; |
| 392 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml
httprequest) | 392 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml
httprequest) |
| 393 activityLogger = V8DOMActivityLogger::currentActivityLogger(); | 393 activityLogger = V8DOMActivityLogger::currentActivityLogger(); |
| 394 else | 394 else |
| 395 activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolate
dWorld(); | 395 activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolate
dWorld(); |
| 396 | 396 |
| 397 if (activityLogger) { | 397 if (activityLogger) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 case Revalidate: | 435 case Revalidate: |
| 436 initializeRevalidation(request, resource.get()); | 436 initializeRevalidation(request, resource.get()); |
| 437 break; | 437 break; |
| 438 case Use: | 438 case Use: |
| 439 memoryCache()->updateForAccess(resource.get()); | 439 memoryCache()->updateForAccess(resource.get()); |
| 440 break; | 440 break; |
| 441 } | 441 } |
| 442 | 442 |
| 443 if (!resource) | 443 if (!resource) |
| 444 return nullptr; | 444 return nullptr; |
| 445 if (resource->type() != factory.type()) { | 445 if (resource->getType() != factory.type()) { |
| 446 ASSERT(request.forPreload()); | 446 ASSERT(request.forPreload()); |
| 447 return nullptr; | 447 return nullptr; |
| 448 } | 448 } |
| 449 | 449 |
| 450 if (!resource->hasClients()) | 450 if (!resource->hasClients()) |
| 451 m_deadStatsRecorder.update(policy); | 451 m_deadStatsRecorder.update(policy); |
| 452 | 452 |
| 453 if (policy != Use) | 453 if (policy != Use) |
| 454 resource->setIdentifier(createUniqueIdentifier()); | 454 resource->setIdentifier(createUniqueIdentifier()); |
| 455 | 455 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 request.setRequestContext(requestContext); | 520 request.setRequestContext(requestContext); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void ResourceFetcher::determineRequestContext(ResourceRequest& request, Resource
::Type type) | 523 void ResourceFetcher::determineRequestContext(ResourceRequest& request, Resource
::Type type) |
| 524 { | 524 { |
| 525 determineRequestContext(request, type, context().isMainFrame()); | 525 determineRequestContext(request, type, context().isMainFrame()); |
| 526 } | 526 } |
| 527 | 527 |
| 528 void ResourceFetcher::initializeResourceRequest(ResourceRequest& request, Resour
ce::Type type) | 528 void ResourceFetcher::initializeResourceRequest(ResourceRequest& request, Resour
ce::Type type) |
| 529 { | 529 { |
| 530 if (request.cachePolicy() == UseProtocolCachePolicy) | 530 if (request.getCachePolicy() == UseProtocolCachePolicy) |
| 531 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ
e)); | 531 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ
e)); |
| 532 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) | 532 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) |
| 533 determineRequestContext(request, type); | 533 determineRequestContext(request, type); |
| 534 if (type == Resource::LinkPrefetch) | 534 if (type == Resource::LinkPrefetch) |
| 535 request.setHTTPHeaderField(HTTPNames::Purpose, "prefetch"); | 535 request.setHTTPHeaderField(HTTPNames::Purpose, "prefetch"); |
| 536 | 536 |
| 537 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour
ce) ? FetchMainResource : FetchSubresource); | 537 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour
ce) ? FetchMainResource : FetchSubresource); |
| 538 } | 538 } |
| 539 | 539 |
| 540 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour
ce* resource) | 540 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour
ce* resource) |
| 541 { | 541 { |
| 542 ASSERT(resource); | 542 ASSERT(resource); |
| 543 ASSERT(memoryCache()->contains(resource)); | 543 ASSERT(memoryCache()->contains(resource)); |
| 544 ASSERT(resource->isLoaded()); | 544 ASSERT(resource->isLoaded()); |
| 545 ASSERT(resource->canUseCacheValidator()); | 545 ASSERT(resource->canUseCacheValidator()); |
| 546 ASSERT(!resource->isCacheValidator()); | 546 ASSERT(!resource->isCacheValidator()); |
| 547 ASSERT(!context().isControlledByServiceWorker()); | 547 ASSERT(!context().isControlledByServiceWorker()); |
| 548 | 548 |
| 549 ResourceRequest revalidatingRequest(resource->resourceRequest()); | 549 ResourceRequest revalidatingRequest(resource->resourceRequest()); |
| 550 revalidatingRequest.clearHTTPReferrer(); | 550 revalidatingRequest.clearHTTPReferrer(); |
| 551 initializeResourceRequest(revalidatingRequest, resource->type()); | 551 initializeResourceRequest(revalidatingRequest, resource->getType()); |
| 552 | 552 |
| 553 const AtomicString& lastModified = resource->response().httpHeaderField(HTTP
Names::Last_Modified); | 553 const AtomicString& lastModified = resource->response().httpHeaderField(HTTP
Names::Last_Modified); |
| 554 const AtomicString& eTag = resource->response().httpHeaderField(HTTPNames::E
Tag); | 554 const AtomicString& eTag = resource->response().httpHeaderField(HTTPNames::E
Tag); |
| 555 if (!lastModified.isEmpty() || !eTag.isEmpty()) { | 555 if (!lastModified.isEmpty() || !eTag.isEmpty()) { |
| 556 ASSERT(context().cachePolicy() != CachePolicyReload); | 556 ASSERT(context().getCachePolicy() != CachePolicyReload); |
| 557 if (context().cachePolicy() == CachePolicyRevalidate) | 557 if (context().getCachePolicy() == CachePolicyRevalidate) |
| 558 revalidatingRequest.setHTTPHeaderField(HTTPNames::Cache_Control, "ma
x-age=0"); | 558 revalidatingRequest.setHTTPHeaderField(HTTPNames::Cache_Control, "ma
x-age=0"); |
| 559 } | 559 } |
| 560 if (!lastModified.isEmpty()) | 560 if (!lastModified.isEmpty()) |
| 561 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_Modified_Since, las
tModified); | 561 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_Modified_Since, las
tModified); |
| 562 if (!eTag.isEmpty()) | 562 if (!eTag.isEmpty()) |
| 563 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); | 563 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); |
| 564 | 564 |
| 565 double stalenessLifetime = resource->stalenessLifetime(); | 565 double stalenessLifetime = resource->stalenessLifetime(); |
| 566 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { | 566 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { |
| 567 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); | 567 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 584 | 584 |
| 585 memoryCache()->add(resource.get()); | 585 memoryCache()->add(resource.get()); |
| 586 return resource; | 586 return resource; |
| 587 } | 587 } |
| 588 | 588 |
| 589 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 589 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
| 590 { | 590 { |
| 591 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter
nal) | 591 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter
nal) |
| 592 return; | 592 return; |
| 593 | 593 |
| 594 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio
ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso
urce::MainResource); | 594 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio
ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->getType() == R
esource::MainResource); |
| 595 | 595 |
| 596 if (resource->isCacheValidator()) { | 596 if (resource->isCacheValidator()) { |
| 597 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF
ield(HTTPNames::Timing_Allow_Origin); | 597 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF
ield(HTTPNames::Timing_Allow_Origin); |
| 598 if (!timingAllowOrigin.isEmpty()) | 598 if (!timingAllowOrigin.isEmpty()) |
| 599 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 599 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
| 600 } | 600 } |
| 601 | 601 |
| 602 if (resource->type() != Resource::MainResource || context().updateTimingInfo
ForIFrameNavigation(info.get())) | 602 if (resource->getType() != Resource::MainResource || context().updateTimingI
nfoForIFrameNavigation(info.get())) |
| 603 m_resourceTimingInfoMap.add(resource, info.release()); | 603 m_resourceTimingInfoMap.add(resource, info.release()); |
| 604 } | 604 } |
| 605 | 605 |
| 606 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy
(Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour
ce, bool isStaticData) const | 606 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy
(Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour
ce, bool isStaticData) const |
| 607 { | 607 { |
| 608 const ResourceRequest& request = fetchRequest.resourceRequest(); | 608 const ResourceRequest& request = fetchRequest.resourceRequest(); |
| 609 | 609 |
| 610 if (!existingResource) | 610 if (!existingResource) |
| 611 return Load; | 611 return Load; |
| 612 | 612 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 635 | 635 |
| 636 // Service Worker's CORS fallback message must not be cached. | 636 // Service Worker's CORS fallback message must not be cached. |
| 637 if (existingResource->response().wasFallbackRequiredByServiceWorker()) | 637 if (existingResource->response().wasFallbackRequiredByServiceWorker()) |
| 638 return Reload; | 638 return Reload; |
| 639 | 639 |
| 640 // We already have a preload going for this URL. | 640 // We already have a preload going for this URL. |
| 641 if (fetchRequest.forPreload() && existingResource->isPreloaded()) | 641 if (fetchRequest.forPreload() && existingResource->isPreloaded()) |
| 642 return Use; | 642 return Use; |
| 643 | 643 |
| 644 // If the same URL has been loaded as a different type, we need to reload. | 644 // If the same URL has been loaded as a different type, we need to reload. |
| 645 if (existingResource->type() != type) { | 645 if (existingResource->getType() != type) { |
| 646 // FIXME: If existingResource is a Preload and the new type is LinkPrefe
tch | 646 // FIXME: If existingResource is a Preload and the new type is LinkPrefe
tch |
| 647 // We really should discard the new prefetch since the preload has more | 647 // We really should discard the new prefetch since the preload has more |
| 648 // specific type information! crbug.com/379893 | 648 // specific type information! crbug.com/379893 |
| 649 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case. | 649 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case. |
| 650 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r
eloading due to type mismatch."); | 650 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r
eloading due to type mismatch."); |
| 651 return Reload; | 651 return Reload; |
| 652 } | 652 } |
| 653 | 653 |
| 654 // Do not load from cache if images are not enabled. The load for this image
will be blocked | 654 // Do not load from cache if images are not enabled. The load for this image
will be blocked |
| 655 // in ImageResource::load. | 655 // in ImageResource::load. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 671 // Certain requests (e.g., XHRs) might have manually set headers that requir
e revalidation. | 671 // Certain requests (e.g., XHRs) might have manually set headers that requir
e revalidation. |
| 672 // FIXME: In theory, this should be a Revalidate case. In practice, the Memo
ryCache revalidation path assumes a whole bunch | 672 // FIXME: In theory, this should be a Revalidate case. In practice, the Memo
ryCache revalidation path assumes a whole bunch |
| 673 // of things about how revalidation works that manual headers violate, so pu
nt to Reload instead. | 673 // of things about how revalidation works that manual headers violate, so pu
nt to Reload instead. |
| 674 if (request.isConditional()) | 674 if (request.isConditional()) |
| 675 return Reload; | 675 return Reload; |
| 676 | 676 |
| 677 // Don't reload resources while pasting. | 677 // Don't reload resources while pasting. |
| 678 if (m_allowStaleResources) | 678 if (m_allowStaleResources) |
| 679 return Use; | 679 return Use; |
| 680 | 680 |
| 681 if (request.cachePolicy() == ResourceRequestCachePolicy::ReloadBypassingCach
e) | 681 if (request.getCachePolicy() == ResourceRequestCachePolicy::ReloadBypassingC
ache) |
| 682 return Reload; | 682 return Reload; |
| 683 | 683 |
| 684 if (!fetchRequest.options().canReuseRequest(existingResource->options())) | 684 if (!fetchRequest.options().canReuseRequest(existingResource->options())) |
| 685 return Reload; | 685 return Reload; |
| 686 | 686 |
| 687 // Always use preloads. | 687 // Always use preloads. |
| 688 if (existingResource->isPreloaded()) | 688 if (existingResource->isPreloaded()) |
| 689 return Use; | 689 return Use; |
| 690 | 690 |
| 691 // CachePolicyHistoryBuffer uses the cache no matter what. | 691 // CachePolicyHistoryBuffer uses the cache no matter what. |
| 692 CachePolicy cachePolicy = context().cachePolicy(); | 692 CachePolicy cachePolicy = context().getCachePolicy(); |
| 693 if (cachePolicy == CachePolicyHistoryBuffer) | 693 if (cachePolicy == CachePolicyHistoryBuffer) |
| 694 return Use; | 694 return Use; |
| 695 | 695 |
| 696 // Don't reuse resources with Cache-control: no-store. | 696 // Don't reuse resources with Cache-control: no-store. |
| 697 if (existingResource->hasCacheControlNoStoreHeader()) { | 697 if (existingResource->hasCacheControlNoStoreHeader()) { |
| 698 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r
eloading due to Cache-control: no-store."); | 698 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r
eloading due to Cache-control: no-store."); |
| 699 return Reload; | 699 return Reload; |
| 700 } | 700 } |
| 701 | 701 |
| 702 // If credentials were sent with the previous request and won't be | 702 // If credentials were sent with the previous request and won't be |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 return clientDefersImage(url) || !m_autoLoadImages; | 811 return clientDefersImage(url) || !m_autoLoadImages; |
| 812 } | 812 } |
| 813 | 813 |
| 814 void ResourceFetcher::reloadImagesIfNotDeferred() | 814 void ResourceFetcher::reloadImagesIfNotDeferred() |
| 815 { | 815 { |
| 816 // TODO(japhet): Once oilpan ships, the const auto& | 816 // TODO(japhet): Once oilpan ships, the const auto& |
| 817 // can be replaced with a Resource*. Also, null checking | 817 // can be replaced with a Resource*. Also, null checking |
| 818 // the resource probably won't be necesssary. | 818 // the resource probably won't be necesssary. |
| 819 for (const auto& documentResource : m_documentResources) { | 819 for (const auto& documentResource : m_documentResources) { |
| 820 Resource* resource = documentResource.value.get(); | 820 Resource* resource = documentResource.value.get(); |
| 821 if (resource && resource->type() == Resource::Image && resource->stillNe
edsLoad() && !clientDefersImage(resource->url())) | 821 if (resource && resource->getType() == Resource::Image && resource->stil
lNeedsLoad() && !clientDefersImage(resource->url())) |
| 822 const_cast<Resource*>(resource)->load(this, defaultResourceOptions()
); | 822 const_cast<Resource*>(resource)->load(this, defaultResourceOptions()
); |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 | 825 |
| 826 void ResourceFetcher::redirectReceived(Resource* resource, const ResourceRespons
e& redirectResponse) | 826 void ResourceFetcher::redirectReceived(Resource* resource, const ResourceRespons
e& redirectResponse) |
| 827 { | 827 { |
| 828 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 828 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
| 829 if (it != m_resourceTimingInfoMap.end()) | 829 if (it != m_resourceTimingInfoMap.end()) |
| 830 it->value->addRedirect(redirectResponse); | 830 it->value->addRedirect(redirectResponse); |
| 831 } | 831 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) | 871 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) |
| 872 { | 872 { |
| 873 #if PRELOAD_DEBUG | 873 #if PRELOAD_DEBUG |
| 874 printPreloadStats(); | 874 printPreloadStats(); |
| 875 #endif | 875 #endif |
| 876 if (!m_preloads) | 876 if (!m_preloads) |
| 877 return; | 877 return; |
| 878 | 878 |
| 879 for (auto resource : *m_preloads) { | 879 for (auto resource : *m_preloads) { |
| 880 resource->decreasePreloadCount(); | 880 resource->decreasePreloadCount(); |
| 881 if (resource->preloadResult() == Resource::PreloadNotReferenced && (poli
cy == ClearAllPreloads || !resource->isLinkPreload())) | 881 if (resource->getPreloadResult() == Resource::PreloadNotReferenced && (p
olicy == ClearAllPreloads || !resource->isLinkPreload())) |
| 882 memoryCache()->remove(resource.get()); | 882 memoryCache()->remove(resource.get()); |
| 883 } | 883 } |
| 884 m_preloads.clear(); | 884 m_preloads.clear(); |
| 885 } | 885 } |
| 886 | 886 |
| 887 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) | 887 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) |
| 888 { | 888 { |
| 889 // Only the top-frame can load MHTML. | 889 // Only the top-frame can load MHTML. |
| 890 if (!context().isMainFrame()) | 890 if (!context().isMainFrame()) |
| 891 return nullptr; | 891 return nullptr; |
| 892 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()
); | 892 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()
); |
| 893 return m_archive ? m_archive->mainResource() : nullptr; | 893 return m_archive ? m_archive->mainResource() : nullptr; |
| 894 } | 894 } |
| 895 | 895 |
| 896 bool ResourceFetcher::scheduleArchiveLoad(Resource* resource, const ResourceRequ
est& request) | 896 bool ResourceFetcher::scheduleArchiveLoad(Resource* resource, const ResourceRequ
est& request) |
| 897 { | 897 { |
| 898 if (resource->type() == Resource::MainResource && !context().isMainFrame()) | 898 if (resource->getType() == Resource::MainResource && !context().isMainFrame(
)) |
| 899 m_archive = context().archive(); | 899 m_archive = context().archive(); |
| 900 | 900 |
| 901 if (!m_archive) | 901 if (!m_archive) |
| 902 return false; | 902 return false; |
| 903 | 903 |
| 904 ArchiveResource* archiveResource = m_archive->subresourceForURL(request.url(
)); | 904 ArchiveResource* archiveResource = m_archive->subresourceForURL(request.url(
)); |
| 905 if (!archiveResource) { | 905 if (!archiveResource) { |
| 906 resource->error(Resource::LoadError); | 906 resource->error(Resource::LoadError); |
| 907 return false; | 907 return false; |
| 908 } | 908 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 context().dispatchWillSendRequest(identifier, request, redirectResponse, ini
tiatorInfo); | 948 context().dispatchWillSendRequest(identifier, request, redirectResponse, ini
tiatorInfo); |
| 949 } | 949 } |
| 950 | 950 |
| 951 void ResourceFetcher::didReceiveResponse(const Resource* resource, const Resourc
eResponse& response) | 951 void ResourceFetcher::didReceiveResponse(const Resource* resource, const Resourc
eResponse& response) |
| 952 { | 952 { |
| 953 // If the response is fetched via ServiceWorker, the original URL of the res
ponse could be different from the URL of the request. | 953 // If the response is fetched via ServiceWorker, the original URL of the res
ponse could be different from the URL of the request. |
| 954 // We check the URL not to load the resources which are forbidden by the pag
e CSP. | 954 // We check the URL not to load the resources which are forbidden by the pag
e CSP. |
| 955 // https://w3c.github.io/webappsec-csp/#should-block-response | 955 // https://w3c.github.io/webappsec-csp/#should-block-response |
| 956 if (response.wasFetchedViaServiceWorker()) { | 956 if (response.wasFetchedViaServiceWorker()) { |
| 957 const KURL& originalURL = response.originalURLViaServiceWorker(); | 957 const KURL& originalURL = response.originalURLViaServiceWorker(); |
| 958 if (!originalURL.isEmpty() && !context().allowResponse(resource->type(),
resource->resourceRequest(), originalURL, resource->options())) { | 958 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType
(), resource->resourceRequest(), originalURL, resource->options())) { |
| 959 resource->loader()->cancel(); | 959 resource->loader()->cancel(); |
| 960 bool isInternalRequest = resource->options().initiatorInfo.name == F
etchInitiatorTypeNames::internal; | 960 bool isInternalRequest = resource->options().initiatorInfo.name == F
etchInitiatorTypeNames::internal; |
| 961 context().dispatchDidFail(resource->identifier(), ResourceError(erro
rDomainBlinkInternal, 0, originalURL.string(), "Unsafe attempt to load URL " + o
riginalURL.elidedString() + " fetched by a ServiceWorker."), isInternalRequest); | 961 context().dispatchDidFail(resource->identifier(), ResourceError(erro
rDomainBlinkInternal, 0, originalURL.string(), "Unsafe attempt to load URL " + o
riginalURL.elidedString() + " fetched by a ServiceWorker."), isInternalRequest); |
| 962 return; | 962 return; |
| 963 } | 963 } |
| 964 } | 964 } |
| 965 context().dispatchDidReceiveResponse(resource->identifier(), response, resou
rce->resourceRequest().frameType(), resource->resourceRequest().requestContext()
, resource->loader()); | 965 context().dispatchDidReceiveResponse(resource->identifier(), response, resou
rce->resourceRequest().frameType(), resource->resourceRequest().requestContext()
, resource->loader()); |
| 966 } | 966 } |
| 967 | 967 |
| 968 void ResourceFetcher::didReceiveData(const Resource* resource, const char* data,
int dataLength, int encodedDataLength) | 968 void ResourceFetcher::didReceiveData(const Resource* resource, const char* data,
int dataLength, int encodedDataLength) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 return context().defersLoading(); | 1045 return context().defersLoading(); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 bool ResourceFetcher::isLoadedBy(ResourceFetcher* possibleOwner) const | 1048 bool ResourceFetcher::isLoadedBy(ResourceFetcher* possibleOwner) const |
| 1049 { | 1049 { |
| 1050 return this == possibleOwner; | 1050 return this == possibleOwner; |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 bool ResourceFetcher::canAccessRedirect(Resource* resource, ResourceRequest& new
Request, const ResourceResponse& redirectResponse, ResourceLoaderOptions& option
s) | 1053 bool ResourceFetcher::canAccessRedirect(Resource* resource, ResourceRequest& new
Request, const ResourceResponse& redirectResponse, ResourceLoaderOptions& option
s) |
| 1054 { | 1054 { |
| 1055 if (!context().canRequest(resource->type(), newRequest, newRequest.url(), op
tions, resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestrictionFor
Type)) | 1055 if (!context().canRequest(resource->getType(), newRequest, newRequest.url(),
options, resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestriction
ForType)) |
| 1056 return false; | 1056 return false; |
| 1057 if (options.corsEnabled == IsCORSEnabled) { | 1057 if (options.corsEnabled == IsCORSEnabled) { |
| 1058 SecurityOrigin* sourceOrigin = options.securityOrigin.get(); | 1058 SecurityOrigin* sourceOrigin = options.securityOrigin.get(); |
| 1059 if (!sourceOrigin) | 1059 if (!sourceOrigin) |
| 1060 sourceOrigin = context().securityOrigin(); | 1060 sourceOrigin = context().securityOrigin(); |
| 1061 | 1061 |
| 1062 String errorMessage; | 1062 String errorMessage; |
| 1063 StoredCredentials withCredentials = resource->lastResourceRequest().allo
wStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; | 1063 StoredCredentials withCredentials = resource->lastResourceRequest().allo
wStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; |
| 1064 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newRequest,
redirectResponse, withCredentials, options, errorMessage)) { | 1064 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newRequest,
redirectResponse, withCredentials, options, errorMessage)) { |
| 1065 resource->setCORSFailed(); | 1065 resource->setCORSFailed(); |
| 1066 context().addConsoleMessage(errorMessage); | 1066 context().addConsoleMessage(errorMessage); |
| 1067 return false; | 1067 return false; |
| 1068 } | 1068 } |
| 1069 } | 1069 } |
| 1070 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u
rl())) | 1070 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newReques
t.url())) |
| 1071 return false; | 1071 return false; |
| 1072 return true; | 1072 return true; |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 void ResourceFetcher::updateAllImageResourcePriorities() | 1075 void ResourceFetcher::updateAllImageResourcePriorities() |
| 1076 { | 1076 { |
| 1077 if (!m_loaders) | 1077 if (!m_loaders) |
| 1078 return; | 1078 return; |
| 1079 | 1079 |
| 1080 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); | 1080 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 if (!m_preloads) | 1113 if (!m_preloads) |
| 1114 return; | 1114 return; |
| 1115 | 1115 |
| 1116 unsigned scripts = 0; | 1116 unsigned scripts = 0; |
| 1117 unsigned scriptMisses = 0; | 1117 unsigned scriptMisses = 0; |
| 1118 unsigned stylesheets = 0; | 1118 unsigned stylesheets = 0; |
| 1119 unsigned stylesheetMisses = 0; | 1119 unsigned stylesheetMisses = 0; |
| 1120 unsigned images = 0; | 1120 unsigned images = 0; |
| 1121 unsigned imageMisses = 0; | 1121 unsigned imageMisses = 0; |
| 1122 for (auto resource : *m_preloads) { | 1122 for (auto resource : *m_preloads) { |
| 1123 if (resource->preloadResult() == Resource::PreloadNotReferenced) | 1123 if (resource->getPreloadResult() == Resource::PreloadNotReferenced) |
| 1124 printf("!! UNREFERENCED PRELOAD %s\n", resource->url().string().lati
n1().data()); | 1124 printf("!! UNREFERENCED PRELOAD %s\n", resource->url().string().lati
n1().data()); |
| 1125 else if (resource->preloadResult() == Resource::PreloadReferencedWhileCo
mplete) | 1125 else if (resource->getPreloadResult() == Resource::PreloadReferencedWhil
eComplete) |
| 1126 printf("HIT COMPLETE PRELOAD %s\n", resource->url().string().latin1(
).data()); | 1126 printf("HIT COMPLETE PRELOAD %s\n", resource->url().string().latin1(
).data()); |
| 1127 else if (resource->preloadResult() == Resource::PreloadReferencedWhileLo
ading) | 1127 else if (resource->getPreloadResult() == Resource::PreloadReferencedWhil
eLoading) |
| 1128 printf("HIT LOADING PRELOAD %s\n", resource->url().string().latin1()
.data()); | 1128 printf("HIT LOADING PRELOAD %s\n", resource->url().string().latin1()
.data()); |
| 1129 | 1129 |
| 1130 if (resource->type() == Resource::Script) { | 1130 if (resource->getType() == Resource::Script) { |
| 1131 scripts++; | 1131 scripts++; |
| 1132 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad
ing) | 1132 if (resource->getPreloadResult() < Resource::PreloadReferencedWhileL
oading) |
| 1133 scriptMisses++; | 1133 scriptMisses++; |
| 1134 } else if (resource->type() == Resource::CSSStyleSheet) { | 1134 } else if (resource->getType() == Resource::CSSStyleSheet) { |
| 1135 stylesheets++; | 1135 stylesheets++; |
| 1136 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad
ing) | 1136 if (resource->getPreloadResult() < Resource::PreloadReferencedWhileL
oading) |
| 1137 stylesheetMisses++; | 1137 stylesheetMisses++; |
| 1138 } else { | 1138 } else { |
| 1139 images++; | 1139 images++; |
| 1140 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad
ing) | 1140 if (resource->getPreloadResult() < Resource::PreloadReferencedWhileL
oading) |
| 1141 imageMisses++; | 1141 imageMisses++; |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 if (resource->errorOccurred()) | 1144 if (resource->errorOccurred()) |
| 1145 memoryCache()->remove(resource.get()); | 1145 memoryCache()->remove(resource.get()); |
| 1146 | 1146 |
| 1147 resource->decreasePreloadCount(); | 1147 resource->decreasePreloadCount(); |
| 1148 } | 1148 } |
| 1149 m_preloads.clear(); | 1149 m_preloads.clear(); |
| 1150 | 1150 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 visitor->trace(m_loaders); | 1210 visitor->trace(m_loaders); |
| 1211 visitor->trace(m_nonBlockingLoaders); | 1211 visitor->trace(m_nonBlockingLoaders); |
| 1212 #if ENABLE(OILPAN) | 1212 #if ENABLE(OILPAN) |
| 1213 visitor->trace(m_documentResources); | 1213 visitor->trace(m_documentResources); |
| 1214 visitor->trace(m_preloads); | 1214 visitor->trace(m_preloads); |
| 1215 visitor->trace(m_resourceTimingInfoMap); | 1215 visitor->trace(m_resourceTimingInfoMap); |
| 1216 #endif | 1216 #endif |
| 1217 } | 1217 } |
| 1218 | 1218 |
| 1219 } // namespace blink | 1219 } // namespace blink |
| OLD | NEW |