2006-10-15 Nikolas Zimmermann <zimmermann@kde.org>
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Oct 2006 19:20:57 +0000 (19:20 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Oct 2006 19:20:57 +0000 (19:20 +0000)
        Reviewed and landed by ap.

        Changed PlatformResponse handling for Qt. Don't just store
        a QString object containing the data but a new PlatformResponseQt struct
        containing data and url, and store it as pointer. This is compatible
        to the OS X handling and removes the Qt plaform specific hacks from
        CachedCSSStyleSheet, CachedResource & loader.

        Add new file LoaderFunctionsQt, similar to LoaderFunctionsMac, and move
        all methods from TemporaryLinkStubs related to loading in there, and implement
        some like ServeSynchronousRequest (yay for xslt handling!).

        * CMakeLists.txt:
        * loader/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::checkNotify):
        * loader/CachedResource.h:
        (WebCore::CachedResource::CachedResource):
        * loader/loader.cpp:
        (WebCore::Loader::receivedResponse):
        * platform/ResourceLoaderClient.h:
        * platform/ResourceLoaderInternal.h:
        * platform/qt/FrameQt.cpp:
        (WebCore::FrameQt::~FrameQt):
        (WebCore::FrameQt::createEmptyDocument):
        * platform/qt/FrameQt.h:
        (WebCore::QtFrame):
        * platform/qt/FrameQtClient.cpp:
        (WebCore::FrameQtClientDefault::setFrame):
        (WebCore::FrameQtClientDefault::openURL):
        (WebCore::FrameQtClientDefault::loadFinished):
        (WebCore::FrameQtClientDefault::receivedAllData):
        * platform/qt/FrameQtClient.h:
        * platform/qt/LoaderFunctionsQt.cpp: Added.
        (WebCore::ServeSynchronousRequest):
        (WebCore::NumberOfPendingOrLoadingRequests):
        (WebCore::CheckIfReloading):
        (WebCore::CheckCacheObjectStatus):
        (WebCore::IsResponseURLEqualToURL):
        (WebCore::ResponseURL):
        (WebCore::ResponseMIMEType):
        (WebCore::ResponseIsMultipart):
        (WebCore::CacheObjectExpiresTime):
        (WebCore::CachedResource::setResponse):
        (WebCore::CachedResource::setAllData):
        * platform/qt/ResourceLoaderManager.cpp:
        (WebCore::ResourceLoaderManager::remove):
        * platform/qt/ResourceLoaderQt.cpp:
        (WebCore::ResourceLoader::~ResourceLoader):
        (WebCore::ResourceLoader::start):
        (WebCore::ResourceLoader::assembleResponseHeaders):
        (WebCore::ResourceLoader::receivedResponse):
        * platform/qt/TemporaryLinkStubs.cpp:

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

15 files changed:
WebCore/CMakeLists.txt
WebCore/ChangeLog
WebCore/loader/CachedCSSStyleSheet.cpp
WebCore/loader/CachedResource.h
WebCore/loader/loader.cpp
WebCore/platform/ResourceLoaderClient.h
WebCore/platform/ResourceLoaderInternal.h
WebCore/platform/qt/FrameQt.cpp
WebCore/platform/qt/FrameQt.h
WebCore/platform/qt/FrameQtClient.cpp
WebCore/platform/qt/FrameQtClient.h
WebCore/platform/qt/LoaderFunctionsQt.cpp [new file with mode: 0644]
WebCore/platform/qt/ResourceLoaderManager.cpp
WebCore/platform/qt/ResourceLoaderQt.cpp
WebCore/platform/qt/TemporaryLinkStubs.cpp

index 9189148..7632084 100644 (file)
@@ -1020,6 +1020,7 @@ set(WebCore_SRCS
     platform/FloatRect.cpp
     platform/ResourceLoader.cpp
     platform/Path.cpp
+    platform/qt/LoaderFunctionsQt.cpp
     platform/qt/FileChooserQt.cpp
     platform/qt/IconQt.cpp
     platform/qt/AffineTransformQt.cpp
index a151d3b..2fb59dd 100644 (file)
@@ -1,3 +1,58 @@
+2006-10-15  Nikolas Zimmermann  <zimmermann@kde.org>
+
+        Reviewed and landed by ap.
+
+        Changed PlatformResponse handling for Qt. Don't just store
+        a QString object containing the data but a new PlatformResponseQt struct
+        containing data and url, and store it as pointer. This is compatible
+        to the OS X handling and removes the Qt plaform specific hacks from
+        CachedCSSStyleSheet, CachedResource & loader.
+
+        Add new file LoaderFunctionsQt, similar to LoaderFunctionsMac, and move
+        all methods from TemporaryLinkStubs related to loading in there, and implement
+        some like ServeSynchronousRequest (yay for xslt handling!).
+
+        * CMakeLists.txt:
+        * loader/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::checkNotify):
+        * loader/CachedResource.h:
+        (WebCore::CachedResource::CachedResource):
+        * loader/loader.cpp:
+        (WebCore::Loader::receivedResponse):
+        * platform/ResourceLoaderClient.h:
+        * platform/ResourceLoaderInternal.h:
+        * platform/qt/FrameQt.cpp:
+        (WebCore::FrameQt::~FrameQt):
+        (WebCore::FrameQt::createEmptyDocument):
+        * platform/qt/FrameQt.h:
+        (WebCore::QtFrame):
+        * platform/qt/FrameQtClient.cpp:
+        (WebCore::FrameQtClientDefault::setFrame):
+        (WebCore::FrameQtClientDefault::openURL):
+        (WebCore::FrameQtClientDefault::loadFinished):
+        (WebCore::FrameQtClientDefault::receivedAllData):
+        * platform/qt/FrameQtClient.h:
+        * platform/qt/LoaderFunctionsQt.cpp: Added.
+        (WebCore::ServeSynchronousRequest):
+        (WebCore::NumberOfPendingOrLoadingRequests):
+        (WebCore::CheckIfReloading):
+        (WebCore::CheckCacheObjectStatus):
+        (WebCore::IsResponseURLEqualToURL):
+        (WebCore::ResponseURL):
+        (WebCore::ResponseMIMEType):
+        (WebCore::ResponseIsMultipart):
+        (WebCore::CacheObjectExpiresTime):
+        (WebCore::CachedResource::setResponse):
+        (WebCore::CachedResource::setAllData):
+        * platform/qt/ResourceLoaderManager.cpp:
+        (WebCore::ResourceLoaderManager::remove):
+        * platform/qt/ResourceLoaderQt.cpp:
+        (WebCore::ResourceLoader::~ResourceLoader):
+        (WebCore::ResourceLoader::start):
+        (WebCore::ResourceLoader::assembleResponseHeaders):
+        (WebCore::ResourceLoader::receivedResponse):
+        * platform/qt/TemporaryLinkStubs.cpp:
+
 2006-10-14  Rob Buis  <buis@kde.org>
 
         Reviewed by Mitz.
index ec94f31..3860f37 100644 (file)
@@ -95,11 +95,7 @@ void CachedCSSStyleSheet::checkNotify()
 
     CachedResourceClientWalker w(m_clients);
     while (CachedResourceClient *c = w.next()) {
-#if !PLATFORM(QT)
         if (m_response && !IsResponseURLEqualToURL(m_response, m_url))
-#else 
-        if (!m_response.isEmpty() && !IsResponseURLEqualToURL(m_response, m_url))
-#endif
             c->setCSSStyleSheet(ResponseURL(m_response), m_decoder->encoding().name(), m_sheet);
         else
             c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), m_sheet);
index b136440..9590b6a 100644 (file)
@@ -79,9 +79,7 @@ namespace WebCore {
             m_free = false;
             m_cachePolicy = cachePolicy;
             m_request = 0;
-#if !PLATFORM(QT)
             m_response = 0;
-#endif
             m_allData = 0;
             m_expireDate = expireDate;
             m_deleted = false;
index 0a6632f..34561ef 100644 (file)
@@ -121,11 +121,7 @@ void Loader::receivedResponse(ResourceLoader* job, PlatformResponse response)
 {
     Request* req = m_requestsLoading.get(job);
     ASSERT(req);
-#if !PLATFORM(QT)
     ASSERT(response);
-#else
-    ASSERT(!response.isEmpty());
-#endif
 
     req->cachedObject()->setResponse(response);
     req->cachedObject()->setExpireDate(CacheObjectExpiresTime(req->docLoader(), response), false);
index 7a028d8..a0a1a89 100644 (file)
@@ -43,6 +43,9 @@ class NSURLResponse;
 
 #if PLATFORM(QT)
 #include <QString>
+#include <wtf/RefPtr.h>
+
+#include "Shared.h"
 #endif
 
 namespace WebCore {
@@ -54,8 +57,14 @@ namespace WebCore {
     typedef NSData* PlatformData;
     typedef NSURLResponse* PlatformResponse;
 #elif PLATFORM(QT)
+    class PlatformResponseQt : public Shared<PlatformResponseQt> {
+    public:
+        QString data;
+        QString url;
+    };
+
     typedef void* PlatformData;
-    typedef QString PlatformResponse;
+    typedef RefPtr<PlatformResponseQt> PlatformResponse;
 #else
     // Not sure what the strategy for this will be on other platforms.
     typedef struct PlatformDataStruct* PlatformData;
index 81d9764..b7ddd88 100644 (file)
@@ -173,7 +173,7 @@ namespace WebCore {
 #if PLATFORM(QT)
         QString m_charset;
         QString m_mimetype;
-        QString m_response;
+        PlatformResponse m_response;
 #endif
         };
 
index 75e5e62..016a437 100644 (file)
@@ -117,10 +117,10 @@ FrameQt::FrameQt(Page* page, Element* ownerElement, FrameQtClient* client)
 
 FrameQt::~FrameQt()
 {
-    closeURL();
-
     setView(0);
     clearRecordedFormValues();
+
+    cancelAndClear();
 }
 
 bool FrameQt::openURL(const KURL& url)
@@ -248,11 +248,15 @@ bool FrameQt::toolbarVisible()
 
 void FrameQt::createEmptyDocument()
 {
-    // FIXME: Implement like described in this comment from FrameMac:
-    //
     // Although it's not completely clear from the name of this function,
     // it does nothing if we already have a document, and just creates an
     // empty one if we have no document at all.
+
+    // Force creation.
+    if (!d->m_doc) {
+        begin();
+        end();
+    }
 }
 
 Range* FrameQt::markedTextRange() const
index f22c59e..cd8950a 100644 (file)
@@ -150,6 +150,9 @@ private:
 
 };
 
+inline FrameQt* QtFrame(Frame* frame) { return static_cast<FrameQt*>(frame); }
+inline const FrameQt* QtFrame(const Frame* frame) { return static_cast<const FrameQt*>(frame); }
+
 }
 
 #endif 
index ba84544..f56844f 100644 (file)
@@ -52,12 +52,14 @@ FrameQtClientDefault::~FrameQtClientDefault()
 
 void FrameQtClientDefault::setFrame(const FrameQt* frame)
 {
-    Q_ASSERT(frame != 0);
+    ASSERT(frame != 0);
     m_frame = const_cast<FrameQt*>(frame);
 }
 
 void FrameQtClientDefault::openURL(const KURL& url)
 {
+    ASSERT(m_frame);
+
     m_frame->didOpenURL(url);
     m_assignedMimetype = false;
 
@@ -118,6 +120,11 @@ bool FrameQtClientDefault::locationbarVisible() const
     return false;
 }
 
+void FrameQtClientDefault::loadFinished() const
+{
+    // no-op
+}
+
 void FrameQtClientDefault::receivedResponse(ResourceLoader*, PlatformResponse)
 {
     // no-op
@@ -147,6 +154,8 @@ void FrameQtClientDefault::receivedAllData(ResourceLoader* job, PlatformData dat
 {
     m_frame->end();
     m_assignedMimetype = false;
+
+    loadFinished();
 }
 
 }
index 2247348..10550b7 100644 (file)
@@ -52,6 +52,8 @@ public:
     virtual bool personalbarVisible() const = 0;
     virtual bool locationbarVisible() const = 0;
 
+    virtual void loadFinished() const = 0;
+
     virtual void runJavaScriptAlert(String const& message) = 0;
     virtual bool runJavaScriptConfirm(const String& message) = 0;
     virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result) = 0;
@@ -80,6 +82,8 @@ public:
     virtual bool personalbarVisible() const;
     virtual bool locationbarVisible() const;
 
+    virtual void loadFinished() const;
+
     // ResourceLoaderClient
     virtual void receivedResponse(ResourceLoader*, PlatformResponse);
     virtual void receivedData(ResourceLoader*, const char*, int);
diff --git a/WebCore/platform/qt/LoaderFunctionsQt.cpp b/WebCore/platform/qt/LoaderFunctionsQt.cpp
new file mode 100644 (file)
index 0000000..b8dbf69
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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 "config.h"
+
+#include <wtf/Vector.h>
+#include <kio/netaccess.h>
+
+#include <QFile>
+
+#include "Cache.h"
+#include "loader.h"
+#include "FrameQt.h"
+#include "DocLoader.h"
+#include "CachedResource.h"
+#include "DeprecatedString.h"
+
+namespace WebCore {
+
+Vector<char> ServeSynchronousRequest(Loader*, DocLoader* docLoader, ResourceLoader*, KURL& url, DeprecatedString&)
+{
+    // FIXME: Handle last paremeter: "responseHeaders"
+    FrameQt* frame = QtFrame(docLoader->frame());
+
+    if (!frame)
+        return Vector<char>();
+
+    // FIXME: We shouldn't use temporary files for sync jobs!
+    QString tempFile;
+    if (!KIO::NetAccess::download(KUrl(url.url()), tempFile, 0))
+        return Vector<char>();
+
+    QFile file(tempFile);
+    if (!file.open(QIODevice::ReadOnly)) {
+        KIO::NetAccess::removeTempFile(tempFile);
+        return Vector<char>();
+    }
+
+    ASSERT(!file.atEnd());
+
+    QByteArray content = file.readAll();
+    KIO::NetAccess::removeTempFile(tempFile);
+    
+    Vector<char> resultBuffer;
+    resultBuffer.append(content.data(), content.size());
+
+    return resultBuffer;
+}
+
+int NumberOfPendingOrLoadingRequests(DocLoader* docLoader)
+{
+    return Cache::loader()->numRequests(docLoader);
+}
+
+bool CheckIfReloading(WebCore::DocLoader* docLoader)
+{
+    // FIXME: Needs a real implementation!
+    return false;
+}
+
+void CheckCacheObjectStatus(DocLoader* docLoader, CachedResource* cachedObject)
+{
+    // Return from the function for objects that we didn't load from the cache.
+    if (!cachedObject)
+        return;
+
+    switch (cachedObject->status()) {
+        case CachedResource::Persistent:
+        case CachedResource::Cached:
+        case CachedResource::Uncacheable:
+            break;
+        case CachedResource::NotCached:
+        case CachedResource::Unknown:
+        case CachedResource::New:
+        case CachedResource::Pending:
+            return;
+    }
+
+    ASSERT(cachedObject->response());
+
+    // FIXME: Notify the caller that we "loaded".
+}
+
+bool IsResponseURLEqualToURL(PlatformResponse response, const String& url)
+{
+    if (!response)
+        return false;
+
+    return response->url == QString(url);
+}
+
+DeprecatedString ResponseURL(PlatformResponse response)
+{
+    if (!response)
+        return DeprecatedString();
+
+    return response->url;
+}
+
+DeprecatedString ResponseMIMEType(PlatformResponse)
+{
+    // FIXME: Store the response mime type in QtPlatformResponse!
+    return DeprecatedString();
+}
+
+bool ResponseIsMultipart(PlatformResponse response)
+{
+    return ResponseMIMEType(response) == "multipart/x-mixed-replace";
+}
+
+time_t CacheObjectExpiresTime(DocLoader*, PlatformResponse)
+{
+    // FIXME: Implement me!
+    return 0;
+}
+
+void CachedResource::setResponse(PlatformResponse response)
+{
+    m_response = response;
+}
+
+void CachedResource::setAllData(PlatformData allData)
+{
+    m_allData = allData;
+}
+
+} // namespace WebCore
index ca9bb3e..3a9722b 100644 (file)
@@ -136,7 +136,11 @@ void ResourceLoaderManager::remove(ResourceLoader* job)
         // Will take care of informing our client...
         // This must be called before receivedAllData(),
         // otherwhise assembleResponseHeaders() is called too early...
-        job->receivedResponse(headers);
+        RefPtr<PlatformResponseQt> response(new PlatformResponseQt());
+        response->data = headers;    
+        response->url = job->url().url();
+
+        job->receivedResponse(response);
     }
 
     d->client->receivedAllData(job, 0);
index 7bbb087..58d0391 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <kio/job.h>
 
+#include "FrameQt.h"
 #include "DocLoader.h"
 #include "ResourceLoader.h"
 #include "DeprecatedString.h"
@@ -44,11 +45,22 @@ ResourceLoaderInternal::~ResourceLoaderInternal()
 ResourceLoader::~ResourceLoader()
 {
     cancel();
+    delete d;
 }
 
-bool ResourceLoader::start(DocLoader*)
+bool ResourceLoader::start(DocLoader* docLoader)
 {
     ref();
+    d->m_loading = true;
+
+    if (docLoader) {
+        FrameQt* frame = QtFrame(docLoader->frame());
+        if (!frame ) {
+            kill();
+            return false;
+        }
+    }
+
     ResourceLoaderManager::self()->add(this);
     return true;
 }
@@ -61,9 +73,10 @@ void ResourceLoader::cancel()
 void ResourceLoader::assembleResponseHeaders() const
 {
     if (!d->assembledResponseHeaders) {
-        d->responseHeaders = d->m_response;
+        ASSERT(d->m_response);
+
+        d->responseHeaders = d->m_response->data;
         d->assembledResponseHeaders = true;
-        d->m_response = QString(); // Reset
     }
 }
 
@@ -75,7 +88,7 @@ void ResourceLoader::retrieveCharset() const
     }
 }
 
-void ResourceLoader::receivedResponse(QString response)
+void ResourceLoader::receivedResponse(PlatformResponse response)
 {
     Q_ASSERT(method() == "POST");
 
index 81ec04d..39b0d56 100644 (file)
@@ -146,16 +146,6 @@ bool IconDatabase::hasEntryForIconURL(const String& url) { return false; }
 IconDatabase* IconDatabase::sharedIconDatabase() { return 0; }
 bool IconDatabase::setIconURLForPageURL(const String& iconURL, const String& pageURL) { return false; }
 
-void CheckCacheObjectStatus(DocLoader*, CachedResource*) { }
-bool CheckIfReloading(WebCore::DocLoader*) { return false; }
-Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, ResourceLoader*, KURL&, DeprecatedString&) { notImplemented(); return Vector<char>(); }
-time_t CacheObjectExpiresTime(DocLoader*, PlatformResponse) { return 0; }
-bool ResponseIsMultipart(PlatformResponse) { return false; }
-DeprecatedString ResponseMIMEType(PlatformResponse) { return DeprecatedString(); }
-bool IsResponseURLEqualToURL(PlatformResponse , const String& URL) { return false; }
-DeprecatedString ResponseURL(PlatformResponse) { return DeprecatedString(); }
-void CachedResource::setResponse(PlatformResponse) { }
-void CachedResource::setAllData(PlatformData) { }
 }
 
 bool WebCore::historyContains(DeprecatedString const&) { return false; }