Reviewed by Maciej, landed by Anders
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Nov 2006 03:11:52 +0000 (03:11 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Nov 2006 03:11:52 +0000 (03:11 +0000)
        * CMakeLists.txt: Make linkage against KDE libraries conditional
        * platform/network/qt/ResourceHandleManager.cpp: Added a simple
          Qt base resource handler that supports only requests to the
          local filesystem. Used when compiling without KDE support.
          ResourceHandleManager.cpp/h are to be split up into ResourceHandleManagerKDE
          and ResourceHandleManagerQt in the future, as well as QtJob.cpp/h.
        (WebCore::QtJob::QtJob):
        (WebCore::QtJob::timerEvent):
        (WebCore::ResourceHandleManager::ResourceHandleManager):
        (WebCore::ResourceHandleManager::~ResourceHandleManager):
        (WebCore::ResourceHandleManager::self):
        (WebCore::ResourceHandleManager::remove):
        (WebCore::ResourceHandleManager::add):
        (WebCore::ResourceHandleManager::cancel):
        (WebCore::ResourceHandleManager::deliverJobData):
        * platform/network/qt/ResourceHandleManager.h:
        * platform/qt/FrameQtClient.cpp:
        (WebCore::FrameQtClientDefault::runJavaScriptAlert):
        (WebCore::FrameQtClientDefault::runJavaScriptConfirm):
        (WebCore::FrameQtClientDefault::runJavaScriptPrompt):
        * platform/qt/LoaderFunctionsQt.cpp: Use the Qt messagebox and
          input dialog functions when compiling without KDE support
        (WebCore::ServeSynchronousRequest):

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

WebCore/CMakeLists.txt
WebCore/ChangeLog
WebCore/platform/network/qt/ResourceHandleManager.cpp
WebCore/platform/network/qt/ResourceHandleManager.h
WebCore/platform/qt/FrameQtClient.cpp
WebCore/platform/qt/LoaderFunctionsQt.cpp

index b57a761..0186a78 100644 (file)
@@ -1194,6 +1194,7 @@ set(WebCore_SRCS
 
 kde4_add_library(WebCore-unity SHARED  ${WebCore_SRCS})
 
+IF (WEBKIT_USE_KDE_SUPPORT)
 target_link_libraries(WebCore-unity
   ${QT_QT3SUPPORT_LIBRARY}
   ${QT_QTCORE_LIBRARY}
@@ -1207,5 +1208,17 @@ target_link_libraries(WebCore-unity
   kjs-unity
   pcre-unity
 )
+ELSE (WEBKIT_USE_KDE_SUPPORT)
+target_link_libraries(WebCore-unity
+  ${QT_QTCORE_LIBRARY}
+  ${QT_QTGUI_LIBRARY}
+  ${LIBXSLT_LIBRARIES}
+  ${LIBXML2_LIBRARIES}
+  icuuc
+  wtf-unity
+  kjs-unity
+  pcre-unity
+)
+ENDIF (WEBKIT_USE_KDE_SUPPORT)
 
 install (TARGETS WebCore-unity DESTINATION ${LIB_INSTALL_DIR})
index b591a56..0803613 100644 (file)
@@ -1,3 +1,31 @@
+2006-11-02  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Maciej, landed by Anders
+
+        * CMakeLists.txt: Make linkage against KDE libraries conditional
+        * platform/network/qt/ResourceHandleManager.cpp: Added a simple
+          Qt base resource handler that supports only requests to the
+          local filesystem. Used when compiling without KDE support.
+          ResourceHandleManager.cpp/h are to be split up into ResourceHandleManagerKDE
+          and ResourceHandleManagerQt in the future, as well as QtJob.cpp/h.
+        (WebCore::QtJob::QtJob):
+        (WebCore::QtJob::timerEvent):
+        (WebCore::ResourceHandleManager::ResourceHandleManager):
+        (WebCore::ResourceHandleManager::~ResourceHandleManager):
+        (WebCore::ResourceHandleManager::self):
+        (WebCore::ResourceHandleManager::remove):
+        (WebCore::ResourceHandleManager::add):
+        (WebCore::ResourceHandleManager::cancel):
+        (WebCore::ResourceHandleManager::deliverJobData):
+        * platform/network/qt/ResourceHandleManager.h:
+        * platform/qt/FrameQtClient.cpp:
+        (WebCore::FrameQtClientDefault::runJavaScriptAlert):
+        (WebCore::FrameQtClientDefault::runJavaScriptConfirm):
+        (WebCore::FrameQtClientDefault::runJavaScriptPrompt):
+        * platform/qt/LoaderFunctionsQt.cpp: Use the Qt messagebox and
+          input dialog functions when compiling without KDE support
+        (WebCore::ServeSynchronousRequest):
+
 2006-11-02  David Carson  <dacarson@gmail.com>
 
         Reviewed by Geoff, landed by Anders.
index 442da8a..3bf029c 100644 (file)
 
 #include "config.h"
 
+#if PLATFORM(KDE)
 #include <kio/job.h>
+#endif
+
+#include <QEvent>
+#include <QFile>
 
 #include "FrameQt.h"
 #include "ResourceHandleManager.h"
@@ -37,6 +42,8 @@ namespace WebCore {
 
 static ResourceHandleManager* s_self = 0;
 
+#if PLATFORM(KDE)
+
 ResourceHandleManager::ResourceHandleManager()
     : m_jobToKioMap()
     , m_kioToJobMap()
@@ -192,6 +199,115 @@ void ResourceHandleManager::cancel(ResourceHandle* job)
     job->setError(1);
 }
 
+#else
+// Qt Resource Handle Manager
+
+QtJob::QtJob(const QString& path)
+    : m_path(path)
+{
+    startTimer(0);
+}
+
+void QtJob::timerEvent(QTimerEvent* e)
+{
+    killTimer(e->timerId());
+
+    QFile f(m_path);
+    QByteArray data;
+    if (f.open(QIODevice::ReadOnly)) {
+        data = f.readAll();
+        f.close();
+    };
+
+    emit finished(this, data);
+
+    deleteLater();
+}
+
+ResourceHandleManager::ResourceHandleManager()
+    : m_frameClient(0)
+{
+}
+
+ResourceHandleManager::~ResourceHandleManager()
+{
+}
+
+ResourceHandleManager* ResourceHandleManager::self()
+{
+    if (!s_self)
+        s_self = new ResourceHandleManager();
+
+    return s_self;
+}
+
+void ResourceHandleManager::remove(ResourceHandle* job)
+{
+    ResourceHandleInternal* d = job->getInternal();
+    if (!d || !d->m_client)
+        return;
+
+    // Check if we know about 'job'...
+    QtJob *qtJob = m_resourceToJob.value(job);
+    if (!qtJob)
+        return;
+
+    d->m_client->receivedAllData(job, 0);
+    d->m_client->didFinishLoading(job);
+
+    m_resourceToJob.remove(job);
+    m_jobToResource.remove(qtJob);
+}
+
+void ResourceHandleManager::add(ResourceHandle* resource, FrameQtClient* frameClient)
+{
+    ResourceHandleInternal* d = resource->getInternal();
+
+    if (resource->method() == "POST"
+        || !d->m_request.url().isLocalFile()) {
+        // ### not supported for the local filesystem
+        return;
+    }
+    QtJob* qtJob =  new QtJob(d->m_request.url().path());
+    connect(qtJob, SIGNAL(finished(QtJob *, const QByteArray &)),
+            this, SLOT(deliverJobData(QtJob *, const QByteArray &)));
+
+    m_resourceToJob.insert(resource, qtJob);
+    m_jobToResource.insert(qtJob, resource);
+
+    if (!m_frameClient)
+        m_frameClient = frameClient;
+    else
+        ASSERT(m_frameClient == frameClient);
+}
+
+void ResourceHandleManager::cancel(ResourceHandle* job)
+{
+    remove(job);
+    job->setError(1);
+}
+
+void ResourceHandleManager::deliverJobData(QtJob* job, const QByteArray& data)
+{
+    ResourceHandle* handle = m_jobToResource.value(job);
+    if (!handle)
+        return;
+
+    ResourceHandleInternal* d = handle->getInternal();
+    if (!d || !d->m_client)
+        return;
+
+    d->m_client->didReceiveData(handle, data.data(), data.size());
+
+    handle->setError(0);
+    remove(handle);
+
+    ASSERT(m_frameClient);
+    m_frameClient->checkLoaded();
+}
+
+#endif
+
 } // namespace WebCore
 
 #include "ResourceHandleManager.moc"
index 533af56..ab8258c 100644 (file)
@@ -37,6 +37,7 @@ namespace WebCore {
 
 class FrameQtClient;
 
+#if PLATFORM(KDE)
 class ResourceHandleManager : public QObject {
 Q_OBJECT
 public:
@@ -62,6 +63,48 @@ private:
 
     FrameQtClient* m_frameClient;
 };
+#else
+
+class QtJob : public QObject
+{
+    Q_OBJECT
+public:
+    QtJob(const QString& url);
+
+Q_SIGNALS:
+    void finished(QtJob* job, const QByteArray& data);
+
+protected:
+    virtual void timerEvent(QTimerEvent*);
+
+private:
+    QString m_path;
+};
+
+class ResourceHandleManager : public QObject {
+Q_OBJECT
+public:
+    static ResourceHandleManager* self();
+
+    void add(ResourceHandle*, FrameQtClient*);
+    void cancel(ResourceHandle*);
+
+public Q_SLOTS:
+    void deliverJobData(QtJob* job, const QByteArray& data);
+
+private:
+    ResourceHandleManager();
+    ~ResourceHandleManager();
+
+    void remove(ResourceHandle*);
+
+    QMap<ResourceHandle*, QtJob*> m_resourceToJob;
+    QMap<QtJob*, ResourceHandle*> m_jobToResource;
+
+    FrameQtClient* m_frameClient;
+};
+
+#endif
 
 }
 
index 8421a82..8c877ad 100644 (file)
 #include "LoaderFunctions.h"
 #include "ResourceHandleInternal.h"
 
+#if PLATFORM(KDE)
 #include <kstdguiitem.h>
 #include <kmessagebox.h>
 #include <kinputdialog.h>
+#else
+#include <QInputDialog>
+#include <QMessageBox>
+#endif
 
 namespace WebCore {
 
@@ -101,20 +106,35 @@ void FrameQtClientDefault::checkLoaded()
 
 void FrameQtClientDefault::runJavaScriptAlert(String const& message)
 {
+#if PLATFORM(KDE)
     KMessageBox::error(m_frame->view()->qwidget(), message, "JavaScript");
+#else
+    QMessageBox::warning(m_frame->view()->qwidget(), "JavaScript", message);
+#endif
 }
 
 bool FrameQtClientDefault::runJavaScriptConfirm(const String& message)
 {
+#if PLATFORM(KDE)
     return KMessageBox::warningYesNo(m_frame->view()->qwidget(), message,
                                      "JavaScript", KStdGuiItem::ok(), KStdGuiItem::cancel())
                                      == KMessageBox::Yes;
+#else
+    return QMessageBox::warning(m_frame->view()->qwidget(), "JavaScript", message,
+                                QMessageBox::Yes | QMessageBox::No)
+                               == QMessageBox::Yes;
+#endif
 }
 
 bool FrameQtClientDefault::runJavaScriptPrompt(const String& message, const String& defaultValue, String& result)
 {
     bool ok;
+#if PLATFORM(KDE)
     result = KInputDialog::getText("JavaScript", message, defaultValue, &ok, m_frame->view()->qwidget());
+#else
+    result = QInputDialog::getText(m_frame->view()->qwidget(), "JavaScript", message,
+            QLineEdit::Normal, defaultValue, &ok);
+#endif
 
     return ok;
 }
index a6f5ad8..38cbeea 100644 (file)
@@ -28,7 +28,9 @@
 #include "config.h"
 
 #include <wtf/Vector.h>
+#if PLATFORM(KDE)
 #include <kio/netaccess.h>
+#endif
 
 #include <QFile>
 
@@ -54,19 +56,30 @@ Vector<char> ServeSynchronousRequest(Loader*, DocLoader *docLoader, const Resour
 
     // FIXME: We shouldn't use temporary files for sync jobs!
     QString tempFile;
+#if PLATFORM(KDE)
     if (!KIO::NetAccess::download(KUrl(request.url().url()), tempFile, 0))
         return Vector<char>();
+#else
+    KURL url = request.url();
+    if (!url.isLocalFile())
+        return Vector<char>();
+    tempFile = url.path();
+#endif
 
     QFile file(tempFile);
     if (!file.open(QIODevice::ReadOnly)) {
+#if PLATFORM(KDE)
         KIO::NetAccess::removeTempFile(tempFile);
+#endif
         return Vector<char>();
     }
 
     ASSERT(!file.atEnd());
 
     QByteArray content = file.readAll();
+#if PLATFORM(KDE)
     KIO::NetAccess::removeTempFile(tempFile);
+#endif
 
     Vector<char> resultBuffer;
     resultBuffer.append(content.data(), content.size());