Diff
Modified: trunk/Source/WebKit2/ChangeLog (101187 => 101188)
--- trunk/Source/WebKit2/ChangeLog 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/ChangeLog 2011-11-26 07:17:59 UTC (rev 101188)
@@ -1,3 +1,43 @@
+2011-11-25 Caio Marcelo de Oliveira Filho <[email protected]>
+
+ [Qt] [WK2] Remove WebContext related code from QtWebPageProxy
+ https://bugs.webkit.org/show_bug.cgi?id=73150
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Creates a QtWebContext class that abstracts away from QtWebPageProxy the
+ handling of creating / maintaining the default WebContext, as well as the
+ code for the WKContextRef clients.
+
+ Another motivation for having this entity is to have a proper place to add
+ objects are bound to the context, like the QtDownloadManager.
+
+ * Target.pri:
+ * UIProcess/qt/ClientImpl.cpp: Removed.
+ * UIProcess/qt/ClientImpl.h: Removed.
+ * UIProcess/qt/QtDownloadManager.cpp:
+ * UIProcess/qt/QtWebContext.cpp: Added.
+ (WebKit::QtWebContext::QtWebContext):
+ (WebKit::QtWebContext::~QtWebContext):
+ (WebKit::QtWebContext::create):
+ (WebKit::QtWebContext::defaultContext):
+ (WebKit::QtWebContext::createWebPage):
+ (WebKit::QtWebContext::setNavigatorQtObjectEnabled):
+ (WebKit::QtWebContext::postMessageToNavigatorQtObject):
+ (WebKit::QtWebContext::initialize):
+ (WebKit::QtWebContext::initializeContextInjectedBundleClient):
+ (WebKit::toQtWebContext):
+ (WebKit::QtWebContext::didReceiveMessageFromInjectedBundle):
+ * UIProcess/qt/QtWebContext.h: Added.
+ (WebKit::QtWebContext::downloadManager):
+ * UIProcess/qt/QtWebPageProxy.cpp:
+ (QtWebPageProxy::QtWebPageProxy):
+ (QtWebPageProxy::~QtWebPageProxy):
+ (QtWebPageProxy::setNavigatorQtObjectEnabled):
+ (QtWebPageProxy::postMessageToNavigatorQtObject):
+ (QtWebPageProxy::handleDownloadRequest):
+ * UIProcess/qt/QtWebPageProxy.h:
+
2011-11-25 Jesus Sanchez-Palencia <[email protected]>
[Qt][WK2] Refactor GestureRecognizers to use QtWebPageEventHandler
Modified: trunk/Source/WebKit2/Target.pri (101187 => 101188)
--- trunk/Source/WebKit2/Target.pri 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/Target.pri 2011-11-26 07:17:59 UTC (rev 101188)
@@ -313,7 +313,7 @@
UIProcess/WebResourceCacheManagerProxy.h \
UIProcess/WebResourceLoadClient.h \
UIProcess/WebUIClient.h \
- UIProcess/qt/ClientImpl.h \
+ UIProcess/qt/QtWebContext.h \
UIProcess/qt/QtWebPageEventHandler.h \
UIProcess/qt/QtGestureRecognizer.h \
UIProcess/qt/QtPanGestureRecognizer.h \
@@ -617,7 +617,7 @@
UIProcess/WebResourceCacheManagerProxy.cpp \
UIProcess/WebResourceLoadClient.cpp \
UIProcess/WebUIClient.cpp \
- UIProcess/qt/ClientImpl.cpp \
+ UIProcess/qt/QtWebContext.cpp \
UIProcess/qt/LayerTreeHostProxyQt.cpp \
UIProcess/qt/QtWebPageEventHandler.cpp \
UIProcess/qt/QtGestureRecognizer.cpp \
Deleted: trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp (101187 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/UIProcess/qt/ClientImpl.cpp 2011-11-26 07:17:59 UTC (rev 101188)
@@ -1,58 +0,0 @@
-/*
- Copyright (C) 2010 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 library 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 library; 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 "ClientImpl.h"
-
-#include "WebPageProxy.h"
-#include "WKAPICast.h"
-#include <WKArray.h>
-#include <WKPage.h>
-#include <WKString.h>
-#include <WKType.h>
-
-using namespace WebKit;
-
-void qt_wk_didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*)
-{
- if (!WKStringIsEqualToUTF8CString(messageName, "MessageFromNavigatorQtObject"))
- return;
-
- ASSERT(messageBody);
- ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID());
-
- WKArrayRef body = static_cast<WKArrayRef>(messageBody);
- ASSERT(WKArrayGetSize(body) == 2);
- ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 0)) == WKPageGetTypeID());
- ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 1)) == WKStringGetTypeID());
-
- WKPageRef page = static_cast<WKPageRef>(WKArrayGetItemAtIndex(body, 0));
- WKStringRef str = static_cast<WKStringRef>(WKArrayGetItemAtIndex(body, 1));
-
- toImpl(page)->didReceiveMessageFromNavigatorQtObject(toImpl(str)->string());
-}
-
-void setupContextInjectedBundleClient(WKContextRef context)
-{
- WKContextInjectedBundleClient injectedBundleClient;
- memset(&injectedBundleClient, 0, sizeof(WKContextInjectedBundleClient));
- injectedBundleClient.version = kWKContextInjectedBundleClientCurrentVersion;
- injectedBundleClient.didReceiveMessageFromInjectedBundle = qt_wk_didReceiveMessageFromInjectedBundle;
- WKContextSetInjectedBundleClient(context, &injectedBundleClient);
-}
Deleted: trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h (101187 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/UIProcess/qt/ClientImpl.h 2011-11-26 07:17:59 UTC (rev 101188)
@@ -1,28 +0,0 @@
-/*
- Copyright (C) 2008 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 library 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 library; 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 ClientImpl_h
-#define ClientImpl_h
-
-#include <WebKit2/WKContext.h>
-
-void setupContextInjectedBundleClient(WKContextRef);
-
-#endif /* ClientImpl_h */
-
Modified: trunk/Source/WebKit2/UIProcess/qt/QtDownloadManager.cpp (101187 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/QtDownloadManager.cpp 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/UIProcess/qt/QtDownloadManager.cpp 2011-11-26 07:17:59 UTC (rev 101188)
@@ -21,7 +21,6 @@
#include "config.h"
#include "QtDownloadManager.h"
-#include "ClientImpl.h"
#include "DownloadProxy.h"
#include "QtWebError.h"
#include "WKStringQt.h"
Added: trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp (0 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp 2011-11-26 07:17:59 UTC (rev 101188)
@@ -0,0 +1,139 @@
+/*
+ * 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 "QtWebContext.h"
+
+#include "MutableArray.h"
+#include "QtDownloadManager.h"
+#include "WKAPICast.h"
+#include "WebContext.h"
+#include "WebPageProxy.h"
+#include <WKArray.h>
+#include <WKPage.h>
+#include <WKString.h>
+#include <WKType.h>
+
+namespace WebKit {
+
+QtWebContext* QtWebContext::s_defaultContext = 0;
+
+QtWebContext::QtWebContext(WebContext* context)
+ : m_context(context)
+{
+}
+
+QtWebContext::~QtWebContext()
+{
+ if (s_defaultContext == this)
+ s_defaultContext = 0;
+}
+
+// Used only by WebKitTestRunner. It avoids calling initialize(), so that we don't register any clients.
+PassRefPtr<QtWebContext> QtWebContext::create(WebContext* context)
+{
+ return adoptRef(new QtWebContext(context));
+}
+
+PassRefPtr<QtWebContext> QtWebContext::defaultContext()
+{
+ if (s_defaultContext)
+ return PassRefPtr<QtWebContext>(s_defaultContext);
+
+ RefPtr<WebContext> context = WebContext::create(String());
+ RefPtr<QtWebContext> defaultContext = QtWebContext::create(context.get());
+ s_defaultContext = defaultContext.get();
+ defaultContext->initialize();
+
+ return defaultContext.release();
+}
+
+PassRefPtr<WebPageProxy> QtWebContext::createWebPage(PageClient* client, WebPageGroup* pageGroup)
+{
+ return m_context->createWebPage(client, pageGroup);
+}
+
+void QtWebContext::setNavigatorQtObjectEnabled(WebPageProxy* webPageProxy, bool enabled)
+{
+ static String messageName("SetNavigatorQtObjectEnabled");
+ RefPtr<MutableArray> body = MutableArray::create();
+ body->append(webPageProxy);
+ RefPtr<WebBoolean> webEnabled = WebBoolean::create(enabled);
+ body->append(webEnabled.get());
+ m_context->postMessageToInjectedBundle(messageName, body.get());
+}
+
+void QtWebContext::postMessageToNavigatorQtObject(WebPageProxy* webPageProxy, const QString& message)
+{
+ static String messageName("MessageToNavigatorQtObject");
+ RefPtr<MutableArray> body = MutableArray::create();
+ body->append(webPageProxy);
+ RefPtr<WebString> contents = WebString::create(String(message));
+ body->append(contents.get());
+ m_context->postMessageToInjectedBundle(messageName, body.get());
+}
+
+void QtWebContext::initialize()
+{
+ m_downloadManager = QtDownloadManager::create(m_context.get());
+ initializeContextInjectedBundleClient();
+}
+
+void QtWebContext::initializeContextInjectedBundleClient()
+{
+ WKContextInjectedBundleClient injectedBundleClient;
+ memset(&injectedBundleClient, 0, sizeof(WKContextInjectedBundleClient));
+ injectedBundleClient.version = kWKContextInjectedBundleClientCurrentVersion;
+ injectedBundleClient.clientInfo = this;
+ injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+ WKContextSetInjectedBundleClient(toAPI(m_context.get()), &injectedBundleClient);
+}
+
+static QtWebContext* toQtWebContext(const void* clientInfo)
+{
+ ASSERT(clientInfo);
+ return reinterpret_cast<QtWebContext*>(const_cast<void*>(clientInfo));
+}
+
+void QtWebContext::didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
+{
+ toQtWebContext(clientInfo)->didReceiveMessageFromInjectedBundle(messageName, messageBody);
+}
+
+void QtWebContext::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
+{
+ if (!WKStringIsEqualToUTF8CString(messageName, "MessageFromNavigatorQtObject"))
+ return;
+
+ ASSERT(messageBody);
+ ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID());
+
+ WKArrayRef body = static_cast<WKArrayRef>(messageBody);
+ ASSERT(WKArrayGetSize(body) == 2);
+ ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 0)) == WKPageGetTypeID());
+ ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 1)) == WKStringGetTypeID());
+
+ WKPageRef page = static_cast<WKPageRef>(WKArrayGetItemAtIndex(body, 0));
+ WKStringRef str = static_cast<WKStringRef>(WKArrayGetItemAtIndex(body, 1));
+
+ toImpl(page)->didReceiveMessageFromNavigatorQtObject(toImpl(str)->string());
+}
+
+}
Added: trunk/Source/WebKit2/UIProcess/qt/QtWebContext.h (0 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/QtWebContext.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebContext.h 2011-11-26 07:17:59 UTC (rev 101188)
@@ -0,0 +1,67 @@
+/*
+ * 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 QtWebContext_h
+#define QtWebContext_h
+
+#include <WKContext.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebKit {
+
+class PageClient;
+class QtDownloadManager;
+class WebContext;
+class WebPageGroup;
+class WebPageProxy;
+
+class QtWebContext : public RefCounted<QtWebContext> {
+public:
+ ~QtWebContext();
+
+ static PassRefPtr<QtWebContext> create(WebContext*);
+ static PassRefPtr<QtWebContext> defaultContext();
+
+ PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebPageGroup*);
+
+ QtDownloadManager* downloadManager() { return m_downloadManager.get(); }
+
+ void setNavigatorQtObjectEnabled(WebPageProxy*, bool);
+ void postMessageToNavigatorQtObject(WebPageProxy*, const QString&);
+
+private:
+ explicit QtWebContext(WebContext*);
+
+ void initialize();
+ void initializeContextInjectedBundleClient();
+
+ static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
+ void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
+
+ static QtWebContext* s_defaultContext;
+
+ RefPtr<WebContext> m_context;
+ RefPtr<QtDownloadManager> m_downloadManager;
+};
+
+}
+
+#endif // QtWebContext_h
Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp (101187 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp 2011-11-26 07:17:59 UTC (rev 101188)
@@ -32,15 +32,14 @@
#include "qwebpreferences_p.h"
#include "qwebpreferences_p_p.h"
-#include "ClientImpl.h"
#include "DownloadProxy.h"
#include "DrawingAreaProxyImpl.h"
#include "qwkhistory.h"
#include "qwkhistory_p.h"
#include "FindIndicator.h"
#include "LocalizedStrings.h"
-#include "MutableArray.h"
#include "NotImplemented.h"
+#include "QtDownloadManager.h"
#include "QtWebPageEventHandler.h"
#include "QtWebUndoCommand.h"
#include "WebBackForwardList.h"
@@ -68,32 +67,15 @@
using namespace WebKit;
using namespace WebCore;
-RefPtr<WebContext> QtWebPageProxy::s_defaultContext;
-RefPtr<QtDownloadManager> QtWebPageProxy::s_downloadManager;
-
-unsigned QtWebPageProxy::s_defaultPageProxyCount = 0;
-
-PassRefPtr<WebContext> QtWebPageProxy::defaultWKContext()
-{
- if (!s_defaultContext) {
- s_defaultContext = WebContext::create(String());
- setupContextInjectedBundleClient(toAPI(s_defaultContext.get()));
- s_downloadManager = QtDownloadManager::create(s_defaultContext.get());
- }
- return s_defaultContext;
-}
-
QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebView, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
: m_qmlWebPage(qmlWebPage)
, m_qmlWebView(qmlWebView)
- , m_context(contextRef ? toImpl(contextRef) : defaultWKContext())
+ , m_context(contextRef ? QtWebContext::create(toImpl(contextRef)) : QtWebContext::defaultContext())
, m_undoStack(adoptPtr(new QUndoStack(this)))
, m_navigatorQtObjectEnabled(false)
{
m_webPageProxy = m_context->createWebPage(this, toImpl(pageGroupRef));
m_history = QWKHistoryPrivate::createHistory(this, m_webPageProxy->backForwardList());
- if (!contextRef)
- s_defaultPageProxyCount++;
}
void QtWebPageProxy::init(QtWebPageEventHandler* eventHandler)
@@ -105,15 +87,6 @@
QtWebPageProxy::~QtWebPageProxy()
{
m_webPageProxy->close();
- // The context is the default one and we're deleting the last QtWebPageProxy.
- if (m_context == s_defaultContext) {
- ASSERT(s_defaultPageProxyCount > 0);
- s_defaultPageProxyCount--;
- if (!s_defaultPageProxyCount) {
- s_defaultContext.clear();
- s_downloadManager.clear();
- }
- }
delete m_history;
}
@@ -423,27 +396,15 @@
void QtWebPageProxy::setNavigatorQtObjectEnabled(bool enabled)
{
- static String messageName("SetNavigatorQtObjectEnabled");
-
ASSERT(enabled != m_navigatorQtObjectEnabled);
// FIXME: Currently we have to keep this information in both processes and the setting is asynchronous.
m_navigatorQtObjectEnabled = enabled;
- RefPtr<MutableArray> body = MutableArray::create();
- body->append(m_webPageProxy.get());
- RefPtr<WebBoolean> webEnabled = WebBoolean::create(enabled);
- body->append(webEnabled.get());
- m_context->postMessageToInjectedBundle(messageName, body.get());
+ m_context->setNavigatorQtObjectEnabled(m_webPageProxy.get(), enabled);
}
void QtWebPageProxy::postMessageToNavigatorQtObject(const QString& message)
{
- static String messageName("MessageToNavigatorQtObject");
-
- RefPtr<MutableArray> body = MutableArray::create();
- body->append(m_webPageProxy.get());
- RefPtr<WebString> contents = WebString::create(String(message));
- body->append(contents.get());
- m_context->postMessageToInjectedBundle(messageName, body.get());
+ m_context->postMessageToNavigatorQtObject(m_webPageProxy.get(), message);
}
void QtWebPageProxy::loadHTMLString(const QString& html, const QUrl& baseUrl)
@@ -550,7 +511,7 @@
downloadItem->d->downloadProxy = download;
connect(downloadItem->d, SIGNAL(receivedResponse(QWebDownloadItem*)), this, SLOT(didReceiveDownloadResponse(QWebDownloadItem*)));
- s_downloadManager->addDownload(download, downloadItem);
+ m_context->downloadManager()->addDownload(download, downloadItem);
}
void QtWebPageProxy::didReceiveDownloadResponse(QWebDownloadItem* downloadItem)
Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h (101187 => 101188)
--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h 2011-11-26 06:15:20 UTC (rev 101187)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h 2011-11-26 07:17:59 UTC (rev 101188)
@@ -24,10 +24,9 @@
#include "DrawingAreaProxy.h"
#include "LayerTreeContext.h"
#include "PageClient.h"
-#include "QtDownloadManager.h"
+#include "QtWebContext.h"
#include "ShareableBitmap.h"
#include "ViewportArguments.h"
-#include "WebContext.h"
#include "WebPageProxy.h"
#include <wtf/RefPtr.h>
#include <QGraphicsView>
@@ -38,13 +37,18 @@
class QUndoStack;
QT_END_NAMESPACE
-class QtWebPageEventHandler;
+class QQuickWebPage;
+class QQuickWebView;
class QtWebError;
+class QtWebPageEventHandler;
+class QWebDownloadItem;
class QWebPreferences;
class QWKHistory;
-class QQuickWebPage;
-class QQuickWebView;
+namespace WebKit {
+class QtWebContext;
+}
+
using namespace WebKit;
// FIXME: needs focus in/out, window activation, support through viewStateDidChange().
@@ -201,12 +205,7 @@
virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
#endif
- static PassRefPtr<WebContext> defaultWKContext();
- static RefPtr<WebContext> s_defaultContext;
- static RefPtr<QtDownloadManager> s_downloadManager;
- static unsigned s_defaultPageProxyCount;
-
- RefPtr<WebContext> m_context;
+ RefPtr<QtWebContext> m_context;
QWKHistory* m_history;
mutable OwnPtr<QWebPreferences> m_preferences;