Changeset 145734 in webkit


Ignore:
Timestamp:
Mar 13, 2013, 12:11:35 PM (12 years ago)
Author:
Nate Chapin
Message:

Merge MainResourceLoader's didFinishLoading and dataReceived into DocumentLoader
https://bugs.webkit.org/show_bug.cgi?id=109952

Reviewed by Antti Koivisto.

No new tests, refactor only.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::DocumentLoader):
(WebCore::DocumentLoader::finishedLoading):
(WebCore::DocumentLoader::responseReceived):
(WebCore::DocumentLoader::receivedData):
(WebCore::DocumentLoader::maybeLoadEmpty):

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

(WebCore::MainResourceLoader::responseReceived): Move content filtering to

DocumentLoader.

(WebCore::MainResourceLoader::dataReceived): Mostly moved to DocumentLoader.
(WebCore::MainResourceLoader::didFinishLoading): Mostly moved to DocumentLoader.

  • loader/MainResourceLoader.h: Expose some variables that haven't been moved

to DocumentLoader yet.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r145728 r145734  
     12013-03-13  Nate Chapin  <japhet@chromium.org>
     2
     3        Merge MainResourceLoader's didFinishLoading and dataReceived into DocumentLoader
     4        https://bugs.webkit.org/show_bug.cgi?id=109952
     5
     6        Reviewed by Antti Koivisto.
     7
     8        No new tests, refactor only.
     9
     10        * loader/DocumentLoader.cpp:
     11        (WebCore::DocumentLoader::DocumentLoader):
     12        (WebCore::DocumentLoader::finishedLoading):
     13        (WebCore::DocumentLoader::responseReceived):
     14        (WebCore::DocumentLoader::receivedData):
     15        (WebCore::DocumentLoader::maybeLoadEmpty):
     16        * loader/DocumentLoader.h:
     17        * loader/MainResourceLoader.cpp:
     18        (WebCore::MainResourceLoader::responseReceived): Move content filtering to
     19            DocumentLoader.
     20        (WebCore::MainResourceLoader::dataReceived): Mostly moved to DocumentLoader.
     21        (WebCore::MainResourceLoader::didFinishLoading): Mostly moved to DocumentLoader.
     22        * loader/MainResourceLoader.h: Expose some variables that haven't been moved
     23            to DocumentLoader yet.
     24
    1252013-03-13  Andrei Bucur  <abucur@adobe.com>
    226
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r144413 r145734  
    4848#include "Logging.h"
    4949#include "MainResourceLoader.h"
     50#include "MemoryCache.h"
    5051#include "Page.h"
    5152#include "ResourceBuffer.h"
     
    6465#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
    6566#include "ArchiveFactory.h"
     67#endif
     68
     69#if USE(CONTENT_FILTERING)
     70#include "ContentFilter.h"
    6671#endif
    6772
     
    104109    , m_substituteResourceDeliveryTimer(this, &DocumentLoader::substituteResourceDeliveryTimerFired)
    105110    , m_didCreateGlobalHistoryEntry(false)
     111    , m_timeOfLastDataReceived(0.0)
    106112    , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this)))
    107113{
     
    298304}
    299305
    300 void DocumentLoader::finishedLoading()
    301 {
     306void DocumentLoader::finishedLoading(double finishTime)
     307{
     308    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
     309    // See <rdar://problem/6304600> for more details.
     310#if !USE(CF)
     311    ASSERT(!m_frame->page()->defersLoading() || InspectorInstrumentation::isDebuggerPaused(m_frame));
     312#endif
     313
     314    if (mainResourceLoader() && mainResourceLoader()->identifierForLoadWithoutResourceLoader()) {
     315        frameLoader()->notifier()->dispatchDidFinishLoading(this, mainResourceLoader()->identifier(), finishTime);
     316        mainResourceLoader()->clearIdentifierForLoadWithoutResourceLoader();
     317    }
     318
     319#if USE(CONTENT_FILTERING)
     320    if (m_contentFilter && m_contentFilter->needsMoreData()) {
     321        m_contentFilter->finishedAddingData();
     322        int length;
     323        const char* data = m_contentFilter->getReplacementData(length);
     324        if (data)
     325            receivedData(data, length);
     326    }
     327#endif
     328
     329    maybeFinishLoadingMultipartContent();
     330
     331    double responseEndTime = finishTime;
     332    if (!responseEndTime)
     333        responseEndTime = m_timeOfLastDataReceived;
     334    if (!responseEndTime)
     335        responseEndTime = monotonicallyIncreasingTime();
     336    timing()->setResponseEnd(responseEndTime);
     337
    302338    commitIfReady();
    303339    if (!frameLoader())
     
    318354    if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument())
    319355        frameLoader()->checkLoadComplete();
     356
     357    // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache
     358    // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
     359    if (frame() && mainResourceLoader()) {
     360        if (mainResourceLoader()->cachedMainResource() && frame()->document()->hasManifest())
     361            memoryCache()->remove(mainResourceLoader()->cachedMainResource());
     362    }
     363    m_applicationCacheHost->finishedLoadingMainResource();
     364}
     365
     366void DocumentLoader::responseReceived(const ResourceResponse& response)
     367{
     368    setResponse(response);
     369
     370#if USE(CONTENT_FILTERING)
     371    if (response.url().protocolIs("https") && ContentFilter::isEnabled())
     372        m_contentFilter = ContentFilter::create(response);
     373#endif
     374
    320375}
    321376
     
    413468void DocumentLoader::receivedData(const char* data, int length)
    414469{
     470    ASSERT(data);
     471    ASSERT(length);
     472    ASSERT(!m_response.isNull());
     473
     474#if USE(CFNETWORK) || PLATFORM(MAC)
     475    // Workaround for <rdar://problem/6060782>
     476    if (m_response.isNull())
     477        setResponse(ResourceResponse(KURL(), "text/html", 0, String(), String()));
     478#endif
     479
     480    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
     481    // See <rdar://problem/6304600> for more details.
     482#if !USE(CF)
     483    ASSERT(!m_frame->page()->defersLoading());
     484#endif
     485
     486#if USE(CONTENT_FILTERING)
     487    bool loadWasBlockedBeforeFinishing = false;
     488    if (m_contentFilter && m_contentFilter->needsMoreData()) {
     489        m_contentFilter->addData(data, length);
     490
     491        if (m_contentFilter->needsMoreData()) {
     492            // Since the filter still needs more data to make a decision,
     493            // transition back to the committed state so that we don't partially
     494            // load content that might later be blocked.
     495            commitLoad(0, 0);
     496            return;
     497        }
     498
     499        data = m_contentFilter->getReplacementData(length);
     500        loadWasBlockedBeforeFinishing = m_contentFilter->didBlockData();
     501    }
     502#endif
     503
     504    if (mainResourceLoader()->identifierForLoadWithoutResourceLoader())
     505        frameLoader()->notifier()->dispatchDidReceiveData(this, mainResourceLoader()->identifier(), data, length, -1);
     506
     507    m_applicationCacheHost->mainResourceDataReceived(data, length, -1, false);
     508    m_timeOfLastDataReceived = monotonicallyIncreasingTime();
     509
    415510    if (!isMultipartReplacingLoad())
    416511        commitLoad(data, length);
     512
     513#if USE(CONTENT_FILTERING)
     514    if (loadWasBlockedBeforeFinishing)
     515        cancelMainResourceLoad(ResourceError());
     516#endif
    417517}
    418518
     
    9001000    String mimeType = shouldLoadEmpty ? "text/html" : frameLoader()->client()->generatedMIMETypeForURLScheme(m_request.url().protocol());
    9011001    setResponse(ResourceResponse(m_request.url(), mimeType, 0, String(), String()));
    902     finishedLoading();
     1002    finishedLoading(monotonicallyIncreasingTime());
    9031003    return true;
    9041004}
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r145592 r145734  
    5757    class ArchiveResourceCollection;
    5858    class CachedResourceLoader;
     59    class ContentFilter;
    5960    class Frame;
    6061    class FrameLoader;
     
    121122        void receivedData(const char*, int);
    122123        void setupForReplace();
    123         void finishedLoading();
     124        void finishedLoading(double finishTime);
    124125        const ResourceResponse& response() const { return m_response; }
    125126        const ResourceError& mainDocumentError() const { return m_mainDocumentError; }
     
    244245        void resetTiming() { m_documentLoadTiming = DocumentLoadTiming(); }
    245246
     247        void responseReceived(const ResourceResponse&);
     248
    246249        // The WebKit layer calls this function when it's ready for the data to
    247250        // actually be added to the document.
     
    354357
    355358        DocumentLoadTiming m_documentLoadTiming;
     359
     360        double m_timeOfLastDataReceived;
    356361   
    357362        RefPtr<IconLoadDecisionCallback> m_iconLoadDecisionCallback;
     
    360365        friend class ApplicationCacheHost;  // for substitute resource delivery
    361366        OwnPtr<ApplicationCacheHost> m_applicationCacheHost;
     367
     368#if USE(CONTENT_FILTERING)
     369        RefPtr<ContentFilter> m_contentFilter;
     370#endif
    362371    };
    363372
  • trunk/Source/WebCore/loader/MainResourceLoader.cpp

    r144949 r145734  
    6565#endif
    6666
    67 #if USE(CONTENT_FILTERING)
    68 #include "ContentFilter.h"
    69 #endif
    70 
    7167namespace WebCore {
    7268
     
    7672    , m_loadingMultipartContent(false)
    7773    , m_waitingForContentPolicy(false)
    78     , m_timeOfLastDataReceived(0.0)
    7974    , m_identifierForLoadWithoutResourceLoader(0)
    8075{
     
    439434    RefPtr<MainResourceLoader> protect(this);
    440435
    441     m_documentLoader->setResponse(r);
     436    m_documentLoader->responseReceived(r);
    442437
    443438    m_response = r;
     
    465460#endif
    466461
    467 #if USE(CONTENT_FILTERING)
    468     if (r.url().protocolIs("https") && ContentFilter::isEnabled())
    469         m_contentFilter = ContentFilter::create(r);
    470 #endif
    471 
    472462    frameLoader()->policyChecker()->checkContentPolicy(m_response, callContinueAfterContentPolicy, this);
    473463}
     
    475465void MainResourceLoader::dataReceived(CachedResource* resource, const char* data, int length)
    476466{
    477     ASSERT(data);
    478     ASSERT(length != 0);
    479467    ASSERT_UNUSED(resource, resource == m_resource);
    480     ASSERT(!m_response.isNull());
    481 
    482 #if USE(CFNETWORK) || PLATFORM(MAC)
    483     // Workaround for <rdar://problem/6060782>
    484     if (m_response.isNull()) {
    485         m_response = ResourceResponse(KURL(), "text/html", 0, String(), String());
    486         if (DocumentLoader* documentLoader = m_documentLoader.get())
    487             documentLoader->setResponse(m_response);
    488     }
    489 #endif
    490 
    491     // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
    492     // See <rdar://problem/6304600> for more details.
    493 #if !USE(CF)
    494     ASSERT(!defersLoading());
    495 #endif
    496 
    497 #if USE(CONTENT_FILTERING)
    498     bool loadWasBlockedBeforeFinishing = false;
    499     if (m_contentFilter && m_contentFilter->needsMoreData()) {
    500         m_contentFilter->addData(data, length);
    501 
    502         if (m_contentFilter->needsMoreData()) {
    503             // Since the filter still needs more data to make a decision,
    504             // transition back to the committed state so that we don't partially
    505             // load content that might later be blocked.
    506             documentLoader()->receivedData(0, 0);
    507             return;
    508         }
    509 
    510         data = m_contentFilter->getReplacementData(length);
    511         loadWasBlockedBeforeFinishing = m_contentFilter->didBlockData();
    512     }
    513 #endif
    514 
    515     if (m_identifierForLoadWithoutResourceLoader)
    516         frameLoader()->notifier()->dispatchDidReceiveData(documentLoader(), identifier(), data, length, -1);
    517 
    518     documentLoader()->applicationCacheHost()->mainResourceDataReceived(data, length, -1, false);
    519 
    520     // The additional processing can do anything including possibly removing the last
    521     // reference to this object; one example of this is 3266216.
    522     RefPtr<MainResourceLoader> protect(this);
    523 
    524     m_timeOfLastDataReceived = monotonicallyIncreasingTime();
    525 
    526468    documentLoader()->receivedData(data, length);
    527 
    528 #if USE(CONTENT_FILTERING)
    529     if (loadWasBlockedBeforeFinishing)
    530         cancel();
    531 #endif
    532469}
    533470
    534471void MainResourceLoader::didFinishLoading(double finishTime)
    535472{
    536     // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
    537     // See <rdar://problem/6304600> for more details.
    538 #if !USE(CF)
    539     ASSERT(!defersLoading() || InspectorInstrumentation::isDebuggerPaused(m_documentLoader->frame()));
    540 #endif
    541 
    542473    // The additional processing can do anything including possibly removing the last
    543474    // reference to this object.
    544475    RefPtr<MainResourceLoader> protect(this);
    545     RefPtr<DocumentLoader> dl = documentLoader();
    546 
    547     if (m_identifierForLoadWithoutResourceLoader) {
    548         frameLoader()->notifier()->dispatchDidFinishLoading(documentLoader(), identifier(), finishTime);
    549         m_identifierForLoadWithoutResourceLoader = 0;
    550     }
    551 
    552 #if USE(CONTENT_FILTERING)
    553     if (m_contentFilter && m_contentFilter->needsMoreData()) {
    554         m_contentFilter->finishedAddingData();
    555 
    556         int length;
    557         const char* data = m_contentFilter->getReplacementData(length);
    558         if (data)
    559             dataReceived(m_resource.get(), data, length);
    560     }
    561 #endif
    562 
    563     if (m_loadingMultipartContent)
    564         dl->maybeFinishLoadingMultipartContent();
    565 
    566     documentLoader()->timing()->setResponseEnd(finishTime ? finishTime : (m_timeOfLastDataReceived ? m_timeOfLastDataReceived : monotonicallyIncreasingTime()));
    567     documentLoader()->finishedLoading();
    568 
    569     // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache
    570     // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
    571     if (Frame* frame = documentLoader()->frame()) {
    572         if (m_resource && frame->document()->hasManifest())
    573             memoryCache()->remove(m_resource.get());
    574     }
    575 
    576     dl->applicationCacheHost()->finishedLoadingMainResource();
     476    documentLoader()->finishedLoading(finishTime);
    577477}
    578478
  • trunk/Source/WebCore/loader/MainResourceLoader.h

    r145592 r145734  
    4747class FormState;
    4848class ResourceRequest;
    49    
    50 #if USE(CONTENT_FILTERING)
    51 class ContentFilter;
    52 #endif
    5349
    5450class MainResourceLoader : public RefCounted<MainResourceLoader>, public CachedRawResourceClient {
     
    7268    typedef Timer<MainResourceLoader> MainResourceLoaderTimer;
    7369#endif
     70
     71    CachedRawResource* cachedMainResource() { return m_resource.get(); }
     72    unsigned long identifierForLoadWithoutResourceLoader() const { return m_identifierForLoadWithoutResourceLoader; }
     73    void clearIdentifierForLoadWithoutResourceLoader() { m_identifierForLoadWithoutResourceLoader = 0; }
    7474
    7575    unsigned long identifier() const;
     
    128128    bool m_loadingMultipartContent;
    129129    bool m_waitingForContentPolicy;
    130     double m_timeOfLastDataReceived;
    131130    unsigned long m_identifierForLoadWithoutResourceLoader;
    132 
    133 #if USE(CONTENT_FILTERING)
    134     RefPtr<ContentFilter> m_contentFilter;
    135 #endif
    136131};
    137132
Note: See TracChangeset for help on using the changeset viewer.