Title: [175348] trunk/Source/WebCore
Revision
175348
Author
[email protected]
Date
2014-10-29 15:01:21 -0700 (Wed, 29 Oct 2014)

Log Message

Notify Settings object when its Page object goes away.
https://bugs.webkit.org/show_bug.cgi?id=138183
rdar://problem/18786900

Patch by Alexey Proskuryakov <[email protected]> on 2014-10-29
Reviewed by Andreas Kling.

I could not make a test for this issue.

* page/Page.cpp:
(WebCore::Page::~Page):
* page/Settings.cpp:
(WebCore::setImageLoadingSettings):
(WebCore::Settings::Settings):
(WebCore::Settings::setTextAutosizingEnabled):
(WebCore::Settings::setTextAutosizingWindowSizeOverride):
(WebCore::Settings::setTextAutosizingFontScaleFactor):
(WebCore::Settings::setMediaTypeOverride):
(WebCore::Settings::setScriptEnabled):
(WebCore::Settings::setUserStyleSheetLocation):
(WebCore::Settings::setMinDOMTimerInterval):
(WebCore::Settings::minDOMTimerInterval):
(WebCore::Settings::domTimerAlignmentInterval):
(WebCore::Settings::setUsesPageCache):
(WebCore::Settings::setScreenFontSubstitutionEnabled):
(WebCore::Settings::setFontRenderingMode):
(WebCore::Settings::setDNSPrefetchingEnabled):
(WebCore::Settings::setStorageBlockingPolicy):
(WebCore::Settings::setBackgroundShouldExtendBeyondPage):
(WebCore::Settings::setScrollingPerformanceLoggingEnabled):
(WebCore::Settings::setHiddenPageDOMTimerThrottlingEnabled):
(WebCore::Settings::setHiddenPageCSSAnimationSuspensionEnabled):
(WebCore::Settings::setFontFallbackPrefersPictographs):
* page/Settings.h:
(WebCore::Settings::pageDestroyed):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (175347 => 175348)


--- trunk/Source/WebCore/CMakeLists.txt	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/CMakeLists.txt	2014-10-29 22:01:21 UTC (rev 175348)
@@ -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 (175347 => 175348)


--- trunk/Source/WebCore/ChangeLog	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/ChangeLog	2014-10-29 22:01:21 UTC (rev 175348)
@@ -62,6 +62,37 @@
 
 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-29  Antti Koivisto  <[email protected]>
+
         Unreviewed, rolling out r175342.
 
         a file ended up in a wrong directory

Modified: trunk/Source/WebCore/WebCore.exp.in (175347 => 175348)


--- trunk/Source/WebCore/WebCore.exp.in	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-10-29 22:01:21 UTC (rev 175348)
@@ -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 (175347 => 175348)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2014-10-29 22:01:21 UTC (rev 175348)
@@ -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 (175347 => 175348)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-10-29 22:01:21 UTC (rev 175348)
@@ -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/cache/CacheValidation.cpp; sourceTree = SOURCE_ROOT; };
+		E467680F1A0177F900B9E26B /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CacheValidation.h; path = loader/cache/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/cache/CacheValidation.cpp (0 => 175348)


--- trunk/Source/WebCore/loader/cache/CacheValidation.cpp	                        (rev 0)
+++ trunk/Source/WebCore/loader/cache/CacheValidation.cpp	2014-10-29 22:01:21 UTC (rev 175348)
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CacheValidation.h"
+
+#include "ResourceResponse.h"
+#include <wtf/CurrentTime.h>
+
+namespace WebCore {
+
+// These response headers are not copied from a revalidated response to the
+// cached response headers. For compatibility, this list is based on Chromium's
+// net/http/http_response_headers.cc.
+const char* const headersToIgnoreAfterRevalidation[] = {
+    "allow",
+    "connection",
+    "etag",
+    "expires",
+    "keep-alive",
+    "last-modified"
+    "proxy-authenticate",
+    "proxy-connection",
+    "trailer",
+    "transfer-encoding",
+    "upgrade",
+    "www-authenticate",
+    "x-frame-options",
+    "x-xss-protection",
+};
+
+// Some header prefixes mean "Don't copy this header from a 304 response.".
+// Rather than listing all the relevant headers, we can consolidate them into
+// this list, also grabbed from Chromium's net/http/http_response_headers.cc.
+const char* const headerPrefixesToIgnoreAfterRevalidation[] = {
+    "content-",
+    "x-content-",
+    "x-webkit-"
+};
+
+static inline bool shouldUpdateHeaderAfterRevalidation(const String& header)
+{
+    for (size_t i = 0; i < WTF_ARRAY_LENGTH(headersToIgnoreAfterRevalidation); i++) {
+        if (equalIgnoringCase(header, headersToIgnoreAfterRevalidation[i]))
+            return false;
+    }
+    for (size_t i = 0; i < WTF_ARRAY_LENGTH(headerPrefixesToIgnoreAfterRevalidation); i++) {
+        if (header.startsWith(headerPrefixesToIgnoreAfterRevalidation[i], false))
+            return false;
+    }
+    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);
+    }
+}
+
+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/cache/CacheValidation.h (0 => 175348)


--- trunk/Source/WebCore/loader/cache/CacheValidation.h	                        (rev 0)
+++ trunk/Source/WebCore/loader/cache/CacheValidation.h	2014-10-29 22:01:21 UTC (rev 175348)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#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 (175347 => 175348)


--- trunk/Source/WebCore/loader/cache/CachedResource.cpp	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp	2014-10-29 22:01:21 UTC (rev 175348)
@@ -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
@@ -62,48 +62,6 @@
 
 namespace WebCore {
 
-// These response headers are not copied from a revalidated response to the
-// cached response headers. For compatibility, this list is based on Chromium's
-// net/http/http_response_headers.cc.
-const char* const headersToIgnoreAfterRevalidation[] = {
-    "allow",
-    "connection",
-    "etag",
-    "expires",
-    "keep-alive",
-    "last-modified"
-    "proxy-authenticate",
-    "proxy-connection",
-    "trailer",
-    "transfer-encoding",
-    "upgrade",
-    "www-authenticate",
-    "x-frame-options",
-    "x-xss-protection",
-};
-
-// Some header prefixes mean "Don't copy this header from a 304 response.".
-// Rather than listing all the relevant headers, we can consolidate them into
-// this list, also grabbed from Chromium's net/http/http_response_headers.cc.
-const char* const headerPrefixesToIgnoreAfterRevalidation[] = {
-    "content-",
-    "x-content-",
-    "x-webkit-"
-};
-
-static inline bool shouldUpdateHeaderAfterRevalidation(const String& header)
-{
-    for (size_t i = 0; i < WTF_ARRAY_LENGTH(headersToIgnoreAfterRevalidation); i++) {
-        if (equalIgnoringCase(header, headersToIgnoreAfterRevalidation[i]))
-            return false;
-    }
-    for (size_t i = 0; i < WTF_ARRAY_LENGTH(headerPrefixesToIgnoreAfterRevalidation); i++) {
-        if (header.startsWith(headerPrefixesToIgnoreAfterRevalidation[i], false))
-            return false;
-    }
-    return true;
-}
-
 static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type type)
 {
     switch (type) {
@@ -146,18 +104,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 +138,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 +344,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 +359,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 +367,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 +652,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 +715,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 (175347 => 175348)


--- trunk/Source/WebCore/loader/cache/CachedResource.h	2014-10-29 21:59:48 UTC (rev 175347)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h	2014-10-29 22:01:21 UTC (rev 175348)
@@ -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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to