Changeset 97765 in webkit


Ignore:
Timestamp:
Oct 18, 2011 9:31:32 AM (13 years ago)
Author:
Nate Chapin
Message:

Source/WebCore: Make DocumentThreadableLoader a CachedResourceClient.
This will allow us to cache ThreadableLoaderClients as
appropriate in a later patch.
https://bugs.webkit.org/show_bug.cgi?id=61225

Reviewed by Antti Koivisto.

No new tests, no functionality change intended.

  • WebCore.gypi:
  • loader/DocumentThreadableLoader.cpp:

(WebCore::DocumentThreadableLoader::notifyFinished): CachedResourceClients don't send separate callbacks

for didFail() and didFinishLoading(), so we need to differentiate here.

(WebCore::DocumentThreadableLoader::loadRequest): Call CachedResourceLoader::requestRawResource()

instead of ResourceLoadScheduler::scheduleSubresourceLoad().

  • loader/DocumentThreadableLoader.h:
  • loader/cache/CachedRawResource.cpp:

(WebCore::CachedRawResource::data): Handle the complexity of some ThreadableLoaderClients setting

DoNotBufferData in ResoureLoaderOptions. If the DataBufferingPolicy is BufferData, then the
'data' input parameter will contain all data received so far, and we need to determine the
incremental data to forward to the clients. If the policy is DoNotBufferData, 'data' is just
the incremental data.

  • loader/cache/CachedRawResource.h:
  • loader/cache/CachedResource.cpp:
  • loader/cache/CachedResource.h:

(WebCore::CachedResource::preloadResult):
(WebCore::CachedResource::didSendData):
(WebCore::CachedResource::didDownloadData):
(WebCore::CachedResource::setLoadFinishTime):
(WebCore::CachedResource::loadFinishTime):

  • loader/cache/CachedResourceClient.h: Add several new callbacks needed by DocumentThreadableLoader.
  • loader/cache/CachedResourceRequest.cpp:

(WebCore::CachedResourceRequest::didReceiveResponse): CachedResource::setResponse() can now cancel

the request, so protect appropriately.

  • loader/cache/CachedResourceRequest.h:
  • loader/chromium/CachedRawResourceChromium.cpp: Added (plumb didDownloadData() to DocumentThreadableLoader).
  • loader/chromium/CachedResourceRequestChromium.cpp: Added (plumb didDownloadData() to DocumentThreadableLoader).
  • loader/chromium/DocumentThreadableLoaderChromium.cpp:
  • platform/network/BlobResourceHandle.cpp:

(WebCore::BlobResourceHandle::notifyResponse): Protect before setting response, since it might kill us.

LayoutTests: Test update for https://bugs.webkit.org/show_bug.cgi?id=61225.
Due to changes in the implementation of DocumentThreadableLoader (and
therefore XHR), this test will have empty (rather than null) content
if we go over the length limit.

Reviewed by Antti Koivisto.

  • http/tests/inspector/network/network-content-replacement-xhr-expected.txt:
Location:
trunk
Files:
16 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r97750 r97765  
     12011-10-18  Nate Chapin  <japhet@chromium.org>
     2
     3        Test update for https://bugs.webkit.org/show_bug.cgi?id=61225.
     4        Due to changes in the implementation of DocumentThreadableLoader (and
     5        therefore XHR), this test will have empty (rather than null) content
     6        if we go over the length limit.
     7
     8        Reviewed by Antti Koivisto.
     9
     10        * http/tests/inspector/network/network-content-replacement-xhr-expected.txt:
     11
    1122011-10-18  Mihnea Ovidenie  <mihnea@adobe.com>
    213
  • trunk/LayoutTests/http/tests/inspector/network/network-content-replacement-xhr-expected.txt

    r90389 r97765  
    33
    44http://127.0.0.1:8000/inspector/network/resources/resource.php?size=200
    5 resource.content: null
     5resource.content:
    66http://127.0.0.1:8000/inspector/network/resources/resource.php?size=100
    77resource.content: ****************************************************************************************************
    88http://127.0.0.1:8000/inspector/network/resources/resource.php?size=201
    9 resource.content: null
     9resource.content:
    1010http://127.0.0.1:8000/inspector/network/resources/resource.php?size=100
    1111resource.content: ****************************************************************************************************
  • trunk/Source/WebCore/ChangeLog

    r97764 r97765  
     12011-10-18  Nate Chapin  <japhet@chromium.org>
     2
     3        Make DocumentThreadableLoader a CachedResourceClient.
     4        This will allow us to cache ThreadableLoaderClients as
     5        appropriate in a later patch.
     6        https://bugs.webkit.org/show_bug.cgi?id=61225
     7
     8        Reviewed by Antti Koivisto.
     9
     10        No new tests, no functionality change intended.
     11
     12        * WebCore.gypi:
     13        * loader/DocumentThreadableLoader.cpp:
     14        (WebCore::DocumentThreadableLoader::notifyFinished): CachedResourceClients don't send separate callbacks
     15            for didFail() and didFinishLoading(), so we need to differentiate here.
     16        (WebCore::DocumentThreadableLoader::loadRequest): Call CachedResourceLoader::requestRawResource()
     17            instead of ResourceLoadScheduler::scheduleSubresourceLoad().
     18        * loader/DocumentThreadableLoader.h:
     19        * loader/cache/CachedRawResource.cpp:
     20        (WebCore::CachedRawResource::data): Handle the complexity of some ThreadableLoaderClients setting
     21            DoNotBufferData in ResoureLoaderOptions. If the DataBufferingPolicy is BufferData, then the
     22            'data' input parameter will contain all data received so far, and we need to determine the
     23            incremental data to forward to the clients. If the policy is DoNotBufferData, 'data' is just
     24            the incremental data.
     25        * loader/cache/CachedRawResource.h:
     26        * loader/cache/CachedResource.cpp:
     27        * loader/cache/CachedResource.h:
     28        (WebCore::CachedResource::preloadResult):
     29        (WebCore::CachedResource::didSendData):
     30        (WebCore::CachedResource::didDownloadData):
     31        (WebCore::CachedResource::setLoadFinishTime):
     32        (WebCore::CachedResource::loadFinishTime):
     33        * loader/cache/CachedResourceClient.h: Add several new callbacks needed by DocumentThreadableLoader.
     34        * loader/cache/CachedResourceRequest.cpp:
     35        (WebCore::CachedResourceRequest::didReceiveResponse): CachedResource::setResponse() can now cancel
     36            the request, so protect appropriately.
     37        * loader/cache/CachedResourceRequest.h:
     38        * loader/chromium/CachedRawResourceChromium.cpp: Added (plumb didDownloadData() to DocumentThreadableLoader).
     39        * loader/chromium/CachedResourceRequestChromium.cpp: Added (plumb didDownloadData() to DocumentThreadableLoader).
     40        * loader/chromium/DocumentThreadableLoaderChromium.cpp:
     41        * platform/network/BlobResourceHandle.cpp:
     42        (WebCore::BlobResourceHandle::notifyResponse): Protect before setting response, since it might kill us.
     43
    1442011-10-18  Sheriff Bot  <webkit.review.bot@gmail.com>
    245
  • trunk/Source/WebCore/WebCore.gypi

    r97756 r97765  
    28542854            'loader/cache/MemoryCache.cpp',
    28552855            'loader/cf/ResourceLoaderCFNet.cpp',
     2856            'loader/chromium/CachedRawResourceChromium.cpp',
     2857            'loader/chromium/CachedResourceRequestChromium.cpp',
    28562858            'loader/chromium/DocumentThreadableLoaderChromium.cpp',
    28572859            'loader/chromium/ResourceLoaderChromium.cpp',
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r96060 r97765  
    3232#include "DocumentThreadableLoader.h"
    3333
    34 #include "AuthenticationChallenge.h"
     34#include "CachedRawResource.h"
     35#include "CachedResourceLoader.h"
    3536#include "CrossOriginAccessControl.h"
    3637#include "CrossOriginPreflightResultCache.h"
     
    3940#include "Frame.h"
    4041#include "FrameLoader.h"
    41 #include "ResourceHandle.h"
    42 #include "ResourceLoadScheduler.h"
     42#include "ResourceError.h"
    4343#include "ResourceRequest.h"
    4444#include "SecurityOrigin.h"
    45 #include "SubresourceLoader.h"
    4645#include "ThreadableLoaderClient.h"
     46#include <wtf/Assertions.h>
    4747#include <wtf/UnusedParam.h>
    4848
     
    6464{
    6565    RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, LoadAsynchronously, request, options));
    66     if (!loader->m_loader)
     66    if (!loader->m_resource)
    6767        loader = 0;
    6868    return loader.release();
     
    134134DocumentThreadableLoader::~DocumentThreadableLoader()
    135135{
    136     if (m_loader)
    137         m_loader->clearClient();
     136    if (m_resource)
     137        m_resource->removeClient(this);
    138138}
    139139
    140140void DocumentThreadableLoader::cancel()
    141141{
    142     if (!m_loader)
    143         return;
    144 
    145     m_loader->cancel();
    146     m_loader->clearClient();
    147     m_loader = 0;
     142    if (m_client) {
     143        ResourceError error(errorDomainWebKitInternal, 0, m_resource->url(), "Load cancelled");
     144        error.setIsCancellation(true);
     145        didFail(error);
     146    }
     147    clearResource();
    148148    m_client = 0;
    149149}
     
    151151void DocumentThreadableLoader::setDefersLoading(bool value)
    152152{
    153     if (m_loader)
    154         m_loader->setDefersLoading(value);
    155 }
    156 
    157 void DocumentThreadableLoader::willSendRequest(SubresourceLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
    158 {
    159     ASSERT(m_client);
    160     ASSERT_UNUSED(loader, loader == m_loader);
     153    if (m_resource)
     154        m_resource->setDefersLoading(value);
     155}
     156
     157void DocumentThreadableLoader::clearResource()
     158{
     159    if (m_resource) {
     160        m_resource->removeClient(this);
     161        m_resource = 0;
     162    }
     163}
     164
     165void DocumentThreadableLoader::redirectReceived(CachedResource* resource, ResourceRequest& request, const ResourceResponse& redirectResponse)
     166{
     167    ASSERT(m_client);
     168    ASSERT_UNUSED(resource, resource == m_resource);
    161169
    162170    if (!isAllowedRedirect(request.url())) {
     
    170178}
    171179
    172 void DocumentThreadableLoader::didSendData(SubresourceLoader* loader, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
    173 {
    174     ASSERT(m_client);
    175     ASSERT_UNUSED(loader, loader == m_loader);
    176 
     180void DocumentThreadableLoader::dataSent(CachedResource* resource, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
     181{
     182    ASSERT(m_client);
     183    ASSERT_UNUSED(resource, resource == m_resource);
    177184    m_client->didSendData(bytesSent, totalBytesToBeSent);
    178185}
    179186
    180 void DocumentThreadableLoader::didReceiveResponse(SubresourceLoader* loader, const ResourceResponse& response)
    181 {
    182     ASSERT(loader == m_loader);
    183     didReceiveResponse(loader->identifier(), response);
     187void DocumentThreadableLoader::responseReceived(CachedResource* resource, const ResourceResponse& response)
     188{
     189    ASSERT_UNUSED(resource, resource == m_resource);
     190    didReceiveResponse(m_resource->identifier(), response);
    184191}
    185192
     
    224231}
    225232
    226 void DocumentThreadableLoader::didReceiveData(SubresourceLoader* loader, const char* data, int dataLength)
    227 {
    228     ASSERT(m_client);
    229     ASSERT_UNUSED(loader, loader == m_loader);
     233void DocumentThreadableLoader::dataReceived(CachedResource* resource, const char* data, int dataLength)
     234{
     235    ASSERT(m_client);
     236    ASSERT_UNUSED(resource, resource == m_resource);
    230237
    231238#if ENABLE(INSPECTOR)
     
    241248}
    242249
    243 void DocumentThreadableLoader::didReceiveCachedMetadata(SubresourceLoader* loader, const char* data, int dataLength)
    244 {
    245     ASSERT(m_client);
    246     ASSERT_UNUSED(loader, loader == m_loader);
    247 
    248     // Preflight data should be invisible to clients.
    249     if (m_actualRequest)
    250         return;
    251 
    252     m_client->didReceiveCachedMetadata(data, dataLength);
    253 }
    254 
    255 void DocumentThreadableLoader::didFinishLoading(SubresourceLoader* loader, double finishTime)
    256 {
    257     ASSERT(loader == m_loader);
    258     ASSERT(m_client);
    259     didFinishLoading(loader->identifier(), finishTime);
     250void DocumentThreadableLoader::notifyFinished(CachedResource* resource)
     251{
     252    ASSERT(m_client);
     253    ASSERT_UNUSED(resource, resource == m_resource);
     254       
     255    if (m_resource && (m_resource->errorOccurred() || m_resource->wasCanceled())) {
     256        ResourceError error("Network Request Failed", 0, m_resource->url(), "Resource failed to load");
     257        if (m_resource->wasCanceled())
     258            error.setIsCancellation(true);
     259        didFail(error);
     260    } else
     261        didFinishLoading(m_resource->identifier(), m_resource->loadFinishTime());
    260262}
    261263
     
    275277}
    276278
    277 void DocumentThreadableLoader::didFail(SubresourceLoader* loader, const ResourceError& error)
    278 {
    279     ASSERT(m_client);
    280     // m_loader may be null if we arrive here via SubresourceLoader::create in the ctor
    281     ASSERT_UNUSED(loader, loader == m_loader || !m_loader);
    282 
     279void DocumentThreadableLoader::didFail(const ResourceError& error)
     280{
    283281#if ENABLE(INSPECTOR)
    284282    if (m_preflightRequestIdentifier)
     
    295293
    296294    actualRequest->setHTTPOrigin(securityOrigin()->toString());
     295
     296    clearResource();
    297297
    298298    // It should be ok to skip the security check since we already asked about the preflight request.
     
    325325        }
    326326
     327        ResourceRequest newRequest(request);
    327328#if ENABLE(INSPECTOR)
    328329        if (m_actualRequest) {
    329             ResourceRequest newRequest(request);
    330330            // Because willSendRequest only gets called during redirects, we initialize the identifier and the first willSendRequest here.
    331331            m_preflightRequestIdentifier = m_document->frame()->page()->progress()->createUniqueIdentifier();
     
    334334        }
    335335#endif
    336 
    337         // Clear the loader so that any callbacks from SubresourceLoader::create will not have the old loader.
    338         m_loader = 0;
    339         m_loader = resourceLoadScheduler()->scheduleSubresourceLoad(m_document->frame(), this, request, ResourceLoadPriorityMedium, options);
     336        ASSERT(!m_resource);
     337        m_resource = m_document->cachedResourceLoader()->requestRawResource(newRequest, options);
     338        if (m_resource)
     339            m_resource->addClient(this);
    340340        return;
    341341    }
     
    368368    const char* bytes = static_cast<const char*>(data.data());
    369369    int len = static_cast<int>(data.size());
    370     didReceiveData(0, bytes, len);
     370    dataReceived(0, bytes, len);
    371371
    372372    didFinishLoading(identifier, 0.0);
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.h

    r95901 r97765  
    3232#define DocumentThreadableLoader_h
    3333
     34#include "CachedRawResource.h"
     35#include "CachedResourceHandle.h"
    3436#include "FrameLoaderTypes.h"
    35 #include "SubresourceLoaderClient.h"
    3637#include "ThreadableLoader.h"
    3738#include <wtf/Forward.h>
     
    4950    class ThreadableLoaderClient;
    5051
    51     class DocumentThreadableLoader : public RefCounted<DocumentThreadableLoader>, public ThreadableLoader, private SubresourceLoaderClient  {
     52    class DocumentThreadableLoader : public RefCounted<DocumentThreadableLoader>, public ThreadableLoader, private CachedRawResourceClient  {
    5253        WTF_MAKE_FAST_ALLOCATED;
    5354    public:
     
    7475        DocumentThreadableLoader(Document*, ThreadableLoaderClient*, BlockingBehavior, const ResourceRequest&, const ThreadableLoaderOptions&);
    7576
    76         virtual void willSendRequest(SubresourceLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
    77         virtual void didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
     77        void clearResource();
    7878
    79         virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
    80         virtual void didReceiveData(SubresourceLoader*, const char*, int dataLength);
    81         virtual void didReceiveCachedMetadata(SubresourceLoader*, const char*, int dataLength);
    82         virtual void didFinishLoading(SubresourceLoader*, double);
    83         virtual void didFail(SubresourceLoader*, const ResourceError&);
    84 
     79        // CachedRawResourceClient
     80        virtual void dataSent(CachedResource*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
     81        virtual void responseReceived(CachedResource*, const ResourceResponse&);
     82        virtual void dataReceived(CachedResource*, const char* data, int dataLength);
     83        virtual void redirectReceived(CachedResource*, ResourceRequest&, const ResourceResponse&);
     84        virtual void notifyFinished(CachedResource*);
    8585#if PLATFORM(CHROMIUM)
    86         virtual void didDownloadData(SubresourceLoader*, int dataLength);
     86        virtual void dataDownloaded(CachedResource*, int);
    8787#endif
    8888
    8989        void didReceiveResponse(unsigned long identifier, const ResourceResponse&);
    9090        void didFinishLoading(unsigned long identifier, double finishTime);
     91        void didFail(const ResourceError&);
    9192        void makeSimpleCrossOriginAccessRequest(const ResourceRequest& request);
    9293        void makeCrossOriginAccessRequestWithPreflight(const ResourceRequest& request);
     
    99100        SecurityOrigin* securityOrigin() const;
    100101
    101         RefPtr<SubresourceLoader> m_loader;
     102        CachedResourceHandle<CachedRawResource> m_resource;
    102103        ThreadableLoaderClient* m_client;
    103104        Document* m_document;
  • trunk/Source/WebCore/loader/cache/CachedRawResource.cpp

    r96961 r97765  
    3838CachedRawResource::CachedRawResource(ResourceRequest& resourceRequest)
    3939    : CachedResource(resourceRequest, RawResource)
     40    , m_dataLength(0)
    4041{
    4142}
     
    4344void CachedRawResource::data(PassRefPtr<SharedBuffer> data, bool allDataReceived)
    4445{
    45     m_data = data;
     46    if (data) {
     47        // If we are buffering data, then we are saving the buffer in m_data and need to manually
     48        // calculate the incremental data. If we are not buffering, then m_data will be null and
     49        // the buffer contains only the incremental data.
     50        size_t previousDataLength = (m_options.shouldBufferData == BufferData) ? m_dataLength : 0;
     51        ASSERT(data->size() >= previousDataLength);
     52        const char* incrementalData = data->data() + previousDataLength;
     53        size_t incrementalDataLength = data->size() - previousDataLength;
     54
     55        if (incrementalDataLength) {
     56            CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);
     57            while (CachedRawResourceClient* c = w.next())
     58                c->dataReceived(this, incrementalData, incrementalDataLength);
     59        }
     60    }
     61   
     62    if (m_options.shouldBufferData == BufferData) {
     63        m_dataLength = data ? data->size() : 0;
     64        m_data = data;
     65    }
    4666    CachedResource::data(m_data, allDataReceived);
     67}
     68
     69void CachedRawResource::didAddClient(CachedResourceClient* c)
     70{
     71    if (m_data) {
     72        static_cast<CachedRawResourceClient*>(c)->responseReceived(this, m_response);
     73        static_cast<CachedRawResourceClient*>(c)->dataReceived(this, m_data->data(), m_data->size());
     74    }
     75    CachedResource::didAddClient(c);
    4776}
    4877
     
    5382}
    5483
     84void CachedRawResource::willSendRequest(ResourceRequest& request, const ResourceResponse& response)
     85{
     86    if (!response.isNull()) {
     87        CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);
     88        while (CachedRawResourceClient* c = w.next())
     89            c->redirectReceived(this, request, response);
     90    }
     91    CachedResource::willSendRequest(request, response);
     92}
     93
     94void CachedRawResource::setResponse(const ResourceResponse& response)
     95{
     96    CachedResource::setResponse(response);
     97    CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);
     98    while (CachedRawResourceClient* c = w.next())
     99        c->responseReceived(this, m_response);
     100}
     101
     102void CachedRawResource::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
     103{
     104    CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);
     105    while (CachedRawResourceClient* c = w.next())
     106        c->dataSent(this, bytesSent, totalBytesToBeSent);
     107}
     108
     109void CachedRawResource::setDefersLoading(bool defers)
     110{
     111    if (m_request)
     112        m_request->setDefersLoading(defers);
     113}
     114
     115unsigned long CachedRawResource::identifier() const
     116{
     117    return m_request ? m_request->identifier() : 0;
     118}
     119
    55120} // namespace WebCore
  • trunk/Source/WebCore/loader/cache/CachedRawResource.h

    r96961 r97765  
    2525
    2626#include "CachedResource.h"
     27#include "CachedResourceClient.h"
    2728
    2829namespace WebCore {
     
    3132public:
    3233    CachedRawResource(ResourceRequest&);
     34
     35    // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and therefore shouldn't
     36    // use CachedRawResource. However, it is, and it needs to be able to defer loading.
     37    // This can be fixed by splitting CORS preflighting out of DocumentThreacableLoader.
     38    virtual void setDefersLoading(bool);
    3339   
     40    // FIXME: This is exposed for the InpsectorInstrumentation for preflights in DocumentThreadableLoader. It's also really lame.
     41    unsigned long identifier() const;
     42
    3443private:
     44    virtual void didAddClient(CachedResourceClient*);
    3545    virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
    3646
    3747    virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
    3848    virtual void allClientsRemoved();
     49
     50    virtual void willSendRequest(ResourceRequest&, const ResourceResponse&);
     51    virtual void setResponse(const ResourceResponse&);
     52    virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
     53#if PLATFORM(CHROMIUM)
     54    virtual void didDownloadData(int);
     55#endif
     56
     57    size_t m_dataLength;
     58};
     59
     60
     61class CachedRawResourceClient : public CachedResourceClient {
     62public:
     63    virtual ~CachedRawResourceClient() { }
     64    static CachedResourceClientType expectedType() { return RawResourceType; }
     65    virtual CachedResourceClientType resourceClientType() { return expectedType(); }
     66
     67    virtual void dataSent(CachedResource*, unsigned long long /* bytesSent */, unsigned long long /* totalBytesToBeSent */) { }
     68    virtual void responseReceived(CachedResource*, const ResourceResponse&) { }
     69    virtual void dataReceived(CachedResource*, const char* /* data */, int /* length */) { }
     70    virtual void redirectReceived(CachedResource*, ResourceRequest&, const ResourceResponse&) { }
     71#if PLATFORM(CHROMIUM)
     72    virtual void dataDownloaded(CachedResource*, int) { }
     73#endif
    3974};
    4075
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r97637 r97765  
    8888    , m_responseTimestamp(currentTime())
    8989    , m_lastDecodedAccessTime(0)
     90    , m_loadFinishTime(0)
    9091    , m_encodedSize(0)
    9192    , m_decodedSize(0)
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r97637 r97765  
    119119    };
    120120    PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_preloadResult); }
    121     void setRequestedFromNetworkingLayer() { m_requestedFromNetworkingLayer = true; }
    122121
    123122    virtual void didAddClient(CachedResourceClient*);
     
    174173    SharedBuffer* data() const { ASSERT(!m_purgeableData); return m_data.get(); }
    175174
    176     void setResponse(const ResourceResponse&);
     175    virtual void willSendRequest(ResourceRequest&, const ResourceResponse&) { m_requestedFromNetworkingLayer = true; }
     176    virtual void setResponse(const ResourceResponse&);
    177177    const ResourceResponse& response() const { return m_response; }
    178178
     
    232232    void clearResourceToRevalidate();
    233233    void updateResponseAfterRevalidation(const ResourceResponse& validatingResponse);
     234   
     235    virtual void didSendData(unsigned long long /* bytesSent */, unsigned long long /* totalBytesToBeSent */) { }
     236#if PLATFORM(CHROMIUM)
     237    virtual void didDownloadData(int) { }
     238#endif
     239
     240    void setLoadFinishTime(double finishTime) { m_loadFinishTime = finishTime; }
     241    double loadFinishTime() const { return m_loadFinishTime; }
    234242
    235243protected:
     
    267275
    268276    double m_lastDecodedAccessTime; // Used as a "thrash guard" in the cache
     277    double m_loadFinishTime;
    269278
    270279    unsigned m_encodedSize;
  • trunk/Source/WebCore/loader/cache/CachedResourceClient.h

    r97637 r97765  
    3939        ImageType,
    4040        FontType,
    41         StyleSheetType
     41        StyleSheetType,
     42        RawResourceType
    4243    };
    4344
  • trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp

    r97637 r97765  
    9191CachedResourceRequest::~CachedResourceRequest()
    9292{
     93    if (m_loader)
     94        m_loader->clearClient();
    9395}
    9496
     
    143145}
    144146
    145 void CachedResourceRequest::willSendRequest(SubresourceLoader* loader, ResourceRequest& req, const ResourceResponse&)
     147void CachedResourceRequest::willSendRequest(SubresourceLoader* loader, ResourceRequest& req, const ResourceResponse& response)
    146148{
    147149    if (!m_cachedResourceLoader->canRequest(m_resource->type(), req.url())) {
     
    149151        return;
    150152    }
    151     m_resource->setRequestedFromNetworkingLayer();
     153    m_resource->willSendRequest(req, response);
    152154}
    153155
     
    159161}
    160162
    161 void CachedResourceRequest::didFinishLoading(SubresourceLoader* loader, double)
     163unsigned long CachedResourceRequest::identifier() const
     164{
     165    return m_loader->identifier();
     166}
     167
     168void CachedResourceRequest::setDefersLoading(bool defers)
     169{
     170    if (m_loader)
     171        m_loader->setDefersLoading(defers);
     172}
     173
     174void CachedResourceRequest::didFinishLoading(SubresourceLoader* loader, double finishTime)
    162175{
    163176    if (m_finishing)
     
    179192    if (!m_resource->errorOccurred()) {
    180193        m_cachedResourceLoader->loadFinishing();
     194        m_resource->setLoadFinishTime(finishTime);
    181195        m_resource->data(loader->resourceData(), true);
    182196        if (!m_resource->errorOccurred())
     
    240254    }
    241255
     256    // setResponse() might cancel the request, so we need to keep ourselves alive. Unfortunately,
     257    // we can't protect a CachedResourceRequest, but we can protect m_resource, which has the
     258    // power to kill the CachedResourceRequest (and will switch isLoading() to false if it does so).
     259    CachedResourceHandle<CachedResource> protect(m_resource);
    242260    m_resource->setResponse(response);
     261    if (!protect->isLoading())
     262        return;
    243263
    244264    String encoding = response.textEncodingName();
     
    272292        return;
    273293
    274     if (m_resource->response().httpStatusCode() >= 400) {
    275         if (!m_resource->shouldIgnoreHTTPStatusCodeErrors())
    276             m_resource->error(CachedResource::LoadError);
    277         return;
    278     }
    279 
    280     // Set the data.
    281     if (m_multipart) {
    282         // The loader delivers the data in a multipart section all at once, send eof.
    283         // The resource data will change as the next part is loaded, so we need to make a copy.
     294    if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgnoreHTTPStatusCodeErrors()) {
     295        m_resource->error(CachedResource::LoadError);
     296        return;
     297    }
     298
     299    // There are two cases where we might need to create our own SharedBuffer instead of copying the one in ResourceLoader.
     300    // (1) Multipart content: The loader delivers the data in a multipart section all at once, then sends eof.
     301    //     The resource data will change as the next part is loaded, so we need to make a copy.
     302    // (2) Our client requested that the data not be buffered at the ResourceLoader level via ResourceLoaderOptions. In this case,
     303    //     ResourceLoader::resourceData() will be null. However, unlike the multipart case, we don't want to tell the CachedResource
     304    //     that all data has been received yet.
     305    if (m_multipart || !loader->resourceData()) {
    284306        RefPtr<SharedBuffer> copiedData = SharedBuffer::create(data, size);
    285         m_resource->data(copiedData.release(), true);
     307        m_resource->data(copiedData.release(), m_multipart);
    286308    } else
    287309        m_resource->data(loader->resourceData(), false);
     
    293315    m_resource->setSerializedCachedMetadata(data, size);
    294316}
    295    
     317
     318void CachedResourceRequest::didSendData(SubresourceLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
     319{
     320    m_resource->didSendData(bytesSent, totalBytesToBeSent);
     321}
     322
    296323void CachedResourceRequest::end()
    297324{
  • trunk/Source/WebCore/loader/cache/CachedResourceRequest.h

    r96961 r97765  
    5050        void cancel();
    5151
     52        // FIXME: Like CachedResource::identifier(), this is a lame hack for preflight InspectorInstrumentation in DocumentThreadableLoader.
     53        unsigned long identifier() const;
     54
     55        // FIXME: See CachedRawResource::setDefersLoading() for the relevant rant.
     56        void setDefersLoading(bool);
     57
    5258    private:
    5359        CachedResourceRequest(CachedResourceLoader*, CachedResource*);
     
    5965        virtual void didFail(SubresourceLoader*, const ResourceError&);
    6066        void end();
     67
     68        virtual void didSendData(SubresourceLoader*, unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/);
     69#if PLATFORM(CHROMIUM)
     70        virtual void didDownloadData(SubresourceLoader*, int);
     71#endif
    6172
    6273        RefPtr<SubresourceLoader> m_loader;
  • trunk/Source/WebCore/loader/chromium/CachedRawResourceChromium.cpp

    r97764 r97765  
    3030
    3131#include "config.h"
    32 #include "DocumentThreadableLoader.h"
     32#include "CachedRawResource.h"
    3333
    34 #include "SubresourceLoader.h"
    35 #include "ThreadableLoaderClient.h"
     34#include "CachedResourceClient.h"
     35#include "CachedResourceClientWalker.h"
    3636
    3737namespace WebCore {
    3838
    39 void DocumentThreadableLoader::didDownloadData(SubresourceLoader* loader, int dataLength)
     39void CachedRawResource::didDownloadData(int dataLength)
    4040{
    41     ASSERT(m_client);
    42     ASSERT_UNUSED(loader, loader == m_loader);
    43     ASSERT(!m_actualRequest);
    44 
    45     m_client->didDownloadData(dataLength);
     41    CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);
     42    while (CachedRawResourceClient* c = w.next())
     43        c->dataDownloaded(this, dataLength);
    4644}
    4745
    48 } // namespace WebCore
     46}
  • trunk/Source/WebCore/loader/chromium/CachedResourceRequestChromium.cpp

    r97764 r97765  
    3030
    3131#include "config.h"
    32 #include "DocumentThreadableLoader.h"
     32#include "CachedResourceRequest.h"
    3333
     34#include "CachedResource.h"
    3435#include "SubresourceLoader.h"
    35 #include "ThreadableLoaderClient.h"
    3636
    3737namespace WebCore {
    3838
    39 void DocumentThreadableLoader::didDownloadData(SubresourceLoader* loader, int dataLength)
     39void CachedResourceRequest::didDownloadData(SubresourceLoader* loader, int length)
    4040{
    41     ASSERT(m_client);
    4241    ASSERT_UNUSED(loader, loader == m_loader);
    43     ASSERT(!m_actualRequest);
    44 
    45     m_client->didDownloadData(dataLength);
     42    m_resource->didDownloadData(length);
    4643}
    4744
    48 } // namespace WebCore
     45}
  • trunk/Source/WebCore/loader/chromium/DocumentThreadableLoaderChromium.cpp

    r95901 r97765  
    3232#include "DocumentThreadableLoader.h"
    3333
    34 #include "SubresourceLoader.h"
     34#include "CachedRawResource.h"
    3535#include "ThreadableLoaderClient.h"
    3636
    3737namespace WebCore {
    3838
    39 void DocumentThreadableLoader::didDownloadData(SubresourceLoader* loader, int dataLength)
     39void DocumentThreadableLoader::dataDownloaded(CachedResource* resource, int dataLength)
    4040{
    4141    ASSERT(m_client);
    42     ASSERT_UNUSED(loader, loader == m_loader);
     42    ASSERT_UNUSED(resource, resource == m_resource);
    4343    ASSERT(!m_actualRequest);
    4444
  • trunk/Source/WebCore/loader/icon/IconLoader.h

    r96961 r97765  
    2727#define IconLoader_h
    2828
    29 #include "CachedResourceClient.h"
     29#include "CachedRawResource.h"
    3030#include "CachedResourceHandle.h"
    3131#include <wtf/Forward.h>
     
    3838class Frame;
    3939
    40 class IconLoader : private CachedResourceClient {
     40class IconLoader : private CachedRawResourceClient {
    4141    WTF_MAKE_NONCOPYABLE(IconLoader); WTF_MAKE_FAST_ALLOCATED;
    4242public:
    4343    static PassOwnPtr<IconLoader> create(Frame*);
    44     ~IconLoader();
     44    virtual ~IconLoader();
    4545
    4646    void startLoading();
  • trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp

    r95901 r97765  
    539539
    540540    if (m_errorCode) {
     541        RefPtr<BlobResourceHandle> protect(this);
    541542        notifyResponseOnError();
    542543        notifyFinish();
Note: See TracChangeset for help on using the changeset viewer.