Title: [101071] trunk/Source/WebKit2
Revision
101071
Author
[email protected]
Date
2011-11-23 05:20:01 -0800 (Wed, 23 Nov 2011)

Log Message

[Qt] [WK2] Move PagePolicyClient related code to QtWebPagePolicyClient
https://bugs.webkit.org/show_bug.cgi?id=72959

Reviewed by Andreas Kling.

Split PagePolicyClient related code from QtWebPageProxy/ClientImpl. The new
QtWebPagePolicyClient registers itself with WKPageRef and it's owned by the
QQuickWebViewPrivate. This is a move to clean up QtWebPageProxy object.

QtPolicyInterface abstraction was not helping us as much as the separation of
the client code will. It was more useful when we had multiple WebViews.

* Target.pri:
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::QQuickWebViewPrivate):
(toPolicyAction):
(QQuickWebViewPrivate::navigationPolicyForURL):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
* UIProcess/qt/ClientImpl.cpp:
* UIProcess/qt/ClientImpl.h:
* UIProcess/qt/QtWebPagePolicyClient.cpp: Added.
(QtWebPagePolicyClient::QtWebPagePolicyClient):
(QtWebPagePolicyClient::decidePolicyForNavigationAction):
(toQtWebPagePolicyClient):
(toQtMouseButton):
(toQtKeyboardModifiers):
(QtWebPagePolicyClient::decidePolicyForResponse):
* UIProcess/qt/QtWebPagePolicyClient.h: Renamed from Source/WebKit2/UIProcess/qt/QtPolicyInterface.h.
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::QtWebPageProxy):
(QtWebPageProxy::init):
* UIProcess/qt/QtWebPageProxy.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (101070 => 101071)


--- trunk/Source/WebKit2/ChangeLog	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-23 13:20:01 UTC (rev 101071)
@@ -1,3 +1,39 @@
+2011-11-22  Caio Marcelo de Oliveira Filho  <[email protected]>
+
+        [Qt] [WK2] Move PagePolicyClient related code to QtWebPagePolicyClient
+        https://bugs.webkit.org/show_bug.cgi?id=72959
+
+        Reviewed by Andreas Kling.
+
+        Split PagePolicyClient related code from QtWebPageProxy/ClientImpl. The new
+        QtWebPagePolicyClient registers itself with WKPageRef and it's owned by the
+        QQuickWebViewPrivate. This is a move to clean up QtWebPageProxy object.
+
+        QtPolicyInterface abstraction was not helping us as much as the separation of
+        the client code will. It was more useful when we had multiple WebViews.
+
+        * Target.pri:
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::QQuickWebViewPrivate):
+        (toPolicyAction):
+        (QQuickWebViewPrivate::navigationPolicyForURL):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        * UIProcess/qt/ClientImpl.cpp:
+        * UIProcess/qt/ClientImpl.h:
+        * UIProcess/qt/QtWebPagePolicyClient.cpp: Added.
+        (QtWebPagePolicyClient::QtWebPagePolicyClient):
+        (QtWebPagePolicyClient::decidePolicyForNavigationAction):
+        (toQtWebPagePolicyClient):
+        (toQtMouseButton):
+        (toQtKeyboardModifiers):
+        (QtWebPagePolicyClient::decidePolicyForResponse):
+        * UIProcess/qt/QtWebPagePolicyClient.h: Renamed from Source/WebKit2/UIProcess/qt/QtPolicyInterface.h.
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::QtWebPageProxy):
+        (QtWebPageProxy::init):
+        * UIProcess/qt/QtWebPageProxy.h:
+
 2011-11-23  Raphael Kubo da Costa  <[email protected]>
 
         [CMake] Move the top-level logic to the top-level directory.

Modified: trunk/Source/WebKit2/Target.pri (101070 => 101071)


--- trunk/Source/WebKit2/Target.pri	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/Target.pri	2011-11-23 13:20:01 UTC (rev 101071)
@@ -314,7 +314,6 @@
     UIProcess/WebResourceLoadClient.h \
     UIProcess/WebUIClient.h \
     UIProcess/qt/ClientImpl.h \
-    UIProcess/qt/QtPolicyInterface.h \
     UIProcess/qt/QtGestureRecognizer.h \
     UIProcess/qt/QtPanGestureRecognizer.h \
     UIProcess/qt/QtPinchGestureRecognizer.h \
@@ -323,6 +322,7 @@
     UIProcess/qt/QtDialogRunner.h \
     UIProcess/qt/QtDownloadManager.h \
     UIProcess/qt/QtWebPageLoadClient.h \
+    UIProcess/qt/QtWebPagePolicyClient.h \
     UIProcess/qt/QtWebPageProxy.h \
     UIProcess/qt/QtWebPageUIClient.h \
     UIProcess/qt/qwkhistory.h \
@@ -630,6 +630,7 @@
     UIProcess/qt/QtDialogRunner.cpp \
     UIProcess/qt/QtDownloadManager.cpp \
     UIProcess/qt/QtWebPageLoadClient.cpp \
+    UIProcess/qt/QtWebPagePolicyClient.cpp \
     UIProcess/qt/QtWebPageProxy.cpp \
     UIProcess/qt/QtWebPageUIClient.cpp \
     UIProcess/qt/qwkhistory.cpp \

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2011-11-23 13:20:01 UTC (rev 101071)
@@ -51,14 +51,15 @@
     pageView.reset(new QQuickWebPage(viewport));
 
     QQuickWebPagePrivate* const pageViewPrivate = pageView.data()->d;
-    setPageProxy(new QtWebPageProxy(pageView.data(), q_ptr, 0, this, contextRef, pageGroupRef));
+    setPageProxy(new QtWebPageProxy(pageView.data(), q_ptr, /* interactionEngine */ 0, contextRef, pageGroupRef));
     pageViewPrivate->setPageProxy(pageProxy.data());
 
     QWebPreferencesPrivate::get(pageProxy->preferences())->setAttribute(QWebPreferencesPrivate::AcceleratedCompositingEnabled, true);
     pageProxy->init();
 
+    pageLoadClient.reset(new QtWebPageLoadClient(pageProxy->pageRef(), q_ptr));
+    pagePolicyClient.reset(new QtWebPagePolicyClient(pageProxy->pageRef(), q_ptr));
     pageUIClient.reset(new QtWebPageUIClient(pageProxy->pageRef(), q_ptr));
-    pageLoadClient.reset(new QtWebPageLoadClient(pageProxy->pageRef(), q_ptr));
 }
 
 void QQuickWebViewPrivate::enableMouseEvents()
@@ -343,18 +344,18 @@
     attached->setView(q);
 }
 
-static QtPolicyInterface::PolicyAction toPolicyAction(QQuickWebView::NavigationPolicy policy)
+static QtWebPagePolicyClient::PolicyAction toPolicyAction(QQuickWebView::NavigationPolicy policy)
 {
     switch (policy) {
     case QQuickWebView::UsePolicy:
-        return QtPolicyInterface::Use;
+        return QtWebPagePolicyClient::Use;
     case QQuickWebView::DownloadPolicy:
-        return QtPolicyInterface::Download;
+        return QtWebPagePolicyClient::Download;
     case QQuickWebView::IgnorePolicy:
-        return QtPolicyInterface::Ignore;
+        return QtWebPagePolicyClient::Ignore;
     }
     ASSERT_NOT_REACHED();
-    return QtPolicyInterface::Ignore;
+    return QtWebPagePolicyClient::Ignore;
 }
 
 static bool hasMetaMethod(QObject* object, const char* methodName)
@@ -371,17 +372,17 @@
     It will be called to decide the policy for a navigation: whether the WebView should ignore the navigation,
     continue it or start a download. The return value must be one of the policies in the NavigationPolicy enumeration.
 */
-QtPolicyInterface::PolicyAction QQuickWebViewPrivate::navigationPolicyForURL(const QUrl& url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
+QtWebPagePolicyClient::PolicyAction QQuickWebViewPrivate::navigationPolicyForURL(const QUrl& url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
 {
     Q_Q(QQuickWebView);
     // We need to check this first because invokeMethod() warns if the method doesn't exist for the object.
     if (!hasMetaMethod(q, "navigationPolicyForUrl(QVariant,QVariant,QVariant)"))
-        return QtPolicyInterface::Use;
+        return QtWebPagePolicyClient::Use;
 
     QVariant ret;
     if (QMetaObject::invokeMethod(q, "navigationPolicyForUrl", Q_RETURN_ARG(QVariant, ret), Q_ARG(QVariant, url), Q_ARG(QVariant, button), Q_ARG(QVariant, QVariant(modifiers))))
         return toPolicyAction(static_cast<QQuickWebView::NavigationPolicy>(ret.toInt()));
-    return QtPolicyInterface::Use;
+    return QtWebPagePolicyClient::Use;
 }
 
 void QQuickWebViewPrivate::setPageProxy(QtWebPageProxy* pageProxy)

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


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2011-11-23 13:20:01 UTC (rev 101071)
@@ -135,6 +135,7 @@
     QQuickWebViewExperimental* m_experimental;
 
     friend class QtWebPageLoadClient;
+    friend class QtWebPagePolicyClient;
     friend class QtWebPageProxy;
     friend class QtWebPageUIClient;
     friend class WTR::PlatformWebView;

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2011-11-23 13:20:01 UTC (rev 101071)
@@ -21,9 +21,9 @@
 #ifndef qquickwebview_p_p_h
 #define qquickwebview_p_p_h
 
-#include "QtPolicyInterface.h"
 #include "QtViewportInteractionEngine.h"
 #include "QtWebPageLoadClient.h"
+#include "QtWebPagePolicyClient.h"
 #include "QtWebPageProxy.h"
 #include "QtWebPageUIClient.h"
 
@@ -41,8 +41,7 @@
 class QFileDialog;
 QT_END_NAMESPACE
 
-class QQuickWebViewPrivate : public WebKit::QtPolicyInterface {
-
+class QQuickWebViewPrivate {
     Q_DECLARE_PUBLIC(QQuickWebView)
     friend class QQuickWebViewExperimental;
 
@@ -71,8 +70,7 @@
     void _q_onOpenPanelFinished(int result);
     void _q_onVisibleChanged();
 
-    // QtPolicyInterface.
-    virtual QtPolicyInterface::PolicyAction navigationPolicyForURL(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers);
+    QtWebPagePolicyClient::PolicyAction navigationPolicyForURL(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers);
 
     void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, QtWebPageUIClient::FileChooserType);
     void runJavaScriptAlert(const QString&);
@@ -112,8 +110,9 @@
 
     void setViewInAttachedProperties(QObject*);
 
-    QScopedPointer<QtWebPageUIClient> pageUIClient;
     QScopedPointer<QtWebPageLoadClient> pageLoadClient;
+    QScopedPointer<QtWebPagePolicyClient> pagePolicyClient;
+    QScopedPointer<QtWebPageUIClient> pageUIClient;
 
     QScopedPointer<QQuickWebPage> pageView;
     QScopedPointer<QtViewportInteractionEngine> interactionEngine;

Modified: trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp	2011-11-23 13:20:01 UTC (rev 101071)
@@ -22,99 +22,13 @@
 
 #include "WebPageProxy.h"
 #include "WKAPICast.h"
-#include "WKURLQt.h"
-#include <QtPolicyInterface.h>
 #include <WKArray.h>
-#include <WKFrame.h>
-#include <WKFramePolicyListener.h>
 #include <WKPage.h>
 #include <WKString.h>
 #include <WKType.h>
-#include <WKURLRequest.h>
 
 using namespace WebKit;
 
-static inline QtPolicyInterface* toQtPolicyInterface(const void* clientInfo)
-{
-    ASSERT(clientInfo);
-    return reinterpret_cast<QtPolicyInterface*>(const_cast<void*>(clientInfo));
-}
-
-static Qt::MouseButton toQtMouseButton(WKEventMouseButton button)
-{
-    switch (button) {
-    case kWKEventMouseButtonLeftButton:
-        return Qt::LeftButton;
-    case kWKEventMouseButtonMiddleButton:
-        return Qt::MiddleButton;
-    case kWKEventMouseButtonRightButton:
-        return Qt::RightButton;
-    }
-    return Qt::NoButton;
-}
-
-static Qt::KeyboardModifiers toQtKeyboardModifiers(WKEventModifiers modifiers)
-{
-    Qt::KeyboardModifiers qtModifiers = Qt::NoModifier;
-    if (modifiers & kWKEventModifiersShiftKey)
-        qtModifiers |= Qt::ShiftModifier;
-    if (modifiers & kWKEventModifiersControlKey)
-        qtModifiers |= Qt::ControlModifier;
-    if (modifiers & kWKEventModifiersAltKey)
-        qtModifiers |= Qt::AltModifier;
-    if (modifiers & kWKEventModifiersMetaKey)
-        qtModifiers |= Qt::MetaModifier;
-    return qtModifiers;
-}
-
-static void qt_wk_decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
-{
-    QtPolicyInterface* policyInterface = toQtPolicyInterface(clientInfo);
-    WKURLRef requestURL = WKURLRequestCopyURL(request);
-    QUrl qUrl = WKURLCopyQUrl(requestURL);
-    WKRelease(requestURL);
-
-    QtPolicyInterface::PolicyAction action = "" toQtMouseButton(mouseButton), toQtKeyboardModifiers(modifiers));
-    switch (action) {
-    case QtPolicyInterface::Use:
-        WKFramePolicyListenerUse(listener);
-        break;
-    case QtPolicyInterface::Download:
-        WKFramePolicyListenerDownload(listener);
-        break;
-    case QtPolicyInterface::Ignore:
-        WKFramePolicyListenerIgnore(listener);
-        break;
-    }
-}
-
-static void qt_wk_decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
-{
-    String type = toImpl(response)->resourceResponse().mimeType();
-    type.makeLower();
-    bool canShowMIMEType = toImpl(frame)->canShowMIMEType(type);
-
-    if (WKPageGetMainFrame(page) == frame) {
-        if (canShowMIMEType) {
-            WKFramePolicyListenerUse(listener);
-            return;
-        }
-
-        // If we can't use (show) it then we should download it.
-        WKFramePolicyListenerDownload(listener);
-        return;
-    }
-
-    // We should ignore downloadable top-level content for subframes, with an exception for text/xml and application/xml so we can still support Acid3 test.
-    // It makes the browser intentionally behave differently when it comes to text(application)/xml content in subframes vs. mainframe.
-    if (!canShowMIMEType && !(type == "text/xml" || type == "application/xml")) {
-        WKFramePolicyListenerIgnore(listener);
-        return;
-    }
-
-    WKFramePolicyListenerUse(listener);
-}
-
 void qt_wk_didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*)
 {
     if (!WKStringIsEqualToUTF8CString(messageName, "MessageFromNavigatorQtObject"))
@@ -134,17 +48,6 @@
     toImpl(page)->didReceiveMessageFromNavigatorQtObject(toImpl(str)->string());
 }
 
-void setupPagePolicyClient(QtPolicyInterface* policyInterface, WebPageProxy* webPageProxy)
-{
-    WKPagePolicyClient policyClient;
-    memset(&policyClient, 0, sizeof(WKPagePolicyClient));
-    policyClient.version = kWKPagePolicyClientCurrentVersion;
-    policyClient.clientInfo = policyInterface;
-    policyClient.decidePolicyForNavigationAction = qt_wk_decidePolicyForNavigationAction;
-    policyClient.decidePolicyForResponse = qt_wk_decidePolicyForResponse;
-    WKPageSetPagePolicyClient(toAPI(webPageProxy), &policyClient);
-}
-
 void setupContextInjectedBundleClient(WKContextRef context)
 {
     WKContextInjectedBundleClient injectedBundleClient;

Modified: trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h	2011-11-23 13:20:01 UTC (rev 101071)
@@ -22,13 +22,6 @@
 
 #include <WebKit2/WKContext.h>
 
-namespace WebKit {
-class QtPolicyInterface;
-class WebPageProxy;
-}
-
-void setupPagePolicyClient(WebKit::QtPolicyInterface*, WebKit::WebPageProxy*);
-
 void setupContextInjectedBundleClient(WKContextRef);
 
 #endif /* ClientImpl_h */

Deleted: trunk/Source/WebKit2/UIProcess/qt/QtPolicyInterface.h (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/QtPolicyInterface.h	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPolicyInterface.h	2011-11-23 13:20:01 UTC (rev 101071)
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this program; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef QtPolicyInterface_h
-#define QtPolicyInterface_h
-
-#include <QtCore/QUrl>
-
-namespace WebKit {
-
-class QtPolicyInterface {
-public:
-    enum PolicyAction {
-        Use,
-        Download,
-        Ignore
-    };
-
-    virtual PolicyAction navigationPolicyForURL(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers) = 0;
-};
-
-}
-
-#endif // QtPolicyInterface_h

Added: trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.cpp (0 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.cpp	2011-11-23 13:20:01 UTC (rev 101071)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtWebPagePolicyClient.h"
+
+#include "WKURLQt.h"
+#include "qquickwebview_p.h"
+#include "qquickwebview_p_p.h"
+#include <WKFramePolicyListener.h>
+#include <WKURLRequest.h>
+
+QtWebPagePolicyClient::QtWebPagePolicyClient(WKPageRef pageRef, QQuickWebView* webView)
+    : m_webView(webView)
+{
+    WKPagePolicyClient policyClient;
+    memset(&policyClient, 0, sizeof(WKPagePolicyClient));
+    policyClient.version = kWKPagePolicyClientCurrentVersion;
+    policyClient.clientInfo = this;
+    policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction;
+    policyClient.decidePolicyForResponse = decidePolicyForResponse;
+    WKPageSetPagePolicyClient(pageRef, &policyClient);
+}
+
+QtWebPagePolicyClient::PolicyAction QtWebPagePolicyClient::decidePolicyForNavigationAction(const QUrl& url, Qt::MouseButton mouseButton, Qt::KeyboardModifiers keyboardModifiers)
+{
+    return m_webView->d_func()->navigationPolicyForURL(url, mouseButton, keyboardModifiers);
+}
+
+static inline QtWebPagePolicyClient* toQtWebPagePolicyClient(const void* clientInfo)
+{
+    ASSERT(clientInfo);
+    return reinterpret_cast<QtWebPagePolicyClient*>(const_cast<void*>(clientInfo));
+}
+
+static Qt::MouseButton toQtMouseButton(WKEventMouseButton button)
+{
+    switch (button) {
+    case kWKEventMouseButtonLeftButton:
+        return Qt::LeftButton;
+    case kWKEventMouseButtonMiddleButton:
+        return Qt::MiddleButton;
+    case kWKEventMouseButtonRightButton:
+        return Qt::RightButton;
+    case kWKEventMouseButtonNoButton:
+        return Qt::NoButton;
+    }
+    ASSERT_NOT_REACHED();
+    return Qt::NoButton;
+}
+
+static Qt::KeyboardModifiers toQtKeyboardModifiers(WKEventModifiers modifiers)
+{
+    Qt::KeyboardModifiers qtModifiers = Qt::NoModifier;
+    if (modifiers & kWKEventModifiersShiftKey)
+        qtModifiers |= Qt::ShiftModifier;
+    if (modifiers & kWKEventModifiersControlKey)
+        qtModifiers |= Qt::ControlModifier;
+    if (modifiers & kWKEventModifiersAltKey)
+        qtModifiers |= Qt::AltModifier;
+    if (modifiers & kWKEventModifiersMetaKey)
+        qtModifiers |= Qt::MetaModifier;
+    return qtModifiers;
+}
+
+void QtWebPagePolicyClient::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo)
+{
+    WKURLRef requestURL = WKURLRequestCopyURL(request);
+    QUrl qUrl = WKURLCopyQUrl(requestURL);
+    WKRelease(requestURL);
+
+    PolicyAction action = "" toQtMouseButton(mouseButton), toQtKeyboardModifiers(modifiers));
+    switch (action) {
+    case Use:
+        WKFramePolicyListenerUse(listener);
+        return;
+    case Download:
+        WKFramePolicyListenerDownload(listener);
+        return;
+    case Ignore:
+        WKFramePolicyListenerIgnore(listener);
+        return;
+    }
+    ASSERT_NOT_REACHED();
+}
+
+void QtWebPagePolicyClient::decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*)
+{
+    String type = toImpl(response)->resourceResponse().mimeType();
+    type.makeLower();
+    bool canShowMIMEType = toImpl(frame)->canShowMIMEType(type);
+
+    if (WKPageGetMainFrame(page) == frame) {
+        if (canShowMIMEType) {
+            WKFramePolicyListenerUse(listener);
+            return;
+        }
+
+        // If we can't use (show) it then we should download it.
+        WKFramePolicyListenerDownload(listener);
+        return;
+    }
+
+    // We should ignore downloadable top-level content for subframes, with an exception for text/xml and application/xml so we can still support Acid3 test.
+    // It makes the browser intentionally behave differently when it comes to text(application)/xml content in subframes vs. mainframe.
+    if (!canShowMIMEType && !(type == "text/xml" || type == "application/xml")) {
+        WKFramePolicyListenerIgnore(listener);
+        return;
+    }
+
+    WKFramePolicyListenerUse(listener);
+}
+

Copied: trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.h (from rev 101069, trunk/Source/WebKit2/UIProcess/qt/QtPolicyInterface.h) (0 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPagePolicyClient.h	2011-11-23 13:20:01 UTC (rev 101071)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtWebPagePolicyClient_h
+#define QtWebPagePolicyClient_h
+
+#include <QtCore/QUrl>
+#include <WKPage.h>
+
+class QQuickWebView;
+
+class QtWebPagePolicyClient {
+public:
+    QtWebPagePolicyClient(WKPageRef, QQuickWebView*);
+
+    enum PolicyAction {
+        Use,
+        Download,
+        Ignore
+    };
+
+private:
+    PolicyAction decidePolicyForNavigationAction(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers);
+
+    // WKPagePolicyClient callbacks.
+    static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);
+    static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);
+
+    QQuickWebView* m_webView;
+};
+
+#endif // QtWebPagePolicyClient_h

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp	2011-11-23 13:20:01 UTC (rev 101071)
@@ -44,7 +44,6 @@
 #include "NativeWebMouseEvent.h"
 #include "NativeWebWheelEvent.h"
 #include "NotImplemented.h"
-#include "QtPolicyInterface.h"
 #include "QtViewportInteractionEngine.h"
 #include "QtWebUndoCommand.h"
 #include "WebBackForwardList.h"
@@ -133,14 +132,13 @@
     return (DragOperation)result;
 }
 
-QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebView, QtViewportInteractionEngine* viewportInteractionEngine, QtPolicyInterface* policyInterface, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
+QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebView, QtViewportInteractionEngine* viewportInteractionEngine, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
     : m_qmlWebPage(qmlWebPage)
     , m_qmlWebView(qmlWebView)
     , m_interactionEngine(viewportInteractionEngine)
     , m_panGestureRecognizer(viewportInteractionEngine)
     , m_pinchGestureRecognizer(viewportInteractionEngine)
     , m_tapGestureRecognizer(viewportInteractionEngine, this)
-    , m_policyInterface(policyInterface)
     , m_context(contextRef ? toImpl(contextRef) : defaultWKContext())
     , m_undoStack(adoptPtr(new QUndoStack(this)))
     , m_navigatorQtObjectEnabled(false)
@@ -154,8 +152,6 @@
 void QtWebPageProxy::init()
 {
     m_webPageProxy->initializeWebPage();
-    if (m_policyInterface)
-        setupPagePolicyClient(m_policyInterface, m_webPageProxy.get());
 }
 
 QtWebPageProxy::~QtWebPageProxy()

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h (101070 => 101071)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h	2011-11-23 13:15:41 UTC (rev 101070)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h	2011-11-23 13:20:01 UTC (rev 101071)
@@ -27,7 +27,6 @@
 #include "QtDownloadManager.h"
 #include "QtPanGestureRecognizer.h"
 #include "QtPinchGestureRecognizer.h"
-#include "QtPolicyInterface.h"
 #include "QtTapGestureRecognizer.h"
 #include "ShareableBitmap.h"
 #include "ViewportArguments.h"
@@ -74,7 +73,7 @@
         WebActionCount
     };
 
-    QtWebPageProxy(QQuickWebPage*, QQuickWebView*, WebKit::QtViewportInteractionEngine* = 0, WebKit::QtPolicyInterface* = 0, WKContextRef = 0, WKPageGroupRef = 0);
+    QtWebPageProxy(QQuickWebPage*, QQuickWebView*, WebKit::QtViewportInteractionEngine* = 0, WKContextRef = 0, WKPageGroupRef = 0);
     ~QtWebPageProxy();
 
     virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
@@ -213,7 +212,6 @@
     QtPanGestureRecognizer m_panGestureRecognizer;
     QtPinchGestureRecognizer m_pinchGestureRecognizer;
     QtTapGestureRecognizer m_tapGestureRecognizer;
-    WebKit::QtPolicyInterface* const m_policyInterface;
 
 private:
     bool handleKeyPressEvent(QKeyEvent*);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to