Changeset 140722 in webkit


Ignore:
Timestamp:
Jan 24, 2013 2:27:44 PM (11 years ago)
Author:
pdr@google.com
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.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r140721 r140722  
     12013-01-24  Philip Rogers  <pdr@google.com>
     2
     3        Preserve container size requests across image loads
     4        https://bugs.webkit.org/show_bug.cgi?id=106733
     5
     6        Reviewed by Tim Horton.
     7
     8        * http/tests/svg/cached-image-sizing-expected.html: Added.
     9        * http/tests/svg/cached-image-sizing.html: Added.
     10        * http/tests/svg/resources/delayCachedLoad.php: Added.
     11        * http/tests/svg/resources/greenSquare.svg: Added.
     12
    1132013-01-24  Sheriff Bot  <webkit.review.bot@gmail.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r140721 r140722  
     12013-01-24  Philip Rogers  <pdr@google.com>
     2
     3        Preserve container size requests across image loads
     4        https://bugs.webkit.org/show_bug.cgi?id=106733
     5
     6        Reviewed by Tim Horton.
     7
     8        Some images, such as SVG with relative dimensions, depend on the renderer's container size.
     9        r137981 introduced the ability to store pending container size requests that are made
     10        after the image element lays out but before the image loads. Before this patch, cached
     11        images could discard these pending container size requests during cache revalidation.
     12
     13        During a cached image load, two CachedImages exist: the image in cache and a new CachedImage
     14        that will be used if the cache is stale. Pending container size requests are stored
     15        on the second cached image which is discarded if a 304 not modified response is received.
     16
     17        This patch modifies the switchClientsToRevalidatedResource logic to maintain pending
     18        container size requests. This fixes a bug where cached SVG images would be sized
     19        incorrectly.
     20
     21        Test: http/tests/svg/cached-image-sizing.html
     22
     23        * loader/cache/CachedImage.cpp:
     24        (WebCore::CachedImage::switchClientsToRevalidatedResource):
     25
     26            In this virtual call we special-case images with pending size requests and
     27            transfer these requests to the revalidating resource. Note that all container size
     28            requests received before revalidation will be pending because the image has not loaded.
     29            Therefore, there is no risk of discarding non-pending container size requests.
     30
     31        (WebCore):
     32        * loader/cache/CachedImage.h:
     33        (CachedImage):
     34        * loader/cache/CachedResource.h:
     35        (CachedResource):
     36
    1372013-01-24  Sheriff Bot  <webkit.review.bot@gmail.com>
    238
  • trunk/Source/WebCore/loader/cache/CachedImage.cpp

    r139589 r140722  
    115115}
    116116
     117void CachedImage::switchClientsToRevalidatedResource()
     118{
     119    ASSERT(resourceToRevalidate());
     120    ASSERT(resourceToRevalidate()->isImage());
     121    // Pending container size requests need to be transferred to the revalidated resource.
     122    if (!m_pendingContainerSizeRequests.isEmpty()) {
     123        // A copy of pending size requests is needed as they are deleted during CachedResource::switchClientsToRevalidateResouce().
     124        ContainerSizeRequests switchContainerSizeRequests;
     125        for (ContainerSizeRequests::iterator it = m_pendingContainerSizeRequests.begin(); it != m_pendingContainerSizeRequests.end(); ++it)
     126            switchContainerSizeRequests.set(it->key, it->value);
     127        CachedResource::switchClientsToRevalidatedResource();
     128        CachedImage* revalidatedCachedImage = static_cast<CachedImage*>(resourceToRevalidate());
     129        for (ContainerSizeRequests::iterator it = switchContainerSizeRequests.begin(); it != switchContainerSizeRequests.end(); ++it)
     130            revalidatedCachedImage->setContainerSizeForRenderer(it->key, it->value.first, it->value.second);
     131        return;
     132    }
     133
     134    CachedResource::switchClientsToRevalidatedResource();
     135}
     136
    117137void CachedImage::allClientsRemoved()
    118138{
  • trunk/Source/WebCore/loader/cache/CachedImage.h

    r138202 r140722  
    110110    void checkShouldPaintBrokenImage();
    111111
     112    virtual void switchClientsToRevalidatedResource() OVERRIDE;
     113
    112114    typedef pair<IntSize, float> SizeAndZoom;
    113115    typedef HashMap<const CachedImageClient*, SizeAndZoom> ContainerSizeRequests;
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r140105 r140722  
    245245    // HTTP revalidation support methods for CachedResourceLoader.
    246246    void setResourceToRevalidate(CachedResource*);
    247     void switchClientsToRevalidatedResource();
     247    virtual void switchClientsToRevalidatedResource();
    248248    void clearResourceToRevalidate();
    249249    void updateResponseAfterRevalidation(const ResourceResponse& validatingResponse);
Note: See TracChangeset for help on using the changeset viewer.