Commit 5b9e78e1 authored by hausmann's avatar hausmann
Browse files

Share WebCoreHttp and therefore HTTP connections among multiple

QWebNetworkInterface instances by moving the code into
QWebNetworkManager.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21701 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 933a2425
......@@ -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)
......
......@@ -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;
......
......@@ -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;
};
......
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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment