Added support for per-QWebPage network interface handlers, clean up the
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2007 16:22:18 +0000 (16:22 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2007 16:22:18 +0000 (16:22 +0000)
http and file loading and fixed a bug in the HTTP redirect handling.

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

WebCore/ChangeLog
WebCore/platform/network/qt/ResourceHandleQt.cpp
WebKitQt/Api/qwebnetworkinterface.cpp
WebKitQt/Api/qwebnetworkinterface.h
WebKitQt/Api/qwebnetworkinterface_p.h
WebKitQt/Api/qwebpage.cpp
WebKitQt/Api/qwebpage.h
WebKitQt/Api/qwebpage_p.h
WebKitQt/ChangeLog

index c93a4f05a578bb82746fbe6b6b14174f61d62465..70b30b11a9a0cbd5e6d80643a6154c5e14967df5 100644 (file)
@@ -1,3 +1,14 @@
+2007-05-23  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Zack, discussed also with Lars.
+
+        Make it possible to have per-QWebPage network interface
+        implementations.
+
+        * platform/network/qt/ResourceHandleQt.cpp:
+        (WebCore::ResourceHandle::start): Pass the page's network interface to
+        the network manager.
+
 2007-05-23  Rob Buis  <buis@kde.org>
 
         Reviewed by Dave Hyatt.
index 86cab69bd4d28246a8afcd7fcac303e4c9b7e725..e7520d46b6c58711204977969f2ec9de49f99493 100644 (file)
@@ -36,6 +36,9 @@
 #include "DeprecatedString.h"
 #include "ResourceHandleInternal.h"
 #include "qwebnetworkinterface_p.h"
+#include "qwebpage_p.h"
+#include "ChromeClientQt.h"
+#include "Page.h"
 
 
 #define notImplemented() qDebug("FIXME: UNIMPLEMENTED: %s:%d (%s)", __FILE__, __LINE__, __FUNCTION__)
@@ -57,9 +60,10 @@ bool ResourceHandle::start(Frame* frame)
     if (!frame)
         return false;
 
+    Page *page = frame->page();
     // If we are no longer attached to a Page, this must be an attempted load from an
     // onUnload handler, so let's just block it.
-    if (!frame->page())
+    if (!page)
         return false;
 
     // check for (probably) broken requests
@@ -68,7 +72,9 @@ bool ResourceHandle::start(Frame* frame)
         return false;
     }
 
-    return QWebNetworkManager::self()->add(this);
+    ChromeClientQt *client = static_cast<ChromeClientQt *>(page->chrome()->client());
+    QWebPagePrivate *webPage = client->m_webPage->d;
+    return QWebNetworkManager::self()->add(this, webPage->networkInterface);
 }
 
 void ResourceHandle::cancel()
index d75103828999d13cd85f45f94b6a254d67e0433d..326dfd6a626c34641b7959919eb66d26999e9548 100644 (file)
@@ -45,6 +45,16 @@ static QWebNetworkManager *manager = 0;
 
 using namespace WebCore;
 
+uint qHash(const HostInfo &info)
+{
+    return qHash(info.host) + info.port;
+}
+
+static bool operator==(const HostInfo &i1, const HostInfo &i2)
+{
+    return i1.port == i2.port && i1.host == i2.host;
+}
+
 void QWebNetworkJobPrivate::setURL(const QUrl &u)
 {
     url = u;
@@ -79,6 +89,7 @@ QWebNetworkJob::QWebNetworkJob()
 {
     d->ref = 1;
     d->redirected = false;
+    d->interface = 0;
 }
 
 /*!
@@ -162,6 +173,14 @@ bool QWebNetworkJob::deref()
     return true;
 }
 
+/*!
+   Returns the network interface that is associated with this job.
+*/
+QWebNetworkInterface *QWebNetworkJob::networkInterface() const
+{
+    return d->interface;
+}
+
 /*!
   \class QWebNetworkManager
   \internal
@@ -179,13 +198,19 @@ QWebNetworkManager *QWebNetworkManager::self()
     return manager;
 }
 
-bool QWebNetworkManager::add(ResourceHandle *handle)
+bool QWebNetworkManager::add(ResourceHandle *handle, QWebNetworkInterface *interface)
 {
     ASSERT(resource);
 
+    if (!interface)
+        interface = default_interface;
+
+    ASSERT(interface);
+
     QWebNetworkJob *job = new QWebNetworkJob();
     handle->getInternal()->m_job = job;
     job->d->resourceHandle = handle;
+    job->d->interface = interface;
 
     KURL url = handle->url();
     QUrl qurl = QString(url.url());
@@ -222,8 +247,8 @@ bool QWebNetworkManager::add(ResourceHandle *handle)
 
     DEBUG() << "QWebNetworkManager::add:" <<  job->d->request.toString();
 
-    default_interface->addJob(job);
-    
+    interface->addJob(job);
+
     return true;
 }
 
@@ -233,7 +258,7 @@ void QWebNetworkManager::cancel(ResourceHandle *handle)
     if (!job)
         return;
     job->d->resourceHandle = 0;
-    default_interface->cancelJob(job);
+    job->d->interface->cancelJob(job);
     handle->getInternal()->m_job = 0;
 }
 
@@ -318,6 +343,9 @@ void QWebNetworkManager::data(QWebNetworkJob *job, const QByteArray &data)
     if (!client)
         return;
 
+    if (job->d->redirected)
+        return; // don't emit the "Document has moved here" type of HTML
+
     DEBUG() << "receivedData" << job->d->url.path();
     client->didReceiveData(job->d->resourceHandle, data.constData(), data.length(), data.length() /*FixMe*/);
     
@@ -334,7 +362,7 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
 
     if (job->d->redirected) {
         job->d->redirected = false;
-        default_interface->addJob(job);
+        job->d->interface->addJob(job);
         return;
     }
     job->d->resourceHandle->getInternal()->m_job = 0;
@@ -356,6 +384,90 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
     job->deref();
 }
 
+void QWebNetworkInterfacePrivate::sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray &data)
+{
+    int error = statusCode >= 400 ? 1 : 0;
+    if (!job->cancelled()) {
+        QHttpResponseHeader response;
+        response.setStatusLine(statusCode);
+        job->setResponse(response);
+        emit q->started(job);
+        if (!data.isEmpty())
+            emit q->data(job, data);
+    }
+    emit q->finished(job, error);
+}
+
+void QWebNetworkInterfacePrivate::parseDataUrl(QWebNetworkJob* job)
+{
+    QByteArray data = job->url().toString().toLatin1();
+    //qDebug() << "handling data url:" << data; 
+
+    ASSERT(data.startsWith("data:"));
+
+    // Here's the syntax of data URLs:
+    // dataurl    := "data:" [ mediatype ] [ ";base64" ] "," data
+    // mediatype  := [ type "/" subtype ] *( ";" parameter )
+    // data       := *urlchar
+    // parameter  := attribute "=" value
+    QByteArray header;
+    bool base64 = false;
+
+    int index = data.indexOf(',');
+    if (index != -1) {
+        header = data.mid(5, index - 5);
+        header = header.toLower();
+        //qDebug() << "header=" << header;
+        data = data.mid(index+1);
+        //qDebug() << "data=" << data;
+
+        if (header.endsWith(";base64")) {
+            //qDebug() << "base64";
+            base64 = true;
+            header = header.left(header.length() - 7);
+            //qDebug() << "mime=" << header;
+        }        
+    } else {
+        data = QByteArray();
+    }
+    if (base64) {
+        data = QByteArray::fromBase64(data);
+    } else {
+        data = QUrl::fromPercentEncoding(data).toLatin1();
+    }
+
+    if (header.isEmpty()) 
+        header = "text/plain;charset=US-ASCII";
+    int statusCode = data.isEmpty() ? 404 : 200;
+    QHttpResponseHeader response;
+    response.setContentType(header);
+    response.setContentLength(data.size());
+    job->setResponse(response);
+
+    sendFileData(job, statusCode, data);
+}
+
+void QWebNetworkInterfacePrivate::addHttpJob(QWebNetworkJob *job)
+{
+    HostInfo hostInfo(job->url());
+    WebCoreHttp *httpConnection = m_hostMapping.value(hostInfo);
+    if (!httpConnection) {
+        // #### fix custom ports
+        DEBUG() << "   new connection to" << hostInfo.host << hostInfo.port;
+        httpConnection = new WebCoreHttp(q, hostInfo);
+        QObject::connect(httpConnection, SIGNAL(connectionClosed(const WebCore::HostInfo&)),
+                         q, SLOT(httpConnectionClosed(const WebCore::HostInfo&)));
+
+        m_hostMapping[hostInfo] = httpConnection;
+    }
+    httpConnection->request(job);
+}
+
+void QWebNetworkInterfacePrivate::httpConnectionClosed(const WebCore::HostInfo &info)
+{
+    WebCoreHttp *connection = m_hostMapping.take(info);
+    delete connection;
+}
 
 /*!
   \class QWebNetworkInterface
@@ -384,12 +496,6 @@ void QWebNetworkInterface::setDefaultInterface(QWebNetworkInterface *defaultInte
     if (default_interface)
         delete default_interface;
     default_interface = defaultInterface;
-    QObject::connect(default_interface, SIGNAL(started(QWebNetworkJob*)),
-                     manager, SLOT(started(QWebNetworkJob*)), Qt::QueuedConnection);
-    QObject::connect(default_interface, SIGNAL(data(QWebNetworkJob*, const QByteArray &)),
-                     manager, SLOT(data(QWebNetworkJob*, const QByteArray &)), Qt::QueuedConnection);
-    QObject::connect(default_interface, SIGNAL(finished(QWebNetworkJob*, int)),
-                     manager, SLOT(finished(QWebNetworkJob*, int)), Qt::QueuedConnection);
 }
 
 /*!
@@ -408,23 +514,21 @@ QWebNetworkInterface *QWebNetworkInterface::defaultInterface()
 /*!
   Constructs a QWebNetworkInterface object.
 */
-QWebNetworkInterface::QWebNetworkInterface()
-    : QObject(0)
+QWebNetworkInterface::QWebNetworkInterface(QObject *parent)
+    : QObject(parent)
 {
     d = new QWebNetworkInterfacePrivate;
+    d->q = this;
+
     if (!manager)
         manager = new QWebNetworkManager;
-    d->fileLoader = new LoaderThread(this);
-    d->fileLoader->start();
-    d->fileLoader->waitForSetup();
 
-    d->networkLoader = new NetworkLoader(this);
-    connect(d->networkLoader, SIGNAL(receivedResponse(QWebNetworkJob*)),
-            this, SIGNAL(started(QWebNetworkJob*)));
-    connect(d->networkLoader, SIGNAL(receivedData(QWebNetworkJob*, QByteArray)),
-            this, SIGNAL(data(QWebNetworkJob*, QByteArray)));
-    connect(d->networkLoader, SIGNAL(receivedFinished(QWebNetworkJob*, int)),
-            this, SIGNAL(finished(QWebNetworkJob*, int)));
+    QObject::connect(this, SIGNAL(started(QWebNetworkJob*)),
+                     manager, SLOT(started(QWebNetworkJob*)), Qt::QueuedConnection);
+    QObject::connect(this, SIGNAL(data(QWebNetworkJob*, const QByteArray &)),
+                     manager, SLOT(data(QWebNetworkJob*, const QByteArray &)), Qt::QueuedConnection);
+    QObject::connect(this, SIGNAL(finished(QWebNetworkJob*, int)),
+                     manager, SLOT(finished(QWebNetworkJob*, int)), Qt::QueuedConnection);
 }
 
 /*!
@@ -452,82 +556,22 @@ void QWebNetworkInterface::addJob(QWebNetworkJob *job)
     QString protocol = job->url().scheme();
     if (protocol == QLatin1String("http")) {
         //DEBUG() << "networkRequest";
-        d->networkLoader->request(job);
+        d->addHttpJob(job);
         return;
     }
 
     // "file", "data" and all unhandled stuff go through here
     //DEBUG() << "fileRequest";
-    job->ref();
-    emit manager->fileRequest(job);
-}
-
-/*!
-  This virtual method gets called whenever QtWebkit needs to cancel a
-  new job.
-
-  The QWebNetworkInterface acknowledge the canceling of the job, by
-  emitting the finished signal with an error code of 1. After emitting
-  the finished signal, the interface should not access the job
-  anymore.
-*/
-void QWebNetworkInterface::cancelJob(QWebNetworkJob *job)
-{
-    QString protocol = job->url().scheme();
-    if (protocol == QLatin1String("http")) 
-        d->networkLoader->cancel(job);
-}
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-LoaderThread::LoaderThread(QWebNetworkInterface *manager)
-    : QThread(manager), m_loader(0), m_manager(manager), m_setup(false)
-{
-}
-
-void LoaderThread::run()
-{
-    m_loader = new FileLoader;
-    connect(manager, SIGNAL(fileRequest(QWebNetworkJob*)),
-            m_loader, SLOT(request(QWebNetworkJob*)));
-    connect(m_loader, SIGNAL(receivedResponse(QWebNetworkJob*)),
-            m_manager, SIGNAL(started(QWebNetworkJob*)));
-    connect(m_loader, SIGNAL(receivedData(QWebNetworkJob*, QByteArray)),
-            m_manager, SIGNAL(data(QWebNetworkJob*, QByteArray)));
-    connect(m_loader, SIGNAL(receivedFinished(QWebNetworkJob*, int)),
-            m_manager, SIGNAL(finished(QWebNetworkJob*, int)));
-    DEBUG() << "calling exec";
-    m_setup = true;
-    exec();
-    DEBUG() << "done exec";
-    delete m_loader;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-FileLoader::FileLoader()
-    : QObject(0)
-{
-    DEBUG() << "FileLoader::FileLoader";
-}
-
-
-void FileLoader::request(QWebNetworkJob* job)
-{
-    if (!job->deref())
-        return;
-    
     DEBUG() << "FileLoader::request" << job->url();
 
     if (job->cancelled()) {
-        sendData(job, 400, QByteArray());
+        d->sendFileData(job, 400, QByteArray());
         return;
     }
 
     QUrl url = job->url();
-    QString protocol = url.scheme();
     if (protocol == QLatin1String("data")) {
-        parseDataUrl(job);
+        d->parseDataUrl(job);
         return;
     }
 
@@ -550,76 +594,32 @@ void FileLoader::request(QWebNetworkJob* job)
     } else {
         statusCode = 404;
     }
-    sendData(job, statusCode, data);
+    d->sendFileData(job, statusCode, data);
 }
 
-void FileLoader::sendData(QWebNetworkJob* job, int statusCode, const QByteArray &data)
-{
-    int error = statusCode >= 400 ? 1 : 0;
-    if (!job->cancelled()) {
-        QHttpResponseHeader response;
-        response.setStatusLine(statusCode);
-        emit receivedResponse(job);
-        if (!data.isEmpty())
-            emit receivedData(job, data);
-    }
-    emit receivedFinished(job, error);
-}
+/*!
+  This virtual method gets called whenever QtWebkit needs to cancel a
+  new job.
 
-void FileLoader::parseDataUrl(QWebNetworkJob* job)
+  The QWebNetworkInterface acknowledge the canceling of the job, by
+  emitting the finished signal with an error code of 1. After emitting
+  the finished signal, the interface should not access the job
+  anymore.
+*/
+void QWebNetworkInterface::cancelJob(QWebNetworkJob *job)
 {
-    QByteArray data = job->url().toString().toLatin1();
-    //qDebug() << "handling data url:" << data; 
-
-    ASSERT(data.startsWith("data:"));
-
-    // Here's the syntax of data URLs:
-    // dataurl    := "data:" [ mediatype ] [ ";base64" ] "," data
-    // mediatype  := [ type "/" subtype ] *( ";" parameter )
-    // data       := *urlchar
-    // parameter  := attribute "=" value
-    QByteArray header;
-    bool base64 = false;
-
-    int index = data.indexOf(',');
-    if (index != -1) {
-        header = data.mid(5, index - 5);
-        header = header.toLower();
-        //qDebug() << "header=" << header;
-        data = data.mid(index+1);
-        //qDebug() << "data=" << data;
-
-        if (header.endsWith(";base64")) {
-            //qDebug() << "base64";
-            base64 = true;
-            header = header.left(header.length() - 7);
-            //qDebug() << "mime=" << header;
-        }        
-    } else {
-        data = QByteArray();
-    }
-    if (base64) {
-        data = QByteArray::fromBase64(data);
-    } else {
-        data = QUrl::fromPercentEncoding(data).toLatin1();
+    QString protocol = job->url().scheme();
+    if (protocol == QLatin1String("http")) {
+        WebCoreHttp *httpConnection = d->m_hostMapping.value(job->url());
+        if (httpConnection)
+            httpConnection->cancel(job);
     }
-
-    if (header.isEmpty()) 
-        header = "text/plain;charset=US-ASCII";
-    int statusCode = data.isEmpty() ? 404 : 200;
-    QHttpResponseHeader response;
-    response.setContentType(header);
-    response.setContentLength(data.size());
-    job->setResponse(response);
-
-    sendData(job, statusCode, data);
 }
 
-
 /////////////////////////////////////////////////////////////////////////////
-WebCoreHttp::WebCoreHttp(NetworkLoader* parent, const HostInfo &hi)
+WebCoreHttp::WebCoreHttp(QWebNetworkInterface* parent, const HostInfo &hi)
     : info(hi),
-      m_loader(parent),
+      m_networkInterface(parent),
       m_inCancel(false)
 {
     for (int i = 0; i < 2; ++i) {
@@ -663,7 +663,7 @@ void WebCoreHttp::scheduleNextRequest()
     while (!job && !m_pendingRequests.isEmpty()) {
         job = m_pendingRequests.takeFirst();
         if (job->cancelled()) {
-            emit m_loader->receivedFinished(job, 1);
+            emit m_networkInterface->finished(job, 1);
             job = 0;
         }
     }
@@ -704,7 +704,7 @@ void WebCoreHttp::onResponseHeaderReceived(const QHttpResponseHeader &resp)
 
     job->setResponse(resp);
 
-    emit m_loader->receivedResponse(job);
+    emit m_networkInterface->started(job);
 }
 
 void WebCoreHttp::onReadyRead()
@@ -717,7 +717,7 @@ void WebCoreHttp::onReadyRead()
     QByteArray data;
     data.resize(http->bytesAvailable());
     http->read(data.data(), data.length());
-    emit m_loader->receivedData(req, data);
+    emit m_networkInterface->data(req, data);
 }
 
 void WebCoreHttp::onRequestFinished(int, bool error)
@@ -738,9 +738,9 @@ void WebCoreHttp::onRequestFinished(int, bool error)
         QByteArray data;
         data.resize(http->bytesAvailable());
         http->read(data.data(), data.length());
-        emit m_loader->receivedData(req, data);
+        emit m_networkInterface->data(req, data);
     }
-    emit m_loader->receivedFinished(req, error ? 1 : 0);
+    emit m_networkInterface->finished(req, error ? 1 : 0);
 
     connection[c].current = 0;
     scheduleNextRequest();
@@ -770,7 +770,7 @@ void WebCoreHttp::cancel(QWebNetworkJob* request)
     m_inCancel = false;
 
     if (doEmit)
-        emit m_loader->receivedFinished(request, 1);
+        emit m_networkInterface->finished(request, 1);
 
     if (m_pendingRequests.isEmpty()
         && !connection[0].current && !connection[1].current)
@@ -790,58 +790,6 @@ HostInfo::HostInfo(const QUrl& url)
     }
 }
 
-
-uint qHash(const HostInfo &info)
-{
-    return qHash(info.host) + info.port;
-}
-
-static bool operator==(const HostInfo &i1, const HostInfo &i2)
-{
-    return i1.port == i2.port && i1.host == i2.host;
-}
-
-
-NetworkLoader::NetworkLoader(QObject *parent)
-    : QObject(parent)
-{
-}
-
-NetworkLoader::~NetworkLoader()
-{
-}
-
-void NetworkLoader::request(QWebNetworkJob* job)
-{
-    DEBUG() << "NetworkLoader::request";
-    HostInfo hostInfo(job->url());
-    WebCoreHttp *httpConnection = m_hostMapping.value(hostInfo);
-    if (!httpConnection) {
-        // #### fix custom ports
-        DEBUG() << "   new connection to" << hostInfo.host << hostInfo.port;
-        httpConnection = new WebCoreHttp(this, hostInfo);
-        connect(httpConnection, SIGNAL(connectionClosed(const HostInfo&)),
-                this, SLOT(connectionClosed(const HostInfo&)));
-
-        m_hostMapping[hostInfo] = httpConnection;
-    }
-    httpConnection->request(job);
-}
-void NetworkLoader::connectionClosed(const HostInfo& info)
-{
-    DEBUG() << "Disconnected";
-    WebCoreHttp *connection = m_hostMapping.take(info);
-    delete connection;
-}
-
-void NetworkLoader::cancel(QWebNetworkJob* job)
-{
-    DEBUG() << "NetworkLoader::cancel";
-    WebCoreHttp *httpConnection = m_hostMapping.value(job->url());
-    if (httpConnection)
-        httpConnection->cancel(job);
-}
-
 #include "qwebnetworkinterface_p.moc"
 #include "qwebnetworkinterface.moc"
 
index c91748a196c6cbb87020214cdb09b6014c89c9d9..9c01b7b3c65af4d2971cbb93b52b748b85300736 100644 (file)
 #include <qwebkitglobal.h>
 
 class QWebNetworkJobPrivate;
+class QWebNetworkInterface;
+
+namespace WebCore {
+    class WebCoreHttp;
+}
 
 class QWEBKIT_EXPORT QWebNetworkJob
 {
@@ -45,6 +50,8 @@ public:
 
     void ref();
     bool deref();
+
+    QWebNetworkInterface *networkInterface() const;
     
 private:
     QWebNetworkJob();
@@ -60,7 +67,7 @@ class QWEBKIT_EXPORT QWebNetworkInterface : public QObject
 {
     Q_OBJECT
 public:
-    QWebNetworkInterface();
+    QWebNetworkInterface(QObject *parent = 0);
     ~QWebNetworkInterface();
 
     static void setDefaultInterface(QWebNetworkInterface *defaultInterface);
@@ -75,7 +82,9 @@ signals:
     void finished(QWebNetworkJob*, int errorCode);
 
 private:
+    Q_PRIVATE_SLOT(d, void httpConnectionClosed(const WebCore::HostInfo &));
     friend class QWebNetworkInterfacePrivate;
+    friend class WebCore::WebCoreHttp;
     QWebNetworkInterfacePrivate *d;
 };
 
index 331755b8a2908643f784c1b35c47529f4a5cf399..9680ecb59fa1b6bde12881910b2e7e18067b2699 100644 (file)
@@ -48,6 +48,8 @@ public:
     WebCore::ResourceHandle *resourceHandle;
     bool redirected;
 
+    QWebNetworkInterface *interface;
+
     void setURL(const QUrl &u);
 };
 
@@ -58,7 +60,7 @@ class QWebNetworkManager : public QObject
 public:
     static QWebNetworkManager *self();
 
-    bool add(WebCore::ResourceHandle *resourceHandle);
+    bool add(WebCore::ResourceHandle *resourceHandle, QWebNetworkInterface *interface);
     void cancel(WebCore::ResourceHandle *resourceHandle);
 
 public slots:
@@ -76,38 +78,6 @@ private:
 
 
 namespace WebCore {
-    
-    class LoaderThread : public QThread {
-        Q_OBJECT
-    public:
-        LoaderThread(QWebNetworkInterface *manager);
-
-        void waitForSetup() { while (!m_setup); }
-    protected:
-        void run();
-    private:
-        QObject* m_loader;
-        QWebNetworkInterface* m_manager;
-        volatile bool m_setup;
-    };
-
-    class FileLoader : public QObject {
-        Q_OBJECT
-    public:
-        FileLoader();
-
-            public slots:
-            void request(QWebNetworkJob*);
-
-        signals:
-        void receivedResponse(QWebNetworkJob* resource);
-        void receivedData(QWebNetworkJob* resource, const QByteArray &data);
-        void receivedFinished(QWebNetworkJob* resource, int errorCode);
-
-    private:
-        void parseDataUrl(QWebNetworkJob* request);
-        void sendData(QWebNetworkJob* request, int statusCode, const QByteArray &data);
-    };
 
     class NetworkLoader;
 
@@ -123,17 +93,17 @@ namespace WebCore {
     {
         Q_OBJECT
     public:
-        WebCoreHttp(NetworkLoader* parent, const HostInfo&);
+        WebCoreHttp(QWebNetworkInterface* parent, const HostInfo&);
         ~WebCoreHttp();
 
         void request(QWebNetworkJob* resource);
         void cancel(QWebNetworkJob*);
 
     signals:
-        void connectionClosed(const HostInfo &);
+        void connectionClosed(const WebCore::HostInfo &);
 
-             private slots:
-             void onResponseHeaderReceived(const QHttpResponseHeader& resp);
+    private slots:
+        void onResponseHeaderReceived(const QHttpResponseHeader& resp);
         void onReadyRead();
         void onRequestFinished(int, bool);
         void onStateChanged(int);
@@ -145,7 +115,7 @@ namespace WebCore {
     public:
         HostInfo info;
     private:
-        NetworkLoader* m_loader;
+        QWebNetworkInterface* m_networkInterface;
         QList<QWebNetworkJob *> m_pendingRequests;
         struct HttpConnection {
             QHttp *http;
@@ -155,34 +125,20 @@ namespace WebCore {
         bool m_inCancel;
     };
 
-    class NetworkLoader : public QObject {
-        Q_OBJECT
-    public:
-        NetworkLoader(QObject *parent);
-        ~NetworkLoader();
-
-
-            public slots:
-            void request(QWebNetworkJob*);
-        void cancel(QWebNetworkJob*);
-        void connectionClosed(const HostInfo &);
-
-    signals:
-        void receivedResponse(QWebNetworkJob* resource);
-        void receivedData(QWebNetworkJob* resource, const QByteArray &data);
-        void receivedFinished(QWebNetworkJob* resource, int errorCode);
-    private:
-        friend class WebCoreHttp;
-        QHash<HostInfo, WebCoreHttp *> m_hostMapping;
-    };
-
 }
 
 class QWebNetworkInterfacePrivate
 {
 public:
-    WebCore::NetworkLoader *networkLoader;
-    WebCore::LoaderThread *fileLoader;
+    void sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray &data);
+    void parseDataUrl(QWebNetworkJob* job);
+
+    void addHttpJob(QWebNetworkJob *job);
+
+    void httpConnectionClosed(const WebCore::HostInfo &);
+
+    QHash<WebCore::HostInfo, WebCore::WebCoreHttp *> m_hostMapping;
+    QWebNetworkInterface *q;
 };
 
 #endif
index 1844a45a82298e188d1b04bc0d4ab66f0b918c57..1f95a911909b0fed77e50e99c3399a580d2b81a7 100644 (file)
@@ -77,6 +77,7 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
 
     undoStack = 0;
     mainFrame = 0;
+    networkInterface = 0;
 }
 
 QWebPagePrivate::~QWebPagePrivate()
@@ -279,4 +280,14 @@ void QWebPage::dropEvent(QDropEvent *ev)
     ev->accept();
 }
 
+void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
+{
+    d->networkInterface = interface;
+}
+
+QWebNetworkInterface *QWebPage::networkInterface() const
+{
+    return d->networkInterface;
+}
+
 #include "qwebpage.moc"
index fcd5622de5e25d4f51008bc5814db6db34c2bd36..7a74131aff768c874cde48578edacaea87d83215 100644 (file)
@@ -34,12 +34,14 @@ class QUrl;
 
 class QWebPagePrivate;
 class QWebFrameData;
+class QWebNetworkInterface;
 
 namespace WebCore {
     class ChromeClientQt;
     class FrameLoaderClientQt;
     class FrameLoadRequest;
     class EditorClientQt;
+    class ResourceHandle;
 }
 
 class QWEBKIT_EXPORT QWebPage : public QWidget
@@ -79,6 +81,9 @@ public:
     virtual void dragMoveEvent(QDragMoveEvent *);
     virtual void dropEvent(QDropEvent *);
 
+    void setNetworkInterface(QWebNetworkInterface *interface);
+    QWebNetworkInterface *networkInterface() const;
+
 public slots:
     /**
      * Stops loading of the page, if loading.
@@ -132,6 +137,7 @@ private:
     friend class WebCore::ChromeClientQt;
     friend class WebCore::EditorClientQt;
     friend class WebCore::FrameLoaderClientQt;
+    friend class WebCore::ResourceHandle;
     QWebPagePrivate *d;
 };
 
index b04aa8ca2996549894c87b1797b443955e690500..3367849d266c70e2b241f26694ef75664af0123d 100644 (file)
@@ -56,6 +56,8 @@ public:
     QWebPage *q;
     QUndoStack *undoStack;
 
+    QWebNetworkInterface *networkInterface;
+
     bool modified;
 };
 
index 79dda0004ffc99db84cc789b5155cdc59a67e1d7..f0a73e2849c8dac674f43d5a2410df8a297ace61 100644 (file)
@@ -1,3 +1,47 @@
+2007-05-23  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Zack, discussed also with Lars.
+
+        Make it possible to specify a per-QWebPage network interface (needed
+        for the KDE KIO integration).
+
+        Merged the file and the network loader into
+        QWebNetworkInterface(Private), which simplifies the loading code.
+
+        When receiving a redirection don't emit the data of the redirected job
+        to the document. (otherwise the kind of "This page has moved" text
+        appears right on top of the real page content)
+
+        * Api/qwebnetworkinterface.cpp:
+        (qHash):
+        (operator==):
+        (QWebNetworkJob::QWebNetworkJob):
+        (QWebNetworkJob::networkInterface):
+        (QWebNetworkManager::add):
+        (QWebNetworkManager::cancel):
+        (QWebNetworkManager::data):
+        (QWebNetworkManager::finished):
+        (QWebNetworkInterfacePrivate::sendFileData):
+        (QWebNetworkInterfacePrivate::parseDataUrl):
+        (QWebNetworkInterfacePrivate::addHttpJob):
+        (QWebNetworkInterfacePrivate::httpConnectionClosed):
+        (QWebNetworkInterface::setDefaultInterface):
+        (QWebNetworkInterface::QWebNetworkInterface):
+        (QWebNetworkInterface::addJob):
+        (QWebNetworkInterface::cancelJob):
+        (WebCoreHttp::scheduleNextRequest):
+        (WebCoreHttp::onResponseHeaderReceived):
+        (WebCoreHttp::onReadyRead):
+        (WebCoreHttp::onRequestFinished):
+        (WebCoreHttp::cancel):
+        * Api/qwebnetworkinterface.h:
+        * Api/qwebnetworkinterface_p.h:
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::QWebPagePrivate):
+        (QWebPage::setNetworkInterface):
+        * Api/qwebpage.h:
+        * Api/qwebpage_p.h:
+
 2007-05-23  Lars Knoll <lars@trolltech.com>
 
         Reviewed by Zack