Move more of committing and starting to write a Document
authorjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Apr 2012 18:51:27 +0000 (18:51 +0000)
committerjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Apr 2012 18:51:27 +0000 (18:51 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@115654 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/DocumentWriter.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h

index 401b159..d157d6c 100644 (file)
@@ -1,3 +1,35 @@
+2012-04-30  Nate Chapin  <japhet@chromium.org>
+
+        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):
+
 2012-04-30  Kentaro Hara  <haraken@chromium.org>
 
         Unreviewed. Fix test crashes in Win/Linux debug builds.
index 829d21a..41babc4 100644 (file)
@@ -276,7 +276,7 @@ void DocumentLoader::setupForReplace()
 
 void DocumentLoader::commitIfReady()
 {
-    if (m_gotFirstByte && !m_committed) {
+    if (!m_committed) {
         m_committed = true;
         frameLoader()->commitProvisionalLoad();
     }
@@ -284,12 +284,17 @@ void DocumentLoader::commitIfReady()
 
 void DocumentLoader::finishedLoading()
 {
-    m_gotFirstByte = true;   
     commitIfReady();
     if (!frameLoader() || frameLoader()->stateMachine()->creatingInitialEmptyDocument())
         return;
     if (!maybeCreateArchive())
         frameLoader()->client()->finishedLoading(this);
+    
+    // If this is an empty document, it will not have actually been created yet. Commit dummy data so that
+    // DocumentWriter::begin() gets called and creates the Document.
+    if (!m_gotFirstByte)
+        commitData(0, 0);
+
     m_writer.end();
     if (!m_mainDocumentError.isNull())
         return;
@@ -317,14 +322,28 @@ void DocumentLoader::commitLoad(const char* data, int length)
 
 void DocumentLoader::commitData(const char* bytes, size_t length)
 {
-    // Set the text encoding.  This is safe to call multiple times.
-    bool userChosen = true;
-    String encoding = overrideEncoding();
-    if (encoding.isNull()) {
-        userChosen = false;
-        encoding = response().textEncodingName();
+    if (!m_gotFirstByte) {
+        m_gotFirstByte = true;
+        m_writer.begin(documentURL(), false);
+        m_writer.setDocumentWasLoadedAsPartOfNavigation();
+        
+#if ENABLE(MHTML)
+        // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
+        // relative URLs are resolved properly.
+        if (m_archive && m_archive->type() == Archive::MHTML)
+            m_frame->document()->setBaseURLOverride(m_archive->mainResource()->url());
+#endif
+
+        frameLoader()->receivedFirstData();
+
+        bool userChosen = true;
+        String encoding = overrideEncoding();
+        if (encoding.isNull()) {
+            userChosen = false;
+            encoding = response().textEncodingName();
+        }
+        m_writer.setEncoding(encoding, userChosen);
     }
-    m_writer.setEncoding(encoding, userChosen);
     ASSERT(m_frame->document()->parsing());
     m_writer.addData(bytes, length);
 }
@@ -335,8 +354,7 @@ bool DocumentLoader::doesProgressiveLoad(const String& MIMEType) const
 }
 
 void DocumentLoader::receivedData(const char* data, int length)
-{    
-    m_gotFirstByte = true;
+{
     if (doesProgressiveLoad(m_response.mimeType()))
         commitLoad(data, length);
 }
@@ -461,10 +479,7 @@ bool DocumentLoader::maybeCreateArchive()
     m_writer.setMIMEType(mainResource->mimeType());
     
     ASSERT(m_frame->document());
-    String userChosenEncoding = overrideEncoding();
-    bool encodingIsUserChosen = !userChosenEncoding.isNull();
-    m_writer.setEncoding(encodingIsUserChosen ? userChosenEncoding : mainResource->textEncoding(), encodingIsUserChosen);
-    m_writer.addData(mainResource->data()->data(), mainResource->data()->size());
+    commitData(mainResource->data()->data(), mainResource->data()->size());
     return true;
 #endif // !ENABLE(WEB_ARCHIVE) && !ENABLE(MHTML)
 }
index 3b2925b..b0b50ea 100644 (file)
@@ -132,7 +132,6 @@ namespace WebCore {
 #endif
 
 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
-        Archive* archive() const { return m_archive.get(); }
         void setArchive(PassRefPtr<Archive>);
         void addAllArchiveResources(Archive*);
         void addArchiveResource(PassRefPtr<ArchiveResource>);
index a14a030..3174afc 100644 (file)
@@ -244,7 +244,6 @@ void DocumentWriter::end()
 
 void DocumentWriter::setEncoding(const String& name, bool userChosen)
 {
-    m_frame->loader()->willSetEncoding();
     m_encoding = name;
     m_encodingWasChosenByUser = userChosen;
 }
index 941bd13..2b284eb 100644 (file)
@@ -184,7 +184,6 @@ FrameLoader::FrameLoader(Frame* frame, FrameLoaderClient* client)
     , m_wasUnloadEventEmitted(false)
     , m_pageDismissalEventBeingDispatched(NoDismissal)
     , m_isComplete(false)
-    , m_hasReceivedFirstData(false)
     , m_needsClear(false)
     , m_checkTimer(this, &FrameLoader::checkTimerFired)
     , m_shouldCallCheckCompleted(false)
@@ -409,8 +408,6 @@ void FrameLoader::stopLoading(UnloadEventPolicy unloadEventPolicy)
         m_frame->document()->setParsing(false);
     }
 
-    m_hasReceivedFirstData = true;
-
     if (Document* doc = m_frame->document()) {
         // FIXME: HTML5 doesn't tell us to set the state to complete when aborting, but we do anyway to match legacy behavior.
         // http://www.w3.org/Bugs/Public/show_bug.cgi?id=10537
@@ -475,7 +472,6 @@ bool FrameLoader::didOpenURL()
             window->setDefaultStatus(String());
         }
     }
-    m_hasReceivedFirstData = false;
 
     started();
 
@@ -561,17 +557,6 @@ void FrameLoader::clear(bool clearWindowProperties, bool clearScriptObjects, boo
 
 void FrameLoader::receivedFirstData()
 {
-    KURL workingURL = activeDocumentLoader()->documentURL();
-    activeDocumentLoader()->writer()->begin(workingURL, false);
-    activeDocumentLoader()->writer()->setDocumentWasLoadedAsPartOfNavigation();
-
-#if ENABLE(MHTML)
-    // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
-    // relative URLs are resolved properly.
-    if (activeDocumentLoader()->archive() && activeDocumentLoader()->archive()->type() == Archive::MHTML)
-        m_frame->document()->setBaseURLOverride(activeDocumentLoader()->archive()->mainResource()->url());
-#endif
-
     dispatchDidCommitLoad();
     dispatchDidClearWindowObjectsInAllWorlds();
     dispatchGlobalObjectAvailableInAllWorlds();
@@ -583,8 +568,6 @@ void FrameLoader::receivedFirstData()
             m_client->dispatchDidReceiveTitle(ptitle);
     }
 
-    m_hasReceivedFirstData = true;
-
     if (!m_documentLoader)
         return;
     if (m_frame->document()->isViewSource())
@@ -973,12 +956,6 @@ void FrameLoader::resetMultipleFormSubmissionProtection()
     m_submittedFormURL = KURL();
 }
 
-void FrameLoader::willSetEncoding()
-{
-    if (!m_hasReceivedFirstData)
-        receivedFirstData();
-}
-
 void FrameLoader::updateFirstPartyForCookies()
 {
     if (m_frame->tree()->parent())
@@ -1934,8 +1911,6 @@ void FrameLoader::open(CachedFrameBase& cachedFrame)
     if (url.protocolIsInHTTPFamily() && !url.host().isEmpty() && url.path().isEmpty())
         url.setPath("/");
 
-    m_hasReceivedFirstData = false;
-
     started();
     clear(true, true, cachedFrame.isMainFrame());
 
index 4a34f06..e5906f6 100644 (file)
@@ -199,7 +199,8 @@ public:
 
     // Callbacks from DocumentWriter
     void didBeginDocument(bool dispatchWindowObjectAvailable);
-    void willSetEncoding();
+
+    void receivedFirstData();
 
     void handledOnloadEvents();
     String userAgent(const KURL&) const;
@@ -291,8 +292,6 @@ private:
     
     void loadProvisionalItemFromCachedPage();
 
-    void receivedFirstData();
-
     void updateFirstPartyForCookies();
     void setFirstPartyForCookies(const KURL&);
     
@@ -405,8 +404,6 @@ private:
 
     RefPtr<SerializedScriptValue> m_pendingStateObject;
 
-    bool m_hasReceivedFirstData;
-
     bool m_needsClear;
 
     KURL m_submittedFormURL;