<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[173173] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/173173">173173</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-09-02 09:00:14 -0700 (Tue, 02 Sep 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>CachedResourceLoader should check redirections to reuse or not cached resources
https://bugs.webkit.org/show_bug.cgi?id=131757
Patch by Youenn Fablet <youenn.fablet@crf.canon.fr> on 2014-09-02
Reviewed by Antti Koivisto.
Source/WebCore:
Added cache-control redirection check to properly determine revalidation policy.
Tightened redirection cache-control header check by testing for no-cache and must-revalidate directives.
Added redirection freshness check.
Test: http/tests/cache/cache-redirections.html
* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::canReuse): Removed redirection check (now handled by CachedResource::redirectChainAllowsReuse).
* loader/cache/CachedResource.cpp:
(WebCore::currentAge): Moved from WebCore::CachedResource::currentAge method to static function. Added response and responseTimestamp as parameters.
(WebCore::CachedResource::CachedResource): Initialized redirection chain status (no redirection and expiracy date set to never).
(WebCore::CachedResource::isExpired): Updated according new currentAge/freshnessLifetime method parameters.
(WebCore::CachedResource::freshnessLifetime): Added response as parameter.
(WebCore::CachedResource::willSendRequest): Computes whether a redirection can be cached, and if cached for how long it will remain fresh.
(WebCore::CachedResource::redirectChainAllowsReuse): Return false if any of the redirection in the redirection chain cannot be cached or expired.
* loader/cache/CachedResource.h: Added cache chain member that stores whether the redirection chain can be cached and if so when it will be expired.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::determineRevalidationPolicy): Added check of the redirection chain.
LayoutTests:
Added test checks that fresh redirections allow reuse of cached resoure and expired or not cacheable redirections trigger reloading of resources.
* http/tests/cache/cache-redirections-expected.txt: Added.
* http/tests/cache/cache-redirections.html: Added.
* http/tests/cache/resources/cache-control-redirect.php: Added.
* http/tests/cache/resources/cacheable-random-text.php: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedRawResourcecpp">trunk/Source/WebCore/loader/cache/CachedRawResource.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourcecpp">trunk/Source/WebCore/loader/cache/CachedResource.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceh">trunk/Source/WebCore/loader/cache/CachedResource.h</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceLoadercpp">trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestscachecacheredirectionsexpectedtxt">trunk/LayoutTests/http/tests/cache/cache-redirections-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscachecacheredirectionshtml">trunk/LayoutTests/http/tests/cache/cache-redirections.html</a></li>
<li><a href="#trunkLayoutTestshttptestscacheresourcescachecontrolredirectphp">trunk/LayoutTests/http/tests/cache/resources/cache-control-redirect.php</a></li>
<li><a href="#trunkLayoutTestshttptestscacheresourcescacheablerandomtextphp">trunk/LayoutTests/http/tests/cache/resources/cacheable-random-text.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (173172 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-09-02 15:54:26 UTC (rev 173172)
+++ trunk/LayoutTests/ChangeLog        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-09-02 Youenn Fablet <youenn.fablet@crf.canon.fr>
+
+ CachedResourceLoader should check redirections to reuse or not cached resources
+ https://bugs.webkit.org/show_bug.cgi?id=131757
+
+ Reviewed by Antti Koivisto.
+
+ Added test checks that fresh redirections allow reuse of cached resoure and expired or not cacheable redirections trigger reloading of resources.
+
+ * http/tests/cache/cache-redirections-expected.txt: Added.
+ * http/tests/cache/cache-redirections.html: Added.
+ * http/tests/cache/resources/cache-control-redirect.php: Added.
+ * http/tests/cache/resources/cacheable-random-text.php: Added.
+
</ins><span class="cx"> 2014-09-02 Manuel Rego Casasnovas <rego@igalia.com>
</span><span class="cx">
</span><span class="cx"> [CSS Grid Layout] Test coverage for first-line pseudo-element
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachecacheredirectionsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/cache-redirections-expected.txt (0 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/cache-redirections-expected.txt         (rev 0)
+++ trunk/LayoutTests/http/tests/cache/cache-redirections-expected.txt        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+
+
+PASS Testing cache reloading strategy according redirections with different cache state
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscachecacheredirectionshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/cache-redirections.html (0 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/cache-redirections.html         (rev 0)
+++ trunk/LayoutTests/http/tests/cache/cache-redirections.html        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -0,0 +1,73 @@
</span><ins>+<html>
+<head>
+ <title>Testing cache reloading strategy according redirections with different cache state</title>
+ <script src="/js-test-resources/testharness.js"></script>
+ <script src="/js-test-resources/testharnessreport.js"></script>
+</head>
+<body>
+<iframe id="iframe1"></iframe>
+<iframe id="iframe2"></iframe>
+<div id="log"></div>
+<script>
+
+var test = async_test();
+test.step(function() {
+
+var counter = 0;
+var resource = "No";
+var baseURL = "resources/cache-control-redirect?code=302&url=cacheable-random-text.php&random_id=1";
+var testCases = [
+{name : "Should reuse resource (cacheable redirection)", expected : true, url : baseURL + "&cache_control=public, max-age=1000", reloadDelay : 0},
+{name : "Should reload resource (no-store redirection)", expected : false, url: baseURL + "&cache_control=no-store&max_age=1000", reloadDelay : 0},
+{name : "Should reload resource (no-cache redirection)", expected : false, url: baseURL + "&cache_control=no-cache&max_age=1000", reloadDelay : 0},
+{name : "Should reload resource (must-revalidate redirection)", expected : false, url: baseURL + "&cache_control=must-revalidate&max_age=1000", reloadDelay : 0},
+{name : "Should reload resource (expired redirection)", expected : false, url: baseURL + "&cache_control=public, max-age=1", reloadDelay : 1000},
+];
+
+function loadResource()
+{
+ setFrame1Loader();
+        document.getElementById('iframe1').src = testCases[counter].url;
+}
+
+function reloadResource()
+{
+ setFrame2Loader();
+        document.getElementById('iframe2').src = testCases[counter].url;
+}
+
+function setFrame1Loader()
+{
+ document.getElementById('iframe2').onload = null;
+ document.getElementById('iframe1').onload = test.step_func(function()
+ {
+ resource = document.getElementById('iframe1').contentDocument.body.innerHTML;
+ setTimeout(test.step_func(reloadResource), testCases[counter].reloadDelay);
+ });
+}
+
+function setFrame2Loader()
+{
+ document.getElementById('iframe1').onload = null;
+ document.getElementById('iframe2').onload = test.step_func(function ()
+ {
+ var testResult = resource == document.getElementById('iframe2').contentDocument.body.innerHTML;
+ assert_true(testResult == testCases[counter].expected, testCases[counter].name);
+
+ document.getElementById('iframe1').contentDocument.body.innerHTML = "frame 1";
+ document.getElementById('iframe2').contentDocument.body.innerHTML = "frame 2";
+ if (++counter < testCases.length)
+ loadResource();
+ else
+ test.done();
+ });
+}
+
+document.onload = setTimeout(loadResource, 1);
+
+});
+
+
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscacheresourcescachecontrolredirectphp"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/resources/cache-control-redirect.php (0 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/resources/cache-control-redirect.php         (rev 0)
+++ trunk/LayoutTests/http/tests/cache/resources/cache-control-redirect.php        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -0,0 +1,27 @@
</span><ins>+<?php
+ $code = $_GET['code'];
+ if (!isset($code))
+ $code = 302;
+ header('HTTP/1.1 ' . $code);
+
+ $url = $_GET['url'];
+ $random_id = $_GET['random_id'];
+ if (isset($random_id)) {
+ $id = '';
+ $charset = 'ABCDEFGHIKLMNOPQRSTUVWXYZ0123456789';
+ for ($i = 0; $i < 16; $i++)
+ $id .= $charset[rand(0, strlen($charset) - 1)];
+ header('Location: ' . $url . '?id=' . $id);
+ }
+ else
+ header('Location: ' . $url);
+
+ $max_age = $_GET['max_age'];
+ if (!isset($max_age)) {
+ $expires = gmdate(DATE_RFC1123, time() + $max_age);
+ header('Expires: ' . $expires);
+ }
+
+ $cache_control = $_GET['cache_control'];
+ header('Cache-Control: ' . $cache_control);
+?>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscacheresourcescacheablerandomtextphp"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/resources/cacheable-random-text.php (0 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/resources/cacheable-random-text.php         (rev 0)
+++ trunk/LayoutTests/http/tests/cache/resources/cacheable-random-text.php        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+<?php
+ $max_age = 12 * 31 * 24 * 60 * 60; //one year
+ header('Cache-Control: public, max-age=' . $max_age);
+ header('Content-Type: text/html');
+
+ $id = $GET['id'];
+ if (!isset($GET['random_id'])) {
+ $id = '';
+ $charset = 'ABCDEFGHIKLMNOPQRSTUVWXYZ0123456789';
+ for ($i = 0; $i < 16; $i++)
+ $id .= $charset[rand(0, strlen($charset) - 1)];
+ }
+ echo '<html><body>Some random text' . $id . '</hml></body>';
+?>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (173172 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-09-02 15:54:26 UTC (rev 173172)
+++ trunk/Source/WebCore/ChangeLog        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2014-09-02 Youenn Fablet <youenn.fablet@crf.canon.fr>
+
+ CachedResourceLoader should check redirections to reuse or not cached resources
+ https://bugs.webkit.org/show_bug.cgi?id=131757
+
+ Reviewed by Antti Koivisto.
+
+ Added cache-control redirection check to properly determine revalidation policy.
+ Tightened redirection cache-control header check by testing for no-cache and must-revalidate directives.
+ Added redirection freshness check.
+
+ Test: http/tests/cache/cache-redirections.html
+
+ * loader/cache/CachedRawResource.cpp:
+ (WebCore::CachedRawResource::canReuse): Removed redirection check (now handled by CachedResource::redirectChainAllowsReuse).
+ * loader/cache/CachedResource.cpp:
+ (WebCore::currentAge): Moved from WebCore::CachedResource::currentAge method to static function. Added response and responseTimestamp as parameters.
+ (WebCore::CachedResource::CachedResource): Initialized redirection chain status (no redirection and expiracy date set to never).
+ (WebCore::CachedResource::isExpired): Updated according new currentAge/freshnessLifetime method parameters.
+ (WebCore::CachedResource::freshnessLifetime): Added response as parameter.
+ (WebCore::CachedResource::willSendRequest): Computes whether a redirection can be cached, and if cached for how long it will remain fresh.
+ (WebCore::CachedResource::redirectChainAllowsReuse): Return false if any of the redirection in the redirection chain cannot be cached or expired.
+ * loader/cache/CachedResource.h: Added cache chain member that stores whether the redirection chain can be cached and if so when it will be expired.
+ * loader/cache/CachedResourceLoader.cpp:
+ (WebCore::CachedResourceLoader::determineRevalidationPolicy): Added check of the redirection chain.
+
</ins><span class="cx"> 2014-09-02 Daewoong Jang <daewoong.jang@navercorp.com>
</span><span class="cx">
</span><span class="cx"> Prevent decoded images from being destroyed when they're in use.
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedRawResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedRawResource.cpp (173172 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedRawResource.cpp        2014-09-02 15:54:26 UTC (rev 173172)
+++ trunk/Source/WebCore/loader/cache/CachedRawResource.cpp        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -255,11 +255,6 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- for (size_t i = 0; i < m_redirectChain.size(); i++) {
- if (m_redirectChain[i].m_redirectResponse.cacheControlContainsNoStore())
- return false;
- }
-
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (173172 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.cpp        2014-09-02 15:54:26 UTC (rev 173172)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -146,6 +146,18 @@
</span><span class="cx"> return memoryCache()->deadDecodedDataDeletionInterval();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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;
+}
+
</ins><span class="cx"> DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("CachedResource"));
</span><span class="cx">
</span><span class="cx"> CachedResource::CachedResource(const ResourceRequest& request, Type type, SessionID sessionID)
</span><span class="lines">@@ -180,6 +192,8 @@
</span><span class="cx"> , m_owningCachedResourceLoader(0)
</span><span class="cx"> , m_resourceToRevalidate(0)
</span><span class="cx"> , m_proxyResource(0)
</span><ins>+ , m_redirectChainCacheStatus(NoRedirection)
+ , m_redirectChainEndOfValidity(std::numeric_limits<double>::max())
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests careless updates of the enum.
</span><span class="cx"> ASSERT(sessionID.isValid());
</span><span class="lines">@@ -386,49 +400,57 @@
</span><span class="cx"> if (m_response.isNull())
</span><span class="cx"> return false;
</span><span class="cx">
</span><del>- return currentAge() > freshnessLifetime();
</del><ins>+ return currentAge(m_response, m_responseTimestamp) > freshnessLifetime(m_response);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-double CachedResource::currentAge() const
</del><ins>+double CachedResource::freshnessLifetime(const ResourceResponse& response) const
</ins><span class="cx"> {
</span><del>- // RFC2616 13.2.3
- // No compensation for latency as that is not terribly important in practice
- double dateValue = m_response.date();
- double apparentAge = std::isfinite(dateValue) ? std::max(0., m_responseTimestamp - dateValue) : 0;
- double ageValue = m_response.age();
- double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge, ageValue) : apparentAge;
- double residentTime = currentTime() - m_responseTimestamp;
- return correctedReceivedAge + residentTime;
-}
-
-double CachedResource::freshnessLifetime() const
-{
- if (!m_response.url().protocolIsInHTTPFamily()) {
</del><ins>+ if (!response.url().protocolIsInHTTPFamily()) {
</ins><span class="cx"> // Don't cache non-HTTP main resources since we can't check for freshness.
</span><span class="cx"> // FIXME: We should not cache subresources either, but when we tried this
</span><span class="cx"> // it caused performance and flakiness issues in our test infrastructure.
</span><del>- if (m_type == MainResource && !SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(m_response.url().protocol()))
</del><ins>+ if (m_type == MainResource && !SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(response.url().protocol()))
</ins><span class="cx"> return 0;
</span><span class="cx">
</span><span class="cx"> return std::numeric_limits<double>::max();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // RFC2616 13.2.4
</span><del>- double maxAgeValue = m_response.cacheControlMaxAge();
</del><ins>+ double maxAgeValue = response.cacheControlMaxAge();
</ins><span class="cx"> if (std::isfinite(maxAgeValue))
</span><span class="cx"> return maxAgeValue;
</span><del>- double expiresValue = m_response.expires();
- double dateValue = m_response.date();
</del><ins>+ double expiresValue = response.expires();
+ double dateValue = response.date();
</ins><span class="cx"> double creationTime = std::isfinite(dateValue) ? dateValue : m_responseTimestamp;
</span><span class="cx"> if (std::isfinite(expiresValue))
</span><span class="cx"> return expiresValue - creationTime;
</span><del>- double lastModifiedValue = m_response.lastModified();
</del><ins>+ double lastModifiedValue = response.lastModified();
</ins><span class="cx"> if (std::isfinite(lastModifiedValue))
</span><span class="cx"> return (creationTime - lastModifiedValue) * 0.1;
</span><span class="cx"> // If no cache headers are present, the specification leaves the decision to the UA. Other browsers seem to opt for 0.
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void CachedResource::willSendRequest(ResourceRequest&, const ResourceResponse& response)
+{
+ 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));
+ }
+}
+
</ins><span class="cx"> void CachedResource::responseReceived(const ResourceResponse& response)
</span><span class="cx"> {
</span><span class="cx"> setResponse(response);
</span><span class="lines">@@ -783,6 +805,19 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool CachedResource::redirectChainAllowsReuse() const
+{
+ switch (m_redirectChainCacheStatus) {
+ case NoRedirection:
+ return true;
+ case NotCachedRedirection:
+ return false;
+ case CachedRedirection:
+ return currentTime() <= m_redirectChainEndOfValidity;
+ }
+ return true;
+}
+
</ins><span class="cx"> unsigned CachedResource::overheadSize() const
</span><span class="cx"> {
</span><span class="cx"> static const int kAverageClientsHashMapSize = 384;
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (173172 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.h        2014-09-02 15:54:26 UTC (rev 173172)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -88,6 +88,12 @@
</span><span class="cx"> DecodeError
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+ enum RedirectChainCacheStatus {
+ NoRedirection,
+ NotCachedRedirection,
+ CachedRedirection
+ };
+
</ins><span class="cx"> CachedResource(const ResourceRequest&, Type, SessionID);
</span><span class="cx"> virtual ~CachedResource();
</span><span class="cx">
</span><span class="lines">@@ -188,7 +194,7 @@
</span><span class="cx">
</span><span class="cx"> ResourceBuffer* resourceBuffer() const { return m_data.get(); }
</span><span class="cx">
</span><del>- virtual void willSendRequest(ResourceRequest&, const ResourceResponse&) { m_requestedFromNetworkingLayer = true; }
</del><ins>+ virtual void willSendRequest(ResourceRequest&, const ResourceResponse&);
</ins><span class="cx"> virtual void responseReceived(const ResourceResponse&);
</span><span class="cx"> void setResponse(const ResourceResponse& response) { m_response = response; }
</span><span class="cx"> const ResourceResponse& response() const { return m_response; }
</span><span class="lines">@@ -225,6 +231,7 @@
</span><span class="cx"> bool canUseCacheValidator() const;
</span><span class="cx">
</span><span class="cx"> virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const;
</span><ins>+ bool redirectChainAllowsReuse() const;
</ins><span class="cx">
</span><span class="cx"> bool isCacheValidator() const { return m_resourceToRevalidate; }
</span><span class="cx"> CachedResource* resourceToRevalidate() const { return m_resourceToRevalidate; }
</span><span class="lines">@@ -299,8 +306,7 @@
</span><span class="cx">
</span><span class="cx"> virtual bool mayTryReplaceEncodedData() const { return false; }
</span><span class="cx">
</span><del>- double currentAge() const;
- double freshnessLifetime() const;
</del><ins>+ double freshnessLifetime(const ResourceResponse&) const;
</ins><span class="cx">
</span><span class="cx"> void addAdditionalRequestHeaders(CachedResourceLoader*);
</span><span class="cx"> void failBeforeStarting();
</span><span class="lines">@@ -355,6 +361,9 @@
</span><span class="cx">
</span><span class="cx"> // These handles will need to be updated to point to the m_resourceToRevalidate in case we get 304 response.
</span><span class="cx"> HashSet<CachedResourceHandleBase*> m_handlesToRevalidate;
</span><ins>+
+ RedirectChainCacheStatus m_redirectChainCacheStatus;
+ double m_redirectChainEndOfValidity;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> #define CACHED_RESOURCE_TYPE_CASTS(ToClassName, FromClassName, CachedResourceType) \
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (173172 => 173173)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp        2014-09-02 15:54:26 UTC (rev 173172)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp        2014-09-02 16:00:14 UTC (rev 173173)
</span><span class="lines">@@ -594,6 +594,12 @@
</span><span class="cx"> return Reload;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ // Validate the redirect chain
+ if (!existingResource->redirectChainAllowsReuse()) {
+ LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy reloading due to not cached or expired redirections.");
+ return Reload;
+ }
+
</ins><span class="cx"> // If credentials were sent with the previous request and won't be
</span><span class="cx"> // with this one, or vice versa, re-fetch the resource.
</span><span class="cx"> //
</span></span></pre>
</div>
</div>
</body>
</html>