| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 break; | 304 break; |
| 305 } | 305 } |
| 306 return true; | 306 return true; |
| 307 } | 307 } |
| 308 | 308 |
| 309 bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
, bool forPreload) | 309 bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
, bool forPreload) |
| 310 { | 310 { |
| 311 if (document() && !document()->securityOrigin()->canDisplay(url)) { | 311 if (document() && !document()->securityOrigin()->canDisplay(url)) { |
| 312 if (!forPreload) | 312 if (!forPreload) |
| 313 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); | 313 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); |
| 314 LOG(ResourceLoading, "CachedResourceLoader::requestResource URL was not
allowed by SecurityOrigin::canDisplay"); | 314 LOG_INFO(ResourceLoading, "CachedResourceLoader::requestResource URL was
not allowed by SecurityOrigin::canDisplay"); |
| 315 return 0; | 315 return 0; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. | 318 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. |
| 319 bool shouldBypassMainWorldContentSecurityPolicy = (frame() && frame()->scrip
t()->shouldBypassMainWorldContentSecurityPolicy()); | 319 bool shouldBypassMainWorldContentSecurityPolicy = (frame() && frame()->scrip
t()->shouldBypassMainWorldContentSecurityPolicy()); |
| 320 | 320 |
| 321 // Some types of resources can be loaded only from the same origin. Other | 321 // Some types of resources can be loaded only from the same origin. Other |
| 322 // types of resources, like Images, Scripts, and CSS, can be loaded from | 322 // types of resources, like Images, Scripts, and CSS, can be loaded from |
| 323 // any URL. | 323 // any URL. |
| 324 switch (type) { | 324 switch (type) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (!checkInsecureContent(type, url)) | 418 if (!checkInsecureContent(type, url)) |
| 419 return false; | 419 return false; |
| 420 | 420 |
| 421 return true; | 421 return true; |
| 422 } | 422 } |
| 423 | 423 |
| 424 CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
dResource::Type type, CachedResourceRequest& request) | 424 CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
dResource::Type type, CachedResourceRequest& request) |
| 425 { | 425 { |
| 426 KURL url = request.resourceRequest().url(); | 426 KURL url = request.resourceRequest().url(); |
| 427 | 427 |
| 428 LOG(ResourceLoading, "CachedResourceLoader::requestResource '%s', charset '%
s', priority=%d, forPreload=%u", url.elidedString().latin1().data(), request.cha
rset().latin1().data(), request.priority(), request.forPreload()); | 428 LOG_INFO(ResourceLoading, "CachedResourceLoader::requestResource '%s', chars
et '%s', priority=%d, forPreload=%u", url.elidedString().latin1().data(), reques
t.charset().latin1().data(), request.priority(), request.forPreload()); |
| 429 | 429 |
| 430 // If only the fragment identifiers differ, it is the same resource. | 430 // If only the fragment identifiers differ, it is the same resource. |
| 431 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); | 431 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); |
| 432 | 432 |
| 433 if (!url.isValid()) | 433 if (!url.isValid()) |
| 434 return 0; | 434 return 0; |
| 435 | 435 |
| 436 if (!canRequest(type, url, request.forPreload())) | 436 if (!canRequest(type, url, request.forPreload())) |
| 437 return 0; | 437 return 0; |
| 438 | 438 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 ASSERT(resource); | 515 ASSERT(resource); |
| 516 ASSERT(resource->inCache()); | 516 ASSERT(resource->inCache()); |
| 517 ASSERT(!memoryCache()->disabled()); | 517 ASSERT(!memoryCache()->disabled()); |
| 518 ASSERT(resource->canUseCacheValidator()); | 518 ASSERT(resource->canUseCacheValidator()); |
| 519 ASSERT(!resource->resourceToRevalidate()); | 519 ASSERT(!resource->resourceToRevalidate()); |
| 520 | 520 |
| 521 // Copy the URL out of the resource to be revalidated in case it gets delete
d by the remove() call below. | 521 // Copy the URL out of the resource to be revalidated in case it gets delete
d by the remove() call below. |
| 522 String url = resource->url(); | 522 String url = resource->url(); |
| 523 CachedResourceHandle<CachedResource> newResource = createResource(resource->
type(), resource->resourceRequest(), resource->encoding()); | 523 CachedResourceHandle<CachedResource> newResource = createResource(resource->
type(), resource->resourceRequest(), resource->encoding()); |
| 524 | 524 |
| 525 LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource.get
(), resource); | 525 LOG_INFO(ResourceLoading, "Resource %p created to revalidate %p", newResourc
e.get(), resource); |
| 526 newResource->setResourceToRevalidate(resource); | 526 newResource->setResourceToRevalidate(resource); |
| 527 | 527 |
| 528 memoryCache()->remove(resource); | 528 memoryCache()->remove(resource); |
| 529 memoryCache()->add(newResource.get()); | 529 memoryCache()->add(newResource.get()); |
| 530 #if ENABLE(RESOURCE_TIMING) | 530 #if ENABLE(RESOURCE_TIMING) |
| 531 storeResourceTimingInitiatorInformation(resource, request); | 531 storeResourceTimingInitiatorInformation(resource, request); |
| 532 #else | 532 #else |
| 533 UNUSED_PARAM(request); | 533 UNUSED_PARAM(request); |
| 534 #endif | 534 #endif |
| 535 return newResource; | 535 return newResource; |
| 536 } | 536 } |
| 537 | 537 |
| 538 CachedResourceHandle<CachedResource> CachedResourceLoader::loadResource(CachedRe
source::Type type, CachedResourceRequest& request, const String& charset) | 538 CachedResourceHandle<CachedResource> CachedResourceLoader::loadResource(CachedRe
source::Type type, CachedResourceRequest& request, const String& charset) |
| 539 { | 539 { |
| 540 ASSERT(!memoryCache()->resourceForRequest(request.resourceRequest())); | 540 ASSERT(!memoryCache()->resourceForRequest(request.resourceRequest())); |
| 541 | 541 |
| 542 LOG(ResourceLoading, "Loading CachedResource for '%s'.", request.resourceReq
uest().url().elidedString().latin1().data()); | 542 LOG_INFO(ResourceLoading, "Loading CachedResource for '%s'.", request.resour
ceRequest().url().elidedString().latin1().data()); |
| 543 | 543 |
| 544 CachedResourceHandle<CachedResource> resource = createResource(type, request
.mutableResourceRequest(), charset); | 544 CachedResourceHandle<CachedResource> resource = createResource(type, request
.mutableResourceRequest(), charset); |
| 545 | 545 |
| 546 if (!memoryCache()->add(resource.get())) | 546 if (!memoryCache()->add(resource.get())) |
| 547 resource->setOwningCachedResourceLoader(this); | 547 resource->setOwningCachedResourceLoader(this); |
| 548 #if ENABLE(RESOURCE_TIMING) | 548 #if ENABLE(RESOURCE_TIMING) |
| 549 storeResourceTimingInitiatorInformation(resource, request); | 549 storeResourceTimingInitiatorInformation(resource, request); |
| 550 #endif | 550 #endif |
| 551 return resource; | 551 return resource; |
| 552 } | 552 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 571 { | 571 { |
| 572 if (!existingResource) | 572 if (!existingResource) |
| 573 return Load; | 573 return Load; |
| 574 | 574 |
| 575 // We already have a preload going for this URL. | 575 // We already have a preload going for this URL. |
| 576 if (forPreload && existingResource->isPreloaded()) | 576 if (forPreload && existingResource->isPreloaded()) |
| 577 return Use; | 577 return Use; |
| 578 | 578 |
| 579 // If the same URL has been loaded as a different type, we need to reload. | 579 // If the same URL has been loaded as a different type, we need to reload. |
| 580 if (existingResource->type() != type) { | 580 if (existingResource->type() != type) { |
| 581 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy
reloading due to type mismatch."); | 581 LOG_INFO(ResourceLoading, "CachedResourceLoader::determineRevalidationPo
licy reloading due to type mismatch."); |
| 582 return Reload; | 582 return Reload; |
| 583 } | 583 } |
| 584 | 584 |
| 585 if (!existingResource->canReuse(request)) | 585 if (!existingResource->canReuse(request)) |
| 586 return Reload; | 586 return Reload; |
| 587 | 587 |
| 588 // Certain requests (e.g., XHRs) might have manually set headers that requir
e revalidation. | 588 // Certain requests (e.g., XHRs) might have manually set headers that requir
e revalidation. |
| 589 // FIXME: In theory, this should be a Revalidate case. In practice, the Memo
ryCache revalidation path assumes a whole bunch | 589 // FIXME: In theory, this should be a Revalidate case. In practice, the Memo
ryCache revalidation path assumes a whole bunch |
| 590 // of things about how revalidation works that manual headers violate, so pu
nt to Reload instead. | 590 // of things about how revalidation works that manual headers violate, so pu
nt to Reload instead. |
| 591 if (request.isConditional()) | 591 if (request.isConditional()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 603 // Alwaus use preloads. | 603 // Alwaus use preloads. |
| 604 if (existingResource->isPreloaded()) | 604 if (existingResource->isPreloaded()) |
| 605 return Use; | 605 return Use; |
| 606 | 606 |
| 607 // CachePolicyHistoryBuffer uses the cache no matter what. | 607 // CachePolicyHistoryBuffer uses the cache no matter what. |
| 608 if (cachePolicy(type) == CachePolicyHistoryBuffer) | 608 if (cachePolicy(type) == CachePolicyHistoryBuffer) |
| 609 return Use; | 609 return Use; |
| 610 | 610 |
| 611 // Don't reuse resources with Cache-control: no-store. | 611 // Don't reuse resources with Cache-control: no-store. |
| 612 if (existingResource->response().cacheControlContainsNoStore()) { | 612 if (existingResource->response().cacheControlContainsNoStore()) { |
| 613 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy
reloading due to Cache-control: no-store."); | 613 LOG_INFO(ResourceLoading, "CachedResourceLoader::determineRevalidationPo
licy reloading due to Cache-control: no-store."); |
| 614 return Reload; | 614 return Reload; |
| 615 } | 615 } |
| 616 | 616 |
| 617 // If credentials were sent with the previous request and won't be | 617 // If credentials were sent with the previous request and won't be |
| 618 // with this one, or vice versa, re-fetch the resource. | 618 // with this one, or vice versa, re-fetch the resource. |
| 619 // | 619 // |
| 620 // This helps with the case where the server sends back | 620 // This helps with the case where the server sends back |
| 621 // "Access-Control-Allow-Origin: *" all the time, but some of the | 621 // "Access-Control-Allow-Origin: *" all the time, but some of the |
| 622 // client's requests are made without CORS and some with. | 622 // client's requests are made without CORS and some with. |
| 623 if (existingResource->resourceRequest().allowCookies() != request.allowCooki
es()) { | 623 if (existingResource->resourceRequest().allowCookies() != request.allowCooki
es()) { |
| 624 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy
reloading due to difference in credentials settings."); | 624 LOG_INFO(ResourceLoading, "CachedResourceLoader::determineRevalidationPo
licy reloading due to difference in credentials settings."); |
| 625 return Reload; | 625 return Reload; |
| 626 } | 626 } |
| 627 | 627 |
| 628 // During the initial load, avoid loading the same resource multiple times f
or a single document, even if the cache policies would tell us to. | 628 // During the initial load, avoid loading the same resource multiple times f
or a single document, even if the cache policies would tell us to. |
| 629 if (document() && !document()->loadEventFinished() && m_validatedURLs.contai
ns(existingResource->url())) | 629 if (document() && !document()->loadEventFinished() && m_validatedURLs.contai
ns(existingResource->url())) |
| 630 return Use; | 630 return Use; |
| 631 | 631 |
| 632 // CachePolicyReload always reloads | 632 // CachePolicyReload always reloads |
| 633 if (cachePolicy(type) == CachePolicyReload) { | 633 if (cachePolicy(type) == CachePolicyReload) { |
| 634 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy
reloading due to CachePolicyReload."); | 634 LOG_INFO(ResourceLoading, "CachedResourceLoader::determineRevalidationPo
licy reloading due to CachePolicyReload."); |
| 635 return Reload; | 635 return Reload; |
| 636 } | 636 } |
| 637 | 637 |
| 638 // We'll try to reload the resource if it failed last time. | 638 // We'll try to reload the resource if it failed last time. |
| 639 if (existingResource->errorOccurred()) { | 639 if (existingResource->errorOccurred()) { |
| 640 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicye
reloading due to resource being in the error state"); | 640 LOG_INFO(ResourceLoading, "CachedResourceLoader::determineRevalidationPo
licye reloading due to resource being in the error state"); |
| 641 return Reload; | 641 return Reload; |
| 642 } | 642 } |
| 643 | 643 |
| 644 // For resources that are not yet loaded we ignore the cache policy. | 644 // For resources that are not yet loaded we ignore the cache policy. |
| 645 if (existingResource->isLoading()) | 645 if (existingResource->isLoading()) |
| 646 return Use; | 646 return Use; |
| 647 | 647 |
| 648 // Check if the cache headers requires us to revalidate (cache expiration fo
r example). | 648 // Check if the cache headers requires us to revalidate (cache expiration fo
r example). |
| 649 if (existingResource->mustRevalidateDueToCacheHeaders(cachePolicy(type))) { | 649 if (existingResource->mustRevalidateDueToCacheHeaders(cachePolicy(type))) { |
| 650 // See if the resource has usable ETag or Last-modified headers. | 650 // See if the resource has usable ETag or Last-modified headers. |
| 651 if (existingResource->canUseCacheValidator()) | 651 if (existingResource->canUseCacheValidator()) |
| 652 return Revalidate; | 652 return Revalidate; |
| 653 | 653 |
| 654 // No, must reload. | 654 // No, must reload. |
| 655 LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy
reloading due to missing cache validators."); | 655 LOG_INFO(ResourceLoading, "CachedResourceLoader::determineRevalidationPo
licy reloading due to missing cache validators."); |
| 656 return Reload; | 656 return Reload; |
| 657 } | 657 } |
| 658 | 658 |
| 659 return Use; | 659 return Use; |
| 660 } | 660 } |
| 661 | 661 |
| 662 void CachedResourceLoader::printAccessDeniedMessage(const KURL& url) const | 662 void CachedResourceLoader::printAccessDeniedMessage(const KURL& url) const |
| 663 { | 663 { |
| 664 if (url.isNull()) | 664 if (url.isNull()) |
| 665 return; | 665 return; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 | 1014 |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions(
) | 1017 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions(
) |
| 1018 { | 1018 { |
| 1019 static ResourceLoaderOptions options(SendCallbacks, SniffContent, BufferData
, AllowStoredCredentials, AskClientForCrossOriginCredentials, DoSecurityCheck); | 1019 static ResourceLoaderOptions options(SendCallbacks, SniffContent, BufferData
, AllowStoredCredentials, AskClientForCrossOriginCredentials, DoSecurityCheck); |
| 1020 return options; | 1020 return options; |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 } | 1023 } |
| OLD | NEW |