[Qt][WK2] Remove QWKContext class and make sure the WebProcessProxy life is correctly...
authoralexis.menard@openbossa.org <alexis.menard@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Aug 2011 15:13:39 +0000 (15:13 +0000)
committeralexis.menard@openbossa.org <alexis.menard@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Aug 2011 15:13:39 +0000 (15:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66886

Reviewed by Benjamin Poulain.

Remove QWKContext class from Qt APIs as it is too low level for the vision
of the Qt5 API. QtWebPageProxy now holds directly a WebContext which can be a custom one
or default created one. This patch also ensure that the WebProcessProxy is correctly
destroyed at application exit by removing the circular references between the WebContext,
WebProcessProxy, and WebPageProxy.

* UIProcess/API/qt/qdesktopwebview.cpp:
(QDesktopWebViewPrivate::QDesktopWebViewPrivate):
* UIProcess/API/qt/qtouchwebview.cpp:
(QTouchWebViewPrivate::QTouchWebViewPrivate):
* UIProcess/qt/ClientImpl.cpp:
(qt_wk_setStatusText):
* UIProcess/qt/ClientImpl.h:
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::defaultWKContext):
(QtWebPageProxy::QtWebPageProxy):
(QtWebPageProxy::~QtWebPageProxy):
* UIProcess/qt/QtWebPageProxy.h:
* UIProcess/qt/qdesktopwebpageproxy.cpp:
(QDesktopWebPageProxy::QDesktopWebPageProxy):
* UIProcess/qt/qdesktopwebpageproxy.h:
* UIProcess/qt/qtouchwebpageproxy.cpp:
(QTouchWebPageProxy::QTouchWebPageProxy):
* UIProcess/qt/qtouchwebpageproxy.h:
* UIProcess/qt/qwkcontext.cpp: Removed.
* UIProcess/qt/qwkcontext.h: Removed.
* UIProcess/qt/qwkcontext_p.h: Removed.
* WebKit2.pro:

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

15 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp
Source/WebKit2/UIProcess/API/qt/qtouchwebview.cpp
Source/WebKit2/UIProcess/qt/ClientImpl.cpp
Source/WebKit2/UIProcess/qt/ClientImpl.h
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebPageProxy.h
Source/WebKit2/UIProcess/qt/qdesktopwebpageproxy.cpp
Source/WebKit2/UIProcess/qt/qdesktopwebpageproxy.h
Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.cpp
Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.h
Source/WebKit2/UIProcess/qt/qwkcontext.cpp [deleted file]
Source/WebKit2/UIProcess/qt/qwkcontext.h [deleted file]
Source/WebKit2/UIProcess/qt/qwkcontext_p.h [deleted file]
Source/WebKit2/WebKit2.pro

index 626ab13..ed6faa9 100644 (file)
@@ -1,3 +1,39 @@
+2011-08-25  Alexis Menard  <alexis.menard@openbossa.org>
+
+        [Qt][WK2] Remove QWKContext class and make sure the WebProcessProxy life is correctly managed.
+        https://bugs.webkit.org/show_bug.cgi?id=66886
+
+        Reviewed by Benjamin Poulain.
+
+        Remove QWKContext class from Qt APIs as it is too low level for the vision
+        of the Qt5 API. QtWebPageProxy now holds directly a WebContext which can be a custom one
+        or default created one. This patch also ensure that the WebProcessProxy is correctly
+        destroyed at application exit by removing the circular references between the WebContext,
+        WebProcessProxy, and WebPageProxy.
+
+        * UIProcess/API/qt/qdesktopwebview.cpp:
+        (QDesktopWebViewPrivate::QDesktopWebViewPrivate):
+        * UIProcess/API/qt/qtouchwebview.cpp:
+        (QTouchWebViewPrivate::QTouchWebViewPrivate):
+        * UIProcess/qt/ClientImpl.cpp:
+        (qt_wk_setStatusText):
+        * UIProcess/qt/ClientImpl.h:
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::defaultWKContext):
+        (QtWebPageProxy::QtWebPageProxy):
+        (QtWebPageProxy::~QtWebPageProxy):
+        * UIProcess/qt/QtWebPageProxy.h:
+        * UIProcess/qt/qdesktopwebpageproxy.cpp:
+        (QDesktopWebPageProxy::QDesktopWebPageProxy):
+        * UIProcess/qt/qdesktopwebpageproxy.h:
+        * UIProcess/qt/qtouchwebpageproxy.cpp:
+        (QTouchWebPageProxy::QTouchWebPageProxy):
+        * UIProcess/qt/qtouchwebpageproxy.h:
+        * UIProcess/qt/qwkcontext.cpp: Removed.
+        * UIProcess/qt/qwkcontext.h: Removed.
+        * UIProcess/qt/qwkcontext_p.h: Removed.
+        * WebKit2.pro:
+
 2011-08-23  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
 
         [Qt][WK2] Drive tiling from the WebProcess and reuse TiledBackingStore.
index 711c683..51ecbd4 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #include "qdesktopwebview.h"
 #include "qdesktopwebview_p.h"
-#include "qwkcontext.h"
 
 #include <QGraphicsSceneResizeEvent>
 #include <QStyleOptionGraphicsItem>
@@ -39,7 +38,7 @@
 
 QDesktopWebViewPrivate::QDesktopWebViewPrivate(QDesktopWebView* q, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
     : q(q)
-    , page(this, contextRef ? new QWKContext(contextRef) : defaultWKContext(), pageGroupRef)
+    , page(this, contextRef, pageGroupRef)
     , isCrashed(false)
     , navigationController(0)
 {
index e95dabb..26aaa33 100644 (file)
@@ -34,7 +34,7 @@ QTouchWebViewPrivate::QTouchWebViewPrivate(QTouchWebView* q)
     , pageView(new QTouchWebPage(q))
     , viewInterface(q, pageView.data())
     , interactionEngine(q, pageView.data())
-    , page(&viewInterface, &interactionEngine, defaultWKContext())
+    , page(&viewInterface, &interactionEngine)
 {
     QTouchWebPagePrivate* const pageViewPrivate = pageView.data()->d;
     pageViewPrivate->setPage(&page);
index da810d3..77c0aa1 100644 (file)
@@ -27,7 +27,6 @@
 #include "qweberror.h"
 #include "qweberror_p.h"
 #include <PolicyInterface.h>
-#include <qwkcontext.h>
 #include <QtWebPageProxy.h>
 #include <ViewInterface.h>
 #include <WKFrame.h>
 
 using namespace WebKit;
 
-static QWKContext* toQWKContext(const void* clientInfo)
-{
-    if (clientInfo)
-        return reinterpret_cast<QWKContext*>(const_cast<void*>(clientInfo));
-    return 0;
-}
-
 static QtWebPageProxy* toQtWebPageProxy(const void* clientInfo)
 {
     if (clientInfo)
@@ -155,16 +147,6 @@ void qt_wk_setStatusText(WKPageRef, WKStringRef text, const void *clientInfo)
     toViewInterface(clientInfo)->didChangeStatusText(qText);
 }
 
-void qt_wk_didChangeIconForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL, const void* clientInfo)
-{
-    QUrl qUrl = WKURLCopyQUrl(pageURL);
-    emit toQWKContext(clientInfo)->iconChangedForPageURL(qUrl);
-}
-
-void qt_wk_didRemoveAllIcons(WKIconDatabaseRef iconDatabase, const void* clientInfo)
-{
-}
-
 static Qt::MouseButton toQtMouseButton(WKEventMouseButton button)
 {
     switch (button) {
index bfb7629..41f899b 100644 (file)
@@ -41,10 +41,6 @@ void qt_wk_didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef, WKSameDocume
 // ui client
 void qt_wk_setStatusText(WKPageRef page, WKStringRef text, const void *clientInfo);
 
-// IconDatabase client.
-void qt_wk_didChangeIconForPageURL(WKIconDatabaseRef, WKURLRef, const void* clientInfo);
-void qt_wk_didRemoveAllIcons(WKIconDatabaseRef, const void* clientInfo);
-
 // Policy client.
 void qt_wk_decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);
 
index ddaa4d6..d22c3b0 100644 (file)
@@ -24,8 +24,6 @@
 #include "qwkpreferences_p.h"
 
 #include "ClientImpl.h"
-#include "qwkcontext.h"
-#include "qwkcontext_p.h"
 #include "qwkhistory.h"
 #include "qwkhistory_p.h"
 #include "ViewInterface.h"
 using namespace WebKit;
 using namespace WebCore;
 
-QWKContext* defaultWKContext()
+
+RefPtr<WebContext> QtWebPageProxy::s_defaultContext;
+
+unsigned QtWebPageProxy::s_defaultPageProxyCount = 0;
+
+PassRefPtr<WebContext> QtWebPageProxy::defaultWKContext()
 {
-    static QWKContext* defaultContext = new QWKContext();
-    return defaultContext;
+    if (!s_defaultContext)
+        s_defaultContext = WebContext::create(String());
+    return s_defaultContext;
 }
 
 static inline Qt::DropActions dragOperationToDropActions(unsigned dragOperations)
@@ -95,18 +99,20 @@ WebCore::DragOperation dropActionToDragOperation(Qt::DropActions actions)
     return (DragOperation)result;
 }
 
-QtWebPageProxy::QtWebPageProxy(ViewInterface* viewInterface, PolicyInterface* policyInterface, QWKContext* c, WKPageGroupRef pageGroupRef)
+QtWebPageProxy::QtWebPageProxy(ViewInterface* viewInterface, PolicyInterface* policyInterface, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
     : m_viewInterface(viewInterface)
     , m_policyInterface(policyInterface)
-    , m_context(c)
+    , m_context(contextRef ? toImpl(contextRef) : defaultWKContext())
     , m_preferences(0)
     , m_undoStack(adoptPtr(new QUndoStack(this)))
     , m_loadProgress(0)
 {
     ASSERT(viewInterface);
     memset(m_actions, 0, sizeof(m_actions));
-    m_webPageProxy = m_context->d->context->createWebPage(this, toImpl(pageGroupRef));
+    m_webPageProxy = m_context->createWebPage(this, toImpl(pageGroupRef));
     m_history = QWKHistoryPrivate::createHistory(this, m_webPageProxy->backForwardList());
+    if (!contextRef)
+        s_defaultPageProxyCount++;
 }
 
 void QtWebPageProxy::init()
@@ -204,6 +210,14 @@ void QtWebPageProxy::init()
 QtWebPageProxy::~QtWebPageProxy()
 {
     m_webPageProxy->close();
+    m_context->disconnectProcess(m_context->process());
+    // 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();
+    }
     delete m_history;
 }
 
index 4bc5ca6..a6c8653 100644 (file)
@@ -30,6 +30,7 @@
 #include "ShareableBitmap.h"
 #include "ViewportArguments.h"
 #include "ViewInterface.h"
+#include "WebContext.h"
 #include "WebPageProxy.h"
 #include <wtf/RefPtr.h>
 #include <QBasicTimer>
@@ -42,14 +43,11 @@ QT_BEGIN_NAMESPACE
 class QUndoStack;
 QT_END_NAMESPACE
 
-class QWKContext;
 class QWKHistory;
 class QWKPreferences;
 
 using namespace WebKit;
 
-QWKContext *defaultWKContext();
-
 WebCore::DragOperation dropActionToDragOperation(Qt::DropActions actions);
 
 // FIXME: needs focus in/out, window activation, support through viewStateDidChange().
@@ -71,7 +69,7 @@ public:
         WebActionCount
     };
 
-    QtWebPageProxy(WebKit::ViewInterface*, WebKit::PolicyInterface*, QWKContext*, WKPageGroupRef = 0);
+    QtWebPageProxy(WebKit::ViewInterface*, WebKit::PolicyInterface* = 0, WKContextRef = 0, WKPageGroupRef = 0);
     ~QtWebPageProxy();
 
     virtual bool handleEvent(QEvent*);
@@ -196,7 +194,11 @@ private:
     bool handleFocusInEvent(QFocusEvent*);
     bool handleFocusOutEvent(QFocusEvent*);
 
-    QWKContext* m_context;
+    static PassRefPtr<WebContext> defaultWKContext();
+    static RefPtr<WebContext> s_defaultContext;
+    static unsigned s_defaultPageProxyCount;
+
+    RefPtr<WebContext> m_context;
     QWKHistory* m_history;
 
     mutable QAction* m_actions[QtWebPageProxy::WebActionCount];
index 5fcfedd..689c55f 100644 (file)
@@ -47,7 +47,7 @@ static inline Qt::DropAction dragOperationToDropAction(unsigned dragOperation)
     return result;
 }
 
-QDesktopWebPageProxy::QDesktopWebPageProxy(QDesktopWebViewPrivate* desktopWebView, QWKContext* context, WKPageGroupRef pageGroup)
+QDesktopWebPageProxy::QDesktopWebPageProxy(QDesktopWebViewPrivate* desktopWebView, WKContextRef context, WKPageGroupRef pageGroup)
     : QtWebPageProxy(desktopWebView, desktopWebView, context, pageGroup)
 {
     init();
index 4835b57..7519822 100644 (file)
@@ -32,7 +32,7 @@ using namespace WebKit;
 class QDesktopWebPageProxy : public QtWebPageProxy
 {
 public:
-    QDesktopWebPageProxy(QDesktopWebViewPrivate*, QWKContext*, WKPageGroupRef = 0);
+    QDesktopWebPageProxy(QDesktopWebViewPrivate*, WKContextRef, WKPageGroupRef = 0);
 
     virtual bool handleEvent(QEvent*);
 
index 766575b..5e7be5f 100644 (file)
@@ -27,8 +27,8 @@
 
 using namespace WebCore;
 
-QTouchWebPageProxy::QTouchWebPageProxy(TouchViewInterface* viewInterface, ViewportInteractionEngine* viewportInteractionEngine, QWKContext* context, WKPageGroupRef pageGroupRef)
-    : QtWebPageProxy(viewInterface, 0, context, pageGroupRef)
+QTouchWebPageProxy::QTouchWebPageProxy(TouchViewInterface* viewInterface, ViewportInteractionEngine* viewportInteractionEngine)
+    : QtWebPageProxy(viewInterface, 0)
     , m_panGestureRecognizer(viewportInteractionEngine)
     , m_pinchGestureRecognizer(viewportInteractionEngine)
 {
index 5abbf61..992f00a 100644 (file)
@@ -39,7 +39,7 @@ using namespace WebKit;
 class QTouchWebPageProxy : public QtWebPageProxy
 {
 public:
-    QTouchWebPageProxy(TouchViewInterface*, ViewportInteractionEngine*, QWKContext*, WKPageGroupRef = 0);
+    QTouchWebPageProxy(TouchViewInterface*, ViewportInteractionEngine*);
 
     virtual bool handleEvent(QEvent*);
 
diff --git a/Source/WebKit2/UIProcess/qt/qwkcontext.cpp b/Source/WebKit2/UIProcess/qt/qwkcontext.cpp
deleted file mode 100644 (file)
index 116b6c8..0000000
+++ /dev/null
@@ -1,108 +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 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 "qwkcontext.h"
-#include "qwkcontext_p.h"
-
-#include "ClientImpl.h"
-#include "IconDatabase.h"
-#include "Image.h"
-#include <QDir>
-#include <QPixmap>
-#include <QUrl>
-#include "WebIconDatabase.h"
-#include "WebPlatformStrategies.h"
-#include "WKIconDatabase.h"
-
-using namespace WebKit;
-
-static inline void initializePlatformStrategiesIfNeeded()
-{
-    static bool initialized = false;
-    if (initialized)
-        return;
-
-    WebPlatformStrategies::initialize();
-    initialized = true;
-}
-
-QWKContextPrivate::QWKContextPrivate(QWKContext* qq, WebContext* webContext)
-    : q(qq)
-{
-    if (!webContext)
-        context = WebContext::create(String());
-    else
-        context = webContext;
-
-    initializePlatformStrategiesIfNeeded();
-
-    WKIconDatabaseClient iconDatabaseClient = {
-        0,      // version
-        qq,     // clientInfo
-        qt_wk_didChangeIconForPageURL,
-        qt_wk_didRemoveAllIcons
-    };
-
-    WKIconDatabaseSetIconDatabaseClient(toAPI(context->iconDatabase()), &iconDatabaseClient);
-}
-
-QWKContextPrivate::~QWKContextPrivate()
-{ }
-
-QWKContext::QWKContext(QObject* parent)
-    : QObject(parent)
-    , d(new QWKContextPrivate(this))
-{ }
-
-QWKContext::QWKContext(WKContextRef contextRef, QObject* parent)
-    : QObject(parent)
-    , d(new QWKContextPrivate(this, toImpl(contextRef)))
-{ }
-
-QWKContext::~QWKContext()
-{
-    delete d;
-}
-
-void QWKContext::setIconDatabasePath(const QString& path)
-{
-    // FIXME: There is currently no way to disable the icon database once it's enabled.
-    QFileInfo info(path);
-    if (info.isDir() && info.isWritable()) {
-        QString databasePath = path + QDir::separator() + QString(WebCore::IconDatabase::defaultDatabaseFilename());
-        d->context->setIconDatabasePath(databasePath);
-    }
-}
-
-QIcon QWKContext::iconForPageURL(const QUrl& pageURL) const
-{
-    RefPtr<WebCore::Image> image = d->context->iconDatabase()->imageForPageURL(pageURL.toString());
-    if (!image)
-        return QIcon();
-
-    QPixmap* nativeImage = image->nativeImageForCurrentFrame();
-    if (!nativeImage)
-        return QIcon();
-
-    return QIcon(*nativeImage);
-}
-
-#include "moc_qwkcontext.cpp"
diff --git a/Source/WebKit2/UIProcess/qt/qwkcontext.h b/Source/WebKit2/UIProcess/qt/qwkcontext.h
deleted file mode 100644 (file)
index b258a24..0000000
+++ /dev/null
@@ -1,52 +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.
-*/
-
-#ifndef qwkcontext_h
-#define qwkcontext_h
-
-#include "qwebkitglobal.h"
-#include <QObject>
-#include <WebKit2/WKContext.h>
-
-class QIcon;
-class QUrl;
-class QWKContextPrivate;
-
-class QWEBKIT_EXPORT QWKContext : public QObject {
-    Q_OBJECT
-public:
-    QWKContext(QObject* parent = 0);
-    virtual ~QWKContext();
-
-    // Bridge from the C API
-    QWKContext(WKContextRef contextRef, QObject* parent = 0);
-
-    void setIconDatabasePath(const QString&);
-    QIcon iconForPageURL(const QUrl&) const;
-
-public:
-    Q_SIGNAL void iconChangedForPageURL(const QUrl&);
-
-private:
-    QWKContextPrivate* d;
-
-    friend class QtWebPageProxy;
-};
-
-#endif /* qwkcontext_h */
diff --git a/Source/WebKit2/UIProcess/qt/qwkcontext_p.h b/Source/WebKit2/UIProcess/qt/qwkcontext_p.h
deleted file mode 100644 (file)
index 5abf979..0000000
+++ /dev/null
@@ -1,37 +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.
-*/
-
-
-#ifndef qwkcontext_p_h
-#define qwkcontext_p_h
-
-#include "WebContext.h"
-#include <wtf/RefPtr.h>
-
-class QWKContextPrivate {
-public:
-    QWKContextPrivate(QWKContext*, WebKit::WebContext* = 0);
-    ~QWKContextPrivate();
-
-    QWKContext* q;
-
-    RefPtr<WebKit::WebContext> context;
-};
-
-#endif /* qkcontext_p_h */
index d0bffaf..74d88f6 100644 (file)
@@ -244,8 +244,6 @@ HEADERS += \
     UIProcess/qt/qdesktopwebpageproxy.h \
     UIProcess/qt/qtouchwebpageproxy.h \
     UIProcess/qt/QtWebPageProxy.h \
-    UIProcess/qt/qwkcontext.h \
-    UIProcess/qt/qwkcontext_p.h \
     UIProcess/qt/qwkhistory.h \
     UIProcess/qt/qwkhistory_p.h \
     UIProcess/qt/qwkpreferences.h \
@@ -477,7 +475,6 @@ SOURCES += \
     UIProcess/qt/qdesktopwebpageproxy.cpp \
     UIProcess/qt/qtouchwebpageproxy.cpp \
     UIProcess/qt/QtWebPageProxy.cpp \
-    UIProcess/qt/qwkcontext.cpp \
     UIProcess/qt/qwkhistory.cpp \
     UIProcess/qt/qwkpreferences.cpp \
     UIProcess/qt/SGAgent.cpp \