Changeset 150169 in webkit


Ignore:
Timestamp:
May 15, 2013 7:54:06 PM (11 years ago)
Author:
aestes@apple.com
Message:

Resources from non-HTTP schemes should not be cached indefinitely
https://bugs.webkit.org/show_bug.cgi?id=113626

Reviewed by Ryosuke Niwa.

Source/WebCore:

With the exception of schemes that we know will always return the same
result for a given URL, we should not indefinitely cache non-HTTP
resources when their freshness cannot be verified.

Writing a test for this is blocked on https://webkit.org/b/116199.

The following two existing tests of memory cache behavior were
converted to HTTP tests so that they continue to function as expected:

Tests: http/tests/cache/display-image-unset-allows-cached-image-load.html

http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html

  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::freshnessLifetime): Returned a freshness
lifetime of 0 for non-HTTP schemes that can't be indefinitely cached.

  • platform/SchemeRegistry.cpp:

(WebCore::SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely):
Checked whether the scheme is blob:, data:, or applewebdata:.

  • platform/SchemeRegistry.h:

LayoutTests:

Convert existing memory cache tests to HTTP tests.

  • fast/loader/resources/compass.jpg: Removed.
  • fast/loader/resources/image1.html: Removed.
  • fast/loader/resources/image2.html: Removed.
  • fast/loader/willsendrequest-returns-null-for-memory-cache-load-expected.txt: Removed.
  • http/tests/cache/display-image-unset-allows-cached-image-load-expected.txt: Renamed from LayoutTests/fast/loader/display-image-unset-allows-cached-image-load-expected.txt.
  • http/tests/cache/display-image-unset-allows-cached-image-load.html: Renamed from LayoutTests/fast/loader/display-image-unset-allows-cached-image-load.html.
  • http/tests/cache/resources/cached-image.html: Renamed from LayoutTests/fast/loader/resources/cached-image.html.
  • http/tests/cache/resources/image1.html: Added.
  • http/tests/cache/resources/image2.html: Added.
  • http/tests/cache/willsendrequest-returns-null-for-memory-cache-load-expected.txt: Added.
  • http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html: Renamed from LayoutTests/fast/loader/willsendrequest-returns-null-for-memory-cache-load.html.
Location:
trunk
Files:
3 added
4 deleted
5 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r150155 r150169  
     12013-05-15  Andy Estes  <aestes@apple.com>
     2
     3        Resources from non-HTTP schemes should not be cached indefinitely
     4        https://bugs.webkit.org/show_bug.cgi?id=113626
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Convert existing memory cache tests to HTTP tests.
     9
     10        * fast/loader/resources/compass.jpg: Removed.
     11        * fast/loader/resources/image1.html: Removed.
     12        * fast/loader/resources/image2.html: Removed.
     13        * fast/loader/willsendrequest-returns-null-for-memory-cache-load-expected.txt: Removed.
     14        * http/tests/cache/display-image-unset-allows-cached-image-load-expected.txt: Renamed from LayoutTests/fast/loader/display-image-unset-allows-cached-image-load-expected.txt.
     15        * http/tests/cache/display-image-unset-allows-cached-image-load.html: Renamed from LayoutTests/fast/loader/display-image-unset-allows-cached-image-load.html.
     16        * http/tests/cache/resources/cached-image.html: Renamed from LayoutTests/fast/loader/resources/cached-image.html.
     17        * http/tests/cache/resources/image1.html: Added.
     18        * http/tests/cache/resources/image2.html: Added.
     19        * http/tests/cache/willsendrequest-returns-null-for-memory-cache-load-expected.txt: Added.
     20        * http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html: Renamed from LayoutTests/fast/loader/willsendrequest-returns-null-for-memory-cache-load.html.
     21
    1222013-05-15  Igor Oliveira  <igor.o@sisa.samsung.com>
    223
  • trunk/LayoutTests/http/tests/cache/resources/cached-image.html

    r150168 r150169  
    33        testRunner.setWillSendRequestReturnsNull(true);
    44</script>
    5 <img src="compass.jpg" onload="console.log('FAIL: image was incorrectly loaded')">
     5<img src="/misc/resources/compass.jpg" onload="console.log('FAIL: image was incorrectly loaded')">
  • trunk/LayoutTests/http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html

    r150168 r150169  
    2222</head>
    2323<body>
    24     <img src="resources/compass.jpg" onload="loadCachedImageInIFrame()">
     24    <img src="/misc/resources/compass.jpg" onload="loadCachedImageInIFrame()">
    2525</body>
    2626</html>
  • trunk/Source/WebCore/ChangeLog

    r150167 r150169  
     12013-05-15  Andy Estes  <aestes@apple.com>
     2
     3        Resources from non-HTTP schemes should not be cached indefinitely
     4        https://bugs.webkit.org/show_bug.cgi?id=113626
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        With the exception of schemes that we know will always return the same
     9        result for a given URL, we should not indefinitely cache non-HTTP
     10        resources when their freshness cannot be verified.
     11
     12        Writing a test for this is blocked on https://webkit.org/b/116199.
     13
     14        The following two existing tests of memory cache behavior were
     15        converted to HTTP tests so that they continue to function as expected:
     16
     17        Tests: http/tests/cache/display-image-unset-allows-cached-image-load.html
     18               http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html
     19
     20        * loader/cache/CachedResource.cpp:
     21        (WebCore::CachedResource::freshnessLifetime): Returned a freshness
     22        lifetime of 0 for non-HTTP schemes that can't be indefinitely cached.
     23        * platform/SchemeRegistry.cpp:
     24        (WebCore::SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely):
     25        Checked whether the scheme is blob:, data:, or applewebdata:.
     26        * platform/SchemeRegistry.h:
     27
    1282013-05-15  Tim Horton  <timothy_horton@apple.com>
    229
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r150104 r150169  
    2525#include "CachedResource.h"
    2626
    27 #include "MemoryCache.h"
    2827#include "CachedResourceClient.h"
    2928#include "CachedResourceClientWalker.h"
     
    3938#include "LoaderStrategy.h"
    4039#include "Logging.h"
     40#include "MemoryCache.h"
    4141#include "PlatformStrategies.h"
    4242#include "PurgeableBuffer.h"
     
    4444#include "ResourceHandle.h"
    4545#include "ResourceLoadScheduler.h"
     46#include "SchemeRegistry.h"
    4647#include "SecurityOrigin.h"
    4748#include "SecurityPolicy.h"
     
    400401    return currentAge() > freshnessLifetime();
    401402}
    402    
     403
    403404double CachedResource::currentAge() const
    404405{
     
    412413    return correctedReceivedAge + residentTime;
    413414}
    414    
     415
    415416double CachedResource::freshnessLifetime() const
    416417{
    417     // Cache non-http resources liberally
     418    if (SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(m_response.url().protocol()))
     419        return std::numeric_limits<double>::max();
     420
     421    // Don't cache other non-HTTP resources since we can't check for freshness.
    418422    if (!m_response.url().protocolIsInHTTPFamily())
    419         return std::numeric_limits<double>::max();
     423        return 0;
    420424
    421425    // RFC2616 13.2.4
  • trunk/Source/WebCore/platform/SchemeRegistry.cpp

    r120684 r150169  
    321321}
    322322
     323bool SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(const String& scheme)
     324{
     325#if PLATFORM(MAC)
     326    if (equalIgnoringCase(scheme, "applewebdata"))
     327        return true;
     328#endif
     329    return equalIgnoringCase(scheme, "blob") || equalIgnoringCase(scheme, "data");
     330}
     331
    323332} // namespace WebCore
  • trunk/Source/WebCore/platform/SchemeRegistry.h

    r127757 r150169  
    8989    static void removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(const String& scheme);
    9090    static bool schemeShouldBypassContentSecurityPolicy(const String& scheme);
     91   
     92    // Schemes whose responses can be cached indefinitely.
     93    static bool shouldCacheResponsesFromURLSchemeIndefinitely(const String& scheme);
    9194};
    9295
Note: See TracChangeset for help on using the changeset viewer.