2006-08-28 Nikolas Zimmermann <zimmermann@kde.org>
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Aug 2006 22:49:41 +0000 (22:49 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Aug 2006 22:49:41 +0000 (22:49 +0000)
        Reviewed by Eric, landed by Anders.

        Fixes one chunk of: http://bugzilla.opendarwin.org/show_bug.cgi?id=10604

        Finish Unity merging. Remove libcurl usage, in favour of KIO.
        This makes the regression testing fly! IO processing is way faster now.

        * CMakeLists.txt:
        * platform/ResourceLoaderInternal.h:
        (WebCore::ResourceLoaderInternal::ResourceLoaderInternal):
        * platform/qt/FrameQt.cpp:
        (WebCore::FrameQt::openURL):
        (WebCore::FrameQt::submitForm):
        (WebCore::FrameQt::urlSelected):
        (WebCore::FrameQt::createEmptyDocument):
        (WebCore::FrameQt::receivedData):
        (WebCore::FrameQt::receivedAllData):
        * platform/qt/FrameQt.h:
        * platform/qt/ResourceLoaderCurl.cpp: Removed.
        * platform/qt/ResourceLoaderManager.cpp:
        (WebCore::ResourceLoaderManager::ResourceLoaderManager):
        (WebCore::ResourceLoaderManager::~ResourceLoaderManager):
        (WebCore::ResourceLoaderManager::self):
        (WebCore::ResourceLoaderManager::slotData):
        (WebCore::ResourceLoaderManager::slotMimetype):
        (WebCore::ResourceLoaderManager::slotResult):
        (WebCore::ResourceLoaderManager::remove):
        (WebCore::ResourceLoaderManager::add):
        * platform/qt/ResourceLoaderManager.h:
        * platform/qt/ResourceLoaderQt.cpp: Added.
        (WebCore::ResourceLoaderInternal::~ResourceLoaderInternal):
        (WebCore::ResourceLoader::~ResourceLoader):
        (WebCore::ResourceLoader::start):
        (WebCore::ResourceLoader::cancel):
        (WebCore::ResourceLoader::assembleResponseHeaders):
        (WebCore::ResourceLoader::retrieveCharset):
        (WebCore::ResourceLoader::receivedResponse):

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

WebCore/CMakeLists.txt
WebCore/ChangeLog
WebCore/platform/ResourceLoaderInternal.h
WebCore/platform/qt/FrameQt.cpp
WebCore/platform/qt/FrameQt.h
WebCore/platform/qt/ResourceLoaderManager.cpp
WebCore/platform/qt/ResourceLoaderManager.h
WebCore/platform/qt/ResourceLoaderQt.cpp [moved from WebCore/platform/qt/ResourceLoaderCurl.cpp with 58% similarity]

index 0e50cd4141b525ebcaf56571b8e033015b347d06..655495e31b366c17949b9f9e6fa2b1845b82b848 100644 (file)
@@ -67,7 +67,9 @@ IF(__KDE_HAVE_WVARIADIC_MACROS)
   add_definitions ( -Wno-variadic-macros )
 ENDIF(__KDE_HAVE_WVARIADIC_MACROS)
 
+kde4_automoc(platform/qt/SharedTimerQt.cpp)
 kde4_automoc(platform/qt/ScrollViewCanvasQt.cpp)
+kde4_automoc(platform/qt/ResourceLoaderManager.cpp)
 
 # rules for generated files
 IF (USE_WEBKIT_SVG_SUPPORT)
@@ -867,8 +869,8 @@ set(WebCore_SRCS
     platform/qt/FontDataQt.cpp
     platform/qt/SharedTimerQt.cpp
     platform/qt/RenderPopupMenuQt.cpp
-    platform/qt/ResourceLoaderCurl.cpp
     platform/qt/ResourceLoaderManager.cpp
+    platform/qt/ResourceLoaderQt.cpp
     platform/qt/FloatPointQt.cpp
     platform/qt/ListBoxQt.cpp
     platform/qt/FloatRectQt.cpp
@@ -1009,9 +1011,6 @@ set(WebCore_SRCS
     ${WebCore-unity-IDLGeneratedSources}
 )
 
-
-kde4_automoc(platform/qt/SharedTimerQt.cpp)
-
 kde4_add_library(WebCore-unity SHARED  ${WebCore_SRCS})
 
 target_link_libraries(WebCore-unity
@@ -1023,9 +1022,8 @@ target_link_libraries(WebCore-unity
   ${LIBXSLT_LIBRARIES}
   ${LIBXML2_LIBRARIES}
   icuuc
-  curl
+  kio
   wtf-unity
   kjs-unity
   pcre-unity
-
 )
index 7c583f3f659d6802619d949aee917de7ae1529dd..8502f8c1c32d1e08aab2b6c6339a39142b503717 100644 (file)
@@ -1,3 +1,43 @@
+2006-08-28  Nikolas Zimmermann  <zimmermann@kde.org>
+
+        Reviewed by Eric, landed by Anders.
+
+        Fixes one chunk of: http://bugzilla.opendarwin.org/show_bug.cgi?id=10604
+
+        Finish Unity merging. Remove libcurl usage, in favour of KIO.
+        This makes the regression testing fly! IO processing is way faster now.
+
+        * CMakeLists.txt:
+        * platform/ResourceLoaderInternal.h:
+        (WebCore::ResourceLoaderInternal::ResourceLoaderInternal):
+        * platform/qt/FrameQt.cpp:
+        (WebCore::FrameQt::openURL):
+        (WebCore::FrameQt::submitForm):
+        (WebCore::FrameQt::urlSelected):
+        (WebCore::FrameQt::createEmptyDocument):
+        (WebCore::FrameQt::receivedData):
+        (WebCore::FrameQt::receivedAllData):
+        * platform/qt/FrameQt.h:
+        * platform/qt/ResourceLoaderCurl.cpp: Removed.
+        * platform/qt/ResourceLoaderManager.cpp:
+        (WebCore::ResourceLoaderManager::ResourceLoaderManager):
+        (WebCore::ResourceLoaderManager::~ResourceLoaderManager):
+        (WebCore::ResourceLoaderManager::self):
+        (WebCore::ResourceLoaderManager::slotData):
+        (WebCore::ResourceLoaderManager::slotMimetype):
+        (WebCore::ResourceLoaderManager::slotResult):
+        (WebCore::ResourceLoaderManager::remove):
+        (WebCore::ResourceLoaderManager::add):
+        * platform/qt/ResourceLoaderManager.h:
+        * platform/qt/ResourceLoaderQt.cpp: Added.
+        (WebCore::ResourceLoaderInternal::~ResourceLoaderInternal):
+        (WebCore::ResourceLoader::~ResourceLoader):
+        (WebCore::ResourceLoader::start):
+        (WebCore::ResourceLoader::cancel):
+        (WebCore::ResourceLoader::assembleResponseHeaders):
+        (WebCore::ResourceLoader::retrieveCharset):
+        (WebCore::ResourceLoader::receivedResponse):
+
 2006-08-29  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Eric.
index 40e16ed4c762f7056ad1ce464e89044468ad2a8a..cb48f57cd86b11718c2f351c417ee5a323579113 100644 (file)
@@ -46,7 +46,6 @@ typedef void CURL;
 
 #if PLATFORM(QT)
 #include <QString>
-typedef void CURL;
 #endif
 
 // The allocations and releases in ResourceLoaderInternal are
@@ -83,7 +82,7 @@ namespace WebCore {
             , m_formDataLength(0)
             , m_bytesRemainingToWrite(0)
 #endif
-#if PLATFORM(GDK) || PLATFORM(QT)
+#if PLATFORM(GDK)
             , m_handle(0)
 #endif
         {
@@ -115,7 +114,7 @@ namespace WebCore {
             , m_formDataLength(0)
             , m_bytesRemainingToWrite(0)
 #endif
-#if PLATFORM(GDK) || PLATFORM(QT)
+#if PLATFORM(GDK)
             , m_handle(0)
 #endif
         {
@@ -158,8 +157,8 @@ namespace WebCore {
         CURL *m_handle;
 #endif
 #if PLATFORM(QT)
-        CURL *m_handle;
-        QString response;
+        QString m_mimetype;
+        QString m_response;
 #endif
         };
 
index aec5a8a39333b9de69c4005a13627c778f153e55..9c9b072ddb81d800cb65df07ee5076e253084647 100644 (file)
@@ -42,6 +42,7 @@
 #include "DOMWindow.h"
 #include "DOMImplementation.h"
 #include "BrowserExtensionQt.h"
+#include "ResourceLoaderInternal.h"
 #include "Document.h"
 #include "Settings.h"
 #include "Plugin.h"
@@ -141,15 +142,10 @@ FrameQt::~FrameQt()
 bool FrameQt::openURL(const KURL& url)
 {
     didOpenURL(url);
+    m_beginCalled = false;
 
-    // FIXME: Use mimetype logic from KIO!
-    // ResourceRequest request(resourceRequest());
-    // request.m_responseMIMEType = "image/svg+xml";
-    // setResourceRequest(request);
-
-    begin(url);
     ResourceLoader* job = new ResourceLoader(this, "GET", url);
-    job->start(document()->docLoader());
+    job->start(0);
     return true;
 }
 
@@ -166,10 +162,10 @@ void FrameQt::submitForm(const ResourceRequest& request)
         m_client->submitForm(request.doPost() ? "POST" : "GET", request.url(), &request.postData);
     */
 
-    begin(request.url());
+    m_beginCalled = false;
 
     ResourceLoader* job = new ResourceLoader(this, request.doPost() ? "POST" : "GET", request.url(), request.postData);
-    job->start(document()->docLoader());
+    job->start(0);
     
     clearRecordedFormValues();
 }
@@ -178,10 +174,12 @@ void FrameQt::urlSelected(const ResourceRequest& request)
 {
     //need to potentially updateLocationBar(str.ascii()); or notify sys of new url mybe event or callback
     const KURL url = request.url();
-    didOpenURL(url);
-    begin(url);
+
+    didOpenURL(url); 
+    m_beginCalled = false;
+
     ResourceLoader* job = new ResourceLoader(this, "GET", url);
-    job->start(document()->docLoader());
+    job->start(0);
 }
 
 String FrameQt::userAgent() const
@@ -276,7 +274,11 @@ bool FrameQt::toolbarVisible()
 
 void FrameQt::createEmptyDocument()
 {
-    notImplemented();
+    // FIXME: Implement like described in this comment from FrameMac:
+    //
+    // 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.
 }
 
 Range* FrameQt::markedTextRange() const
@@ -527,12 +529,27 @@ void FrameQt::receivedResponse(ResourceLoader*, PlatformResponse)
 
 void FrameQt::receivedData(ResourceLoader* job, const char* data, int length)
 {
+    if (!m_beginCalled) {
+        m_beginCalled = true;
+
+        // Assign correct mimetype _before_ calling begin()!
+        ResourceLoaderInternal* d = job->getInternal();
+        if (d) {
+            ResourceRequest request(resourceRequest());
+            request.m_responseMIMEType = d->m_mimetype;
+            setResourceRequest(request);
+        }
+
+        begin(job->url());
+    }
+
     write(data, length);
 }
 
 void FrameQt::receivedAllData(ResourceLoader* job, PlatformData data)
 {
     end();
+    m_beginCalled = false;
 }
 
 void FrameQt::setFrameGeometry(const IntRect& r)
index 11e28074224954e923937bb42c2cf12098667633..df1a57793762a0522896ed2de50734aed2d27989 100644 (file)
@@ -146,7 +146,7 @@ private:
     virtual bool passMouseDownEventToWidget(Widget*);
 
     FrameQtClient* m_client;
-    
+    bool m_beginCalled : 1;    
 };
 
 }
index 7a27c2162b2abc7b4494a5601d35200a6e588388..9832c2608ae0806aaee301777e97e010c9427c8f 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
- * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 
 #include "config.h"
-#include "ResourceLoaderManager.h"
 
-#include "ResourceLoader.h"
+#include <kio/job.h>
+
+#include "FrameQt.h"
+#include "ResourceLoaderManager.h"
 #include "ResourceLoaderInternal.h"
 
 namespace WebCore {
 
-const int selectTimeoutMS = 5;
-const double pollTimeSeconds = 0.05;
+static ResourceLoaderManager* s_self = 0;
 
 ResourceLoaderManager::ResourceLoaderManager()
-    : m_useSimple(false)
-    , jobs(new HashSet<ResourceLoader*>)
-    , m_downloadTimer(this, &ResourceLoaderManager::downloadTimerCallback)
+    : m_jobToKioMap()
+    , m_kioToJobMap()
 {
-    curl_global_init(CURL_GLOBAL_ALL);
-    curlMultiHandle = curl_multi_init();
 }
 
-ResourceLoaderManager* ResourceLoaderManager::get()
+ResourceLoaderManager::~ResourceLoaderManager()
 {
-    static ResourceLoaderManager* s_singleton;
-
-    if (!s_singleton)
-        s_singleton = new ResourceLoaderManager;
-
-    return s_singleton;
 }
 
-void ResourceLoaderManager::useSimpleTransfer(bool useSimple)
+ResourceLoaderManager* ResourceLoaderManager::self()
 {
-    m_useSimple = useSimple;
+    if (!s_self)
+        s_self = new ResourceLoaderManager();
+
+    return s_self;
 }
 
-static size_t writeCallback(void* ptr, size_t size, size_t nmemb, void* obj)
+void ResourceLoaderManager::slotData(KIO::Job* kioJob, const QByteArray& data)
 {
-    ResourceLoader* job = static_cast<ResourceLoader*>(obj);
+
+    ResourceLoader* job = 0;
+
+    // Check if we know about 'kioJob'...
+    QMap<KIO::Job*, ResourceLoader*>::const_iterator it = m_kioToJobMap.find(kioJob);
+    if (it != m_kioToJobMap.end())
+        job = it.value();
+
+    if (!job)
+        return;
+
     ResourceLoaderInternal* d = job->getInternal();
-    int totalSize = size * nmemb;
-    d->client->receivedData(job, static_cast<char*>(ptr), totalSize);
-    return totalSize;
+    if (!d || !d->client)
+        return;
+
+    d->client->receivedData(job, data.data(), data.size());
 }
 
-static size_t headerCallback(char* ptr, size_t size, size_t nmemb, void* obj)
+void ResourceLoaderManager::slotMimetype(KIO::Job* kioJob, const QString& type)
 {
-    ResourceLoader* job = static_cast<ResourceLoader*>(obj);
-    if (job->method() == "POST")
-        job->receivedResponse(ptr);
-    
-    int totalSize = size * nmemb;
-    return totalSize;
+
+    ResourceLoader* job = 0;
+
+    // Check if we know about 'kioJob'...
+    QMap<KIO::Job*, ResourceLoader*>::const_iterator it = m_kioToJobMap.find(kioJob);
+    if (it != m_kioToJobMap.end())
+        job = it.value();
+
+    if (!job)
+        return;
+
+    ResourceLoaderInternal* d = job->getInternal();
+    if (!d || !d->client)
+        return;
+
+    d->m_mimetype = type;
 }
 
-void ResourceLoaderManager::downloadTimerCallback(Timer<ResourceLoaderManager>* timer)
+void ResourceLoaderManager::slotResult(KJob* kjob)
 {
-    if (jobs->isEmpty()) {
-        m_downloadTimer.stop();
+  
+    KIO::Job* kioJob = qobject_cast<KIO::Job*>(kjob);
+    if (!kioJob)
         return;
-    }
 
-    if (m_useSimple) {
-        for (HashSet<ResourceLoader*>::iterator it = jobs->begin(); it != jobs->end(); ++it) {
-            ResourceLoader* job = *it;
-            ResourceLoaderInternal* d = job->getInternal();
-            CURLcode res = curl_easy_perform(d->m_handle);
-            if (res != CURLE_OK)
-                printf("Error WITH JOB %d\n", res);
-            d->client->receivedAllData(job, 0);
-            d->client->receivedAllData(job);
-            curl_easy_cleanup(d->m_handle);
-            d->m_handle = 0;
-        }
-
-        jobs->clear();
-        m_downloadTimer.stop();
-    } else {
-        FD_ZERO(&fdread);
-        FD_ZERO(&fdwrite);
-        FD_ZERO(&fdexcep);
-        curl_multi_fdset(curlMultiHandle, &fdread, &fdwrite, &fdexcep, &maxfd);
-        int nrunning;
-        struct timeval timeout;
-        int retval;
-        timeout.tv_sec = 0;
-        timeout.tv_usec = selectTimeoutMS * 1000;       // select waits microseconds
-        retval = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
-        switch (retval) {
-            case -1:                        // select error
-                /* fallthrough*/
-            case 0:                 // select timeout
-                /* fallthrough. this can be the first perform to be made */
-            default:                        // 1+ descriptors have data
-                while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curlMultiHandle, &nrunning))
-                    { }
-        }
-
-        // check the curl messages indicating completed transfers
-        // and free their resources
-        int nmsgs;
-        while (CURLMsg* msg = curl_multi_info_read(curlMultiHandle, &nmsgs)) {
-            if (msg->msg == CURLMSG_DONE) {
-                // find the node which has same d->m_handle as completed transfer
-                CURL* chandle = msg->easy_handle;
-                assert(chandle);
-                ResourceLoader* job;
-                curl_easy_getinfo(chandle, CURLINFO_PRIVATE, &job);
-                assert(job); //fixme: assert->if ?
-                // if found, delete it
-                if (job) {
-                    ResourceLoaderInternal* d = job->getInternal();
-                    switch (msg->data.result) {
-                        case CURLE_OK: {
-                            // use this to authenticate
-                            long respCode = -1;
-                            curl_easy_getinfo(d->m_handle, CURLINFO_RESPONSE_CODE, &respCode);
-                            remove(job);
-                            break;
-                        }
-                        default:
-                            printf("Curl ERROR %s\n", curl_easy_strerror(msg->data.result));
-                            job->setError(msg->data.result);
-                            remove(job);
-                            break;
-                    }
-                } else {
-                    printf("CurlRequest not found, eventhough curl d->m_handle finished\n");
-                    assert(0);
-                }
-            }
-
-        }
-    }
-    if (!jobs->isEmpty())
-        m_downloadTimer.startOneShot(pollTimeSeconds);
+    ResourceLoader* job = 0;
+
+    // Check if we know about 'kioJob'...
+    QMap<KIO::Job*, ResourceLoader*>::const_iterator it = m_kioToJobMap.find(kioJob);
+    if (it != m_kioToJobMap.end())
+        job = it.value();
+
+    if (!job)
+        return;
+
+    job->setError(kjob->error());
+    remove(job);
 }
 
 void ResourceLoaderManager::remove(ResourceLoader* job)
 {
     ResourceLoaderInternal* d = job->getInternal();
-    if (!d->m_handle)
+    if (!d || !d->client)
+        return;
+
+    KIO::Job* kioJob = 0;
+
+    // Check if we know about 'job'...
+    QMap<ResourceLoader*, KIO::Job*>::const_iterator it = m_jobToKioMap.find(job);
+    if (it != m_jobToKioMap.end())
+        kioJob = it.value();
+
+    if (!kioJob)
         return;
-    if (jobs->contains(job))
-        jobs->remove(job);
-    if (jobs->isEmpty())
-        m_downloadTimer.stop();
+
+    if (job->method() == "POST") {
+        // Will take care of informing our client...
+        // This must be called before receivedAllData(),
+        // otherwhise assembleResponseHeaders() is called too early...
+        job->receivedResponse(kioJob->queryMetaData("HTTP-Headers"));
+    }
+
     d->client->receivedAllData(job, 0);
     d->client->receivedAllData(job);
-    if (d->m_handle) {
-        curl_multi_remove_handle(curlMultiHandle, d->m_handle);
-        curl_easy_cleanup(d->m_handle);
-        d->m_handle = NULL;
-    }
+
+    m_jobToKioMap.remove(job);
+    m_kioToJobMap.remove(kioJob);
 }
 
 void ResourceLoaderManager::add(ResourceLoader* job)
 {
-    bool startTimer = jobs->isEmpty();
     ResourceLoaderInternal* d = job->getInternal();
     DeprecatedString url = d->URL.url();
-    d->m_handle = curl_easy_init();
-    curl_easy_setopt(d->m_handle, CURLOPT_PRIVATE, job);
-    curl_easy_setopt(d->m_handle, CURLOPT_ERRORBUFFER, error_buffer);
-    curl_easy_setopt(d->m_handle, CURLOPT_WRITEFUNCTION, writeCallback);
-    curl_easy_setopt(d->m_handle, CURLOPT_WRITEDATA, job);
-    curl_easy_setopt(d->m_handle, CURLOPT_HEADERFUNCTION, headerCallback);
-    curl_easy_setopt(d->m_handle, CURLOPT_WRITEHEADER, job);
-    curl_easy_setopt(d->m_handle, CURLOPT_FOLLOWLOCATION, 1);
-    curl_easy_setopt(d->m_handle, CURLOPT_MAXREDIRS, 10);
-    curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
-    // url ptr must remain valid through the request
-    curl_easy_setopt(d->m_handle, CURLOPT_URL, url.ascii());
 
-    if (job->method() == "POST") {
-        DeprecatedString postData = job->postData().flattenToString();
+    KIO::Job* kioJob = 0;
 
-        char* postDataString = (char*)malloc(postData.length() + 1);
-        strncpy(postDataString, postData.ascii(), postData.length());
-        postDataString[postData.length()] = '\0';
+    if (job->method() == "GET")
+        kioJob = KIO::get(KUrl(url), false, false);
+    else if (job->method() == "POST") {
+        DeprecatedString postData = job->postData().flattenToString();
+        QByteArray postDataArray(postData.ascii(), postData.length());
 
-        // FIXME: Do it properly after we got rid of libcurl! (also leaks the headerlist. hmpf.)
-        curl_easy_setopt(d->m_handle, CURLOPT_POSTFIELDS, postDataString);
+        kioJob = KIO::http_post(KUrl(url), postDataArray, false);
+        kioJob->addMetaData("PropagateHttpHeader", "true");
+        kioJob->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded");
     }
 
-    if (m_useSimple)
-        jobs->add(job);
-    else {
-        CURLMcode ret = curl_multi_add_handle(curlMultiHandle, d->m_handle);
-        // don't call perform, because events must be async
-        // timeout will occur and do curl_multi_perform
-        if (ret && ret != CURLM_CALL_MULTI_PERFORM) {
-            printf("Error %d starting job %s\n", ret, d->URL.url().ascii());
-            job->setError(1);
-            startTimer =false;
-        } else
-            jobs->add(job);
-    }
-    if (startTimer)
-        m_downloadTimer.startOneShot(pollTimeSeconds);
+    Q_ASSERT(kioJob != 0);
+
+    QObject::connect(kioJob, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(slotData(KIO::Job*, const QByteArray&)));
+    QObject::connect(kioJob, SIGNAL(mimetype(KIO::Job*, const QString&)), this, SLOT(slotMimetype(KIO::Job*, const QString&)));
+    QObject::connect(kioJob, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
+
+    m_jobToKioMap.insert(job, kioJob);
+    m_kioToJobMap.insert(kioJob, job);
 }
 
 void ResourceLoaderManager::cancel(ResourceLoader* job)
@@ -235,4 +183,4 @@ void ResourceLoaderManager::cancel(ResourceLoader* job)
 
 } // namespace WebCore
 
-// vim: ts=4 sw=4 et
+#include "ResourceLoaderManager.moc"
index 9d8cb57b5223bd111887a343d5d0821868d569bd..e3b1d812ced7126a5bb0aeefb8ab63593c0952f1 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
- * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ResourceLoaderManager_H_
-#define ResourceLoaderManager_H_
+#ifndef ResourceLoaderManager_H
+#define ResourceLoaderManager_H
+
+#include <QMap>
+#include <QObject>
 
 #include "Frame.h"
 #include "Timer.h"
-#include "ResourceLoaderClient.h"
-#include <curl/curl.h>
+#include "ResourceLoader.h"
 
 namespace WebCore {
 
-class ResourceLoaderManager {
+class ResourceLoaderManager : public QObject {
+Q_OBJECT
 public:
-    static ResourceLoaderManager* get();
+    static ResourceLoaderManager* self();
+
     void add(ResourceLoader*);
     void cancel(ResourceLoader*);
 
-    // If true, don't multiplex downloads: download completely one at a time.
-    void useSimpleTransfer(bool useSimple);
-
+public Q_SLOTS:
+    void slotData(KIO::Job*, const QByteArray& data);
+    void slotMimetype(KIO::Job*, const QString& type);
+    void slotResult(KJob*);
+    
 private:
     ResourceLoaderManager();
-    void downloadTimerCallback(Timer<ResourceLoaderManager>*);
-    void remove(ResourceLoader*);
+    ~ResourceLoaderManager();
 
-    bool m_useSimple;
-    HashSet<ResourceLoader*>* jobs;
-    Timer<ResourceLoaderManager> m_downloadTimer;
-    CURLM* curlMultiHandle; // not freed
-
-    // curl filehandles to poll with select
-    fd_set fdread;
-    fd_set fdwrite;
-    fd_set fdexcep;
-
-    int maxfd;
-    char error_buffer[CURL_ERROR_SIZE];
+    void remove(ResourceLoader*);
 
-    // NULL-terminated list of supported protocols
-    const char* const* curl_protocols; // not freed
+    // KIO Job <-> WebKit Job mapping
+    QMap<ResourceLoader*, KIO::Job*> m_jobToKioMap;
+    QMap<KIO::Job*, ResourceLoader*> m_kioToJobMap;
 };
 
 }
 
 #endif
-
-// vim: ts=4 sw=4 et
similarity index 58%
rename from WebCore/platform/qt/ResourceLoaderCurl.cpp
rename to WebCore/platform/qt/ResourceLoaderQt.cpp
index 9e8de771cf9337189e49ecd4d6500ab077660787..312d9c8b2343a55a003f3f032982cc4f66371dc7 100644 (file)
@@ -1,8 +1,6 @@
 /*
- * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
- * Copyright (C) 2005, 2006 Michael Emmel mike.emmel@gmail.com 
  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 
 #include "config.h"
-#include "ResourceLoader.h"
+
+#include <kio/job.h>
 
 #include "DocLoader.h"
-#include "ResourceLoaderInternal.h"
+#include "ResourceLoader.h"
+#include "DeprecatedString.h"
 #include "ResourceLoaderManager.h"
-
-#define notImplemented() do { fprintf(stderr, "FIXME: UNIMPLEMENTED: %s:%d\n", __FILE__, __LINE__); } while(0)
+#include "ResourceLoaderInternal.h"
 
 namespace WebCore {
 
@@ -47,41 +46,45 @@ ResourceLoader::~ResourceLoader()
     cancel();
 }
 
-bool ResourceLoader::start(DocLoader* docLoader)
+bool ResourceLoader::start(DocLoader*)
 {
-    ResourceLoaderManager::get()->add(this);
+    ResourceLoaderManager::self()->add(this);
     return true;
 }
 
 void ResourceLoader::cancel()
 {
-    ResourceLoaderManager::get()->cancel(this);
+    ResourceLoaderManager::self()->cancel(this);
 }
 
 void ResourceLoader::assembleResponseHeaders() const
 {
     if (!d->assembledResponseHeaders) {
-        d->responseHeaders = DeprecatedString::fromUtf8(d->response.toUtf8(), d->response.length());
+        d->responseHeaders = d->m_response;
         d->assembledResponseHeaders = true;
-        // FIXME: Move the client activation to receivedResponse(), once
-        // we use KIO, and receivedResponse() is called only once.
-        if (d->client)
-            d->client->receivedResponse(const_cast<ResourceLoader*>(this), d->response);
-
-        d->response = QString(); // Reset
+        d->m_response = QString(); // Reset
     }
 }
 
 void ResourceLoader::retrieveCharset() const
 {
-    if (!d->retrievedCharset)
+    if (!d->retrievedCharset) {
         d->retrievedCharset = true;
 
-    // FIXME: We can just parse the headers here, but once we use KIO
-    // we can set the response parameter to sth. else than a "char*".
-    // I save my time but not implementing it for now :-)
-    notImplemented();
+        int pos = d->responseHeaders.find("content-type:", 0, false);
+
+        if (pos > -1) {
+            pos += 13;
+            int index = d->responseHeaders.find('\n', pos);
+            QString type = d->responseHeaders.mid(pos, (index - pos));
+            index = type.indexOf(';');
+
+            if (index > -1) {
+                QString encoding = type.mid(index + 1).remove(QRegExp("charset[ ]*=[ ]*", Qt::CaseInsensitive)).trimmed();
+                d->metaData.set("charset", encoding);
+            }
+        }
+    }
 }
 
 void ResourceLoader::receivedResponse(QString response)
@@ -90,18 +93,10 @@ void ResourceLoader::receivedResponse(QString response)
 
     d->assembledResponseHeaders = false;
     d->retrievedCharset = false;
+    d->m_response = response;
 
-    // FIXME: This is flawed:
-    // - usually receivedResponse() should be called _once_, when the
-    //   response is available - seems very unflexible to do that with libcurl
-    //   (so let's wait until it dies and do it properly with KIO then.)
-    // - QString::fromLatin1() is also wrong, of course.
-    //
-    // Anyway, let's collect the response data here, as the ResourceLoaderManager
-    // calls us for every line of the header it receives.
-    d->response += response;
+    if (d->client)
+        d->client->receivedResponse(const_cast<ResourceLoader*>(this), response);
 }
 
 } // namespace WebCore
-
-// vim: ts=4 sw=4 et