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) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // RFC2616 13.2.3 | 275 // RFC2616 13.2.3 |
276 // No compensation for latency as that is not terribly important in practice | 276 // No compensation for latency as that is not terribly important in practice |
277 double dateValue = response.date(); | 277 double dateValue = response.date(); |
278 double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimesta
mp - dateValue) : 0; | 278 double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimesta
mp - dateValue) : 0; |
279 double ageValue = response.age(); | 279 double ageValue = response.age(); |
280 double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge
, ageValue) : apparentAge; | 280 double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge
, ageValue) : apparentAge; |
281 double residentTime = currentTime() - responseTimestamp; | 281 double residentTime = currentTime() - responseTimestamp; |
282 return correctedReceivedAge + residentTime; | 282 return correctedReceivedAge + residentTime; |
283 } | 283 } |
284 | 284 |
285 static double freshnessLifetime(const ResourceResponse& response, double respons
eTimestamp) | 285 static double freshnessLifetime(ResourceResponse& response, double responseTimes
tamp) |
286 { | 286 { |
287 #if !OS(ANDROID) | 287 #if !OS(ANDROID) |
288 // On desktop, local files should be reloaded in case they change. | 288 // On desktop, local files should be reloaded in case they change. |
289 if (response.url().isLocalFile()) | 289 if (response.url().isLocalFile()) |
290 return 0; | 290 return 0; |
291 #endif | 291 #endif |
292 | 292 |
293 // Cache other non-http / non-filesystem resources liberally. | 293 // Cache other non-http / non-filesystem resources liberally. |
294 if (!response.url().protocolIsInHTTPFamily() | 294 if (!response.url().protocolIsInHTTPFamily() |
295 && !response.url().protocolIs("filesystem")) | 295 && !response.url().protocolIs("filesystem")) |
296 return std::numeric_limits<double>::max(); | 296 return std::numeric_limits<double>::max(); |
297 | 297 |
298 // RFC2616 13.2.4 | 298 // RFC2616 13.2.4 |
299 double maxAgeValue = response.cacheControlMaxAge(); | 299 double maxAgeValue = response.cacheControlMaxAge(); |
300 if (std::isfinite(maxAgeValue)) | 300 if (std::isfinite(maxAgeValue)) |
301 return maxAgeValue; | 301 return maxAgeValue; |
302 double expiresValue = response.expires(); | 302 double expiresValue = response.expires(); |
303 double dateValue = response.date(); | 303 double dateValue = response.date(); |
304 double creationTime = std::isfinite(dateValue) ? dateValue : responseTimesta
mp; | 304 double creationTime = std::isfinite(dateValue) ? dateValue : responseTimesta
mp; |
305 if (std::isfinite(expiresValue)) | 305 if (std::isfinite(expiresValue)) |
306 return expiresValue - creationTime; | 306 return expiresValue - creationTime; |
307 double lastModifiedValue = response.lastModified(); | 307 double lastModifiedValue = response.lastModified(); |
308 if (std::isfinite(lastModifiedValue)) | 308 if (std::isfinite(lastModifiedValue)) |
309 return (creationTime - lastModifiedValue) * 0.1; | 309 return (creationTime - lastModifiedValue) * 0.1; |
310 // If no cache headers are present, the specification leaves the decision to
the UA. Other browsers seem to opt for 0. | 310 // If no cache headers are present, the specification leaves the decision to
the UA. Other browsers seem to opt for 0. |
311 return 0; | 311 return 0; |
312 } | 312 } |
313 | 313 |
314 static bool canUseResponse(const ResourceResponse& response, double responseTime
stamp) | 314 static bool canUseResponse(ResourceResponse& response, double responseTimestamp) |
315 { | 315 { |
316 if (response.isNull()) | 316 if (response.isNull()) |
317 return false; | 317 return false; |
318 | 318 |
319 // FIXME: Why isn't must-revalidate considered a reason we can't use the res
ponse? | 319 // FIXME: Why isn't must-revalidate considered a reason we can't use the res
ponse? |
320 if (response.cacheControlContainsNoCache() || response.cacheControlContainsN
oStore()) | 320 if (response.cacheControlContainsNoCache() || response.cacheControlContainsN
oStore()) |
321 return false; | 321 return false; |
322 | 322 |
323 if (response.httpStatusCode() == 303) { | 323 if (response.httpStatusCode() == 303) { |
324 // Must not be cached. | 324 // Must not be cached. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 bool deleted = deleteIfPossible(); | 486 bool deleted = deleteIfPossible(); |
487 if (!deleted && !hasClients()) { | 487 if (!deleted && !hasClients()) { |
488 memoryCache()->makeDead(this); | 488 memoryCache()->makeDead(this); |
489 if (!m_switchingClientsToRevalidatedResource) | 489 if (!m_switchingClientsToRevalidatedResource) |
490 allClientsRemoved(); | 490 allClientsRemoved(); |
491 | 491 |
492 // RFC2616 14.9.2: | 492 // RFC2616 14.9.2: |
493 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" | 493 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" |
494 // "... History buffers MAY store such responses as part of their normal
operation." | 494 // "... History buffers MAY store such responses as part of their normal
operation." |
495 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. | 495 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. |
496 if (response().cacheControlContainsNoStore() && url().protocolIs("https"
)) { | 496 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { |
497 memoryCache()->remove(this); | 497 memoryCache()->remove(this); |
498 memoryCache()->prune(); | 498 memoryCache()->prune(); |
499 } else { | 499 } else { |
500 memoryCache()->prune(this); | 500 memoryCache()->prune(this); |
501 } | 501 } |
502 } | 502 } |
503 // This object may be dead here. | 503 // This object may be dead here. |
504 } | 504 } |
505 | 505 |
506 void Resource::allClientsRemoved() | 506 void Resource::allClientsRemoved() |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 | 735 |
736 if (!m_handleCount) { | 736 if (!m_handleCount) { |
737 if (deleteIfPossible()) | 737 if (deleteIfPossible()) |
738 return; | 738 return; |
739 unlock(); | 739 unlock(); |
740 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { | 740 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { |
741 unlock(); | 741 unlock(); |
742 } | 742 } |
743 } | 743 } |
744 | 744 |
745 bool Resource::canReuseRedirectChain() const | 745 bool Resource::canReuseRedirectChain() |
746 { | 746 { |
747 for (size_t i = 0; i < m_redirectChain.size(); ++i) { | 747 for (size_t i = 0; i < m_redirectChain.size(); ++i) { |
748 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim
estamp)) | 748 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim
estamp)) |
749 return false; | 749 return false; |
| 750 if (m_redirectChain[i].m_request.cacheControlContainsNoCache() || m_redi
rectChain[i].m_request.cacheControlContainsNoStore()) |
| 751 return false; |
750 } | 752 } |
751 return true; | 753 return true; |
752 } | 754 } |
753 | 755 |
754 bool Resource::mustRevalidateDueToCacheHeaders() const | 756 bool Resource::hasCacheControlNoStoreHeader() |
755 { | 757 { |
756 return !canUseResponse(m_response, m_responseTimestamp); | 758 return m_response.cacheControlContainsNoStore() || m_resourceRequest.cacheCo
ntrolContainsNoStore(); |
757 } | 759 } |
758 | 760 |
759 bool Resource::canUseCacheValidator() const | 761 bool Resource::mustRevalidateDueToCacheHeaders() |
| 762 { |
| 763 return !canUseResponse(m_response, m_responseTimestamp) || m_resourceRequest
.cacheControlContainsNoCache() || m_resourceRequest.cacheControlContainsNoStore(
); |
| 764 } |
| 765 |
| 766 bool Resource::canUseCacheValidator() |
760 { | 767 { |
761 if (m_loading || errorOccurred()) | 768 if (m_loading || errorOccurred()) |
762 return false; | 769 return false; |
763 | 770 |
764 if (m_response.cacheControlContainsNoStore()) | 771 if (hasCacheControlNoStoreHeader()) |
765 return false; | 772 return false; |
766 return m_response.hasCacheValidatorFields(); | 773 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal
idatorFields(); |
767 } | 774 } |
768 | 775 |
769 bool Resource::isPurgeable() const | 776 bool Resource::isPurgeable() const |
770 { | 777 { |
771 return m_data && !m_data->isLocked(); | 778 return m_data && !m_data->isLocked(); |
772 } | 779 } |
773 | 780 |
774 bool Resource::wasPurged() const | 781 bool Resource::wasPurged() const |
775 { | 782 { |
776 return m_wasPurged; | 783 return m_wasPurged; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 return "Shader"; | 949 return "Shader"; |
943 case Resource::ImportResource: | 950 case Resource::ImportResource: |
944 return "ImportResource"; | 951 return "ImportResource"; |
945 } | 952 } |
946 ASSERT_NOT_REACHED(); | 953 ASSERT_NOT_REACHED(); |
947 return "Unknown"; | 954 return "Unknown"; |
948 } | 955 } |
949 #endif // !LOG_DISABLED | 956 #endif // !LOG_DISABLED |
950 | 957 |
951 } | 958 } |
OLD | NEW |