2009-03-29 Darin Adler <darin@apple.com>
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Mar 2009 01:59:29 +0000 (01:59 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Mar 2009 01:59:29 +0000 (01:59 +0000)
        Reviewed by Dan Bernstein.

        Bug 24672: ASSERTION FAILURE: !m_purgeableData in WebCore::CachedResource::data() saving a WebArchive
        https://bugs.webkit.org/show_bug.cgi?id=24672
        rdar://problem/6574263

        I couldn't create a test case for this. In fact, the case in the bug doesn't exist any more,
        but there is an Apple-internal website I was able to use to reproduce and fix.

        * loader/CachedResource.h: Made makePurgeable public.
        * loader/DocumentLoader.cpp:
        (WebCore::DocumentLoader::subresource): Call makePurgeable to make the resource non-purgeable
        so we can get its data if it hasn't yet been purged.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@42095 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/loader/CachedResource.h
WebCore/loader/DocumentLoader.cpp

index 44993c9..d7ee771 100644 (file)
@@ -1,5 +1,21 @@
 2009-03-29  Darin Adler  <darin@apple.com>
 
+        Reviewed by Dan Bernstein.
+
+        Bug 24672: ASSERTION FAILURE: !m_purgeableData in WebCore::CachedResource::data() saving a WebArchive
+        https://bugs.webkit.org/show_bug.cgi?id=24672
+        rdar://problem/6574263
+
+        I couldn't create a test case for this. In fact, the case in the bug doesn't exist any more,
+        but there is an Apple-internal website I was able to use to reproduce and fix.
+
+        * loader/CachedResource.h: Made makePurgeable public.
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::subresource): Call makePurgeable to make the resource non-purgeable
+        so we can get its data if it hasn't yet been purged.
+
+2009-03-29  Darin Adler  <darin@apple.com>
+
         Fix build again.
 
         * loader/EmptyClients.h: Fix typo in name of FormState.h.
@@ -12,7 +28,7 @@
 
 2009-03-29  Greg Bolsinga  <bolsinga@apple.com>
 
-        Undo that last build fix.
+        Undo that last build fix, since it turned out the file wasn't deleted.
 
         * WebCore.xcodeproj/project.pbxproj:
 
index 63c250b..02fa6d3 100644 (file)
@@ -172,12 +172,16 @@ public:
     bool isPurgeable() const;
     bool wasPurged() const;
     
+    // This is used by the archive machinery to get at a purged resource without
+    // triggering a load. We should make it protected again if we can find a
+    // better way to handle the archive case.
+    bool makePurgeable(bool purgeable);
+
 protected:
     void setEncodedSize(unsigned);
     void setDecodedSize(unsigned);
     void didAccessDecodedData(double timeStamp);
 
-    bool makePurgeable(bool purgeable);
     bool isSafeToMakePurgeable() const;
     
     HashCountedSet<CachedResourceClient*> m_clients;
index 00be097..119cc2a 100644 (file)
@@ -549,13 +549,28 @@ PassRefPtr<ArchiveResource> DocumentLoader::subresource(const KURL& url) const
     if (!isCommitted())
         return 0;
     
-    Document* doc = m_frame->document();
-        
-    CachedResource* resource = doc->docLoader()->cachedResource(url);
+    CachedResource* resource = m_frame->document()->docLoader()->cachedResource(url);
     if (!resource || resource->preloadResult() == CachedResource::PreloadReferenced)
         return archiveResourceForURL(url);
-        
-    return ArchiveResource::create(resource->data(), url, resource->response());
+
+    bool wasPurgeable = resource->isPurgeable();
+    if (wasPurgeable) {
+        if (!resource->makePurgeable(false))
+            return 0;
+    }
+    RefPtr<SharedBuffer> data = resource->data();
+    if (wasPurgeable) {
+        // At the time of this writing, the following operation is a no-op, because
+        // makePurgeable has no effect if someone is holding a reference to the
+        // SharedBuffer. So we could just leave it out, but it seems that some day
+        // we might want to change the design so this does have an effect, and
+        // this call is otherwise harmless.
+        resource->makePurgeable(true);
+    }
+    if (!data)
+        return 0;
+
+    return ArchiveResource::create(data.release(), url, resource->response());
 }
 
 void DocumentLoader::getSubresources(Vector<PassRefPtr<ArchiveResource> >& subresources) const