Share WebCoreHttp and therefore HTTP connections among multiple
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 May 2007 07:47:03 +0000 (07:47 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 May 2007 07:47:03 +0000 (07:47 +0000)
QWebNetworkInterface instances by moving the code into
QWebNetworkManager.

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

WebKitQt/Api/qwebnetworkinterface.cpp
WebKitQt/Api/qwebnetworkinterface.h
WebKitQt/Api/qwebnetworkinterface_p.h
WebKitQt/ChangeLog

index 326dfd6a626c34641b7959919eb66d26999e9548..94af1d8dcdedfff1a89770ede9288a60cb20f445 100644 (file)
@@ -384,6 +384,35 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
     job->deref();
 }
 
+void QWebNetworkManager::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(this, hostInfo);
+        QObject::connect(httpConnection, SIGNAL(connectionClosed(const WebCore::HostInfo&)),
+                         this, SLOT(httpConnectionClosed(const WebCore::HostInfo&)));
+
+        m_hostMapping[hostInfo] = httpConnection;
+    }
+    httpConnection->request(job);
+}
+
+void QWebNetworkManager::cancelHttpJob(QWebNetworkJob *job)
+{
+    WebCoreHttp *httpConnection = m_hostMapping.value(job->url());
+    if (httpConnection)
+        httpConnection->cancel(job);
+}
+
+void QWebNetworkManager::httpConnectionClosed(const WebCore::HostInfo &info)
+{
+    WebCoreHttp *connection = m_hostMapping.take(info);
+    delete connection;
+}
+
 void QWebNetworkInterfacePrivate::sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray &data)
 {
     int error = statusCode >= 400 ? 1 : 0;
@@ -447,28 +476,6 @@ void QWebNetworkInterfacePrivate::parseDataUrl(QWebNetworkJob* job)
     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
 
@@ -555,8 +562,7 @@ void QWebNetworkInterface::addJob(QWebNetworkJob *job)
 {
     QString protocol = job->url().scheme();
     if (protocol == QLatin1String("http")) {
-        //DEBUG() << "networkRequest";
-        d->addHttpJob(job);
+        QWebNetworkManager::self()->addHttpJob(job);
         return;
     }
 
@@ -609,17 +615,13 @@ void QWebNetworkInterface::addJob(QWebNetworkJob *job)
 void QWebNetworkInterface::cancelJob(QWebNetworkJob *job)
 {
     QString protocol = job->url().scheme();
-    if (protocol == QLatin1String("http")) {
-        WebCoreHttp *httpConnection = d->m_hostMapping.value(job->url());
-        if (httpConnection)
-            httpConnection->cancel(job);
-    }
+    if (protocol == QLatin1String("http"))
+        QWebNetworkManager::self()->cancelHttpJob(job);
 }
 
 /////////////////////////////////////////////////////////////////////////////
-WebCoreHttp::WebCoreHttp(QWebNetworkInterface* parent, const HostInfo &hi)
-    : info(hi),
-      m_networkInterface(parent),
+WebCoreHttp::WebCoreHttp(QObject* parent, const HostInfo &hi)
+    : QObject(parent), info(hi),
       m_inCancel(false)
 {
     for (int i = 0; i < 2; ++i) {
@@ -663,7 +665,7 @@ void WebCoreHttp::scheduleNextRequest()
     while (!job && !m_pendingRequests.isEmpty()) {
         job = m_pendingRequests.takeFirst();
         if (job->cancelled()) {
-            emit m_networkInterface->finished(job, 1);
+            emit job->networkInterface()->finished(job, 1);
             job = 0;
         }
     }
@@ -704,7 +706,7 @@ void WebCoreHttp::onResponseHeaderReceived(const QHttpResponseHeader &resp)
 
     job->setResponse(resp);
 
-    emit m_networkInterface->started(job);
+    emit job->networkInterface()->started(job);
 }
 
 void WebCoreHttp::onReadyRead()
@@ -717,7 +719,7 @@ void WebCoreHttp::onReadyRead()
     QByteArray data;
     data.resize(http->bytesAvailable());
     http->read(data.data(), data.length());
-    emit m_networkInterface->data(req, data);
+    emit req->networkInterface()->data(req, data);
 }
 
 void WebCoreHttp::onRequestFinished(int, bool error)
@@ -738,9 +740,9 @@ void WebCoreHttp::onRequestFinished(int, bool error)
         QByteArray data;
         data.resize(http->bytesAvailable());
         http->read(data.data(), data.length());
-        emit m_networkInterface->data(req, data);
+        emit req->networkInterface()->data(req, data);
     }
-    emit m_networkInterface->finished(req, error ? 1 : 0);
+    emit req->networkInterface()->finished(req, error ? 1 : 0);
 
     connection[c].current = 0;
     scheduleNextRequest();
@@ -770,7 +772,7 @@ void WebCoreHttp::cancel(QWebNetworkJob* request)
     m_inCancel = false;
 
     if (doEmit)
-        emit m_networkInterface->finished(request, 1);
+        emit request->networkInterface()->finished(request, 1);
 
     if (m_pendingRequests.isEmpty()
         && !connection[0].current && !connection[1].current)
index 9c01b7b3c65af4d2971cbb93b52b748b85300736..5a34b9ecd13b69c836672fba0304c0759cd7c7de 100644 (file)
@@ -82,7 +82,6 @@ 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 9680ecb59fa1b6bde12881910b2e7e18067b2699..8edbaa8cad4369f8eeb05c0bee9a1f616a87bf93 100644 (file)
@@ -63,6 +63,9 @@ public:
     bool add(WebCore::ResourceHandle *resourceHandle, QWebNetworkInterface *interface);
     void cancel(WebCore::ResourceHandle *resourceHandle);
 
+    void addHttpJob(QWebNetworkJob *job);
+    void cancelHttpJob(QWebNetworkJob *job);
+
 public slots:
     void started(QWebNetworkJob *);
     void data(QWebNetworkJob *, const QByteArray &data);
@@ -71,9 +74,13 @@ public slots:
 signals:
     void fileRequest(QWebNetworkJob*);
 
+private slots:
+    void httpConnectionClosed(const WebCore::HostInfo &);
+
 private:
     friend class QWebNetworkInterface;
     QWebNetworkManager();
+    QHash<WebCore::HostInfo, WebCore::WebCoreHttp *> m_hostMapping;
 };
 
 
@@ -93,7 +100,7 @@ namespace WebCore {
     {
         Q_OBJECT
     public:
-        WebCoreHttp(QWebNetworkInterface* parent, const HostInfo&);
+        WebCoreHttp(QObject *parent, const HostInfo&);
         ~WebCoreHttp();
 
         void request(QWebNetworkJob* resource);
@@ -115,7 +122,6 @@ namespace WebCore {
     public:
         HostInfo info;
     private:
-        QWebNetworkInterface* m_networkInterface;
         QList<QWebNetworkJob *> m_pendingRequests;
         struct HttpConnection {
             QHttp *http;
@@ -133,11 +139,6 @@ public:
     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;
 };
 
index f0a73e2849c8dac674f43d5a2410df8a297ace61..5f0e2376beebf9d970b2ea8f06f3a922f9aab29f 100644 (file)
@@ -1,3 +1,25 @@
+2007-05-23  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Zack, idea from Lars.
+
+        Share WebCoreHttp and therefore HTTP connections among multiple
+        QWebNetworkInterface instances by moving the code into
+        QWebNetworkManager.
+
+        * Api/qwebnetworkinterface.cpp:
+        (QWebNetworkManager::addHttpJob):
+        (QWebNetworkManager::cancelHttpJob):
+        (QWebNetworkManager::httpConnectionClosed):
+        (QWebNetworkInterface::addJob):
+        (QWebNetworkInterface::cancelJob):
+        (WebCoreHttp::scheduleNextRequest):
+        (WebCoreHttp::onResponseHeaderReceived):
+        (WebCoreHttp::onReadyRead):
+        (WebCoreHttp::onRequestFinished):
+        (WebCoreHttp::cancel):
+        * Api/qwebnetworkinterface.h:
+        * Api/qwebnetworkinterface_p.h:
+
 2007-05-23  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Zack, discussed also with Lars.