Changeset 146239 in webkit


Ignore:
Timestamp:
Mar 19, 2013 12:39:44 PM (11 years ago)
Author:
Nate Chapin
Message:

Merge MainResourceLoader's SubstituteData loading + others into DocumentLoader
https://bugs.webkit.org/show_bug.cgi?id=112722

Part of the ongoing effort to merge MainResourceLoader entirely
into DocumentLoader.

Reviewed by Antti Koivisto.

No new tests, refactor only.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::mainReceivedError): Moved from MainResourceLoader::receivedError

and the failure case in MainResourceLoader::notifyFinished.

(WebCore::DocumentLoader::stopLoading):
(WebCore::DocumentLoader::finishedLoading):
(WebCore::DocumentLoader::handleSubstituteDataLoadNow): Moved from MainResourceLoader.
(WebCore::DocumentLoader::startDataLoadTimer): Moved from MainResourceLoader.
(WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Moved from MainResourceLoader.
(WebCore::DocumentLoader::willSendRequest):
(WebCore::DocumentLoader::continueAfterNavigationPolicy):
(WebCore::DocumentLoader::responseReceived):
(WebCore::DocumentLoader::receivedData):
(WebCore::DocumentLoader::startLoadingMainResource): Most of MainResourceLoader::load

moved here.

(WebCore::DocumentLoader::cancelMainResourceLoad): MainResourceLoader::cancel

moved here.

  • loader/DocumentLoader.h:
  • loader/MainResourceLoader.cpp:

(WebCore::MainResourceLoader::notifyFinished):
(WebCore::MainResourceLoader::reportMemoryUsage):
(WebCore::MainResourceLoader::load):
(WebCore::MainResourceLoader::identifier):

  • loader/MainResourceLoader.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r146238 r146239  
     12013-03-19  Nate Chapin  <japhet@chromium.org>
     2
     3        Merge MainResourceLoader's SubstituteData loading + others into DocumentLoader
     4        https://bugs.webkit.org/show_bug.cgi?id=112722
     5
     6        Part of the ongoing effort to merge MainResourceLoader entirely
     7        into DocumentLoader.
     8
     9        Reviewed by Antti Koivisto.
     10
     11        No new tests, refactor only.
     12
     13        * loader/DocumentLoader.cpp:
     14        (WebCore::DocumentLoader::mainReceivedError): Moved from MainResourceLoader::receivedError
     15            and the failure case in MainResourceLoader::notifyFinished.
     16        (WebCore::DocumentLoader::stopLoading):
     17        (WebCore::DocumentLoader::finishedLoading):
     18        (WebCore::DocumentLoader::handleSubstituteDataLoadNow): Moved from MainResourceLoader.
     19        (WebCore::DocumentLoader::startDataLoadTimer): Moved from MainResourceLoader.
     20        (WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Moved from MainResourceLoader.
     21        (WebCore::DocumentLoader::willSendRequest):
     22        (WebCore::DocumentLoader::continueAfterNavigationPolicy):
     23        (WebCore::DocumentLoader::responseReceived):
     24        (WebCore::DocumentLoader::receivedData):
     25        (WebCore::DocumentLoader::startLoadingMainResource): Most of MainResourceLoader::load
     26            moved here.
     27        (WebCore::DocumentLoader::cancelMainResourceLoad): MainResourceLoader::cancel
     28            moved here.
     29        * loader/DocumentLoader.h:
     30        * loader/MainResourceLoader.cpp:
     31        (WebCore::MainResourceLoader::notifyFinished):
     32        (WebCore::MainResourceLoader::reportMemoryUsage):
     33        (WebCore::MainResourceLoader::load):
     34        (WebCore::MainResourceLoader::identifier):
     35        * loader/MainResourceLoader.h:
     36
    1372013-03-19  Ryosuke Niwa  <rniwa@webkit.org>
    238
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r146216 r146239  
    5252#include "MemoryCache.h"
    5353#include "Page.h"
     54#include "ProgressTracker.h"
    5455#include "ResourceBuffer.h"
    5556#include "SchemeRegistry.h"
     
    113114    , m_didCreateGlobalHistoryEntry(false)
    114115    , m_timeOfLastDataReceived(0.0)
     116    , m_identifierForLoadWithoutResourceLoader(0)
     117    , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow)
    115118    , m_waitingForContentPolicy(false)
    116119    , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this)))
     
    217220{
    218221    ASSERT(!error.isNull());
     222    if (m_applicationCacheHost->maybeLoadFallbackForMainError(request(), error))
     223        return;
     224
     225    if (m_identifierForLoadWithoutResourceLoader) {
     226        ASSERT(!mainResourceLoader());
     227        frameLoader()->client()->dispatchDidFailLoading(this, m_identifierForLoadWithoutResourceLoader, error);
     228    }
     229
     230    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
     231    // See <rdar://problem/6304600> for more details.
     232#if !USE(CF)
     233    ASSERT(!m_frame->page()->defersLoading());
     234#endif
    219235
    220236    m_applicationCacheHost->failedLoadingMainResource();
     
    279295    if (m_mainResourceLoader)
    280296        // Stop the main resource loader and let it send the cancelled message.
    281         m_mainResourceLoader->cancel(frameLoader->cancelledError(m_request));
     297        cancelMainResourceLoad(frameLoader->cancelledError(m_request));
    282298    else if (!m_subresourceLoaders.isEmpty())
    283299        // The main resource loader already finished loading. Set the cancelled error on the
     
    325341    RefPtr<DocumentLoader> protect(this);
    326342
    327     if (m_mainResourceLoader && m_mainResourceLoader->identifierForLoadWithoutResourceLoader()) {
    328         frameLoader()->notifier()->dispatchDidFinishLoading(this, m_mainResourceLoader->identifier(), finishTime);
    329         m_mainResourceLoader->clearIdentifierForLoadWithoutResourceLoader();
     343    if (m_identifierForLoadWithoutResourceLoader) {
     344        frameLoader()->notifier()->dispatchDidFinishLoading(this, m_identifierForLoadWithoutResourceLoader, finishTime);
     345        m_identifierForLoadWithoutResourceLoader = 0;
    330346    }
    331347
     
    388404
    389405    return false;
     406}
     407
     408void DocumentLoader::handleSubstituteDataLoadNow(DocumentLoaderTimer*)
     409{
     410    KURL url = m_substituteData.responseURL();
     411    if (url.isEmpty())
     412        url = m_request.url();
     413    ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding(), "");
     414    responseReceived(response);
     415}
     416
     417void DocumentLoader::startDataLoadTimer()
     418{
     419    m_dataLoadTimer.startOneShot(0);
     420
     421#if HAVE(RUNLOOP_TIMER)
     422    if (SchedulePairHashSet* scheduledPairs = m_frame->page()->scheduledRunLoopPairs())
     423        m_dataLoadTimer.schedule(*scheduledPairs);
     424#endif
     425}
     426
     427void DocumentLoader::handleSubstituteDataLoadSoon()
     428{
     429    if (deferMainResourceDataLoad())
     430        startDataLoadTimer();
     431    else
     432        handleSubstituteDataLoadNow(0);
    390433}
    391434
     
    443486        m_applicationCacheHost->maybeLoadMainResourceForRedirect(newRequest, m_substituteData);
    444487        if (m_substituteData.isValid())
    445             m_mainResourceLoader->takeIdentifierFromResourceLoader();
     488            m_identifierForLoadWithoutResourceLoader = mainResourceLoader()->identifier();
    446489    }
    447490
     
    459502}
    460503
    461 void DocumentLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue)
     504void DocumentLoader::continueAfterNavigationPolicy(const ResourceRequest&, bool shouldContinue)
    462505{
    463506    if (!shouldContinue)
     
    478521        m_mainResourceLoader->clearResource();
    479522        resourceLoader->setSendCallbackPolicy(SendCallbacks);
    480         m_mainResourceLoader->handleSubstituteDataLoadSoon(request);
     523        handleSubstituteDataLoadSoon();
    481524    }
    482525}
     
    505548    if (it != response.httpHeaderFields().end()) {
    506549        String content = it->value;
    507         unsigned long identifier = m_mainResourceLoader->identifier();
     550        unsigned long identifier = m_identifierForLoadWithoutResourceLoader ? m_identifierForLoadWithoutResourceLoader : mainResourceLoader()->identifier();
    508551        if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response.url(), identifier)) {
    509552            InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame, this, identifier, response);
     
    531574    setResponse(response);
    532575
    533     if (m_mainResourceLoader->identifierForLoadWithoutResourceLoader())
    534         frameLoader()->notifier()->dispatchDidReceiveResponse(this, m_mainResourceLoader->identifierForLoadWithoutResourceLoader(), m_response, 0);
     576    if (m_identifierForLoadWithoutResourceLoader)
     577        frameLoader()->notifier()->dispatchDidReceiveResponse(this, m_identifierForLoadWithoutResourceLoader, m_response, 0);
    535578
    536579    ASSERT(!m_waitingForContentPolicy);
     
    781824#endif
    782825
    783     if (m_mainResourceLoader->identifierForLoadWithoutResourceLoader())
    784         frameLoader()->notifier()->dispatchDidReceiveData(this, m_mainResourceLoader->identifier(), data, length, -1);
     826    if (m_identifierForLoadWithoutResourceLoader)
     827        frameLoader()->notifier()->dispatchDidReceiveData(this, m_identifierForLoadWithoutResourceLoader, data, length, -1);
    785828
    786829    m_applicationCacheHost->mainResourceDataReceived(data, length, -1, false);
     
    13121355    m_applicationCacheHost->maybeLoadMainResource(m_request, m_substituteData);
    13131356
     1357    if (m_substituteData.isValid()) {
     1358        m_identifierForLoadWithoutResourceLoader = m_frame->page()->progress()->createUniqueIdentifier();
     1359        frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, this, m_request);
     1360        frameLoader()->notifier()->dispatchWillSendRequest(this, m_identifierForLoadWithoutResourceLoader, m_request, ResourceResponse());
     1361        handleSubstituteDataLoadSoon();
     1362        return;
     1363    }
     1364
     1365    ResourceRequest request(m_request);
    13141366    m_mainResourceLoader->load(m_request);
    13151367
     
    13211373        m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this));
    13221374        maybeLoadEmpty();
    1323     }
     1375        return;
     1376    }
     1377
     1378    if (!mainResourceLoader()) {
     1379        m_identifierForLoadWithoutResourceLoader = m_frame->page()->progress()->createUniqueIdentifier();
     1380        frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, this, request);
     1381        frameLoader()->notifier()->dispatchWillSendRequest(this, m_identifierForLoadWithoutResourceLoader, request, ResourceResponse());
     1382    }
     1383
     1384    // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those.
     1385    if (mainResourceLoader())
     1386        request = mainResourceLoader()->originalRequest();
     1387    // If there was a fragment identifier on m_request, the cache will have stripped it. m_request should include
     1388    // the fragment identifier, so add that back in.
     1389    if (equalIgnoringFragmentIdentifier(m_request.url(), request.url()))
     1390        request.setURL(m_request.url());
     1391    setRequest(request);
    13241392}
    13251393
     
    13271395{
    13281396    ASSERT(!error.isNull());
    1329 
     1397    RefPtr<DocumentLoader> protect(this);
     1398
     1399    m_dataLoadTimer.stop();
    13301400    if (m_waitingForContentPolicy) {
    13311401        frameLoader()->policyChecker()->cancelCheck();
     
    13331403        m_waitingForContentPolicy = false;
    13341404    }
    1335     m_mainResourceLoader->cancel(error);
     1405
     1406    if (mainResourceLoader())
     1407        mainResourceLoader()->cancel(error);
     1408
     1409    mainReceivedError(error);
    13361410}
    13371411
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r146216 r146239  
    4646#include <wtf/Vector.h>
    4747
     48#if HAVE(RUNLOOP_TIMER)
     49#include "RunLoopTimer.h"
     50#endif
     51
    4852namespace WTF {
    4953class SchedulePair;
     
    292296        ResourceError interruptedForPolicyChangeError() const;
    293297
     298#if HAVE(RUNLOOP_TIMER)
     299        typedef RunLoopTimer<DocumentLoader> DocumentLoaderTimer;
     300#else
     301        typedef Timer<DocumentLoader> DocumentLoaderTimer;
     302#endif
     303        void handleSubstituteDataLoadSoon();
     304        void handleSubstituteDataLoadNow(DocumentLoaderTimer*);
     305        void startDataLoadTimer();
     306
    294307        void deliverSubstituteResourcesAfterDelay();
    295308        void substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*);
     
    376389
    377390        double m_timeOfLastDataReceived;
    378 
     391        unsigned long m_identifierForLoadWithoutResourceLoader;
     392
     393        DocumentLoaderTimer m_dataLoadTimer;
    379394        bool m_waitingForContentPolicy;
    380    
     395
    381396        RefPtr<IconLoadDecisionCallback> m_iconLoadDecisionCallback;
    382397        RefPtr<IconDataCallback> m_iconDataCallback;
  • trunk/Source/WebCore/loader/MainResourceLoader.cpp

    r146216 r146239  
    6767
    6868MainResourceLoader::MainResourceLoader(DocumentLoader* documentLoader)
    69     : m_dataLoadTimer(this, &MainResourceLoader::handleSubstituteDataLoadNow)
    70     , m_documentLoader(documentLoader)
    71     , m_identifierForLoadWithoutResourceLoader(0)
     69    : m_documentLoader(documentLoader)
    7270{
    7371}
     
    8179{
    8280    return adoptRef(new MainResourceLoader(documentLoader));
    83 }
    84 
    85 void MainResourceLoader::receivedError(const ResourceError& error)
    86 {
    87     // Calling receivedMainResourceError will likely result in the last reference to this object to go away.
    88     RefPtr<MainResourceLoader> protect(this);
    89     RefPtr<Frame> protectFrame(m_documentLoader->frame());
    90 
    91     if (m_identifierForLoadWithoutResourceLoader) {
    92         ASSERT(!loader());
    93         frameLoader()->client()->dispatchDidFailLoading(documentLoader(), m_identifierForLoadWithoutResourceLoader, error);
    94     }
    95 
    96     // It is important that we call DocumentLoader::mainReceivedError before calling
    97     // ResourceLoadNotifier::didFailToLoad because mainReceivedError clears out the relevant
    98     // document loaders. Also, mainReceivedError ends up calling a FrameLoadDelegate method
    99     // and didFailToLoad calls a ResourceLoadDelegate method and they need to be in the correct order.
    100     documentLoader()->mainReceivedError(error);
    101 }
    102 
    103 void MainResourceLoader::cancel()
    104 {
    105     cancel(ResourceError());
    106 }
    107 
    108 void MainResourceLoader::cancel(const ResourceError& error)
    109 {
    110     RefPtr<MainResourceLoader> protect(this);
    111     ResourceError resourceError = error.isNull() ? frameLoader()->cancelledError(request()) : error;
    112 
    113     m_dataLoadTimer.stop();
    114     if (loader())
    115         loader()->cancel(resourceError);
    116 
    117     clearResource();
    118     receivedError(resourceError);
    11981}
    12082
     
    178140    }
    179141#endif
    180 
    181     const ResourceError& error = m_resource->resourceError();
    182     if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainError(request(), error))
    183         return;
    184 
    185     // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
    186     // See <rdar://problem/6304600> for more details.
    187 #if !USE(CF)
    188     ASSERT(!defersLoading());
    189 #endif
    190    
    191     receivedError(error);
     142    m_documentLoader->mainReceivedError(m_resource->resourceError());
    192143}
    193144
     
    197148    info.addMember(m_resource, "resource");
    198149    info.addMember(m_initialRequest, "initialRequest");
    199     info.addMember(m_dataLoadTimer, "dataLoadTimer");
    200150    info.addMember(m_documentLoader, "documentLoader");
    201 }
    202 
    203 void MainResourceLoader::handleSubstituteDataLoadNow(MainResourceLoaderTimer*)
    204 {
    205     RefPtr<MainResourceLoader> protect(this);
    206 
    207     KURL url = m_documentLoader->substituteData().responseURL();
    208     if (url.isEmpty())
    209         url = m_initialRequest.url();
    210 
    211     // Clear the initial request here so that subsequent entries into the
    212     // loader will not think there's still a deferred load left to do.
    213     m_initialRequest = ResourceRequest();
    214        
    215     ResourceResponse response(url, m_documentLoader->substituteData().mimeType(), m_documentLoader->substituteData().content()->size(), m_documentLoader->substituteData().textEncoding(), "");
    216     responseReceived(0, response);
    217 }
    218 
    219 void MainResourceLoader::startDataLoadTimer()
    220 {
    221     m_dataLoadTimer.startOneShot(0);
    222 
    223 #if HAVE(RUNLOOP_TIMER)
    224     if (SchedulePairHashSet* scheduledPairs = m_documentLoader->frame()->page()->scheduledRunLoopPairs())
    225         m_dataLoadTimer.schedule(*scheduledPairs);
    226 #endif
    227 }
    228 
    229 void MainResourceLoader::handleSubstituteDataLoadSoon(const ResourceRequest& r)
    230 {
    231     m_initialRequest = r;
    232    
    233     if (m_documentLoader->deferMainResourceDataLoad())
    234         startDataLoadTimer();
    235     else
    236         handleSubstituteDataLoadNow(0);
    237151}
    238152
    239153void MainResourceLoader::load(const ResourceRequest& initialRequest)
    240154{
    241     RefPtr<MainResourceLoader> protect(this);
    242155    ResourceRequest request(initialRequest);
    243 
    244     if (m_documentLoader->substituteData().isValid()) {
    245         m_identifierForLoadWithoutResourceLoader = m_documentLoader->frame()->page()->progress()->createUniqueIdentifier();
    246         frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, documentLoader(), request);
    247         frameLoader()->notifier()->dispatchWillSendRequest(documentLoader(), m_identifierForLoadWithoutResourceLoader, request, ResourceResponse());
    248         handleSubstituteDataLoadSoon(request);
    249         return;
    250     }
    251156
    252157    DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions,
     
    258163        return;
    259164    }
    260     if (!loader()) {
    261         m_identifierForLoadWithoutResourceLoader = m_documentLoader->frame()->page()->progress()->createUniqueIdentifier();
    262         frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, documentLoader(), request);
    263         frameLoader()->notifier()->dispatchWillSendRequest(documentLoader(), m_identifierForLoadWithoutResourceLoader, request, ResourceResponse());
    264     }
    265165    m_resource->addClient(this);
    266 
    267     // A bunch of headers are set when the underlying ResourceLoader is created, and DocumentLoader::m_request needs to include those.
    268     if (loader())
    269         request = loader()->originalRequest();
    270     // If there was a fragment identifier on initialRequest, the cache will have stripped it. DocumentLoader::m_request should include
    271     // the fragment identifier, so add that back in.
    272     if (equalIgnoringFragmentIdentifier(initialRequest.url(), request.url()))
    273         request.setURL(initialRequest.url());
    274     documentLoader()->setRequest(request);
    275166}
    276167
     
    299190unsigned long MainResourceLoader::identifier() const
    300191{
    301     ASSERT(!m_identifierForLoadWithoutResourceLoader || !loader() || !loader()->identifier());
    302     if (m_identifierForLoadWithoutResourceLoader)
    303         return m_identifierForLoadWithoutResourceLoader;
    304192    if (ResourceLoader* resourceLoader = loader())
    305193        return resourceLoader->identifier();
  • trunk/Source/WebCore/loader/MainResourceLoader.h

    r146216 r146239  
    3737#include <wtf/Forward.h>
    3838
    39 #if HAVE(RUNLOOP_TIMER)
    40 #include <wtf/RunLoopTimer.h>
    41 #else
    42 #include "Timer.h"
    43 #endif
    44 
    4539namespace WebCore {
    4640
     
    5448
    5549    void load(const ResourceRequest&);
    56     void cancel();
    57     void cancel(const ResourceError&);
    5850    ResourceLoader* loader() const;
    5951    PassRefPtr<ResourceBuffer> resourceData();
     
    6254    void setDataBufferingPolicy(DataBufferingPolicy);
    6355
    64 #if HAVE(RUNLOOP_TIMER)
    65     typedef RunLoopTimer<MainResourceLoader> MainResourceLoaderTimer;
    66 #else
    67     typedef Timer<MainResourceLoader> MainResourceLoaderTimer;
    68 #endif
    69 
    7056    CachedRawResource* cachedMainResource() { return m_resource.get(); }
    71     unsigned long identifierForLoadWithoutResourceLoader() const { return m_identifierForLoadWithoutResourceLoader; }
    72     void clearIdentifierForLoadWithoutResourceLoader() { m_identifierForLoadWithoutResourceLoader = 0; }
    7357
    7458    unsigned long identifier() const;
     
    7660    void reportMemoryUsage(MemoryObjectInfo*) const;
    7761
    78     void takeIdentifierFromResourceLoader() { m_identifierForLoadWithoutResourceLoader = identifier(); }
    79     void handleSubstituteDataLoadSoon(const ResourceRequest&);
    8062    void clearResource();
    8163
     
    8769    virtual void dataReceived(CachedResource*, const char* data, int dataLength) OVERRIDE;
    8870    virtual void notifyFinished(CachedResource*) OVERRIDE;
    89 
    90     void handleSubstituteDataLoadNow(MainResourceLoaderTimer*);
    91 
    92     void startDataLoadTimer();
    93 
    94     void receivedError(const ResourceError&);
    95    
    96 #if PLATFORM(QT)
    97     void substituteMIMETypeFromPluginDatabase(const ResourceResponse&);
    98 #endif
    9971
    10072    FrameLoader* frameLoader() const;
     
    10981    ResourceRequest m_initialRequest;
    11082
    111     MainResourceLoaderTimer m_dataLoadTimer;
    11283    RefPtr<DocumentLoader> m_documentLoader;
    113 
    114     unsigned long m_identifierForLoadWithoutResourceLoader;
    11584};
    11685
Note: See TracChangeset for help on using the changeset viewer.