Title: [103330] trunk/Source
Revision
103330
Author
[email protected]
Date
2011-12-20 07:35:52 -0800 (Tue, 20 Dec 2011)

Log Message

[Qt] Extend QQuickWebview::navigationRequested API
https://bugs.webkit.org/show_bug.cgi?id=73818

Patch by Rafael Brandao <[email protected]> on 2011-12-20
Reviewed by Simon Hausmann.

Source/WebKit/qt:

* declarative/experimental/plugin.cpp:

Source/WebKit2:

Added url of the originating frame on QWebNavigationRequest,
accessible via 'request.originatingUrl' on QML. Download action
was moved to experimental, so in order to use it you should set
'request.action = "" on QML.

* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qwebnavigationrequest.cpp:
(QWebNavigationRequestPrivate::QWebNavigationRequestPrivate):
(QWebNavigationRequest::QWebNavigationRequest):
(QWebNavigationRequest::originatingUrl):
* UIProcess/API/qt/qwebnavigationrequest_p.h:
* UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml:
Tests were modified a bit to reuse urls and also added a test case to check
originating url once a request is done.
* UIProcess/qt/QtWebPagePolicyClient.cpp:
(QtWebPagePolicyClient::decidePolicyForNavigationAction):
* UIProcess/qt/QtWebPagePolicyClient.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/qt/ChangeLog (103329 => 103330)


--- trunk/Source/WebKit/qt/ChangeLog	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit/qt/ChangeLog	2011-12-20 15:35:52 UTC (rev 103330)
@@ -1,3 +1,12 @@
+2011-12-20  Rafael Brandao  <[email protected]>
+
+        [Qt] Extend QQuickWebview::navigationRequested API
+        https://bugs.webkit.org/show_bug.cgi?id=73818
+
+        Reviewed by Simon Hausmann.
+
+        * declarative/experimental/plugin.cpp:
+
 2011-12-20  Jarred Nicholls  <[email protected]>
 
         [Qt] HTTP header injection via QWebPage::userAgentForUrl()

Modified: trunk/Source/WebKit/qt/declarative/experimental/plugin.cpp (103329 => 103330)


--- trunk/Source/WebKit/qt/declarative/experimental/plugin.cpp	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit/qt/declarative/experimental/plugin.cpp	2011-12-20 15:35:52 UTC (rev 103330)
@@ -48,8 +48,8 @@
         qmlRegisterUncreatableType<QWebNavigationListModel>(uri, 3, 0, "NavigationListModel", QObject::tr("Cannot create separate instance of NavigationListModel"));
         qmlRegisterUncreatableType<QWebNavigationHistory>(uri, 3, 0, "NavigationHistory", QObject::tr("Cannot create separate instance of NavigationHistory"));
         qmlRegisterExtendedType<QQuickWebView, QQuickWebViewExperimentalExtension>(uri, 3, 0, "WebView");
-        qmlRegisterUncreatableType<QQuickWebViewExperimental>(uri, 3, 0, "QQuickWebViewExperimental",
-            QObject::tr("Cannot create separate instance of QQuickWebViewExperimental"));
+        qmlRegisterUncreatableType<QQuickWebViewExperimental>(uri, 3, 0, "WebViewExperimental",
+            QObject::tr("Cannot create separate instance of WebViewExperimental"));
         qmlRegisterUncreatableType<QWebViewportInfo>(uri, 3, 0, "QWebViewportInfo",
             QObject::tr("Cannot create separate instance of QWebViewportInfo"));
     }

Modified: trunk/Source/WebKit2/ChangeLog (103329 => 103330)


--- trunk/Source/WebKit2/ChangeLog	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-20 15:35:52 UTC (rev 103330)
@@ -1,3 +1,28 @@
+2011-12-20  Rafael Brandao  <[email protected]>
+
+        [Qt] Extend QQuickWebview::navigationRequested API
+        https://bugs.webkit.org/show_bug.cgi?id=73818
+
+        Reviewed by Simon Hausmann.
+
+        Added url of the originating frame on QWebNavigationRequest,
+        accessible via 'request.originatingUrl' on QML. Download action
+        was moved to experimental, so in order to use it you should set
+        'request.action = "" on QML.
+
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qwebnavigationrequest.cpp:
+        (QWebNavigationRequestPrivate::QWebNavigationRequestPrivate):
+        (QWebNavigationRequest::QWebNavigationRequest):
+        (QWebNavigationRequest::originatingUrl):
+        * UIProcess/API/qt/qwebnavigationrequest_p.h:
+        * UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml:
+        Tests were modified a bit to reuse urls and also added a test case to check
+        originating url once a request is done.
+        * UIProcess/qt/QtWebPagePolicyClient.cpp:
+        (QtWebPagePolicyClient::decidePolicyForNavigationAction):
+        * UIProcess/qt/QtWebPagePolicyClient.h:
+
 2011-12-20  Balazs Kelemen  <[email protected]>
 
         [Qt] WK2 Debugging quirks need some improvement

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h (103329 => 103330)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2011-12-20 15:35:52 UTC (rev 103330)
@@ -65,8 +65,7 @@
 public:
     enum NavigationRequestAction {
         AcceptRequest,
-        IgnoreRequest,
-        DownloadRequest
+        IgnoreRequest
     };
 
     enum ErrorDomain {
@@ -178,8 +177,13 @@
     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
     Q_PROPERTY(bool useTraditionalDesktopBehaviour READ useTraditionalDesktopBehaviour WRITE setUseTraditionalDesktopBehaviour)
     Q_PROPERTY(QWebViewportInfo* viewportInfo READ viewportInfo CONSTANT FINAL)
+    Q_ENUMS(NavigationRequestAction)
 
 public:
+    enum NavigationRequestAction {
+        DownloadRequest = 2
+    };
+
     QQuickWebViewExperimental(QQuickWebView* webView);
     virtual ~QQuickWebViewExperimental();
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwebnavigationrequest.cpp (103329 => 103330)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwebnavigationrequest.cpp	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwebnavigationrequest.cpp	2011-12-20 15:35:52 UTC (rev 103330)
@@ -25,8 +25,9 @@
 
 class QWebNavigationRequestPrivate {
 public:
-    QWebNavigationRequestPrivate(const QUrl& url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
+    QWebNavigationRequestPrivate(const QUrl& url, const QUrl& originatingUrl, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
         : url(url)
+        , originatingUrl(originatingUrl)
         , button(button)
         , modifiers(modifiers)
         , action(QQuickWebView::AcceptRequest)
@@ -38,14 +39,15 @@
     }
 
     QUrl url;
+    QUrl originatingUrl;
     Qt::MouseButton button;
     Qt::KeyboardModifiers modifiers;
     int action;
 };
 
-QWebNavigationRequest::QWebNavigationRequest(const QUrl& url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, QObject* parent)
+QWebNavigationRequest::QWebNavigationRequest(const QUrl& url, const QUrl& originatingUrl, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, QObject* parent)
     : QObject(parent)
-    , d(new QWebNavigationRequestPrivate(url, button, modifiers))
+    , d(new QWebNavigationRequestPrivate(url, originatingUrl, button, modifiers))
 {
 }
 
@@ -68,6 +70,11 @@
     return d->url;
 }
 
+QUrl QWebNavigationRequest::originatingUrl() const
+{
+    return d->originatingUrl;
+}
+
 int QWebNavigationRequest::button() const
 {
     return int(d->button);

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwebnavigationrequest_p.h (103329 => 103330)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwebnavigationrequest_p.h	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwebnavigationrequest_p.h	2011-12-20 15:35:52 UTC (rev 103330)
@@ -30,15 +30,17 @@
 class QWEBKIT_EXPORT QWebNavigationRequest : public QObject {
     Q_OBJECT
     Q_PROPERTY(QUrl url READ url CONSTANT FINAL)
+    Q_PROPERTY(QUrl originatingUrl READ originatingUrl CONSTANT FINAL)
     Q_PROPERTY(int button READ button CONSTANT FINAL)
     Q_PROPERTY(int modifiers READ modifiers CONSTANT FINAL)
     Q_PROPERTY(int action READ action WRITE setAction NOTIFY actionChanged FINAL)
 
 public:
-    QWebNavigationRequest(const QUrl& url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, QObject* parent = 0);
+    QWebNavigationRequest(const QUrl& url, const QUrl& originatingUrl, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, QObject* parent = 0);
     ~QWebNavigationRequest();
 
     QUrl url() const;
+    QUrl originatingUrl() const;
     int button() const;
     int modifiers() const;
     int action() const;

Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml (103329 => 103330)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior/tst_navigationRequested.qml	2011-12-20 15:35:52 UTC (rev 103330)
@@ -1,11 +1,15 @@
 import QtQuick 2.0
 import QtTest 1.0
 import QtWebKit 3.0
+import QtWebKit.experimental 3.0
 
 Item {
     property int expectedLength: 0
     property int totalBytes: 0
     property bool shouldDownload: false
+    property string originatingUrl: ""
+    property url beginUrl: Qt.resolvedUrl("../common/test2.html")
+    property url endUrl: Qt.resolvedUrl("../common/test1.html")
 
     DesktopWebView {
         id: webView
@@ -16,11 +20,12 @@
 
         onNavigationRequested: {
             if (shouldDownload)
-                request.action = ""
+                request.action = ""
             else if (request.button == Qt.MiddleButton && request.modifiers & Qt.ControlModifier) {
                 otherWebView.load(request.url)
                 request.action = ""
             }
+            originatingUrl = request.originatingUrl
         }
 
         experimental.onDownloadRequested: {
@@ -86,20 +91,22 @@
             downloadSpy.clear()
             downloadFinishedSpy.clear()
             shouldDownload = false
+            originatingUrl = ""
         }
 
         function test_usePolicy() {
-            webView.load(Qt.resolvedUrl("../common/test2.html"))
+            webView.load(beginUrl)
             spy.wait()
             spy.clear()
             mouseClick(webView, 100, 100, Qt.LeftButton)
             spy.wait()
             compare(spy.count, 1)
             compare(webView.title, "Test page 1")
+            compare(webView.url, endUrl)
         }
 
         function test_ignorePolicy() {
-            webView.load(Qt.resolvedUrl("../common/test2.html"))
+            webView.load(beginUrl)
             spy.wait()
             spy.clear()
             compare(spy.count, 0)
@@ -108,11 +115,13 @@
             otherSpy.wait()
             compare(spy.count, 0)
             compare(otherSpy.count, 1)
+            compare(webView.url, beginUrl)
             compare(otherWebView.title, "Test page 1")
+            compare(otherWebView.url, endUrl)
         }
 
         function test_downloadPolicy() {
-            webView.load(Qt.resolvedUrl("../common/test2.html"))
+            webView.load(beginUrl)
             spy.wait()
             spy.clear()
             compare(spy.count, 0)
@@ -127,5 +136,16 @@
             compare(downloadFinishedSpy.count, 1)
             compare(totalBytes, expectedLength)
         }
+
+        function test_originatingUrl() {
+            webView.load(beginUrl)
+            spy.wait()
+            spy.clear()
+            mouseClick(webView, 100, 100, Qt.LeftButton)
+            spy.wait()
+            compare(webView.title, "Test page 1")
+            compare(webView.url, endUrl)
+            compare(originatingUrl, beginUrl)
+        }
     }
 }

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.cpp (103329 => 103330)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.cpp	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.cpp	2011-12-20 15:35:52 UTC (rev 103330)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "QtWebPagePolicyClient.h"
 
+#include "WKFrame.h"
 #include "WKURLQt.h"
 #include "qquickwebview_p.h"
 #include "qquickwebview_p_p.h"
@@ -41,18 +42,18 @@
     WKPageSetPagePolicyClient(pageRef, &policyClient);
 }
 
-void QtWebPagePolicyClient::decidePolicyForNavigationAction(const QUrl& url, Qt::MouseButton mouseButton, Qt::KeyboardModifiers keyboardModifiers, WKFramePolicyListenerRef listener)
+void QtWebPagePolicyClient::decidePolicyForNavigationAction(const QUrl& url, const QUrl& originatingUrl, Qt::MouseButton mouseButton, Qt::KeyboardModifiers keyboardModifiers, WKFramePolicyListenerRef listener)
 {
     // NOTE: even though the C API (and the WebKit2 IPC) supports an asynchronous answer, this is not currently working.
     // We are expected to call the listener immediately. See the patch for https://bugs.webkit.org/show_bug.cgi?id=53785.
-    QWebNavigationRequest navigationRequest(url, mouseButton, keyboardModifiers);
+    QWebNavigationRequest navigationRequest(url, originatingUrl, mouseButton, keyboardModifiers);
     emit m_webView->navigationRequested(&navigationRequest);
 
     switch (QQuickWebView::NavigationRequestAction(navigationRequest.action())) {
     case QQuickWebView::IgnoreRequest:
         WKFramePolicyListenerIgnore(listener);
         return;
-    case QQuickWebView::DownloadRequest:
+    case QQuickWebViewExperimental::DownloadRequest:
         WKFramePolicyListenerDownload(listener);
         return;
     case QQuickWebView::AcceptRequest:
@@ -98,12 +99,13 @@
     return qtModifiers;
 }
 
-void QtWebPagePolicyClient::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo)
+void QtWebPagePolicyClient::decidePolicyForNavigationAction(WKPageRef, WKFrameRef frame, WKFrameNavigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo)
 {
-    WKURLRef requestURL = WKURLRequestCopyURL(request);
-    QUrl qUrl = WKURLCopyQUrl(requestURL);
-    WKRelease(requestURL);
-    toQtWebPagePolicyClient(clientInfo)->decidePolicyForNavigationAction(qUrl, toQtMouseButton(mouseButton), toQtKeyboardModifiers(modifiers), listener);
+    WKRetainPtr<WKURLRef> frameURL(AdoptWK, WKFrameCopyURL(frame));
+    WKRetainPtr<WKURLRef> requestURL(AdoptWK, WKURLRequestCopyURL(request));
+    QUrl qUrlFrame = WKURLCopyQUrl(frameURL.get());
+    QUrl qUrl = WKURLCopyQUrl(requestURL.get());
+    toQtWebPagePolicyClient(clientInfo)->decidePolicyForNavigationAction(qUrl, qUrlFrame, toQtMouseButton(mouseButton), toQtKeyboardModifiers(modifiers), listener);
 }
 
 void QtWebPagePolicyClient::decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*)

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.h (103329 => 103330)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.h	2011-12-20 15:21:49 UTC (rev 103329)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.h	2011-12-20 15:35:52 UTC (rev 103330)
@@ -31,7 +31,7 @@
     QtWebPagePolicyClient(WKPageRef, QQuickWebView*);
 
 private:
-    void decidePolicyForNavigationAction(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers, WKFramePolicyListenerRef);
+    void decidePolicyForNavigationAction(const QUrl&, const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers, WKFramePolicyListenerRef);
 
     // WKPagePolicyClient callbacks.
     static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to