Start using the loader in the Qt port.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/loader/FrameLoader.cpp b/WebCore/loader/FrameLoader.cpp
index e65d99b..9a07e23 100644
--- a/WebCore/loader/FrameLoader.cpp
+++ b/WebCore/loader/FrameLoader.cpp
@@ -718,11 +718,11 @@
         return;
     m_needsClear = false;
 
-#if !PLATFORM(MAC)
+#if !PLATFORM(MAC) && !PLATFORM(QT)
     // FIXME: Remove this after making other platforms do loading more like Mac.
     detachChildren();
 #endif
-
+    
     if (m_frame->document()) {
         m_frame->document()->cancelParsing();
         m_frame->document()->willRemove();
@@ -2514,10 +2514,6 @@
 
 KURL FrameLoader::URL() const
 {
-#if PLATFORM(QT)
-    if (!activeDocumentLoader())
-        return KURL();
-#endif
     return activeDocumentLoader()->URL();
 }
 
@@ -2693,7 +2689,7 @@
     return m_client;
 }
 
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || PLATFORM(QT)
 void FrameLoader::submitForm(const FrameLoadRequest& request, Event* event)
 {
 #ifdef MULTIPLE_FORM_SUBMISSION_PROTECTION
@@ -2731,7 +2727,7 @@
     load(copy, true, event, 0, HashMap<String, String>());
 }
 #endif
-
+    
 String FrameLoader::userAgent() const
 {
     return m_client->userAgent();
@@ -2742,16 +2738,11 @@
     // Although it's not completely clear from the name of this function,
     // it does nothing if we already have a document, and just creates an
     // empty one if we have no document at all.
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || PLATFORM(QT)
     if (!m_frame->document()) {
         loadEmptyDocumentSynchronously();
         updateBaseURLForEmptyDocument();
     }
-#elif PLATFORM(QT)
-    if (!m_frame->document()) {
-        begin();
-        end();
-    }
 #endif
 }
 
diff --git a/WebCore/loader/qt/FrameLoaderQt.cpp b/WebCore/loader/qt/FrameLoaderQt.cpp
index 79c454c..b335446 100644
--- a/WebCore/loader/qt/FrameLoaderQt.cpp
+++ b/WebCore/loader/qt/FrameLoaderQt.cpp
@@ -52,6 +52,7 @@
 #include "HTMLDocument.h"
 #include "HTMLElement.h"
 #include "HTMLFormElement.h"
+#include "HistoryItem.h"
 #include "JSLock.h"
 #include "MouseEventWithHitTestResults.h"
 #include "Page.h"
@@ -78,49 +79,10 @@
 
 namespace WebCore {
 
-void FrameLoader::submitForm(const FrameLoadRequest& frameLoadRequest, Event*)
-{
-#ifdef MULTIPLE_FORM_SUBMISSION_PROTECTION
-    // FIXME: We'd like to remove this altogether and fix the multiple form submission issue another way.
-    // We do not want to submit more than one form from the same page,
-    // nor do we want to submit a single form more than once.
-    // This flag prevents these from happening; not sure how other browsers prevent this.
-    // The flag is reset in each time we start handle a new mouse or key down event, and
-    // also in setView since this part may get reused for a page from the back/forward cache.
-    // The form multi-submit logic here is only needed when we are submitting a form that affects this frame.
-    // FIXME: Frame targeting is only one of the ways the submission could end up doing something other
-    // than replacing this frame's content, so this check is flawed. On the other hand, the check is hardly
-    // needed any more now that we reset m_submittedFormURL on each mouse or key down event.
-    Frame* target = m_frame->tree()->find(frameLoadRequest.frameName());
-    if (m_frame->tree()->isDescendantOf(target)) {
-        if (m_submittedFormURL == frameLoadRequest.resourceRequest().url())
-            return;
-        m_submittedFormURL = frameLoadRequest.resourceRequest().url();
-    }
-#endif
-
-    RefPtr<FormData> formData = frameLoadRequest.resourceRequest().httpBody();
-    if (formData && !formData->isEmpty() && QtFrame(m_frame)->client())
-        QtFrame(m_frame)->client()->submitForm(frameLoadRequest.resourceRequest().httpMethod(),
-                                               frameLoadRequest.resourceRequest().url(),
-                                               formData);
-
-    clearRecordedFormValues();
-}
-
-void FrameLoader::urlSelected(const FrameLoadRequest& frameLoadRequest, Event*)
-{
-    const ResourceRequest& request = frameLoadRequest.resourceRequest();
-
-    if (!QtFrame(m_frame)->client())
-        return;
-
-    QtFrame(m_frame)->client()->openURL(request.url());
-}
 
 void FrameLoader::setTitle(const String& title)
 {
-    client()->setTitle(title, URL());
+    documentLoader()->setTitle(title);
 }
 
 Frame* FrameLoader::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer)
@@ -149,8 +111,7 @@
 
 KURL FrameLoader::originalRequestURL() const
 {
-    notImplemented();
-    return KURL();
+    return activeDocumentLoader()->initialRequest().url();
 }
 
 String FrameLoader::overrideMediaType() const
@@ -161,8 +122,7 @@
 
 String FrameLoader::referrer() const
 {
-    notImplemented();
-    return String();
+    return documentLoader()->request().httpReferrer();
 }
 
 
@@ -170,46 +130,90 @@
 void FrameLoader::checkLoadCompleteForThisFrame()
 {
     ASSERT(m_client->hasWebView());
-    //notImplemented();
 
     switch (m_state) {
-    case FrameStateProvisional: {
-    }
+        case FrameStateProvisional: {
+            if (m_delegateIsHandlingProvisionalLoadError)
+                return;
 
-    case FrameStateCommittedPage: {
-        DocumentLoader* dl = m_documentLoader.get();
-        if (!dl || dl->isLoadingInAPISense())
+            RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader;
+            if (!pdl)
+                return;
+                
+            // If we've received any errors we may be stuck in the provisional state and actually complete.
+            const ResourceError& error = pdl->mainDocumentError();
+            if (error.isNull())
+                return;
+
+            // Check all children first.
+            RefPtr<HistoryItem> item;
+            if (isBackForwardLoadType(loadType()) && m_frame == m_frame->page()->mainFrame())
+                item = m_currentHistoryItem;
+                
+            bool shouldReset = true;
+            if (!pdl->isLoadingInAPISense()) {
+                m_delegateIsHandlingProvisionalLoadError = true;
+                m_client->dispatchDidFailProvisionalLoad(error);
+                m_delegateIsHandlingProvisionalLoadError = false;
+
+                // FIXME: can stopping loading here possibly have any effect, if isLoading is false,
+                // which it must be to be in this branch of the if? And is it OK to just do a full-on
+                // stopAllLoaders instead of stopLoadingSubframes?
+                stopLoadingSubframes();
+                pdl->stopLoading();
+
+                // Finish resetting the load state, but only if another load hasn't been started by the
+                // delegate callback.
+                if (pdl == m_provisionalDocumentLoader)
+                    clearProvisionalLoad();
+                else if (m_documentLoader) {
+                    KURL unreachableURL = m_documentLoader->unreachableURL();
+                    if (!unreachableURL.isEmpty() && unreachableURL == pdl->request().url())
+                        shouldReset = false;
+                }
+            }
+            if (shouldReset && item && m_frame->page())
+                 m_frame->page()->backForwardList()->goToItem(item.get());
+
             return;
-
-        markLoadComplete();
-
-        // FIXME: Is this subsequent work important if we already navigated away?
-        // Maybe there are bugs because of that, or extra work we can skip because
-        // the new page is ready.
-
-        m_client->forceLayoutForNonHTML();
-             
-        // If the user had a scroll point, scroll to it, overriding the anchor point if any.
-//         if ((isBackForwardLoadType(m_loadType) || m_loadType == FrameLoadTypeReload)
-//             && m_client->hasBackForwardList())
-//             m_client->restoreScrollPositionAndViewState();
-
-//         if (error)
-//             m_client->dispatchDidFailLoad(error);
-//         else
-            m_client->dispatchDidFinishLoad();
-            
-        m_client->progressCompleted();
-        return;
-    }
+        }
         
-    case FrameStateComplete:
-        // Even if already complete, we might have set a previous item on a frame that
-        // didn't do any data loading on the past transaction. Make sure to clear these out.
-        m_client->frameLoadCompleted();
-        return;
+        case FrameStateCommittedPage: {
+            DocumentLoader* dl = m_documentLoader.get();            
+            if (dl->isLoadingInAPISense())
+                return;
+
+            markLoadComplete();
+
+            // FIXME: Is this subsequent work important if we already navigated away?
+            // Maybe there are bugs because of that, or extra work we can skip because
+            // the new page is ready.
+
+            m_client->forceLayoutForNonHTML();
+             
+            // If the user had a scroll point, scroll to it, overriding the anchor point if any.
+            if ((isBackForwardLoadType(m_loadType) || m_loadType == FrameLoadTypeReload)
+                    && m_frame->page() && m_frame->page()->backForwardList())
+                restoreScrollPositionAndViewState();
+
+            const ResourceError& error = dl->mainDocumentError();
+            if (!error.isNull())
+                m_client->dispatchDidFailLoad(error);
+            else
+                m_client->dispatchDidFinishLoad();
+
+            m_client->progressCompleted();
+            return;
+        }
+        
+        case FrameStateComplete:
+            // Even if already complete, we might have set a previous item on a frame that
+            // didn't do any data loading on the past transaction. Make sure to clear these out.
+            m_client->frameLoadCompleted();
+            return;
     }
 
+    ASSERT_NOT_REACHED();
 }
 
 void FrameLoader::partClearedInBegin()