Ported of the network backend of the Qt platform to Qt 4.4's new networking API.
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jan 2008 11:35:55 +0000 (11:35 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jan 2008 11:35:55 +0000 (11:35 +0000)
Signed-off-by: Lars
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29222 268f45cc-cd09-0410-ab3c-d52691b4dbfc

31 files changed:
WebCore/ChangeLog
WebCore/WebCore.pro
WebCore/platform/network/ResourceHandleInternal.h
WebCore/platform/network/qt/QNetworkReplyHandler.cpp [new file with mode: 0644]
WebCore/platform/network/qt/QNetworkReplyHandler.h [new file with mode: 0644]
WebCore/platform/network/qt/ResourceHandleQt.cpp
WebCore/platform/network/qt/ResourceRequest.h
WebCore/platform/network/qt/ResourceRequestQt.cpp [new file with mode: 0644]
WebCore/platform/qt/MIMETypeRegistryQt.cpp
WebCore/platform/qt/PlugInInfoStoreQt.cpp
WebKit/qt/Api/qwebframe.cpp
WebKit/qt/Api/qwebframe.h
WebKit/qt/Api/qwebnetworkinterface.cpp
WebKit/qt/Api/qwebnetworkinterface.h
WebKit/qt/Api/qwebnetworkinterface_p.h
WebKit/qt/Api/qwebobjectplugin.cpp
WebKit/qt/Api/qwebobjectplugin.h
WebKit/qt/Api/qwebobjectplugin_p.h
WebKit/qt/Api/qwebobjectpluginconnector.cpp
WebKit/qt/Api/qwebobjectpluginconnector.h
WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage.h
WebKit/qt/Api/qwebpage_p.h
WebKit/qt/Api/qwebview.cpp
WebKit/qt/Api/qwebview.h
WebKit/qt/ChangeLog
WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/qt/main.cpp
WebKitTools/DumpRenderTree/qt/testplugin.cpp
WebKitTools/DumpRenderTree/qt/testplugin.h

index 43ce08c..29df236 100644 (file)
@@ -1,3 +1,35 @@
+2008-01-07  Simon Hausmann  <hausmann@webkit.org>
+
+        Reviewed by Lars.
+
+        Ported of the network backend of the Qt platform to Qt 4.4's new networking API.
+
+        * WebCore.pro:
+        * platform/network/ResourceHandleInternal.h:
+        * platform/network/qt/QNetworkReplyHandler.cpp: Added.
+        (WebCore::QNetworkReplyHandler::QNetworkReplyHandler):
+        (WebCore::QNetworkReplyHandler::abort):
+        (WebCore::QNetworkReplyHandler::finish):
+        (WebCore::QNetworkReplyHandler::sendResponseIfNeeded):
+        (WebCore::QNetworkReplyHandler::forwardData):
+        (WebCore::QNetworkReplyHandler::start):
+        * platform/network/qt/QNetworkReplyHandler.h: Added.
+        (WebCore::QNetworkReplyHandler::reply):
+        * platform/network/qt/ResourceHandleQt.cpp:
+        (WebCore::ResourceHandle::start):
+        (WebCore::ResourceHandle::cancel):
+        (WebCore::ResourceHandle::loadResourceSynchronously):
+        * platform/network/qt/ResourceRequest.h:
+        (WebCore::ResourceRequest::ResourceRequest):
+        * platform/network/qt/ResourceRequestQt.cpp: Added.
+        (WebCore::ResourceRequest::toNetworkRequest):
+        * platform/qt/MIMETypeRegistryQt.cpp:
+        (WebCore::MIMETypeRegistry::getMIMETypeForExtension):
+        * platform/qt/PlugInInfoStoreQt.cpp:
+        (WebCore::PlugInInfoStore::createPluginInfoForPluginAtIndex):
+        (WebCore::PlugInInfoStore::pluginCount):
+        (WebCore::PlugInInfoStore::pluginNameForMIMEType):
+
 2008-01-07  Holger Hans Peter Freyther  <holger.freyther@trolltech.com>
 
         Reviewed by Lars.
index 6c11eeb..709b3d8 100644 (file)
@@ -880,7 +880,8 @@ qt-port {
     $$PWD/../WebKit/qt/Api/qwebobjectpluginconnector.h \
     $$PWD/../WebKit/qt/Api/qwebhistoryinterface.h \
     $$PWD/../WebKit/qt/Api/qcookiejar.h \
-    $$PWD/../WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h
+    $$PWD/../WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h \
+    $$PWD/platform/network/qt/QNetworkReplyHandler.h
 
     SOURCES += \
     page/qt/DragControllerQt.cpp \
@@ -901,6 +902,8 @@ qt-port {
     platform/graphics/qt/IntSizeQt.cpp \
     platform/graphics/qt/PathQt.cpp \
     platform/network/qt/ResourceHandleQt.cpp \
+    platform/network/qt/ResourceRequestQt.cpp \
+    platform/network/qt/QNetworkReplyHandler.cpp \
     editing/qt/EditorQt.cpp \
     platform/qt/ClipboardQt.cpp \
     platform/qt/ContextMenuItemQt.cpp \
index e6d6064..8dc4c1f 100644 (file)
@@ -47,6 +47,9 @@
 #if PLATFORM(QT)
 class QWebFrame;
 class QWebNetworkJob;
+namespace WebCore {
+class QNetworkReplyHandler;
+}
 #endif
 
 #if PLATFORM(MAC)
@@ -153,8 +156,12 @@ namespace WebCore {
         bool m_cancelled;
 #endif
 #if PLATFORM(QT)
-        QWebNetworkJob *m_job;
-        QWebFrame *m_frame;
+#if QT_VERSION < 0x040400
+        QWebNetworkJob* m_job;
+#else
+        QNetworkReplyHandler* m_job;
+#endif
+        QWebFrame* m_frame;
 #endif
 #if PLATFORM(MAC)
         NSURLAuthenticationChallenge *m_currentMacChallenge;
diff --git a/WebCore/platform/network/qt/QNetworkReplyHandler.cpp b/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
new file mode 100644 (file)
index 0000000..ea6f8f7
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+    Copyright (C) 2007 Trolltech ASA
+    Copyright (C) 2007 Staikos Computing Services Inc.  <info@staikos.net>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+#include "config.h"
+#include "QNetworkReplyHandler.h"
+
+#if QT_VERSION >= 0x040400
+
+#include "HTTPParsers.h"
+#include "MIMETypeRegistry.h"
+#include "ResourceHandle.h"
+#include "ResourceHandleClient.h"
+#include "ResourceHandleInternal.h"
+#include "ResourceResponse.h"
+#include "ResourceRequest.h"
+#include <QNetworkReply>
+#include <QNetworkCookie>
+#include <qwebframe.h>
+#include <qwebpage.h>
+
+namespace WebCore {
+
+QNetworkReplyHandler::QNetworkReplyHandler(ResourceHandle *handle)
+    : QObject(0)
+      , m_resourceHandle(handle)
+      , m_reply(0)
+      , m_redirected(false)
+      , m_responseSent(false)
+{
+    const ResourceRequest &r = m_resourceHandle->request();
+
+    if (r.httpMethod() == "GET")
+        m_method = QNetworkAccessManager::GetOperation;
+    else if (r.httpMethod() == "HEAD")
+        m_method = QNetworkAccessManager::HeadOperation;
+    else if (r.httpMethod() == "POST")
+        m_method = QNetworkAccessManager::PostOperation;
+    else if (r.httpMethod() == "PUT")
+        m_method = QNetworkAccessManager::PutOperation;
+    else
+        m_method = QNetworkAccessManager::UnknownOperation;
+
+    m_request = r.toNetworkRequest();
+    start();
+}
+
+void QNetworkReplyHandler::abort()
+{
+    if (m_reply) {
+        m_reply->abort();
+        deleteLater();
+    }
+}
+
+void QNetworkReplyHandler::finish()
+{
+    sendResponseIfNeeded();
+
+    ResourceHandleClient* client = m_resourceHandle->client();
+    m_reply->deleteLater();
+    if (!client)
+        return;
+    if (m_redirected) {
+        m_redirected = false;
+        start();
+    } else if (m_reply->error() != QNetworkReply::NoError) {
+        QUrl url = m_reply->url();
+        ResourceError error(url.host(), m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(),
+                            url.toString(), m_reply->errorString());
+        client->didFail(m_resourceHandle, error);
+    } else {
+        client->didFinishLoading(m_resourceHandle);
+    }
+}
+
+void QNetworkReplyHandler::sendResponseIfNeeded()
+{
+    if (m_responseSent)
+        return;
+    m_responseSent = true;
+
+    ResourceHandleClient* client = m_resourceHandle->client();
+    if (!client)
+        return;
+
+    WebCore::String contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
+    WebCore::String encoding = extractCharsetFromMediaType(contentType);
+    WebCore::String mimeType = extractMIMETypeFromMediaType(contentType);
+
+    if (mimeType.isEmpty()) {
+        // let's try to guess from the extension
+        QString extension = m_reply->url().path();
+        int index = extension.lastIndexOf(QLatin1Char('.'));
+        if (index > 0) {
+            extension = extension.mid(index + 1);
+            mimeType = MIMETypeRegistry::getMIMETypeForExtension(extension);
+        }
+    }
+
+    KURL url(m_reply->url().toString());
+    String contentDisposition = QString::fromAscii(m_reply->rawHeader("Content-Disposition"));
+
+    ResourceResponse response(url, mimeType,
+                              m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(),
+                              encoding,
+                              filenameFromHTTPContentDisposition(contentDisposition));
+
+    int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+    if (m_reply->url().scheme() != QLatin1String("file"))
+        response.setHTTPStatusCode(statusCode);
+    else if (m_reply->error() == QNetworkReply::ContentNotFoundError)
+        response.setHTTPStatusCode(404);
+
+
+    /* Fill in the other fields */
+    foreach (QByteArray headerName, m_reply->rawHeaderList())
+        response.setHTTPHeaderField(QString::fromAscii(headerName), QString::fromAscii(m_reply->rawHeader(headerName)));
+
+    QUrl redirection = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
+    if (redirection.isValid()) {
+        QUrl newUrl = m_reply->url().resolved(redirection);
+        ResourceRequest newRequest = m_resourceHandle->request();
+        newRequest.setURL(KURL(newUrl.toString()));
+        client->willSendRequest(m_resourceHandle, newRequest, response);
+
+        if (statusCode >= 301 && statusCode <= 303 && m_method == QNetworkAccessManager::PostOperation)
+            m_method = QNetworkAccessManager::GetOperation;
+        m_redirected = true;
+        m_responseSent = false;
+
+        m_request.setUrl(newUrl);
+    } else {
+        client->didReceiveResponse(m_resourceHandle, response);
+    }
+}
+
+void QNetworkReplyHandler::forwardData()
+{
+    sendResponseIfNeeded();
+
+    // don't emit the "Document has moved here" type of HTML
+    if (m_redirected)
+        return;
+
+    QByteArray data = m_reply->read(m_reply->bytesAvailable());
+
+    ResourceHandleClient* client = m_resourceHandle->client();
+    if (!client)
+        return;
+
+    if (!data.isEmpty())
+        client->didReceiveData(m_resourceHandle, data.constData(), data.length(), data.length() /*FixMe*/);
+}
+
+void QNetworkReplyHandler::start()
+{
+    ResourceHandleInternal* d = m_resourceHandle->getInternal();
+
+    QNetworkAccessManager* manager = d->m_frame->page()->networkAccessManager();
+
+    switch (m_method) {
+        case QNetworkAccessManager::GetOperation:
+            m_reply = manager->get(m_request);
+            break;
+        case QNetworkAccessManager::PostOperation: {
+            DeprecatedString pd = d->m_request.httpBody()->flattenToString().deprecatedString();
+            m_reply = manager->post(m_request, QByteArray(pd.ascii(), pd.length()));
+            break;
+        }
+        case QNetworkAccessManager::HeadOperation:
+            m_reply = manager->head(m_request);
+            break;
+        case QNetworkAccessManager::PutOperation: {
+            // ### data?
+            DeprecatedString pd = d->m_request.httpBody()->flattenToString().deprecatedString();
+            m_reply = manager->put(m_request, QByteArray(pd.ascii(), pd.length()));
+            break;
+        }
+        case QNetworkAccessManager::UnknownOperation:
+            break; // eh?
+    }
+
+    m_reply->setParent(this);
+
+    connect(m_reply, SIGNAL(finished()),
+            this, SLOT(finish()));
+
+    // For http(s) we know that the headers are complete upon metaDataChanged() emission, so we
+    // can send the response as early as possible
+    QString scheme = m_request.url().scheme();
+    if (scheme == QLatin1String("http") || scheme == QLatin1String("https"))
+        connect(m_reply, SIGNAL(metaDataChanged()),
+                this, SLOT(sendResponseIfNeeded()));
+
+    connect(m_reply, SIGNAL(readyRead()),
+            this, SLOT(forwardData()));
+}
+
+}
+
+#include "moc_QNetworkReplyHandler.cpp"
+
+#endif
diff --git a/WebCore/platform/network/qt/QNetworkReplyHandler.h b/WebCore/platform/network/qt/QNetworkReplyHandler.h
new file mode 100644 (file)
index 0000000..913c5d8
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+    Copyright (C) 2007 Trolltech ASA
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+#ifndef QNETWORKREPLYHANDLER_H
+#define QNETWORKREPLYHANDLER_H
+
+#include <QObject>
+
+#if QT_VERSION >= 0x040400
+
+#include <QNetworkRequest>
+#include <QNetworkAccessManager>
+
+class QNetworkReply;
+
+namespace WebCore {
+
+class ResourceHandle;
+
+class QNetworkReplyHandler : public QObject
+{
+    Q_OBJECT
+public:
+    QNetworkReplyHandler(ResourceHandle *handle);
+
+    QNetworkReply* reply() const { return m_reply; }
+
+    void abort();
+
+private slots:
+    void finish();
+    void sendResponseIfNeeded();
+    void forwardData();
+
+private:
+    void start();
+
+    QNetworkReply* m_reply;
+    ResourceHandle* m_resourceHandle;
+    bool m_redirected;
+    bool m_responseSent;
+    QNetworkAccessManager::Operation m_method;
+    QNetworkRequest m_request;
+};
+
+}
+
+#endif
+
+#endif // QNETWORKREPLYHANDLER_H
index f403352..fd9fae7 100644 (file)
 #include "ChromeClientQt.h"
 #include "FrameLoaderClientQt.h"
 #include "Page.h"
+#include "QNetworkReplyHandler.h"
 
 #include "NotImplemented.h"
 
 #include <QCoreApplication>
+#include <QUrl>
+#if QT_VERSION >= 0x040400
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#endif
 
 namespace WebCore {
 
@@ -122,12 +129,22 @@ bool ResourceHandle::start(Frame* frame)
         return false;
 
     getInternal()->m_frame = static_cast<FrameLoaderClientQt*>(frame->loader()->client())->webFrame();
+#if QT_VERSION < 0x040400
     return QWebNetworkManager::self()->add(this, getInternal()->m_frame->page()->d->networkInterface);
+#else
+    ResourceHandleInternal *d = getInternal();
+    d->m_job = new QNetworkReplyHandler(this);
+    return true;
+#endif
 }
 
 void ResourceHandle::cancel()
 {
+#if QT_VERSION < 0x040400
     QWebNetworkManager::self()->cancel(this);
+#else
+    d->m_job->abort();
+#endif
 }
 
 bool ResourceHandle::loadsBlocked()
@@ -154,6 +171,7 @@ PassRefPtr<SharedBuffer> ResourceHandle::bufferedData()
 
 void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& data)
 {
+#if QT_VERSION < 0x040400
     WebCoreSynchronousLoader syncLoader;
     ResourceHandle handle(request, &syncLoader, true, false, true);
 
@@ -168,6 +186,9 @@ void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request, R
     data = syncLoader.data();
     qDebug() << data.size();
     response = syncLoader.resourceResponse();
+#else
+    notImplemented(); // #### implement me
+#endif
 }
 
  
index a33ccda..dab4ffa 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "ResourceRequestBase.h"
 
+class QNetworkRequest;
+
 namespace WebCore {
 
     struct ResourceRequest : ResourceRequestBase {
@@ -49,12 +51,16 @@ namespace WebCore {
         {
             setHTTPReferrer(referrer);
         }
-        
+
         ResourceRequest()
             : ResourceRequestBase(KURL(), UseProtocolCachePolicy)
         {
         }
-        
+
+#if QT_VERSION >= 0x040400
+        QNetworkRequest toNetworkRequest() const;
+#endif
+
     private:
         friend class ResourceRequestBase;
 
diff --git a/WebCore/platform/network/qt/ResourceRequestQt.cpp b/WebCore/platform/network/qt/ResourceRequestQt.cpp
new file mode 100644 (file)
index 0000000..763d0ff
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+    Copyright (C) 2007 Trolltech ASA
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "ResourceRequest.h"
+
+#include <qglobal.h>
+#if QT_VERSION >= 0x040400
+
+#include <QNetworkRequest>
+#include <QUrl>
+
+namespace WebCore {
+
+QNetworkRequest ResourceRequest::toNetworkRequest() const
+{
+    QNetworkRequest request;
+    request.setUrl(QUrl(url().string()));
+
+    const HTTPHeaderMap &headers = httpHeaderFields();
+    for (HTTPHeaderMap::const_iterator it = headers.begin(), end = headers.end();
+         it != end; ++it) {
+        QByteArray name = QString(it->first).toAscii();
+        QByteArray value = QString(it->second).toAscii();
+        request.setRawHeader(name, value);
+    }
+
+    return request;
+}
+
+}
+
+#endif
index a8b157a..a3dbd64 100644 (file)
@@ -77,9 +77,12 @@ String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
             return e->mimeType;
         ++e;
     }
+    // ### FIXME: Qt 4.4
+#if QT_VERSION < 0x040400
     QString type = QWebFactoryLoader::self()->mimeTypeForExtension(ext);
     if (!type.isEmpty())
         return type;
+#endif
 
     return "application/octet-stream";
 }
index 303b9e4..4678edf 100644 (file)
@@ -30,6 +30,7 @@ PluginInfo* PlugInInfoStore::createPluginInfoForPluginAtIndex(unsigned i)
 {
     //qDebug() << ">>>>>>>>>>> PlugInInfoStore::createPluginInfoForPluginAtIndex(" << i << ")";
 
+#if QT_VERSION < 0x040400
     QWebFactoryLoader *loader = QWebFactoryLoader::self();
     if (i > loader->m_pluginInfo.count())
         return 0;
@@ -46,12 +47,19 @@ PluginInfo* PlugInInfoStore::createPluginInfoForPluginAtIndex(unsigned i)
         info->mimes.append(mime);
     }
     return info;
+#else
+    return 0; // ### FIXME
+#endif
 }
 
 unsigned PlugInInfoStore::pluginCount() const
 {
+#if QT_VERSION < 0x040400
     //qDebug() << ">>>>>>>>>>> PlugInInfoStore::count =" << QWebFactoryLoader::self()->keys().count();
     return QWebFactoryLoader::self()->keys().count();
+#else
+    return 0;
+#endif
 }
 
 String PlugInInfoStore::pluginNameForMIMEType(const String& mimeType)
@@ -63,7 +71,11 @@ String PlugInInfoStore::pluginNameForMIMEType(const String& mimeType)
     
 bool PlugInInfoStore::supportsMIMEType(const WebCore::String& string)
 {
+#if QT_VERSION < 0x040400
     bool supports = QWebFactoryLoader::self()->supportsMimeType(string);
+#else
+    bool supports = false;
+#endif
     //qDebug() << ">>>>>>>>>>> PlugInInfoStore::supportsMIMEType(" << string << ") =" << supports;
     return supports;
 }
index e12ab00..68d06db 100644 (file)
@@ -65,6 +65,9 @@
 #include <qdebug.h>
 #include <qevent.h>
 #include <qpainter.h>
+#if QT_VERSION >= 0x040400
+#include <qnetworkrequest.h>
+#endif
 
 using namespace WebCore;
 
@@ -225,9 +228,14 @@ QWebPage * QWebFrame::page() const
 
 void QWebFrame::load(const QUrl &url)
 {
+#if QT_VERSION < 0x040400
     load(QWebNetworkRequest(url));
+#else
+    load(QNetworkRequest(url));
+#endif
 }
 
+#if QT_VERSION < 0x040400
 void QWebFrame::load(const QWebNetworkRequest &req)
 {
     if (d->parentFrame())
@@ -260,6 +268,38 @@ void QWebFrame::load(const QWebNetworkRequest &req)
         d->page->d->insideOpenCall = false;
 }
 
+#else
+
+void QWebFrame::load(const QNetworkRequest &req)
+{
+    if (d->parentFrame())
+        d->page->d->insideOpenCall = true;
+
+    QUrl url = req.url();
+    QByteArray postData; // ### FIXME = req.postData();
+
+    WebCore::ResourceRequest request(KURL(url.toString()));
+
+    // ### FIXME httpHeader.method();
+
+    QList<QByteArray> httpHeaders = req.rawHeaderList();
+    for (int i = 0; i < httpHeaders.size(); ++i) {
+        const QByteArray &headerName = httpHeaders.at(i);
+        request.addHTTPHeaderField(QString::fromLatin1(headerName), QString::fromLatin1(req.rawHeader(headerName)));
+    }
+
+    if (!postData.isEmpty()) {
+        WTF::RefPtr<WebCore::FormData> formData = new WebCore::FormData(postData.constData(), postData.size());
+        request.setHTTPBody(formData);
+    }
+
+    d->frame->loader()->load(request);
+
+    if (d->parentFrame())
+        d->page->d->insideOpenCall = false;
+}
+#endif
+
 void QWebFrame::setHtml(const QString &html, const QUrl &baseUrl)
 {
     KURL kurl(baseUrl.toString());
index 31ce844..4820533 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <QtCore/qobject.h>
 #include <QtCore/qurl.h>
-
 #include "qwebkitglobal.h"
 
 class QRect;
@@ -36,6 +35,7 @@ class QPixmap;
 class QMouseEvent;
 class QWheelEvent;
 class QWebNetworkRequest;
+class QNetworkRequest;
 
 class QWebFramePrivate;
 class QWebPage;
@@ -59,7 +59,11 @@ public:
     QWebPage *page() const;
 
     void load(const QUrl &url);
+#if QT_VERSION < 0x040400
     void load(const QWebNetworkRequest &request);
+#else
+    void load(const QNetworkRequest &request);
+#endif
     void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
     void setHtml(const QByteArray &html, const QUrl &baseUrl = QUrl());
     void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
index 9a72c84..6888f7b 100644 (file)
@@ -22,6 +22,7 @@
   pages from the web. It has a memory cache for these objects.
 */
 #include <qglobal.h>
+#if QT_VERSION < 0x040400
 #include "qwebframe.h"
 #include "qwebnetworkinterface.h"
 #include "qwebnetworkinterface_p.h"
@@ -1259,3 +1260,4 @@ HostInfo::HostInfo(const QUrl& url)
     }
 }
 
+#endif
index 9f976d5..fdc38d1 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "qwebkitglobal.h"
 
+#if QT_VERSION < 0x040400
+
 class QAuthenticator;
 class QNetworkProxy;
 class QSslError;
@@ -169,3 +171,5 @@ private:
 };
 
 #endif
+
+#endif
index 1e59520..c712ae4 100644 (file)
@@ -23,6 +23,7 @@
 #define QWEBNETWORKINTERFACE_P_H
 
 #include "qwebnetworkinterface.h"
+#if QT_VERSION < 0x040400
 #include <qthread.h>
 #include <qmutex.h>
 
@@ -218,3 +219,5 @@ public:
 };
 
 #endif
+
+#endif
index a0e0a8a..b24d604 100644 (file)
@@ -22,6 +22,8 @@
 #include <qcoreapplication.h>
 #include <qfileinfo.h>
 
+#if QT_VERSION < 0x040400
+
 #ifndef QT_NO_LIBRARY
 Q_GLOBAL_STATIC_WITH_ARGS(QWebFactoryLoader, loader,
                           (QWebObjectPluginFactoryInterface_iid, QCoreApplication::libraryPaths(), QLatin1String("/webplugins")))
@@ -187,4 +189,4 @@ QStringList QWebObjectPlugin::extensionsForMimetype(const QString &mimeType) con
   from the &lt;param&gt; elements contained in the HTML object tag.
 */
 
-
+#endif
index 25e8171..3c7caf7 100644 (file)
@@ -23,6 +23,9 @@
 #include "qwebkitglobal.h"
 #include <QtCore/qplugin.h>
 #include <QtCore/qfactoryinterface.h>
+
+#if QT_VERSION < 0x040400
+
 class QWebObjectPluginConnector;
 class QUrl;
 
@@ -59,3 +62,5 @@ public:
 };
 
 #endif
+
+#endif
index 969230a..e20261f 100644 (file)
@@ -4,6 +4,8 @@
 #include <QtCore/qglobal.h>
 #include "qwebobjectplugin.h"
 
+#if QT_VERSION < 0x040400
+
 /*
   FIXME: This is copied from qfactoryloader_p.h.
   Remove this once we made qfactoryloader public in Qt
@@ -70,3 +72,5 @@ public:
 };
 
 #endif
+
+#endif
index 89fb294..f53c164 100644 (file)
@@ -18,6 +18,7 @@
   
 */
 #include "qwebobjectpluginconnector.h"
+#if QT_VERSION < 0x040400
 #include "qwebnetworkinterface.h"
 #include "qwebnetworkinterface_p.h"
 #include "qwebframe.h"
@@ -59,3 +60,5 @@ QWebNetworkJob *QWebObjectPluginConnector::requestUrl(const QWebNetworkRequest &
     d->frame->page()->networkInterface()->addJob(job);
     return job;
 }
+
+#endif
index 7e289be..62251a3 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "qwebkitglobal.h"
 #include <QtCore/qobject.h>
+
+#if QT_VERSION < 0x040400
+
 #include "qwebnetworkinterface.h"
 
 class QWebFrame;
@@ -62,3 +65,5 @@ private:
 };
 
 #endif
+
+#endif
index a523044..c8e5833 100644 (file)
@@ -73,6 +73,9 @@
 #include <QUndoStack>
 #include <QUrl>
 #include <QPainter>
+#if QT_VERSION >= 0x040400
+#include <QNetworkAccessManager>
+#endif
 
 using namespace WebCore;
 
@@ -118,7 +121,11 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
 
     undoStack = 0;
     mainFrame = 0;
+#if QT_VERSION < 0x040400
     networkInterface = 0;
+#else
+    networkManager = 0;
+#endif
     insideOpenCall = false;
 
     history.d = new QWebPageHistoryPrivate(page->backForwardList());
@@ -130,8 +137,12 @@ QWebPagePrivate::~QWebPagePrivate()
     delete undoStack;
     delete settings;
     delete page;
+#if QT_VERSION >= 0x040400
+    delete networkManager;
+#endif
 }
 
+#if QT_VERSION < 0x040400
 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
 {
     if (insideOpenCall
@@ -139,6 +150,15 @@ QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFra
         return QWebPage::AcceptNavigationRequest;
     return q->navigationRequested(frame, request, type);
 }
+#else
+QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
+{
+    if (insideOpenCall
+        && frame == mainFrame)
+        return QWebPage::AcceptNavigationRequest;
+    return q->navigationRequested(frame, request, type);
+}
+#endif
 
 void QWebPagePrivate::createMainFrame()
 {
@@ -934,7 +954,11 @@ void QWebPage::setViewportSize(const QSize &size) const
 }
 
 
+#if QT_VERSION < 0x040400
 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
+#else
+QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
+#endif
 {
     Q_UNUSED(request)
     return AcceptNavigationRequest;
@@ -1169,19 +1193,6 @@ bool QWebPage::focusNextPrevChild(bool next)
     return false;
 }
 
-void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
-{
-    d->networkInterface = interface;
-}
-
-QWebNetworkInterface *QWebPage::networkInterface() const
-{
-    if (d->networkInterface)
-        return d->networkInterface;
-    else
-        return QWebNetworkInterface::defaultInterface();
-}
-
 QWebSettings *QWebPage::settings()
 {
     return d->settings;
@@ -1197,6 +1208,21 @@ QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
 #endif
 }
 
+#if QT_VERSION < 0x040400
+
+void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
+{
+    d->networkInterface = interface;
+}
+
+QWebNetworkInterface *QWebPage::networkInterface() const
+{
+    if (d->networkInterface)
+        return d->networkInterface;
+    else
+        return QWebNetworkInterface::defaultInterface();
+}
+
 #ifndef QT_NO_NETWORKPROXY
 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
 {
@@ -1209,6 +1235,27 @@ QNetworkProxy QWebPage::networkProxy() const
 }
 #endif
 
+#else
+
+void QWebPage::setNetworkAccessManager(QNetworkAccessManager *manager)
+{
+    if (manager == d->networkManager)
+        return;
+    delete d->networkManager;
+    d->networkManager = manager;
+}
+
+QNetworkAccessManager *QWebPage::networkAccessManager() const
+{
+    if (!d->networkManager) {
+        QWebPage *that = const_cast<QWebPage *>(this);
+        that->d->networkManager = new QNetworkAccessManager(that);
+    }
+    return d->networkManager;
+}
+
+#endif
+
 QString QWebPage::userAgentFor(const QUrl& url) const {
     Q_UNUSED(url)
     return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
index e42f638..d69c305 100644 (file)
@@ -35,6 +35,8 @@ class QUndoStack;
 class QUrl;
 class QWebFrame;
 class QWebNetworkRequest;
+class QNetworkRequest;
+class QNetworkAccessManager;
 
 class QWebPagePrivate;
 class QWebFrameData;
@@ -154,6 +156,7 @@ public:
     bool isModified() const;
     QUndoStack *undoStack() const;
 
+#if QT_VERSION < 0x040400
     void setNetworkInterface(QWebNetworkInterface *interface);
     QWebNetworkInterface *networkInterface() const;
 
@@ -163,6 +166,11 @@ public:
     QNetworkProxy networkProxy() const;
 #endif
 
+#else
+    void setNetworkAccessManager(QNetworkAccessManager *manager);
+    QNetworkAccessManager *networkAccessManager() const;
+#endif
+
     quint64 totalBytes() const;
     quint64 bytesReceived() const;
 
@@ -212,7 +220,11 @@ protected:
     virtual QWebPage *createModalDialog();
     virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
 
+#if QT_VERSION < 0x040400
     virtual NavigationRequestResponse navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, NavigationType type);
+#else
+    virtual NavigationRequestResponse navigationRequested(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
+#endif
     virtual QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
     virtual void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg);
     virtual bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg);
index e5d2574..1b9fc33 100644 (file)
@@ -129,19 +129,25 @@ public:
     QUndoStack *undoStack;
     QWidget *view;
 
-    QWebNetworkInterface *networkInterface;
-
     bool modified;
 
     bool insideOpenCall;
     quint64 m_totalBytes;
     quint64 m_bytesReceived;
 
+#if QT_VERSION < 0x040400
     QWebPage::NavigationRequestResponse navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type);
+
+    QWebNetworkInterface *networkInterface;
 #ifndef QT_NO_NETWORKPROXY
     QNetworkProxy networkProxy;
 #endif
 
+#else
+    QWebPage::NavigationRequestResponse navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type);
+    QNetworkAccessManager *networkManager;
+#endif
+
     QWebPageHistory history;
     QWebPageContext currentContext;
     QWebSettings *settings;
index e372da9..4896900 100644 (file)
@@ -132,7 +132,11 @@ void QWebView::load(const QUrl &url)
     page()->mainFrame()->load(url);
 }
 
+#if QT_VERSION < 0x040400
 void QWebView::load(const QWebNetworkRequest &request)
+#else
+void QWebView::load(const QNetworkRequest &request)
+#endif
 {
     page()->mainFrame()->load(request);
 }
index dd7d644..2bb04db 100644 (file)
@@ -26,6 +26,8 @@
 
 class QWebPage;
 class QWebViewPrivate;
+class QNetworkRequest;
+class QWebNetworkRequest;
 
 class QWEBKIT_EXPORT QWebView : public QWidget
 {
@@ -44,7 +46,11 @@ public:
     void setPage(QWebPage *page);
 
     void load(const QUrl &url);
+#if QT_VERSION < 0x040400
     void load(const QWebNetworkRequest &request);
+#else
+    void load(const QNetworkRequest &request);
+#endif
     void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
     void setHtml(const QByteArray &html, const QUrl &baseUrl = QUrl());
     void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
index 2328103..88cb4c5 100644 (file)
@@ -1,3 +1,38 @@
+2008-01-07  Simon Hausmann  <hausmann@webkit.org>
+
+        Reviewed by Lars.
+
+        Ported of the network backend of the Qt platform to Qt 4.4's new networking API.
+        
+
+        * Api/qwebframe.cpp:
+        (QWebFrame::load):
+        * Api/qwebframe.h:
+        * Api/qwebnetworkinterface.cpp:
+        * Api/qwebnetworkinterface.h:
+        * Api/qwebnetworkinterface_p.h:
+        * Api/qwebobjectplugin.cpp:
+        * Api/qwebobjectplugin.h:
+        * Api/qwebobjectplugin_p.h:
+        * Api/qwebobjectpluginconnector.cpp:
+        * Api/qwebobjectpluginconnector.h:
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::QWebPagePrivate):
+        (QWebPagePrivate::~QWebPagePrivate):
+        (QWebPagePrivate::navigationRequested):
+        (QWebPage::setNetworkInterface):
+        (QWebPage::networkInterface):
+        (QWebPage::setNetworkAccessManager):
+        (QWebPage::networkAccessManager):
+        * Api/qwebpage.h:
+        * Api/qwebpage_p.h:
+        * Api/qwebview.cpp:
+        * Api/qwebview.h:
+        * WebCoreSupport/FrameLoaderClientQt.cpp:
+        (WebCore::FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction):
+        (WebCore::FrameLoaderClientQt::objectContentType):
+        (WebCore::FrameLoaderClientQt::createPlugin):
+
 2008-01-07  Holger Hans Peter Freyther  <holger.freyther@trolltech.com>
 
         Reviewed by Simon.
index 0ada499..912e360 100644 (file)
@@ -53,6 +53,9 @@
 #include <qfileinfo.h>
 
 #include <QDebug>
+#if QT_VERSION >= 0x040400
+#include <QNetworkRequest>
+#endif
 
 namespace WebCore
 {
@@ -798,7 +801,11 @@ void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFun
     Q_ASSERT(!m_policyFunction);
     m_policyFunction = function;
     if (m_webFrame) {
+#if QT_VERSION < 0x040400
         QWebNetworkRequest r(request);
+#else
+        QNetworkRequest r(request.toNetworkRequest());
+#endif
         QWebPage *page = m_webFrame->page();
 
         if (page->d->navigationRequested(m_webFrame, r, QWebPage::NavigationType(action.type())) ==
@@ -883,8 +890,11 @@ ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const
     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
         return ObjectContentImage;
 
+    // ### FIXME Qt 4.4
+#if QT_VERSION < 0x040400
     if (QWebFactoryLoader::self()->supportsMimeType(mimeType))
         return ObjectContentNetscapePlugin;
+#endif
 
     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
         return ObjectContentFrame;
@@ -945,8 +955,11 @@ Widget* FrameLoaderClientQt::createPlugin(const IntSize&, Element* element, cons
         }
     }
 
+    // ### FIXME: qt 4.4
+#if QT_VERSION < 0x040400
     if (!object)
         object = QWebFactoryLoader::self()->create(m_webFrame, qurl, mimeType, params, values);
+#endif
 
     if (object) {
         QWidget *widget = qobject_cast<QWidget *>(object);
index 36a606b..a416ef3 100644 (file)
@@ -1,3 +1,14 @@
+2008-01-07  Simon Hausmann  <hausmann@webkit.org>
+
+        Reviewed by Lars.
+
+        Ported of the network backend of the Qt platform to Qt 4.4's new networking API.
+        
+
+        * DumpRenderTree/qt/main.cpp:
+        * DumpRenderTree/qt/testplugin.cpp:
+        * DumpRenderTree/qt/testplugin.h:
+
 2008-01-05  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Alp Toker.
index d60b4a9..dd4c0e9 100644 (file)
@@ -49,7 +49,9 @@
 #include <execinfo.h>
 #endif
 
+#if QT_VERSION < 0x040400
 Q_IMPORT_PLUGIN(testplugin)
+#endif
 
 void messageHandler(QtMsgType type, const char *message)
 {
index 7305302..27558c9 100644 (file)
@@ -27,6 +27,8 @@
  */
 #include "testplugin.h"
 
+#if QT_VERSION < 0x040400
+
 TestPlugin::TestPlugin(QObject *parent)
     : QWebObjectPlugin(parent)
 {
@@ -66,3 +68,4 @@ QObject *TestPlugin::create(QWebObjectPluginConnector *,
 }
 
 Q_EXPORT_PLUGIN2(testplugin, TestPlugin)
+#endif
index 1b2d2a4..e305069 100644 (file)
@@ -25,6 +25,8 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+#include <qglobal.h>
+#if QT_VERSION < 0x040400
 #define QT_STATICPLUGIN
 #include <qwebobjectplugin.h>
 
@@ -46,3 +48,5 @@ public:
                             const QStringList &argumentNames,
                             const QStringList &argumentValues) const;
 };
+
+#endif