Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (175341 => 175342)
--- trunk/Source/WebCore/CMakeLists.txt 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/CMakeLists.txt 2014-10-29 20:54:45 UTC (rev 175342)
@@ -1857,6 +1857,7 @@
loader/cache/CachedSVGDocumentReference.cpp
loader/cache/CachedScript.cpp
loader/cache/CachedXSLStyleSheet.cpp
+ loader/cache/CacheValidation.cpp
loader/cache/MemoryCache.cpp
loader/icon/IconController.cpp
Modified: trunk/Source/WebCore/ChangeLog (175341 => 175342)
--- trunk/Source/WebCore/ChangeLog 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/ChangeLog 2014-10-29 20:54:45 UTC (rev 175342)
@@ -1,3 +1,34 @@
+2014-10-29 Antti Koivisto <[email protected]>
+
+ Factor cache validity computation functions out of CachedResource
+ https://bugs.webkit.org/show_bug.cgi?id=138156
+
+ Reviewed by Andreas Kling.
+
+ These can be used to implement cache logic on WebKit level.
+
+ * CMakeLists.txt:
+ * WebCore.exp.in:
+ * WebCore.vcxproj/WebCore.vcxproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * loader/CacheValidation.cpp: Added.
+ (WebCore::computeCurrentAge):
+ (WebCore::computeFreshnessLifetimeForHTTPFamily):
+ (WebCore::updateRedirectChainStatus):
+ (WebCore::redirectChainAllowsReuse):
+ * loader/CacheValidation.h: Added.
+ (WebCore::RedirectChainCacheStatus::RedirectChainCacheStatus):
+ * loader/cache/CachedResource.cpp:
+ (WebCore::updateResponseHeadersAfterRevalidation):
+ (WebCore::CachedResource::CachedResource):
+ (WebCore::CachedResource::isExpired):
+ (WebCore::CachedResource::freshnessLifetime):
+ (WebCore::CachedResource::willSendRequest):
+ (WebCore::CachedResource::updateResponseAfterRevalidation):
+ (WebCore::CachedResource::redirectChainAllowsReuse):
+ (WebCore::currentAge): Deleted.
+ * loader/cache/CachedResource.h:
+
2014-10-28 Ada Chan <[email protected]>
Add API to mute/unmute a page.
Modified: trunk/Source/WebCore/WebCore.exp.in (175341 => 175342)
--- trunk/Source/WebCore/WebCore.exp.in 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/WebCore.exp.in 2014-10-29 20:54:45 UTC (rev 175342)
@@ -779,6 +779,7 @@
__ZN7WebCore17SQLiteTransactionD1Ev
__ZN7WebCore17SubresourceLoader6createEPNS_5FrameEPNS_14CachedResourceERKNS_15ResourceRequestERKNS_21ResourceLoaderOptionsE
__ZN7WebCore17cacheDOMStructureEPNS_17JSDOMGlobalObjectEPN3JSC9StructureEPKNS2_9ClassInfoE
+__ZN7WebCore17computeCurrentAgeERKNS_16ResourceResponseEd
__ZN7WebCore17encodeForFileNameERKN3WTF6StringE
__ZN7WebCore17execStateFromPageERNS_15DOMWrapperWorldEPNS_4PageE
__ZN7WebCore17languageDidChangeEv
@@ -844,6 +845,7 @@
__ZN7WebCore19ResourceRequestBase13setHTTPMethodERKN3WTF6StringE
__ZN7WebCore19ResourceRequestBase15setHTTPReferrerERKN3WTF6StringE
__ZN7WebCore19ResourceRequestBase18setHTTPContentTypeERKN3WTF6StringE
+__ZN7WebCore19ResourceRequestBase18setHTTPHeaderFieldENS_14HTTPHeaderNameERKN3WTF6StringE
__ZN7WebCore19ResourceRequestBase19setHTTPHeaderFieldsENS_13HTTPHeaderMapE
__ZN7WebCore19ResourceRequestBase22defaultTimeoutIntervalEv
__ZN7WebCore19ResourceRequestBase24s_defaultTimeoutIntervalE
@@ -1042,10 +1044,12 @@
__ZN7WebCore24fileSystemRepresentationERKN3WTF6StringE
__ZN7WebCore24notifyHistoryItemChangedE
__ZN7WebCore24pathByAppendingComponentERKN3WTF6StringES3_
+__ZN7WebCore24redirectChainAllowsReuseENS_24RedirectChainCacheStatusE
__ZN7WebCore25addLanguageChangeObserverEPvPFvS0_E
__ZN7WebCore25computeViewportAttributesENS_17ViewportArgumentsEiiifNS_7IntSizeE
__ZN7WebCore25createCanonicalUUIDStringEv
__ZN7WebCore25getOutOfLineCachedWrapperEPNS_17JSDOMGlobalObjectEPNS_4NodeE
+__ZN7WebCore25updateRedirectChainStatusERNS_24RedirectChainCacheStatusERKNS_16ResourceResponseE
__ZN7WebCore26ContextDestructionObserver16contextDestroyedEv
__ZN7WebCore26ContextDestructionObserverC2EPNS_22ScriptExecutionContextE
__ZN7WebCore26ContextDestructionObserverD2Ev
@@ -1087,6 +1091,8 @@
__ZN7WebCore36standardUserAgentWithApplicationNameERKN3WTF6StringES3_
__ZN7WebCore37WidgetHierarchyUpdatesSuspensionScope11moveWidgetsEv
__ZN7WebCore37WidgetHierarchyUpdatesSuspensionScope35s_widgetHierarchyUpdateSuspendCountE
+__ZN7WebCore37computeFreshnessLifetimeForHTTPFamilyERKNS_16ResourceResponseEd
+__ZN7WebCore38updateResponseHeadersAfterRevalidationERNS_16ResourceResponseERKS0_
__ZN7WebCore3URL10invalidateEv
__ZN7WebCore3URL11setProtocolERKN3WTF6StringE
__ZN7WebCore3URL7setPathERKN3WTF6StringE
@@ -1842,7 +1848,11 @@
__ZNK7WebCore19ProtectionSpaceBase5realmEv
__ZNK7WebCore19ProtectionSpaceBase7isProxyEv
__ZNK7WebCore19ResourceRequestBase10httpMethodEv
+__ZNK7WebCore19ResourceRequestBase11cachePolicyEv
+__ZNK7WebCore19ResourceRequestBase13isConditionalEv
__ZNK7WebCore19ResourceRequestBase15httpContentTypeEv
+__ZNK7WebCore19ResourceRequestBase15httpHeaderFieldENS_14HTTPHeaderNameE
+__ZNK7WebCore19ResourceRequestBase15httpHeaderFieldERKN3WTF6StringE
__ZNK7WebCore19ResourceRequestBase20firstPartyForCookiesEv
__ZNK7WebCore19ResourceRequestBase3urlEv
__ZNK7WebCore19ResourceRequestBase6isNullEv
@@ -1863,6 +1873,10 @@
__ZNK7WebCore20ResourceResponseBase17suggestedFilenameEv
__ZNK7WebCore20ResourceResponseBase21expectedContentLengthEv
__ZNK7WebCore20ResourceResponseBase22includeCertificateInfoEv
+__ZNK7WebCore20ResourceResponseBase23hasCacheValidatorFieldsEv
+__ZNK7WebCore20ResourceResponseBase27cacheControlContainsNoCacheEv
+__ZNK7WebCore20ResourceResponseBase27cacheControlContainsNoStoreEv
+__ZNK7WebCore20ResourceResponseBase34cacheControlContainsMustRevalidateEv
__ZNK7WebCore20ResourceResponseBase3urlEv
__ZNK7WebCore20ResourceResponseBase6isHTTPEv
__ZNK7WebCore20ResourceResponseBase8lazyInitENS0_9InitLevelE
@@ -2279,6 +2293,7 @@
__ZN7WebCore15ResourceRequest41updateFromDelegatePreservingOldPropertiesERKS0_
__ZN7WebCore16FontPlatformDataC1EP6NSFontfbbbNS_15FontOrientationENS_16FontWidthVariantE
__ZN7WebCore16FontPlatformDataC2EP6NSFontfbbbNS_15FontOrientationENS_16FontWidthVariantE
+__ZN7WebCore16JSXMLHttpRequest9toWrappedEN3JSC7JSValueE
__ZN7WebCore16colorFromNSColorEP7NSColor
__ZN7WebCore16deleteAllCookiesERKNS_21NetworkStorageSessionE
__ZN7WebCore16enclosingIntRectERK7_NSRect
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (175341 => 175342)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2014-10-29 20:54:45 UTC (rev 175342)
@@ -7340,6 +7340,7 @@
<ClCompile Include="..\loader\cache\CachedSVGDocumentReference.cpp" />
<ClCompile Include="..\loader\cache\CachedTextTrack.cpp" />
<ClCompile Include="..\loader\cache\CachedXSLStyleSheet.cpp" />
+ <ClCompile Include="..\loader\cache\CacheValidation.cpp" />
<ClCompile Include="..\loader\cache\MemoryCache.cpp" />
<ClCompile Include="..\platform\audio\AudioHardwareListener.cpp" />
<ClCompile Include="..\platform\CalculationValue.cpp" />
@@ -19308,6 +19309,7 @@
<ClInclude Include="..\loader\cache\CachedTextTrack.h" />
<ClInclude Include="..\loader\cache\CachedXSLStyleSheet.h" />
<ClInclude Include="..\loader\cache\CachePolicy.h" />
+ <ClInclude Include="..\loader\cache\CacheValidation.h" />
<ClInclude Include="..\loader\cache\MemoryCache.h" />
<ClInclude Include="..\platform\audio\AudioHardwareListener.h" />
<ClInclude Include="..\platform\CalculationValue.h" />
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (175341 => 175342)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-10-29 20:54:45 UTC (rev 175342)
@@ -6164,6 +6164,8 @@
E453904D0EAFD637003695C8 /* WidgetIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E453903C0EAFD637003695C8 /* WidgetIOS.mm */; };
E45390AE0EAFF4B5003695C8 /* SystemMemoryIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E45390AD0EAFF4B5003695C8 /* SystemMemoryIOS.cpp */; };
E462A4A1113E71BE004A4220 /* IntPointHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E462A4A0113E71BE004A4220 /* IntPointHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ E467680E1A0177EE00B9E26B /* CacheValidation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E467680D1A0177EE00B9E26B /* CacheValidation.cpp */; };
+ E46768101A0177F900B9E26B /* CacheValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E467680F1A0177F900B9E26B /* CacheValidation.h */; settings = {ATTRIBUTES = (Private, ); }; };
E46A2B1C17CA65B9000DBCD8 /* TypedElementDescendantIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A2B1B17CA65B9000DBCD8 /* TypedElementDescendantIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
E46A2B1E17CA76B1000DBCD8 /* ElementChildIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
E47127CA163438A100ED6F5A /* StyleInvalidationAnalysis.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47A97CE163059FC005DCD99 /* StyleInvalidationAnalysis.cpp */; };
@@ -13693,6 +13695,8 @@
E453903C0EAFD637003695C8 /* WidgetIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WidgetIOS.mm; path = ios/WidgetIOS.mm; sourceTree = "<group>"; };
E45390AD0EAFF4B5003695C8 /* SystemMemoryIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemMemoryIOS.cpp; path = ios/SystemMemoryIOS.cpp; sourceTree = "<group>"; };
E462A4A0113E71BE004A4220 /* IntPointHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntPointHash.h; sourceTree = "<group>"; };
+ E467680D1A0177EE00B9E26B /* CacheValidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CacheValidation.cpp; path = loader/CacheValidation.cpp; sourceTree = SOURCE_ROOT; };
+ E467680F1A0177F900B9E26B /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CacheValidation.h; path = loader/CacheValidation.h; sourceTree = SOURCE_ROOT; };
E46A2B1B17CA65B9000DBCD8 /* TypedElementDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypedElementDescendantIterator.h; sourceTree = "<group>"; };
E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementChildIterator.h; sourceTree = "<group>"; };
E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomEvent.cpp; sourceTree = "<group>"; };
@@ -19625,6 +19629,8 @@
BCB16C0E0979C3BD00467741 /* CachedXSLStyleSheet.cpp */,
BCB16C0F0979C3BD00467741 /* CachedXSLStyleSheet.h */,
F587864902DE3A9A01EA4122 /* CachePolicy.h */,
+ E467680D1A0177EE00B9E26B /* CacheValidation.cpp */,
+ E467680F1A0177F900B9E26B /* CacheValidation.h */,
BCB16BFE0979C3BD00467741 /* MemoryCache.cpp */,
BCB16BFF0979C3BD00467741 /* MemoryCache.h */,
);
@@ -23669,6 +23675,7 @@
975CA28B130365F800E99AD9 /* Crypto.h in Headers */,
E172AF6E180F24C600FBADB9 /* CryptoAlgorithm.h in Headers */,
E125F8421824253A00D84CD9 /* CryptoAlgorithmAES_CBC.h in Headers */,
+ E46768101A0177F900B9E26B /* CacheValidation.h in Headers */,
E1FE137B184D21BB00892F13 /* CryptoAlgorithmAES_KW.h in Headers */,
E125F83A1824104800D84CD9 /* CryptoAlgorithmAesCbcParams.h in Headers */,
E19AC3F71824E5D100349426 /* CryptoAlgorithmAesKeyGenParams.h in Headers */,
@@ -27189,6 +27196,7 @@
FD3160BB12B0272A00C1A359 /* AudioBusMac.mm in Sources */,
FD31607D12B026F700C1A359 /* AudioChannel.cpp in Sources */,
FD31600412B0267600C1A359 /* AudioContext.cpp in Sources */,
+ E467680E1A0177EE00B9E26B /* CacheValidation.cpp in Sources */,
CD0EEE0E14743F39003EAFA2 /* AudioDestinationIOS.cpp in Sources */,
FD3160BC12B0272A00C1A359 /* AudioDestinationMac.cpp in Sources */,
FD31600712B0267600C1A359 /* AudioDestinationNode.cpp in Sources */,
Added: trunk/Source/WebCore/loader/CacheValidation.cpp (0 => 175342)
--- trunk/Source/WebCore/loader/CacheValidation.cpp (rev 0)
+++ trunk/Source/WebCore/loader/CacheValidation.cpp 2014-10-29 20:54:45 UTC (rev 175342)
@@ -0,0 +1,92 @@
+/*
+ Copyright (C) 1998 Lars Knoll ([email protected])
+ Copyright (C) 2001 Dirk Mueller ([email protected])
+ Copyright (C) 2002 Waldo Bastian ([email protected])
+ Copyright (C) 2006 Samuel Weinig ([email protected])
+ Copyright (C) 2004-2011, 2014 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "CacheValidation.h"
+
+#include "ResourceResponse.h"
+#include <wtf/CurrentTime.h>
+
+namespace WebCore {
+
+double computeCurrentAge(const ResourceResponse& response, double responseTimestamp)
+{
+ // RFC2616 13.2.3
+ // No compensation for latency as that is not terribly important in practice
+ double dateValue = response.date();
+ double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimestamp - dateValue) : 0;
+ double ageValue = response.age();
+ double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge, ageValue) : apparentAge;
+ double residentTime = currentTime() - responseTimestamp;
+ return correctedReceivedAge + residentTime;
+}
+
+double computeFreshnessLifetimeForHTTPFamily(const ResourceResponse& response, double responseTimestamp)
+{
+ ASSERT(response.url().protocolIsInHTTPFamily());
+ // RFC2616 13.2.4
+ double maxAgeValue = response.cacheControlMaxAge();
+ if (std::isfinite(maxAgeValue))
+ return maxAgeValue;
+ double expiresValue = response.expires();
+ double dateValue = response.date();
+ double creationTime = std::isfinite(dateValue) ? dateValue : responseTimestamp;
+ if (std::isfinite(expiresValue))
+ return expiresValue - creationTime;
+ double lastModifiedValue = response.lastModified();
+ if (std::isfinite(lastModifiedValue))
+ return (creationTime - lastModifiedValue) * 0.1;
+ // If no cache headers are present, the specification leaves the decision to the UA. Other browsers seem to opt for 0.
+ return 0;
+}
+
+void updateRedirectChainStatus(RedirectChainCacheStatus& redirectChainCacheStatus, const ResourceResponse& response)
+{
+ if (redirectChainCacheStatus.status == RedirectChainCacheStatus::NotCachedRedirection)
+ return;
+ if (response.cacheControlContainsNoStore() || response.cacheControlContainsNoCache() || response.cacheControlContainsMustRevalidate()) {
+ redirectChainCacheStatus.status = RedirectChainCacheStatus::NotCachedRedirection;
+ return;
+ }
+ redirectChainCacheStatus.status = RedirectChainCacheStatus::CachedRedirection;
+ double responseTimestamp = currentTime();
+ // Store the nearest end of cache validity date
+ double endOfValidity = responseTimestamp + computeFreshnessLifetimeForHTTPFamily(response, responseTimestamp) - computeCurrentAge(response, responseTimestamp);
+ redirectChainCacheStatus.endOfValidity = std::min(redirectChainCacheStatus.endOfValidity, endOfValidity);
+}
+
+bool redirectChainAllowsReuse(RedirectChainCacheStatus redirectChainCacheStatus)
+{
+ switch (redirectChainCacheStatus.status) {
+ case RedirectChainCacheStatus::NoRedirection:
+ return true;
+ case RedirectChainCacheStatus::NotCachedRedirection:
+ return false;
+ case RedirectChainCacheStatus::CachedRedirection:
+ return currentTime() <= redirectChainCacheStatus.endOfValidity;
+ }
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
+}
Added: trunk/Source/WebCore/loader/CacheValidation.h (0 => 175342)
--- trunk/Source/WebCore/loader/CacheValidation.h (rev 0)
+++ trunk/Source/WebCore/loader/CacheValidation.h 2014-10-29 20:54:45 UTC (rev 175342)
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 1998 Lars Knoll ([email protected])
+ Copyright (C) 2001 Dirk Mueller ([email protected])
+ Copyright (C) 2006 Samuel Weinig ([email protected])
+ Copyright (C) 2004-2011, 2014 Apple Inc. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef CacheValidation_h
+#define CacheValidation_h
+
+namespace WebCore {
+
+class ResourceResponse;
+
+struct RedirectChainCacheStatus {
+ enum Status {
+ NoRedirection,
+ NotCachedRedirection,
+ CachedRedirection
+ };
+ RedirectChainCacheStatus()
+ : status(NoRedirection)
+ , endOfValidity(std::numeric_limits<double>::max())
+ { }
+ Status status;
+ double endOfValidity;
+};
+
+double computeCurrentAge(const ResourceResponse&, double responseTimestamp);
+double computeFreshnessLifetimeForHTTPFamily(const ResourceResponse&, double responseTimestamp);
+void updateResponseHeadersAfterRevalidation(ResourceResponse&, const ResourceResponse& validatingResponse);
+void updateRedirectChainStatus(RedirectChainCacheStatus&, const ResourceResponse&);
+bool redirectChainAllowsReuse(RedirectChainCacheStatus);
+
+}
+
+#endif
Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (175341 => 175342)
--- trunk/Source/WebCore/loader/cache/CachedResource.cpp 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp 2014-10-29 20:54:45 UTC (rev 175342)
@@ -3,7 +3,7 @@
Copyright (C) 2001 Dirk Mueller ([email protected])
Copyright (C) 2002 Waldo Bastian ([email protected])
Copyright (C) 2006 Samuel Weinig ([email protected])
- Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
+ Copyright (C) 2004-2011, 2014 Apple Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -104,6 +104,22 @@
return true;
}
+void updateResponseHeadersAfterRevalidation(ResourceResponse& response, const ResourceResponse& validatingResponse)
+{
+ // RFC2616 10.3.5
+ // Update cached headers from the 304 response
+ for (const auto& header : validatingResponse.httpHeaderFields()) {
+ // Entity headers should not be sent by servers when generating a 304
+ // response; misconfigured servers send them anyway. We shouldn't allow
+ // such headers to update the original request. We'll base this on the
+ // list defined by RFC2616 7.1, with a few additions for extension headers
+ // we care about.
+ if (!shouldUpdateHeaderAfterRevalidation(header.key))
+ continue;
+ response.setHTTPHeaderField(header.key, header.value);
+ }
+}
+
static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type type)
{
switch (type) {
@@ -146,18 +162,6 @@
return memoryCache()->deadDecodedDataDeletionInterval();
}
-static double currentAge(const ResourceResponse& response, double responseTimestamp)
-{
- // RFC2616 13.2.3
- // No compensation for latency as that is not terribly important in practice
- double dateValue = response.date();
- double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimestamp - dateValue) : 0;
- double ageValue = response.age();
- double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge, ageValue) : apparentAge;
- double residentTime = currentTime() - responseTimestamp;
- return correctedReceivedAge + residentTime;
-}
-
DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("CachedResource"));
CachedResource::CachedResource(const ResourceRequest& request, Type type, SessionID sessionID)
@@ -192,8 +196,6 @@
, m_owningCachedResourceLoader(0)
, m_resourceToRevalidate(0)
, m_proxyResource(0)
- , m_redirectChainCacheStatus(NoRedirection)
- , m_redirectChainEndOfValidity(std::numeric_limits<double>::max())
{
ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests careless updates of the enum.
ASSERT(sessionID.isValid());
@@ -400,7 +402,7 @@
if (m_response.isNull())
return false;
- return currentAge(m_response, m_responseTimestamp) > freshnessLifetime(m_response);
+ return computeCurrentAge(m_response, m_responseTimestamp) > freshnessLifetime(m_response);
}
double CachedResource::freshnessLifetime(const ResourceResponse& response) const
@@ -415,20 +417,7 @@
return std::numeric_limits<double>::max();
}
- // RFC2616 13.2.4
- double maxAgeValue = response.cacheControlMaxAge();
- if (std::isfinite(maxAgeValue))
- return maxAgeValue;
- double expiresValue = response.expires();
- double dateValue = response.date();
- double creationTime = std::isfinite(dateValue) ? dateValue : m_responseTimestamp;
- if (std::isfinite(expiresValue))
- return expiresValue - creationTime;
- double lastModifiedValue = response.lastModified();
- if (std::isfinite(lastModifiedValue))
- return (creationTime - lastModifiedValue) * 0.1;
- // If no cache headers are present, the specification leaves the decision to the UA. Other browsers seem to opt for 0.
- return 0;
+ return computeFreshnessLifetimeForHTTPFamily(response, m_responseTimestamp);
}
void CachedResource::willSendRequest(ResourceRequest&, const ResourceResponse& response)
@@ -436,19 +425,7 @@
m_requestedFromNetworkingLayer = true;
if (response.isNull())
return;
- if (m_redirectChainCacheStatus == NotCachedRedirection)
- return;
- if (response.cacheControlContainsNoStore()
- || response.cacheControlContainsNoCache()
- || response.cacheControlContainsMustRevalidate())
- m_redirectChainCacheStatus = NotCachedRedirection;
- else {
- m_redirectChainCacheStatus = CachedRedirection;
- double responseTimestamp = currentTime();
- // Store the nearest end of cache validity date
- m_redirectChainEndOfValidity = std::min(m_redirectChainEndOfValidity,
- responseTimestamp + freshnessLifetime(response) - currentAge(response, responseTimestamp));
- }
+ updateRedirectChainStatus(m_redirectChainCacheStatus, response);
}
void CachedResource::responseReceived(const ResourceResponse& response)
@@ -733,18 +710,7 @@
{
m_responseTimestamp = currentTime();
- // RFC2616 10.3.5
- // Update cached headers from the 304 response
- for (const auto& header : validatingResponse.httpHeaderFields()) {
- // Entity headers should not be sent by servers when generating a 304
- // response; misconfigured servers send them anyway. We shouldn't allow
- // such headers to update the original request. We'll base this on the
- // list defined by RFC2616 7.1, with a few additions for extension headers
- // we care about.
- if (!shouldUpdateHeaderAfterRevalidation(header.key))
- continue;
- m_response.setHTTPHeaderField(header.key, header.value);
- }
+ updateResponseHeadersAfterRevalidation(m_response, validatingResponse);
}
void CachedResource::registerHandle(CachedResourceHandleBase* h)
@@ -807,15 +773,7 @@
bool CachedResource::redirectChainAllowsReuse() const
{
- switch (m_redirectChainCacheStatus) {
- case NoRedirection:
- return true;
- case NotCachedRedirection:
- return false;
- case CachedRedirection:
- return currentTime() <= m_redirectChainEndOfValidity;
- }
- return true;
+ return WebCore::redirectChainAllowsReuse(m_redirectChainCacheStatus);
}
unsigned CachedResource::overheadSize() const
Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (175341 => 175342)
--- trunk/Source/WebCore/loader/cache/CachedResource.h 2014-10-29 20:48:31 UTC (rev 175341)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h 2014-10-29 20:54:45 UTC (rev 175342)
@@ -24,6 +24,7 @@
#define CachedResource_h
#include "CachePolicy.h"
+#include "CacheValidation.h"
#include "FrameLoaderTypes.h"
#include "ResourceError.h"
#include "ResourceLoadPriority.h"
@@ -88,12 +89,6 @@
DecodeError
};
- enum RedirectChainCacheStatus {
- NoRedirection,
- NotCachedRedirection,
- CachedRedirection
- };
-
CachedResource(const ResourceRequest&, Type, SessionID);
virtual ~CachedResource();
@@ -358,7 +353,6 @@
HashSet<CachedResourceHandleBase*> m_handlesToRevalidate;
RedirectChainCacheStatus m_redirectChainCacheStatus;
- double m_redirectChainEndOfValidity;
};
} // namespace WebCore