Changeset 115654 in webkit


Ignore:
Timestamp:
Apr 30, 2012 11:51:27 AM (12 years ago)
Author:
Nate Chapin
Message:

Move more of committing and starting to write a Document
to DocumentLoader.
https://bugs.webkit.org/show_bug.cgi?id=83908

Reviewed by Adam Barth.

No new tests, refactor only.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::commitIfReady): Ignore m_gotFirstByte here, since

it was always true here anyway.

(WebCore::DocumentLoader::finishedLoading): If we are finishing an empty

document, create the document now, so that FrameLoaderClient doesn't
have to do it later (FrameLoaderClient code will be removed in a later
patch).

(WebCore::DocumentLoader::commitData): Call receivedFirstData() directly and

do some work receivedFirstData() used to do, setEncoding() only once per
load.

(WebCore::DocumentLoader::receivedData):
(WebCore::DocumentLoader::maybeCreateArchive):

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

(WebCore::DocumentWriter::setEncoding):

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::receivedFirstData): Move DocumentLoader calls

to DocumentLoader.

  • loader/FrameLoader.h: Remove m_hasReceivedFirstData and willSetEncoding(),

allow hasReceivedData() to be called directly.

(FrameLoader):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r115652 r115654  
     12012-04-30  Nate Chapin  <japhet@chromium.org>
     2
     3        Move more of committing and starting to write a Document
     4        to DocumentLoader.
     5        https://bugs.webkit.org/show_bug.cgi?id=83908
     6
     7        Reviewed by Adam Barth.
     8
     9        No new tests, refactor only.
     10
     11        * loader/DocumentLoader.cpp:
     12        (WebCore::DocumentLoader::commitIfReady): Ignore m_gotFirstByte here, since
     13            it was always true here anyway.
     14        (WebCore::DocumentLoader::finishedLoading): If we are finishing an empty
     15            document, create the document now, so that FrameLoaderClient doesn't
     16            have to do it later (FrameLoaderClient code will be removed in a later
     17            patch).
     18        (WebCore::DocumentLoader::commitData): Call receivedFirstData() directly and
     19            do some work receivedFirstData() used to do, setEncoding() only once per
     20            load.
     21        (WebCore::DocumentLoader::receivedData):
     22        (WebCore::DocumentLoader::maybeCreateArchive):
     23        * loader/DocumentLoader.h:
     24        * loader/DocumentWriter.cpp:
     25        (WebCore::DocumentWriter::setEncoding):
     26        * loader/FrameLoader.cpp:
     27        (WebCore::FrameLoader::receivedFirstData): Move DocumentLoader calls
     28            to DocumentLoader.
     29        * loader/FrameLoader.h: Remove m_hasReceivedFirstData and willSetEncoding(),
     30            allow hasReceivedData() to be called directly.
     31        (FrameLoader):
     32
    1332012-04-30  Kentaro Hara  <haraken@chromium.org>
    234
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r114016 r115654  
    277277void DocumentLoader::commitIfReady()
    278278{
    279     if (m_gotFirstByte && !m_committed) {
     279    if (!m_committed) {
    280280        m_committed = true;
    281281        frameLoader()->commitProvisionalLoad();
     
    285285void DocumentLoader::finishedLoading()
    286286{
    287     m_gotFirstByte = true;   
    288287    commitIfReady();
    289288    if (!frameLoader() || frameLoader()->stateMachine()->creatingInitialEmptyDocument())
     
    291290    if (!maybeCreateArchive())
    292291        frameLoader()->client()->finishedLoading(this);
     292   
     293    // If this is an empty document, it will not have actually been created yet. Commit dummy data so that
     294    // DocumentWriter::begin() gets called and creates the Document.
     295    if (!m_gotFirstByte)
     296        commitData(0, 0);
     297
    293298    m_writer.end();
    294299    if (!m_mainDocumentError.isNull())
     
    318323void DocumentLoader::commitData(const char* bytes, size_t length)
    319324{
    320     // Set the text encoding.  This is safe to call multiple times.
    321     bool userChosen = true;
    322     String encoding = overrideEncoding();
    323     if (encoding.isNull()) {
    324         userChosen = false;
    325         encoding = response().textEncodingName();
    326     }
    327     m_writer.setEncoding(encoding, userChosen);
     325    if (!m_gotFirstByte) {
     326        m_gotFirstByte = true;
     327        m_writer.begin(documentURL(), false);
     328        m_writer.setDocumentWasLoadedAsPartOfNavigation();
     329       
     330#if ENABLE(MHTML)
     331        // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
     332        // relative URLs are resolved properly.
     333        if (m_archive && m_archive->type() == Archive::MHTML)
     334            m_frame->document()->setBaseURLOverride(m_archive->mainResource()->url());
     335#endif
     336
     337        frameLoader()->receivedFirstData();
     338
     339        bool userChosen = true;
     340        String encoding = overrideEncoding();
     341        if (encoding.isNull()) {
     342            userChosen = false;
     343            encoding = response().textEncodingName();
     344        }
     345        m_writer.setEncoding(encoding, userChosen);
     346    }
    328347    ASSERT(m_frame->document()->parsing());
    329348    m_writer.addData(bytes, length);
     
    336355
    337356void DocumentLoader::receivedData(const char* data, int length)
    338 {   
    339     m_gotFirstByte = true;
     357{
    340358    if (doesProgressiveLoad(m_response.mimeType()))
    341359        commitLoad(data, length);
     
    462480   
    463481    ASSERT(m_frame->document());
    464     String userChosenEncoding = overrideEncoding();
    465     bool encodingIsUserChosen = !userChosenEncoding.isNull();
    466     m_writer.setEncoding(encodingIsUserChosen ? userChosenEncoding : mainResource->textEncoding(), encodingIsUserChosen);
    467     m_writer.addData(mainResource->data()->data(), mainResource->data()->size());
     482    commitData(mainResource->data()->data(), mainResource->data()->size());
    468483    return true;
    469484#endif // !ENABLE(WEB_ARCHIVE) && !ENABLE(MHTML)
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r114016 r115654  
    133133
    134134#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
    135         Archive* archive() const { return m_archive.get(); }
    136135        void setArchive(PassRefPtr<Archive>);
    137136        void addAllArchiveResources(Archive*);
  • trunk/Source/WebCore/loader/DocumentWriter.cpp

    r114062 r115654  
    245245void DocumentWriter::setEncoding(const String& name, bool userChosen)
    246246{
    247     m_frame->loader()->willSetEncoding();
    248247    m_encoding = name;
    249248    m_encodingWasChosenByUser = userChosen;
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r115549 r115654  
    185185    , m_pageDismissalEventBeingDispatched(NoDismissal)
    186186    , m_isComplete(false)
    187     , m_hasReceivedFirstData(false)
    188187    , m_needsClear(false)
    189188    , m_checkTimer(this, &FrameLoader::checkTimerFired)
     
    410409    }
    411410
    412     m_hasReceivedFirstData = true;
    413 
    414411    if (Document* doc = m_frame->document()) {
    415412        // FIXME: HTML5 doesn't tell us to set the state to complete when aborting, but we do anyway to match legacy behavior.
     
    476473        }
    477474    }
    478     m_hasReceivedFirstData = false;
    479475
    480476    started();
     
    562558void FrameLoader::receivedFirstData()
    563559{
    564     KURL workingURL = activeDocumentLoader()->documentURL();
    565     activeDocumentLoader()->writer()->begin(workingURL, false);
    566     activeDocumentLoader()->writer()->setDocumentWasLoadedAsPartOfNavigation();
    567 
    568 #if ENABLE(MHTML)
    569     // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
    570     // relative URLs are resolved properly.
    571     if (activeDocumentLoader()->archive() && activeDocumentLoader()->archive()->type() == Archive::MHTML)
    572         m_frame->document()->setBaseURLOverride(activeDocumentLoader()->archive()->mainResource()->url());
    573 #endif
    574 
    575560    dispatchDidCommitLoad();
    576561    dispatchDidClearWindowObjectsInAllWorlds();
     
    583568            m_client->dispatchDidReceiveTitle(ptitle);
    584569    }
    585 
    586     m_hasReceivedFirstData = true;
    587570
    588571    if (!m_documentLoader)
     
    972955{
    973956    m_submittedFormURL = KURL();
    974 }
    975 
    976 void FrameLoader::willSetEncoding()
    977 {
    978     if (!m_hasReceivedFirstData)
    979         receivedFirstData();
    980957}
    981958
     
    19341911    if (url.protocolIsInHTTPFamily() && !url.host().isEmpty() && url.path().isEmpty())
    19351912        url.setPath("/");
    1936 
    1937     m_hasReceivedFirstData = false;
    19381913
    19391914    started();
  • trunk/Source/WebCore/loader/FrameLoader.h

    r115083 r115654  
    200200    // Callbacks from DocumentWriter
    201201    void didBeginDocument(bool dispatchWindowObjectAvailable);
    202     void willSetEncoding();
     202
     203    void receivedFirstData();
    203204
    204205    void handledOnloadEvents();
     
    292293    void loadProvisionalItemFromCachedPage();
    293294
    294     void receivedFirstData();
    295 
    296295    void updateFirstPartyForCookies();
    297296    void setFirstPartyForCookies(const KURL&);
     
    405404
    406405    RefPtr<SerializedScriptValue> m_pendingStateObject;
    407 
    408     bool m_hasReceivedFirstData;
    409406
    410407    bool m_needsClear;
Note: See TracChangeset for help on using the changeset viewer.