Added the possibility to intercept url requests through QWebPage::navigationRequested.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jun 2007 13:49:46 +0000 (13:49 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jun 2007 13:49:46 +0000 (13:49 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@22095 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitQt/Api/qwebpage.cpp
WebKitQt/Api/qwebpage.h
WebKitQt/Api/qwebpage_p.h
WebKitQt/ChangeLog
WebKitQt/WebCoreSupport/FrameLoaderClientQt.cpp

index ae197d1648b836a6f18803221f1867d74eb31617..41832d6bb5c28a6c50a6c852ec62f8e43bdec3e1 100644 (file)
@@ -65,6 +65,7 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
     undoStack = 0;
     mainFrame = 0;
     networkInterface = 0;
+    insideOpenCall = false;
 }
 
 QWebPagePrivate::~QWebPagePrivate()
@@ -73,6 +74,14 @@ QWebPagePrivate::~QWebPagePrivate()
     delete page;
 }
 
+QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QUrl &url, const QHttpRequestHeader &request, const QByteArray &postData)
+{
+    if (insideOpenCall
+        && frame == mainFrame)
+        return QWebPage::AcceptNavigationRequest;
+    return q->navigationRequested(frame, url, request, postData);
+}
+
 void QWebPagePrivate::createMainFrame()
 {
     if (!mainFrame) {
@@ -120,7 +129,9 @@ QWebFrame *QWebPage::createFrame(QWebFrame *parentFrame, QWebFrameData *frameDat
 
 void QWebPage::open(const QUrl &url)
 {
+    d->insideOpenCall = true;
     mainFrame()->d->frame->loader()->load(KURL(url.toString()));
+    d->insideOpenCall = false;
 }
 
 QUrl QWebPage::url() const
@@ -189,6 +200,15 @@ QWebPage *QWebPage::createWindow()
     return 0;
 }
 
+QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QUrl &url, const QHttpRequestHeader &request, const QByteArray &postData)
+{
+    Q_UNUSED(frame)
+    Q_UNUSED(url)
+    Q_UNUSED(request)
+    Q_UNUSED(postData)
+    return AcceptNavigationRequest;
+}
+
 void QWebPage::setWindowGeometry(const QRect& geom)
 {
     Q_UNUSED(geom)
index 3b688e1df96bbe25e28566b4a45a5983a8d0cae7..058ad3782c342eaa82b6f058a17a6dc1d604fabb 100644 (file)
@@ -37,6 +37,8 @@ class QWebPagePrivate;
 class QWebFrameData;
 class QWebNetworkInterface;
 
+class QHttpRequestHeader;
+
 namespace WebCore {
     class ChromeClientQt;
     class FrameLoaderClientQt;
@@ -51,6 +53,11 @@ class QWEBKIT_EXPORT QWebPage : public QWidget
 
     Q_PROPERTY(bool modified READ isModified)
 public:
+    enum NavigationRequestResponse {
+        AcceptNavigationRequest,
+        IgnoreNavigationRequest
+    };
+
     QWebPage(QWidget *parent);
     ~QWebPage();
 
@@ -135,6 +142,8 @@ protected:
     virtual QWebFrame *createFrame(QWebFrame *parentFrame, QWebFrameData *frameData);
     virtual QWebPage *createWindow();
 
+    virtual NavigationRequestResponse navigationRequested(QWebFrame *frame, const QUrl &url, const QHttpRequestHeader &request, const QByteArray &postData);
+
 private:
     friend class QWebFrame;
     friend class QWebPagePrivate;
index 3367849d266c70e2b241f26694ef75664af0123d..219a670f83456aaa28a367a8ddf1038ff06f9505 100644 (file)
@@ -59,6 +59,9 @@ public:
     QWebNetworkInterface *networkInterface;
 
     bool modified;
+
+    bool insideOpenCall;
+    QWebPage::NavigationRequestResponse navigationRequested(QWebFrame *frame, const QUrl &url, const QHttpRequestHeader &request, const QByteArray &postData);
 };
 
 #endif
index e066e62f51e530baeca6fdd81428a275c2870ee1..6ac464b5f5232b3e75a7b5700919dc6a484cab2f 100644 (file)
@@ -1,3 +1,16 @@
+2007-06-11  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Added the possibility to intercept url requests through QWebPage::navigationRequested.
+
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::QWebPagePrivate):
+        (QWebPage::createFrame):
+        * Api/qwebpage.h:
+        * Api/qwebpage_p.h:
+        * WebCoreSupport/FrameLoaderClientQt.cpp:
+
 2007-06-11  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.
index 3762b83120e05b2c18687d2380bcb900d85f2774..a1f139fc0c967d4d0aee9f1a82d45440b9c36811 100644 (file)
@@ -45,6 +45,7 @@
 #include "qwebframe.h"
 #include "qwebframe_p.h"
 #include "qwebobjectplugin_p.h"
+#include "qwebnetworkinterface_p.h"
 
 #include <qfileinfo.h>
 
@@ -809,6 +810,16 @@ void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFun
 {
     Q_ASSERT(!m_policyFunction);
     m_policyFunction = function;
+    if (m_webFrame) {
+        QWebNetworkRequest r;
+        r.init(request);
+        QWebPage *page = m_webFrame->page();
+
+        if (page->d->navigationRequested(m_webFrame, r.url, r.request, r.postData) == QWebPage::IgnoreNavigationRequest) {
+            slotCallPolicyFunction(PolicyIgnore);
+            return;
+        }
+    }
     slotCallPolicyFunction(PolicyUse);
     return;
 }