Commit 92a952bc authored by japhet@chromium.org's avatar japhet@chromium.org

2010-07-12 Nate Chapin <japhet@chromium.org>

        Reviewed by Darin Fisher.

        Ensure that a cache policy that forces validation is cleared once
        the load event is fired, rather than only doing so at the next
        navigation. This leads to a lot of unnecessary load on AJAX-y
        websites.

        https://bugs.webkit.org/show_bug.cgi?id=41813

        Test: http/tests/xmlhttprequest/cache-headers-after-reload.html

        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::handledOnloadEvents): Reset m_loadType to FrameLoadTypeStandard.
        (WebCore::FrameLoader::addExtraFieldsToRequest): Only respect the original request's cache policy if the
            DocumentLoader is still loading, and handle the other cache policy settings that were scattered around the loader.
        (WebCore::FrameLoader::loadResourceSynchronously): Merge cachePolicy setting into FrameLoader::addExtraFieldsToRequest.
        * loader/SubresourceLoader.cpp:
        (WebCore::SubresourceLoader::create): Merge cachePolicy setting into FrameLoader::addExtraFieldsToRequest.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63100 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 472201fc
2010-07-12 Nate Chapin <japhet@chromium.org>
Reviewed by Darin Fisher.
Test that Cache-Control headers are not included on XHRs that occur
after the load event.
https://bugs.webkit.org/show_bug.cgi?id=41813
* http/tests/xmlhttprequest/cache-headers-after-reload-expected.txt: Added.
* http/tests/xmlhttprequest/cache-headers-after-reload.html: Added.
* http/tests/xmlhttprequest/resources/print-cache-control-header.cgi: Added.
2010-07-12 Csaba Osztrogonác <ossy@webkit.org>
Unreviewed.
This test does the following:
1. Load a page, trigger an XHR.
2. Reload the page.
3. Dump the http readers for the reload of the XHR.
The XHR is trigger after onload has fired. There should not be an HTTP_CACHE_CONTROL header forcing reload, so an http cache could load the resource without contacting the server.
The test passes if there is no HTTP_CACHE_CONTROL header displayed below.
<html>
<body onload="setTimeout(test, 100);">
This test does the following:<br>
1. Load a page, trigger an XHR.<br>
2. Reload the page.<br>
3. Dump the http readers for the reload of the XHR.<br><br>
The XHR is trigger after onload has fired. There should not be an HTTP_CACHE_CONTROL header forcing reload, so an http cache
could load the resource without contacting the server.<br>
The test passes if there is no HTTP_CACHE_CONTROL header displayed below.<br>
<div id="console"></div>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
function log(message) {
document.getElementById("console").appendChild(document.createTextNode(message));
}
var xhr;
function test() {
xhr = new XMLHttpRequest();
if (localStorage.reloaded)
xhr.onload = finish;
else
xhr.onload = reload;
xhr.open("GET", "resources/print-cache-control-header.cgi", true);
xhr.send(null);
}
function reload() {
localStorage.reloaded = true;
location.reload(true);
}
function finish() {
log(xhr.responseText);
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
#!/usr/bin/perl -wT
use strict;
print "Content-Type: text/plain\n\n";
foreach (keys %ENV) {
if ($_ =~ "HTTP_CACHE_CONTROL") {
print $_ . ": " . $ENV{$_} . "\n";
}
}
2010-07-12 Nate Chapin <japhet@chromium.org>
Reviewed by Darin Fisher.
Ensure that a cache policy that forces validation is cleared once
the load event is fired, rather than only doing so at the next
navigation. This leads to a lot of unnecessary load on AJAX-y
websites.
https://bugs.webkit.org/show_bug.cgi?id=41813
Test: http/tests/xmlhttprequest/cache-headers-after-reload.html
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::handledOnloadEvents): Reset m_loadType to FrameLoadTypeStandard.
(WebCore::FrameLoader::addExtraFieldsToRequest): Only respect the original request's cache policy if the
DocumentLoader is still loading, and handle the other cache policy settings that were scattered around the loader.
(WebCore::FrameLoader::loadResourceSynchronously): Merge cachePolicy setting into FrameLoader::addExtraFieldsToRequest.
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::create): Merge cachePolicy setting into FrameLoader::addExtraFieldsToRequest.
2010-07-12 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Oliver Hunt.
......@@ -2605,6 +2605,9 @@ String FrameLoader::userAgent(const KURL& url) const
void FrameLoader::handledOnloadEvents()
{
m_client->dispatchDidHandleOnloadEvents();
m_loadType = FrameLoadTypeStandard;
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
if (documentLoader())
documentLoader()->applicationCacheHost()->stopDeferringEvents();
......@@ -2677,6 +2680,13 @@ void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, FrameLoadTyp
applyUserAgent(request);
// If we inherit cache policy from a main resource, we use the DocumentLoader's
// original request cache policy for two reasons:
// 1. For POST requests, we mutate the cache policy for the main resource,
// but we do not want this to apply to subresources
// 2. Delegates that modify the cache policy using willSendRequest: should
// not affect any other resources. Such changes need to be done
// per request.
if (loadType == FrameLoadTypeReload) {
request.setCachePolicy(ReloadIgnoringCacheData);
request.setHTTPHeaderField("Cache-Control", "max-age=0");
......@@ -2684,8 +2694,12 @@ void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, FrameLoadTyp
request.setCachePolicy(ReloadIgnoringCacheData);
request.setHTTPHeaderField("Cache-Control", "no-cache");
request.setHTTPHeaderField("Pragma", "no-cache");
} else if (isBackForwardLoadType(loadType) && !request.url().protocolIs("https"))
} else if (request.isConditional())
request.setCachePolicy(ReloadIgnoringCacheData);
else if (isBackForwardLoadType(loadType) && !request.url().protocolIs("https"))
request.setCachePolicy(ReturnCacheDataElseLoad);
else if (!mainResource && documentLoader()->isLoadingInAPISense())
request.setCachePolicy(documentLoader()->originalRequest().cachePolicy());
if (mainResource)
request.setHTTPAccept(defaultAcceptHeader);
......@@ -2782,17 +2796,6 @@ unsigned long FrameLoader::loadResourceSynchronously(const ResourceRequest& requ
ResourceRequest initialRequest = request;
initialRequest.setTimeoutInterval(10);
// Use the original request's cache policy for two reasons:
// 1. For POST requests, we mutate the cache policy for the main resource,
// but we do not want this to apply to subresources
// 2. Delegates that modify the cache policy using willSendRequest: should
// not affect any other resources. Such changes need to be done
// per request.
if (initialRequest.isConditional())
initialRequest.setCachePolicy(ReloadIgnoringCacheData);
else
initialRequest.setCachePolicy(originalRequest().cachePolicy());
if (!referrer.isEmpty())
initialRequest.setHTTPReferrer(referrer);
addHTTPOriginIfNeeded(initialRequest, outgoingOrigin());
......@@ -2800,6 +2803,8 @@ unsigned long FrameLoader::loadResourceSynchronously(const ResourceRequest& requ
if (Page* page = m_frame->page())
initialRequest.setFirstPartyForCookies(page->mainFrame()->loader()->documentLoader()->request().url());
initialRequest.setHTTPUserAgent(client()->userAgent(request.url()));
addExtraFieldsToSubresourceRequest(initialRequest);
unsigned long identifier = 0;
ResourceRequest newRequest(initialRequest);
......
......@@ -84,17 +84,6 @@ PassRefPtr<SubresourceLoader> SubresourceLoader::create(Frame* frame, Subresourc
newRequest.setHTTPReferrer(fl->outgoingReferrer());
FrameLoader::addHTTPOriginIfNeeded(newRequest, fl->outgoingOrigin());
// Use the original request's cache policy for two reasons:
// 1. For POST requests, we mutate the cache policy for the main resource,
// but we do not want this to apply to subresources
// 2. Delegates that modify the cache policy using willSendRequest: should
// not affect any other resources. Such changes need to be done
// per request.
if (newRequest.isConditional())
newRequest.setCachePolicy(ReloadIgnoringCacheData);
else
newRequest.setCachePolicy(fl->originalRequest().cachePolicy());
fl->addExtraFieldsToSubresourceRequest(newRequest);
RefPtr<SubresourceLoader> subloader(adoptRef(new SubresourceLoader(frame, client, sendResourceLoadCallbacks, shouldContentSniff)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment