2009-05-19  Brady Eidson  <beidson@apple.com>

        Reviewed by Antti Koivisto. 

        <rdar://problem/6886382> REGRESSION (Safari 4PB -> ToT): HTTP cache revalidation broken.

        This was caused in http://trac.webkit.org/changeset/41425, which fixed an image caching bug
        in QuickLooks (rdar://problem/6619630).

        We need to respect the DocumentLoader's request cache policy when deciding the cache policy
        for subresources, but the check (originally removed in r39304 and added back in in the same
        place in r41424) needs to be tweaked and relocated a bit.

        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::subresourceCachePolicy): Renamed from cachePolicy().  Move checking
          the DocumentLoader's request to a more appropriate place. Add code to handle the recently 
          added FIXME regarding POSTs. Add a new FIXME describing a great way to make this code 
          cleaner in the future.
        * loader/FrameLoader.h:

        * loader/DocLoader.cpp:
        (WebCore::DocLoader::cachePolicy): Calls the newly renamed subresourceCachePolicy().



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@43878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/loader/FrameLoader.cpp b/WebCore/loader/FrameLoader.cpp
index b3b3bda..578eb59 100644
--- a/WebCore/loader/FrameLoader.cpp
+++ b/WebCore/loader/FrameLoader.cpp
@@ -3238,22 +3238,28 @@
     return m_loadType;
 }
     
-CachePolicy FrameLoader::cachePolicy() const
+CachePolicy FrameLoader::subresourceCachePolicy() const
 {
     if (m_isComplete)
         return CachePolicyVerify;
 
-    // FIXME: This will return CachePolicyReload for any subresource of a document resulting from a POST request,
-    // making WebCore cache malfunction for such documents (see DocLoader::checkForReload()).
-    if (m_loadType == FrameLoadTypeReloadFromOrigin || documentLoader()->request().cachePolicy() == ReloadIgnoringCacheData)
+    if (m_loadType == FrameLoadTypeReloadFromOrigin)
         return CachePolicyReload;
 
     if (Frame* parentFrame = m_frame->tree()->parent()) {
-        CachePolicy parentCachePolicy = parentFrame->loader()->cachePolicy();
+        CachePolicy parentCachePolicy = parentFrame->loader()->subresourceCachePolicy();
         if (parentCachePolicy != CachePolicyVerify)
             return parentCachePolicy;
     }
 
+    // FIXME: POST documents are always Reloads, but their subresources should still be Revalidate.
+    // If we bring the CachePolicy.h and ResourceRequest cache policy enums in sync with each other and
+    // remember "Revalidate" in ResourceRequests, we can remove this "POST" check and return either "Reload" 
+    // or "Revalidate" if the DocumentLoader was requested with either.
+    const ResourceRequest& request(documentLoader()->request());
+    if (request.cachePolicy() == ReloadIgnoringCacheData && !equalIgnoringCase(request.httpMethod(), "post"))
+        return CachePolicyRevalidate;
+
     if (m_loadType == FrameLoadTypeReload)
         return CachePolicyRevalidate;