Title: [140722] trunk
Revision
140722
Author
[email protected]
Date
2013-01-24 14:27:44 -0800 (Thu, 24 Jan 2013)

Log Message

Preserve container size requests across image loads
https://bugs.webkit.org/show_bug.cgi?id=106733

Reviewed by Tim Horton.

Source/WebCore:

Some images, such as SVG with relative dimensions, depend on the renderer's container size.
r137981 introduced the ability to store pending container size requests that are made
after the image element lays out but before the image loads. Before this patch, cached
images could discard these pending container size requests during cache revalidation.

During a cached image load, two CachedImages exist: the image in cache and a new CachedImage
that will be used if the cache is stale. Pending container size requests are stored
on the second cached image which is discarded if a 304 not modified response is received.

This patch modifies the switchClientsToRevalidatedResource logic to maintain pending
container size requests. This fixes a bug where cached SVG images would be sized
incorrectly.

Test: http/tests/svg/cached-image-sizing.html

* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::switchClientsToRevalidatedResource):

    In this virtual call we special-case images with pending size requests and
    transfer these requests to the revalidating resource. Note that all container size
    requests received before revalidation will be pending because the image has not loaded.
    Therefore, there is no risk of discarding non-pending container size requests.

(WebCore):
* loader/cache/CachedImage.h:
(CachedImage):
* loader/cache/CachedResource.h:
(CachedResource):

LayoutTests:

* http/tests/svg/cached-image-sizing-expected.html: Added.
* http/tests/svg/cached-image-sizing.html: Added.
* http/tests/svg/resources/delayCachedLoad.php: Added.
* http/tests/svg/resources/greenSquare.svg: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (140721 => 140722)


--- trunk/LayoutTests/ChangeLog	2013-01-24 22:11:23 UTC (rev 140721)
+++ trunk/LayoutTests/ChangeLog	2013-01-24 22:27:44 UTC (rev 140722)
@@ -1,3 +1,15 @@
+2013-01-24  Philip Rogers  <[email protected]>
+
+        Preserve container size requests across image loads
+        https://bugs.webkit.org/show_bug.cgi?id=106733
+
+        Reviewed by Tim Horton.
+
+        * http/tests/svg/cached-image-sizing-expected.html: Added.
+        * http/tests/svg/cached-image-sizing.html: Added.
+        * http/tests/svg/resources/delayCachedLoad.php: Added.
+        * http/tests/svg/resources/greenSquare.svg: Added.
+
 2013-01-24  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r140296.

Added: trunk/LayoutTests/http/tests/svg/cached-image-sizing-expected.html (0 => 140722)


--- trunk/LayoutTests/http/tests/svg/cached-image-sizing-expected.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/cached-image-sizing-expected.html	2013-01-24 22:27:44 UTC (rev 140722)
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+Test for webkit.org/b/106733: This test passes if there is a green square (not rectangle) below:<br/>
+<img src="" width="200" height="200">
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/svg/cached-image-sizing.html (0 => 140722)


--- trunk/LayoutTests/http/tests/svg/cached-image-sizing.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/cached-image-sizing.html	2013-01-24 22:27:44 UTC (rev 140722)
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+Test for webkit.org/b/106733: This test passes if there is a green square (not rectangle) below:<br/>
+<img src="" width="200" height="200">
+<script>
+
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+window._onload_ = function(){
+    if (location.hash == "") {
+        location.hash = "#reloading";
+        location.reload(true);
+    } else if (location.hash == "#reloading") {
+        location.hash = "#finished";
+        if (window.testRunner)
+            testRunner.notifyDone();
+    }
+}
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/svg/resources/delayCachedLoad.php (0 => 140722)


--- trunk/LayoutTests/http/tests/svg/resources/delayCachedLoad.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/resources/delayCachedLoad.php	2013-01-24 22:27:44 UTC (rev 140722)
@@ -0,0 +1,7 @@
+<?php
+  // Delay load by 0.07s. This was found to be the lowest value
+  // required for webkit.org/b/106733
+  usleep(70000);
+  header('Cache-Control: no-cache, must-revalidate');
+  header('Location: http://127.0.0.1:8000/svg/resources/greenSquare.svg');
+?>

Added: trunk/LayoutTests/http/tests/svg/resources/greenSquare.svg (0 => 140722)


--- trunk/LayoutTests/http/tests/svg/resources/greenSquare.svg	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/resources/greenSquare.svg	2013-01-24 22:27:44 UTC (rev 140722)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- The rectangular viewBox causes the green rect to render as a 100x100 square. -->
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200">
+  <rect width="100%" height="50%" fill="green"/>
+</svg>

Modified: trunk/Source/WebCore/ChangeLog (140721 => 140722)


--- trunk/Source/WebCore/ChangeLog	2013-01-24 22:11:23 UTC (rev 140721)
+++ trunk/Source/WebCore/ChangeLog	2013-01-24 22:27:44 UTC (rev 140722)
@@ -1,3 +1,39 @@
+2013-01-24  Philip Rogers  <[email protected]>
+
+        Preserve container size requests across image loads
+        https://bugs.webkit.org/show_bug.cgi?id=106733
+
+        Reviewed by Tim Horton.
+
+        Some images, such as SVG with relative dimensions, depend on the renderer's container size.
+        r137981 introduced the ability to store pending container size requests that are made
+        after the image element lays out but before the image loads. Before this patch, cached
+        images could discard these pending container size requests during cache revalidation.
+
+        During a cached image load, two CachedImages exist: the image in cache and a new CachedImage
+        that will be used if the cache is stale. Pending container size requests are stored
+        on the second cached image which is discarded if a 304 not modified response is received.
+
+        This patch modifies the switchClientsToRevalidatedResource logic to maintain pending
+        container size requests. This fixes a bug where cached SVG images would be sized
+        incorrectly.
+
+        Test: http/tests/svg/cached-image-sizing.html
+
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::switchClientsToRevalidatedResource):
+
+            In this virtual call we special-case images with pending size requests and
+            transfer these requests to the revalidating resource. Note that all container size
+            requests received before revalidation will be pending because the image has not loaded.
+            Therefore, there is no risk of discarding non-pending container size requests.
+
+        (WebCore):
+        * loader/cache/CachedImage.h:
+        (CachedImage):
+        * loader/cache/CachedResource.h:
+        (CachedResource):
+
 2013-01-24  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r140296.

Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (140721 => 140722)


--- trunk/Source/WebCore/loader/cache/CachedImage.cpp	2013-01-24 22:11:23 UTC (rev 140721)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp	2013-01-24 22:27:44 UTC (rev 140722)
@@ -114,6 +114,26 @@
     CachedResource::didRemoveClient(c);
 }
 
+void CachedImage::switchClientsToRevalidatedResource()
+{
+    ASSERT(resourceToRevalidate());
+    ASSERT(resourceToRevalidate()->isImage());
+    // Pending container size requests need to be transferred to the revalidated resource.
+    if (!m_pendingContainerSizeRequests.isEmpty()) {
+        // A copy of pending size requests is needed as they are deleted during CachedResource::switchClientsToRevalidateResouce().
+        ContainerSizeRequests switchContainerSizeRequests;
+        for (ContainerSizeRequests::iterator it = m_pendingContainerSizeRequests.begin(); it != m_pendingContainerSizeRequests.end(); ++it)
+            switchContainerSizeRequests.set(it->key, it->value);
+        CachedResource::switchClientsToRevalidatedResource();
+        CachedImage* revalidatedCachedImage = static_cast<CachedImage*>(resourceToRevalidate());
+        for (ContainerSizeRequests::iterator it = switchContainerSizeRequests.begin(); it != switchContainerSizeRequests.end(); ++it)
+            revalidatedCachedImage->setContainerSizeForRenderer(it->key, it->value.first, it->value.second);
+        return;
+    }
+
+    CachedResource::switchClientsToRevalidatedResource();
+}
+
 void CachedImage::allClientsRemoved()
 {
     m_pendingContainerSizeRequests.clear();

Modified: trunk/Source/WebCore/loader/cache/CachedImage.h (140721 => 140722)


--- trunk/Source/WebCore/loader/cache/CachedImage.h	2013-01-24 22:11:23 UTC (rev 140721)
+++ trunk/Source/WebCore/loader/cache/CachedImage.h	2013-01-24 22:27:44 UTC (rev 140722)
@@ -109,6 +109,8 @@
     virtual PurgePriority purgePriority() const { return PurgeFirst; }
     void checkShouldPaintBrokenImage();
 
+    virtual void switchClientsToRevalidatedResource() OVERRIDE;
+
     typedef pair<IntSize, float> SizeAndZoom;
     typedef HashMap<const CachedImageClient*, SizeAndZoom> ContainerSizeRequests;
     ContainerSizeRequests m_pendingContainerSizeRequests;

Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (140721 => 140722)


--- trunk/Source/WebCore/loader/cache/CachedResource.h	2013-01-24 22:11:23 UTC (rev 140721)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h	2013-01-24 22:27:44 UTC (rev 140722)
@@ -244,7 +244,7 @@
     
     // HTTP revalidation support methods for CachedResourceLoader.
     void setResourceToRevalidate(CachedResource*);
-    void switchClientsToRevalidatedResource();
+    virtual void switchClientsToRevalidatedResource();
     void clearResourceToRevalidate();
     void updateResponseAfterRevalidation(const ResourceResponse& validatingResponse);
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to