Implemented FrameLoaderClient::startDownload() and FrameLoaderClient::download().
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2008 09:43:52 +0000 (09:43 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2008 09:43:52 +0000 (09:43 +0000)
Added two signals to QWebPage to handle downloading of links and handling of
unsupported content.

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

WebCore/ChangeLog
WebCore/platform/network/qt/QNetworkReplyHandler.cpp
WebCore/platform/network/qt/QNetworkReplyHandler.h
WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage.h
WebKit/qt/ChangeLog
WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp

index 84070a8..79c9399 100644 (file)
@@ -1,3 +1,17 @@
+2008-01-23  Simon Hausmann  <hausmann@webkit.org>
+
+        Reviewed by Lars.
+
+        Implemented FrameLoaderClient::startDownload() and FrameLoaderClient::download().
+        
+        Added two signals to QWebPage to handle downloading of links and handling of
+        unsupported content.
+        
+
+        * platform/network/qt/QNetworkReplyHandler.cpp:
+        (WebCore::QNetworkReplyHandler::release):
+        * platform/network/qt/QNetworkReplyHandler.h:
+
 2008-01-22  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Adele Peterson.
index ab240f5..254cb90 100644 (file)
@@ -72,6 +72,16 @@ void QNetworkReplyHandler::abort()
     }
 }
 
+QNetworkReply *QNetworkReplyHandler::release()
+{
+    QNetworkReply *reply = m_reply;
+    if (m_reply) {
+        disconnect(m_reply, 0, this, 0);
+        m_reply = 0;
+    }
+    return reply;
+}
+
 void QNetworkReplyHandler::finish()
 {
     sendResponseIfNeeded();
index 913c5d8..3fe0775 100644 (file)
@@ -42,6 +42,8 @@ public:
 
     void abort();
 
+    QNetworkReply *release();
+
 private slots:
     void finish();
     void sendResponseIfNeeded();
index bde7eeb..aaabcfc 100644 (file)
@@ -864,7 +864,6 @@ void QWebPage::triggerAction(WebAction action, bool checked)
             break;
         case OpenFrameInNewWindow:
             break;
-        case DownloadLinkToDisk:
         case CopyLinkToClipboard:
             editor->copyURL(d->currentContext.linkUrl(), d->currentContext.text());
             break;
@@ -872,6 +871,9 @@ void QWebPage::triggerAction(WebAction action, bool checked)
             openNewWindow(d->currentContext.imageUrl(), frame);
             break;
         case DownloadImageToDisk:
+        case DownloadLinkToDisk:
+            frame->loader()->client()->startDownload(WebCore::ResourceRequest(d->currentContext.linkUrl(), frame->loader()->outgoingReferrer()));
+            break;
         case CopyImageToClipboard:
             break;
         case GoBack:
@@ -1558,4 +1560,18 @@ QWebFrame *QWebPageContext::targetFrame() const
     page to \a geom. This can happen for example through JavaScript.
 */
 
+/*!
+    \fn void QWebPage::handleUnsupportedContent(QNetworkReply *reply)
+
+    This signals is emitted when webkit cannot handle a link the user navigated to.
+
+    At signal emissions time the meta data of the QNetworkReply is available.
+*/
+
+/*!
+    \fn void QWebPage::download(const QNetworkRequest &request)
+
+    This signals is emitted when the user decides to download a link.
+*/
+
 #include "moc_qwebpage.cpp"
index ccfc0a6..e76f935 100644 (file)
@@ -35,6 +35,7 @@ class QUrl;
 class QWebFrame;
 class QWebNetworkRequest;
 class QNetworkRequest;
+class QNetworkReply;
 class QNetworkAccessManager;
 class QWebHistory;
 
@@ -194,6 +195,11 @@ Q_SIGNALS:
     void frameCreated(QWebFrame *frame);
     void geometryChangeRequest(const QRect& geom);
 
+#if QT_VERSION >= 0x040400
+    void handleUnsupportedContent(QNetworkReply *reply);
+    void download(const QNetworkRequest &request);
+#endif
+
     //void addEmbeddableWidget(QWidget *widget);
     //void addEmbeddableWidget(const QString &classid, QWidget *widget);
     //void removeEmbeddableWidget(QWidget *widget);
index f1d7610..63db62a 100644 (file)
@@ -1,3 +1,23 @@
+2008-01-23  Simon Hausmann  <hausmann@webkit.org>
+
+        Reviewed by Lars.
+
+        Implemented FrameLoaderClient::startDownload() and FrameLoaderClient::download().
+        
+        Added two signals to QWebPage to handle downloading of links and handling of
+        unsupported content.
+        
+
+        * Api/qwebpage.cpp:
+        (QWebPage::triggerAction):
+        * Api/qwebpage.h:
+        * WebCoreSupport/FrameLoaderClientQt.cpp:
+        (WebCore::FrameLoaderClientQt::download):
+        (WebCore::FrameLoaderClientQt::assignIdentifierToInitialRequest):
+        (WebCore::FrameLoaderClientQt::dispatchDecidePolicyForMIMEType):
+        (WebCore::FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction):
+        (WebCore::FrameLoaderClientQt::willUseArchive):
+
 2008-01-22  Lars Knoll  <lars@trolltech.com>
 
         Reviewed by Simon.
index 03e08a3..bc7ef4a 100644 (file)
@@ -42,6 +42,9 @@
 #include "HistoryItem.h"
 #include "HTMLFormElement.h"
 #include "NotImplemented.h"
+#include "QNetworkReplyHandler.h"
+#include "ResourceHandleInternal.h"
+#include "ResourceHandle.h"
 
 #include "qwebpage.h"
 #include "qwebframe.h"
@@ -53,6 +56,7 @@
 #include <QDebug>
 #if QT_VERSION >= 0x040400
 #include <QNetworkRequest>
+#include <QNetworkReply>
 #else
 #include "qwebnetworkinterface_p.h"
 #include "qwebobjectplugin_p.h"
@@ -699,9 +703,19 @@ WTF::PassRefPtr<WebCore::DocumentLoader> FrameLoaderClientQt::createDocumentLoad
     return loader.release();
 }
 
-void FrameLoaderClientQt::download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
+void FrameLoaderClientQt::download(WebCore::ResourceHandle* handle, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
 {
-    notImplemented();
+#if QT_VERSION >= 0x040400
+    QNetworkReplyHandler* handler = handle->getInternal()->m_job;
+    QNetworkReply* reply = handler->release();
+    if (reply) {
+        QWebPage *page = m_webFrame->page();
+        if (page->receivers(SIGNAL(handleUnsupportedContent(QNetworkReply *))))
+            emit m_webFrame->page()->handleUnsupportedContent(reply);
+        else
+            reply->abort();
+    }
+#endif
 }
 
 void FrameLoaderClientQt::assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&)
@@ -777,12 +791,15 @@ WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage()
     return newPage->mainFrame()->d->frame.get();
 }
 
-void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String&, const WebCore::ResourceRequest&)
+void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String& MIMEType, const WebCore::ResourceRequest&)
 {
     // we need to call directly here
     Q_ASSERT(!m_policyFunction);
     m_policyFunction = function;
-    slotCallPolicyFunction(PolicyUse);
+    if (canShowMIMEType(MIMEType))
+        slotCallPolicyFunction(PolicyUse);
+    else
+        slotCallPolicyFunction(PolicyDownload);
 }
 
 void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::String&)
@@ -819,9 +836,12 @@ void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::Resourc
     notImplemented();
 }
 
-void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest&)
+void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request)
 {
-    notImplemented();
+#if QT_VERSION >= 0x040400
+    QWebPage *page = m_webFrame->page();
+    emit m_webFrame->page()->download(request.toNetworkRequest());
+#endif
 }
 
 bool FrameLoaderClientQt::willUseArchive(WebCore::ResourceLoader*, const WebCore::ResourceRequest&, const WebCore::KURL&) const