From 2d991d73cf413f7d04debf15bcb33a1cf4ef54ad Mon Sep 17 00:00:00 2001 From: andersca Date: Fri, 3 Nov 2006 03:11:52 +0000 Subject: [PATCH] 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): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17552 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/CMakeLists.txt | 13 ++ WebCore/ChangeLog | 28 +++++ .../network/qt/ResourceHandleManager.cpp | 116 ++++++++++++++++++ .../network/qt/ResourceHandleManager.h | 43 +++++++ WebCore/platform/qt/FrameQtClient.cpp | 20 +++ WebCore/platform/qt/LoaderFunctionsQt.cpp | 13 ++ 6 files changed, 233 insertions(+) diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt index b57a76141edd..0186a7894ddd 100644 --- a/WebCore/CMakeLists.txt +++ b/WebCore/CMakeLists.txt @@ -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}) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index b591a5694120..0803613c9169 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,31 @@ +2006-11-02 Simon Hausmann + + 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 Reviewed by Geoff, landed by Anders. diff --git a/WebCore/platform/network/qt/ResourceHandleManager.cpp b/WebCore/platform/network/qt/ResourceHandleManager.cpp index 442da8aa8923..3bf029c61299 100644 --- a/WebCore/platform/network/qt/ResourceHandleManager.cpp +++ b/WebCore/platform/network/qt/ResourceHandleManager.cpp @@ -27,7 +27,12 @@ #include "config.h" +#if PLATFORM(KDE) #include +#endif + +#include +#include #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" diff --git a/WebCore/platform/network/qt/ResourceHandleManager.h b/WebCore/platform/network/qt/ResourceHandleManager.h index 533af563a719..ab8258c69890 100644 --- a/WebCore/platform/network/qt/ResourceHandleManager.h +++ b/WebCore/platform/network/qt/ResourceHandleManager.h @@ -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 m_resourceToJob; + QMap m_jobToResource; + + FrameQtClient* m_frameClient; +}; + +#endif } diff --git a/WebCore/platform/qt/FrameQtClient.cpp b/WebCore/platform/qt/FrameQtClient.cpp index 8421a8247d91..8c877add1685 100644 --- a/WebCore/platform/qt/FrameQtClient.cpp +++ b/WebCore/platform/qt/FrameQtClient.cpp @@ -36,9 +36,14 @@ #include "LoaderFunctions.h" #include "ResourceHandleInternal.h" +#if PLATFORM(KDE) #include #include #include +#else +#include +#include +#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; } diff --git a/WebCore/platform/qt/LoaderFunctionsQt.cpp b/WebCore/platform/qt/LoaderFunctionsQt.cpp index a6f5ad8bf094..38cbeea7035a 100644 --- a/WebCore/platform/qt/LoaderFunctionsQt.cpp +++ b/WebCore/platform/qt/LoaderFunctionsQt.cpp @@ -28,7 +28,9 @@ #include "config.h" #include +#if PLATFORM(KDE) #include +#endif #include @@ -54,19 +56,30 @@ Vector 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(); +#else + KURL url = request.url(); + if (!url.isLocalFile()) + return Vector(); + tempFile = url.path(); +#endif QFile file(tempFile); if (!file.open(QIODevice::ReadOnly)) { +#if PLATFORM(KDE) KIO::NetAccess::removeTempFile(tempFile); +#endif return Vector(); } ASSERT(!file.atEnd()); QByteArray content = file.readAll(); +#if PLATFORM(KDE) KIO::NetAccess::removeTempFile(tempFile); +#endif Vector resultBuffer; resultBuffer.append(content.data(), content.size()); -- 2.36.0