Title: [118618] trunk
Revision
118618
Author
[email protected]
Date
2012-05-26 17:46:11 -0700 (Sat, 26 May 2012)

Log Message

Source/WebCore: Cancel CachedResource loads when the last client is removed.
https://bugs.webkit.org/show_bug.cgi?id=35377

Reviewed by Darin Adler.

Test: http/tests/cache/cancel-in-progress-load.html

* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::errorLoadingResource):
* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::allClientsRemoved):
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::allClientsRemoved):
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::allClientsRemoved):
* loader/cache/CachedRawResource.cpp:
(WebCore):
* loader/cache/CachedRawResource.h:
(WebCore::CachedRawResource::shouldIgnoreHTTPStatusCodeErrors):
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::allClientsRemoved):
(WebCore):
* loader/cache/CachedResource.h:
(CachedResource):
* loader/cache/CachedScript.cpp:
(WebCore::CachedScript::allClientsRemoved):

LayoutTests: Test for https://bugs.webkit.org/show_bug.cgi?id=35377.

Reviewed by Darin Adler.

* http/tests/cache/cancel-in-progress-load-expected.txt: Added.
* http/tests/cache/cancel-in-progress-load.html: Added.
* http/tests/misc/write-while-waiting.html: Add waitUntilDone()/notifyDone().
    The slow script will now be cancelled when the script element is removed from the document.
    Without waitUntilDone(), LayoutTestController will immediately end the test upon cancellation
    of the last resource.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (118617 => 118618)


--- trunk/LayoutTests/ChangeLog	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/LayoutTests/ChangeLog	2012-05-27 00:46:11 UTC (rev 118618)
@@ -1,3 +1,16 @@
+2012-05-26  Nate Chapin  <[email protected]>
+
+        Test for https://bugs.webkit.org/show_bug.cgi?id=35377.
+
+        Reviewed by Darin Adler.
+
+        * http/tests/cache/cancel-in-progress-load-expected.txt: Added.
+        * http/tests/cache/cancel-in-progress-load.html: Added.
+        * http/tests/misc/write-while-waiting.html: Add waitUntilDone()/notifyDone().
+            The slow script will now be cancelled when the script element is removed from the document.
+            Without waitUntilDone(), LayoutTestController will immediately end the test upon cancellation
+            of the last resource.
+
 2012-05-26  Simon Fraser  <[email protected]>
 
         fast/block/inline-children-root-linebox-crash.html asserts after r118567

Added: trunk/LayoutTests/http/tests/cache/cancel-in-progress-load-expected.txt (0 => 118618)


--- trunk/LayoutTests/http/tests/cache/cancel-in-progress-load-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/cancel-in-progress-load-expected.txt	2012-05-27 00:46:11 UTC (rev 118618)
@@ -0,0 +1,6 @@
+http://127.0.0.1:8000/cache/resources/random.cgi - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/resources/random.cgi, main document URL http://127.0.0.1:8000/cache/cancel-in-progress-load.html, http method GET> redirectResponse (null)
+<unknown> - didFinishLoading
+http://127.0.0.1:8000/cache/resources/random.cgi - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/resources/random.cgi, http status code 200>
+<unknown> - didFailLoadingWithError: <NSError domain NSURLErrorDomain, code -999, failing URL "http://127.0.0.1:8000/navigation/resources/slow-resource.pl">
+http://127.0.0.1:8000/cache/resources/random.cgi - didFinishLoading
+

Added: trunk/LayoutTests/http/tests/cache/cancel-in-progress-load.html (0 => 118618)


--- trunk/LayoutTests/http/tests/cache/cancel-in-progress-load.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/cancel-in-progress-load.html	2012-05-27 00:46:11 UTC (rev 118618)
@@ -0,0 +1,19 @@
+<html>
+<body>
+<img id="img" _onload_="finish()"; _onerror_="finish();" src=""
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    layoutTestController.dumpResourceLoadCallbacks();
+}
+
+function finish() {
+     (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+document.getElementById("img").src = ""
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/http/tests/misc/write-while-waiting.html (118617 => 118618)


--- trunk/LayoutTests/http/tests/misc/write-while-waiting.html	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/LayoutTests/http/tests/misc/write-while-waiting.html	2012-05-27 00:46:11 UTC (rev 118618)
@@ -2,10 +2,12 @@
 <body>
 FAIL
 <script>
-if (window.layoutTestController)
+if (window.layoutTestController) {
     layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
 
-setTimeout("document.write('PASS');document.close();", 100);
+setTimeout("document.write('PASS');document.close(); if (window.layoutTestController) layoutTestController.notifyDone();", 100);
 </script>
 <script src=""
 </body>

Modified: trunk/Source/WebCore/ChangeLog (118617 => 118618)


--- trunk/Source/WebCore/ChangeLog	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/ChangeLog	2012-05-27 00:46:11 UTC (rev 118618)
@@ -1,3 +1,32 @@
+2012-05-26  Nate Chapin  <[email protected]>
+
+        Cancel CachedResource loads when the last client is removed.
+        https://bugs.webkit.org/show_bug.cgi?id=35377
+
+        Reviewed by Darin Adler.
+
+        Test: http/tests/cache/cancel-in-progress-load.html
+
+        * loader/SubresourceLoader.cpp:
+        (WebCore::SubresourceLoader::errorLoadingResource):
+        * loader/cache/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::allClientsRemoved):
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::allClientsRemoved):
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::allClientsRemoved):
+        * loader/cache/CachedRawResource.cpp:
+        (WebCore):
+        * loader/cache/CachedRawResource.h:
+        (WebCore::CachedRawResource::shouldIgnoreHTTPStatusCodeErrors):
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::allClientsRemoved):
+        (WebCore):
+        * loader/cache/CachedResource.h:
+        (CachedResource):
+        * loader/cache/CachedScript.cpp:
+        (WebCore::CachedScript::allClientsRemoved):
+
 2012-05-26  Simon Fraser  <[email protected]>
 
         fast/block/inline-children-root-linebox-crash.html asserts after r118567

Modified: trunk/Source/WebCore/loader/SubresourceLoader.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/SubresourceLoader.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/SubresourceLoader.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -232,8 +232,8 @@
     if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnoreHTTPStatusCodeErrors())
         return false;
 
+    m_state = Finishing;
     m_resource->error(CachedResource::LoadError);
-    m_state = Finishing;
     cancel();
     return true;
 }

Modified: trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -66,6 +66,7 @@
 {
     if (!MemoryCache::shouldMakeResourcePurgeableOnEviction() && isSafeToMakePurgeable())
         makePurgeable(true);
+    CachedResource::allClientsRemoved();
 }
 
 void CachedCSSStyleSheet::setEncoding(const String& chs)

Modified: trunk/Source/WebCore/loader/cache/CachedFont.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedFont.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedFont.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -185,6 +185,7 @@
         m_fontData = 0;
     }
 #endif
+    CachedResource::allClientsRemoved();
 }
 
 void CachedFont::checkNotify()

Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedImage.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -124,6 +124,7 @@
         m_image->resetAnimation();
     if (double interval = memoryCache()->deadDecodedDataDeletionInterval())
         m_decodedDataDeletionTimer.startOneShot(interval);
+    CachedResource::allClientsRemoved();
 }
 
 pair<Image*, float> CachedImage::brokenImage(float deviceScaleFactor) const

Modified: trunk/Source/WebCore/loader/cache/CachedRawResource.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedRawResource.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedRawResource.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -87,12 +87,6 @@
     CachedResource::didAddClient(client);
 }
 
-void CachedRawResource::allClientsRemoved()
-{
-    if (m_loader)
-        m_loader->cancelIfNotFinishing();
-}
-
 void CachedRawResource::willSendRequest(ResourceRequest& request, const ResourceResponse& response)
 {
     if (!response.isNull()) {

Modified: trunk/Source/WebCore/loader/cache/CachedRawResource.h (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedRawResource.h	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedRawResource.h	2012-05-27 00:46:11 UTC (rev 118618)
@@ -49,7 +49,6 @@
     virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
 
     virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
-    virtual void allClientsRemoved();
 
     virtual void willSendRequest(ResourceRequest&, const ResourceResponse&);
     virtual void setResponse(const ResourceResponse&);

Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedResource.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -387,6 +387,12 @@
         c->notifyFinished(this);
 }
 
+void CachedResource::allClientsRemoved()
+{
+    if (m_loader)
+        m_loader->cancelIfNotFinishing();
+}
+
 bool CachedResource::addClientToSet(CachedResourceClient* client)
 {
     ASSERT(!isPurgeable());

Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedResource.h	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h	2012-05-27 00:46:11 UTC (rev 118618)
@@ -126,7 +126,7 @@
     PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_preloadResult); }
 
     virtual void didAddClient(CachedResourceClient*);
-    virtual void allClientsRemoved() { }
+    virtual void allClientsRemoved();
 
     unsigned count() const { return m_clients.size(); }
 

Modified: trunk/Source/WebCore/loader/cache/CachedScript.cpp (118617 => 118618)


--- trunk/Source/WebCore/loader/cache/CachedScript.cpp	2012-05-27 00:43:12 UTC (rev 118617)
+++ trunk/Source/WebCore/loader/cache/CachedScript.cpp	2012-05-27 00:46:11 UTC (rev 118618)
@@ -67,6 +67,7 @@
 {
     if (double interval = memoryCache()->deadDecodedDataDeletionInterval())
         m_decodedDataDeletionTimer.startOneShot(interval);
+    CachedResource::allClientsRemoved();
 }
 
 void CachedScript::setEncoding(const String& chs)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to