[Qt][WK2] Allow QtWebContext to call directly to QQuickWebView with a WKPageRef
authorjocelyn.turcotte@digia.com <jocelyn.turcotte@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 11:13:31 +0000 (11:13 +0000)
committerjocelyn.turcotte@digia.com <jocelyn.turcotte@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 11:13:31 +0000 (11:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109829

Reviewed by Allan Sandfeld Jensen.
Signed off for WebKit2 by Benjamin Poulain.

Instead of going through WebPageProxy and PageClient to forward
injected bundle messages received by the context, maintain a static map
of WKPageRef to QQuickWebViewPrivate.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::get):
(QQuickWebViewPrivate::~QQuickWebViewPrivate):
(QQuickWebViewPrivate::initialize):
(QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtObject):
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):
* UIProcess/API/qt/raw/qrawwebview.cpp:
* UIProcess/API/qt/raw/qrawwebview_p_p.h:
* UIProcess/PageClient.h:
(PageClient):
* UIProcess/WebPageProxy.h:
(WebPageProxy):
* UIProcess/qt/QtPageClient.cpp:
* UIProcess/qt/QtPageClient.h:
(QtPageClient):
* UIProcess/qt/QtWebContext.cpp:
(WebKit::didReceiveMessageFromInjectedBundle):
* UIProcess/qt/WebPageProxyQt.cpp:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Source/WebKit2/UIProcess/API/qt/raw/qrawwebview.cpp
Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p_p.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/qt/QtPageClient.cpp
Source/WebKit2/UIProcess/qt/QtPageClient.h
Source/WebKit2/UIProcess/qt/QtWebContext.cpp
Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp

index 6ea993b..6931f62 100644 (file)
@@ -1,5 +1,37 @@
 2013-02-14  Jocelyn Turcotte  <jocelyn.turcotte@digia.com>
 
+        [Qt][WK2] Allow QtWebContext to call directly to QQuickWebView with a WKPageRef
+        https://bugs.webkit.org/show_bug.cgi?id=109829
+
+        Reviewed by Allan Sandfeld Jensen.
+        Signed off for WebKit2 by Benjamin Poulain.
+
+        Instead of going through WebPageProxy and PageClient to forward
+        injected bundle messages received by the context, maintain a static map
+        of WKPageRef to QQuickWebViewPrivate.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::get):
+        (QQuickWebViewPrivate::~QQuickWebViewPrivate):
+        (QQuickWebViewPrivate::initialize):
+        (QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtObject):
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+        * UIProcess/API/qt/raw/qrawwebview.cpp:
+        * UIProcess/API/qt/raw/qrawwebview_p_p.h:
+        * UIProcess/PageClient.h:
+        (PageClient):
+        * UIProcess/WebPageProxy.h:
+        (WebPageProxy):
+        * UIProcess/qt/QtPageClient.cpp:
+        * UIProcess/qt/QtPageClient.h:
+        (QtPageClient):
+        * UIProcess/qt/QtWebContext.cpp:
+        (WebKit::didReceiveMessageFromInjectedBundle):
+        * UIProcess/qt/WebPageProxyQt.cpp:
+
+2013-02-14  Jocelyn Turcotte  <jocelyn.turcotte@digia.com>
+
         [Qt][WK2] Keep the WebContext alive during the whole application's lifetime
         https://bugs.webkit.org/show_bug.cgi?id=109827
 
index 32ec42b..c772e91 100644 (file)
@@ -44,6 +44,7 @@
 #endif
 #include "WebPageGroup.h"
 #include "WebPreferences.h"
+#include "qglobal.h"
 #include "qquicknetworkreply_p.h"
 #include "qquicknetworkrequest_p.h"
 #include "qquickwebpage_p_p.h"
@@ -60,6 +61,7 @@
 #include <JavaScriptCore/JSBase.h>
 #include <JavaScriptCore/JSRetainPtr.h>
 #include <QDateTime>
+#include <QMap>
 #include <QtCore/QFile>
 #include <QtQml/QJSValue>
 #include <QtQuick/QQuickView>
@@ -86,6 +88,9 @@ static const int kAxisLockSampleCount = 5;
 static const qreal kAxisLockVelocityThreshold = 300;
 static const qreal kAxisLockVelocityDirectionThreshold = 50;
 
+typedef QMap<WKPageRef, QQuickWebViewPrivate*> PageToViewMap;
+Q_GLOBAL_STATIC(PageToViewMap, pageToView)
+
 static inline QQuickWebViewPrivate* toQQuickWebViewPrivate(const void* clientInfo)
 {
     ASSERT(clientInfo);
@@ -198,6 +203,11 @@ static QQuickWebViewPrivate* createPrivateObject(QQuickWebView* publicObject)
     return new QQuickWebViewLegacyPrivate(publicObject);
 }
 
+QQuickWebViewPrivate* QQuickWebViewPrivate::get(WKPageRef page)
+{
+    return pageToView()->value(page);
+}
+
 QQuickWebViewPrivate::FlickableAxisLocker::FlickableAxisLocker()
     : m_allowedDirection(QQuickFlickable::AutoFlickDirection)
     , m_time(0), m_sampleCount(0)
@@ -301,6 +311,7 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport)
 QQuickWebViewPrivate::~QQuickWebViewPrivate()
 {
     webPageProxy->close();
+    pageToView()->remove(webPage.get());
 }
 
 // Note: we delay this initialization to make sure that QQuickWebView has its d-ptr in-place.
@@ -313,6 +324,8 @@ void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pa
     context = contextRef ? QtWebContext::create(toImpl(contextRef)) : QtWebContext::defaultContext();
     webPageProxy = context->createWebPage(&pageClient, toImpl(pageGroup.get()));
     webPage = toAPI(webPageProxy.get());
+    pageToView()->insert(webPage.get(), this);
+
     webPageProxy->setUseFixedLayout(s_flickableViewportEnabled);
 #if ENABLE(FULLSCREEN_API)
     webPageProxy->fullScreenManager()->setWebView(q_ptr);
@@ -913,10 +926,10 @@ WebCore::IntSize QQuickWebViewPrivate::viewSize() const
 
     \sa postMessage
 */
-void QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtObject(const String& message)
+void QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtObject(WKStringRef message)
 {
     QVariantMap variantMap;
-    variantMap.insert(QLatin1String("data"), QString(message));
+    variantMap.insert(QLatin1String("data"), WKStringCopyQString(message));
     variantMap.insert(QLatin1String("origin"), q_ptr->url());
     emit q_ptr->experimental()->messageReceived(variantMap);
 }
index 6580c82..94936e8 100644 (file)
@@ -65,6 +65,7 @@ class QQuickWebViewPrivate {
 
 public:
     static QQuickWebViewPrivate* get(QQuickWebView* q) { return q->d_ptr.data(); }
+    static QQuickWebViewPrivate* get(WKPageRef);
 
     virtual ~QQuickWebViewPrivate();
 
@@ -124,13 +125,14 @@ public:
 
     // PageClient.
     WebCore::IntSize viewSize() const;
-    void didReceiveMessageFromNavigatorQtObject(const String& message);
     virtual void pageDidRequestScroll(const QPoint& pos) { }
     void processDidCrash();
     void didRelaunchProcess();
     PassOwnPtr<WebKit::DrawingAreaProxy> createDrawingAreaProxy();
     void handleDownloadRequest(WebKit::DownloadProxy*);
 
+    void didReceiveMessageFromNavigatorQtObject(WKStringRef message);
+
 protected:
     class FlickableAxisLocker {
         QQuickFlickable::FlickableDirection m_allowedDirection;
index 4aa3533..500d8f7 100644 (file)
 #include <WebCore/CoordinatedGraphicsScene.h>
 #include <WebKit2/qrawwebview_p.h>
 
-void QRawWebViewPrivate::didReceiveMessageFromNavigatorQtObject(const String& message)
-{
-    notImplemented();
-}
-
 void QRawWebViewPrivate::didChangeViewportProperties(const WebCore::ViewportAttributes& attr)
 {
     notImplemented();
index 029956e..5a8fc34 100644 (file)
@@ -46,7 +46,6 @@ public:
     virtual void countStringMatchesInCustomRepresentation(const String&, WebKit::FindOptions, unsigned maxMatchCount) { }
     virtual void clearAllEditCommands() { }
 
-    virtual void didReceiveMessageFromNavigatorQtObject(const String& message);
     virtual void didChangeViewportProperties(const WebCore::ViewportAttributes& attr);
     virtual void handleDownloadRequest(WebKit::DownloadProxy* download);
 
index d08cc91..2ec20ab 100644 (file)
@@ -121,7 +121,6 @@ public:
 #endif
 #if PLATFORM(QT)
     virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&) = 0;
-    virtual void didReceiveMessageFromNavigatorQtObject(const String&) = 0;
     virtual void handleAuthenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password) = 0;
     virtual void handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors) = 0;
     virtual void handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password) = 0;
index 1d64528..60aa9f6 100644 (file)
@@ -655,7 +655,6 @@ public:
 
 #if PLATFORM(QT)
     void findZoomableAreaForPoint(const WebCore::IntPoint&, const WebCore::IntSize&);
-    void didReceiveMessageFromNavigatorQtObject(const String&);
 #endif
 
 #if PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
index 89a40c9..86ca387 100644 (file)
@@ -245,11 +245,6 @@ void QtPageClient::didFindZoomableArea(const IntPoint& target, const IntRect& ar
     m_eventHandler->didFindZoomableArea(target, area);
 }
 
-void QtPageClient::didReceiveMessageFromNavigatorQtObject(const String& message)
-{
-    QQuickWebViewPrivate::get(m_webView)->didReceiveMessageFromNavigatorQtObject(message);
-}
-
 void QtPageClient::updateTextInputState()
 {
     ASSERT(m_eventHandler);
index bc3e3f1..cb97ce4 100644 (file)
@@ -47,7 +47,6 @@ public:
     virtual WebCore::IntSize viewSize();
     virtual bool isViewFocused();
     virtual bool isViewVisible();
-    virtual void didReceiveMessageFromNavigatorQtObject(const String&);
     virtual void pageDidRequestScroll(const WebCore::IntPoint&);
     virtual void didChangeContentsSize(const WebCore::IntSize&);
     virtual void didChangeViewportProperties(const WebCore::ViewportAttributes&);
index 2675f51..7182d50 100644 (file)
@@ -26,7 +26,7 @@
 #include "WKAPICast.h"
 #include "WebContext.h"
 #include "WebInspectorServer.h"
-#include "WebPageProxy.h"
+#include "qquickwebview_p_p.h"
 #include <WKArray.h>
 #include <WKPage.h>
 #include <WKString.h>
@@ -99,7 +99,7 @@ static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messag
     WKPageRef page = static_cast<WKPageRef>(WKArrayGetItemAtIndex(body, 0));
     WKStringRef str = static_cast<WKStringRef>(WKArrayGetItemAtIndex(body, 1));
 
-    toImpl(page)->didReceiveMessageFromNavigatorQtObject(toImpl(str)->string());
+    QQuickWebViewPrivate::get(page)->didReceiveMessageFromNavigatorQtObject(str);
 }
 
 static void initializeContextInjectedBundleClient(WebContext* context)
index e6d9b90..4f26d65 100644 (file)
@@ -99,11 +99,6 @@ void WebPageProxy::findZoomableAreaForPoint(const IntPoint& point, const IntSize
     m_process->send(Messages::WebPage::FindZoomableAreaForPoint(point, area), m_pageID);
 }
 
-void WebPageProxy::didReceiveMessageFromNavigatorQtObject(const String& contents)
-{
-    m_pageClient->didReceiveMessageFromNavigatorQtObject(contents);
-}
-
 void WebPageProxy::authenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password)
 {
     m_pageClient->handleAuthenticationRequiredRequest(hostname, realm, prefilledUsername, username, password);