Title: [145513] trunk/Source/WebKit2
Revision
145513
Author
jocelyn.turco...@digia.com
Date
2013-03-12 04:12:28 -0700 (Tue, 12 Mar 2013)

Log Message

[Qt][WK2] Keep the WebContext alive during the whole application's lifetime
https://bugs.webkit.org/show_bug.cgi?id=109827

Reviewed by Simon Hausmann.
Signed off for WebKit2 by Benjamin Poulain.

The lifetime of the WebContext is difficult to manage because of a circular
reference kept with the WebProcessProxy until it shuts itself down, 60
seconds after the last page is closed. There was some notification
in place to handle this in the upper layer, but having to go through the
C API (done in a following patch) makes this quite awkward.

Keeping the WebContext alive also includes the icon database which is
quite heavy, in the future we should only enable it once the
QQuickWebView::icon property is read.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::QQuickWebViewPrivate):
(QQuickWebViewPrivate::handleDownloadRequest):
(QQuickWebViewPrivate::updateIcon):
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):
* UIProcess/API/qt/qwebiconimageprovider.cpp:
(QWebIconImageProvider::requestImage):
* UIProcess/qt/QtWebContext.cpp:
(WebKit):
(WebKit::QtWebContext::QtWebContext):
(WebKit::QtWebContext::~QtWebContext):
(WebKit::QtWebContext::create):
(WebKit::QtWebContext::defaultContext):
* UIProcess/qt/QtWebContext.h:
(QtWebContext):
(WebKit::QtWebContext::downloadManager):
(WebKit::QtWebContext::iconDatabase):
* UIProcess/qt/WebContextQt.cpp:
(WebKit::WebContext::platformInvalidateContext):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (145512 => 145513)


--- trunk/Source/WebKit2/ChangeLog	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-12 11:12:28 UTC (rev 145513)
@@ -1,5 +1,44 @@
 2013-02-14  Jocelyn Turcotte  <jocelyn.turco...@digia.com>
 
+        [Qt][WK2] Keep the WebContext alive during the whole application's lifetime
+        https://bugs.webkit.org/show_bug.cgi?id=109827
+
+        Reviewed by Simon Hausmann.
+        Signed off for WebKit2 by Benjamin Poulain.
+
+        The lifetime of the WebContext is difficult to manage because of a circular
+        reference kept with the WebProcessProxy until it shuts itself down, 60
+        seconds after the last page is closed. There was some notification
+        in place to handle this in the upper layer, but having to go through the
+        C API (done in a following patch) makes this quite awkward.
+
+        Keeping the WebContext alive also includes the icon database which is
+        quite heavy, in the future we should only enable it once the
+        QQuickWebView::icon property is read.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::QQuickWebViewPrivate):
+        (QQuickWebViewPrivate::handleDownloadRequest):
+        (QQuickWebViewPrivate::updateIcon):
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+        * UIProcess/API/qt/qwebiconimageprovider.cpp:
+        (QWebIconImageProvider::requestImage):
+        * UIProcess/qt/QtWebContext.cpp:
+        (WebKit):
+        (WebKit::QtWebContext::QtWebContext):
+        (WebKit::QtWebContext::~QtWebContext):
+        (WebKit::QtWebContext::create):
+        (WebKit::QtWebContext::defaultContext):
+        * UIProcess/qt/QtWebContext.h:
+        (QtWebContext):
+        (WebKit::QtWebContext::downloadManager):
+        (WebKit::QtWebContext::iconDatabase):
+        * UIProcess/qt/WebContextQt.cpp:
+        (WebKit::WebContext::platformInvalidateContext):
+
+2013-02-14  Jocelyn Turcotte  <jocelyn.turco...@digia.com>
+
         [Qt][WK2] Favor QUrl and QString over WTF::String in the Qt API layer
         https://bugs.webkit.org/show_bug.cgi?id=109468
 

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


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2013-03-12 11:12:28 UTC (rev 145513)
@@ -273,6 +273,7 @@
 QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport)
     : q_ptr(viewport)
     , experimental(new QQuickWebViewExperimental(viewport, this))
+    , context(0)
     , alertDialog(0)
     , confirmDialog(0)
     , promptDialog(0)
@@ -612,7 +613,7 @@
     downloadItem->d->downloadProxy = download;
 
     q->connect(downloadItem->d, SIGNAL(receivedResponse(QWebDownloadItem*)), q, SLOT(_q_onReceivedResponseFromDownload(QWebDownloadItem*)));
-    QtWebContext::downloadManager()->addDownload(download, downloadItem);
+    QtWebContext::defaultContext()->downloadManager()->addDownload(download, downloadItem);
 }
 
 void QQuickWebViewPrivate::_q_onVisibleChanged()
@@ -647,7 +648,7 @@
     if (!provider)
         return;
 
-    QUrl iconUrl = provider->iconURLForPageURLInContext(m_currentUrl, context.get());
+    QUrl iconUrl = provider->iconURLForPageURLInContext(m_currentUrl, context);
 
     if (iconUrl == m_iconUrl)
         return;

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


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2013-03-12 11:12:28 UTC (rev 145513)
@@ -165,7 +165,6 @@
     static void didChangeBackForwardList(WKPageRef, WKBackForwardListItemRef, WKArrayRef, const void *clientInfo);
 
     QQuickWebViewPrivate(QQuickWebView* viewport);
-    RefPtr<WebKit::QtWebContext> context;
     RefPtr<WebKit::WebPageProxy> webPageProxy;
     WKRetainPtr<WKPageRef> webPage;
     WKRetainPtr<WKPageGroupRef> pageGroup;
@@ -181,6 +180,7 @@
     QScopedPointer<QQuickWebPage> pageView;
     QQuickWebView* q_ptr;
     QQuickWebViewExperimental* experimental;
+    WebKit::QtWebContext* context;
 
     FlickableAxisLocker axisLocker;
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp (145512 => 145513)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp	2013-03-12 11:12:28 UTC (rev 145513)
@@ -67,7 +67,7 @@
 {
     QString pageURL = QString::fromUtf8(QByteArray::fromBase64(id.midRef(id.indexOf('#') + 1).toLatin1()));
 
-    QtWebIconDatabaseClient* iconDatabase = QtWebContext::iconDatabase();
+    QtWebIconDatabaseClient* iconDatabase = QtWebContext::defaultContext()->iconDatabase();
     if (!iconDatabase)
         return QImage();
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp (145512 => 145513)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp	2013-03-12 11:12:28 UTC (rev 145513)
@@ -34,10 +34,12 @@
 
 namespace WebKit {
 
-static WebContext* s_defaultWebContext = 0;
+// Prevent the destruction of the WKContext for two reasons:
+// - An internal reference is kept to the WebContext waiting until the web process shut down, which
+// does so 60 seconds after the last page closed. We want to reuse that web process if possible and
+// avoid creating a second parallel WKContext + web process.
+// - The IconDatabase wasn't designed to have more than one instance, or to be quickly opened/closed.
 static QtWebContext* s_defaultQtWebContext = 0;
-static OwnPtr<QtDownloadManager> s_downloadManager;
-static OwnPtr<QtWebIconDatabaseClient> s_iconDatabase;
 
 static void initInspectorServer()
 {
@@ -109,58 +111,38 @@
     WKContextSetInjectedBundleClient(toAPI(context), &injectedBundleClient);
 }
 
-QtWebContext::QtWebContext(WebContext* context)
+QtWebContext::QtWebContext(PassRefPtr<WebContext> context)
     : m_context(context)
+    , m_downloadManager(new QtDownloadManager(m_context.get()))
+    , m_iconDatabase(new QtWebIconDatabaseClient(m_context.get()))
 {
 }
 
 QtWebContext::~QtWebContext()
 {
-    ASSERT(!s_defaultQtWebContext || s_defaultQtWebContext == this);
-    s_defaultQtWebContext = 0;
 }
 
 // Used directly only by WebKitTestRunner.
-PassRefPtr<QtWebContext> QtWebContext::create(WebContext* context)
+QtWebContext* QtWebContext::create(PassRefPtr<WebContext> context)
 {
     globalInitialization();
-    // The lifetime of WebContext is a bit special, it is bound to the reference held
-    // by QtWebContext at first and then enters a circular dependency with WebProcessProxy
-    // once the first page is created until the web process exits. Because of this we can't
-    // assume that destroying the last QtWebContext will destroy the WebContext and we
-    // have to make sure that WebContext's clients follow its lifetime and aren't attached
-    // to QtWebContext. QtWebContext itself is only attached to QQuickWebView.
-    // Since we only support one WebContext at a time, initialize those clients globally
-    // here. They have to be available to views spawned by WebKitTestRunner as well.
-    if (!s_downloadManager)
-        s_downloadManager = adoptPtr(new QtDownloadManager(context));
-    if (!s_iconDatabase)
-        s_iconDatabase = adoptPtr(new QtWebIconDatabaseClient(context));
-    return adoptRef(new QtWebContext(context));
+    return new QtWebContext(context);
 }
 
-PassRefPtr<QtWebContext> QtWebContext::defaultContext()
+QtWebContext* QtWebContext::defaultContext()
 {
-    // Keep local references until we can return a ref to QtWebContext holding the WebContext.
-    RefPtr<WebContext> webContext(s_defaultWebContext);
-    RefPtr<QtWebContext> qtWebContext(s_defaultQtWebContext);
-
-    if (!webContext) {
-        webContext = WebContext::create(String());
-        s_defaultWebContext = webContext.get();
+    if (!s_defaultQtWebContext) {
+        RefPtr<WebContext> webContext = WebContext::create(String());
         // Make sure for WebKitTestRunner that the injected bundle client isn't initialized
-        // and that the page cache isn't enabled (defaultContext isn't used there).
+        // and that the page cache isn't enabled (defaultContext() isn't used there).
         initializeContextInjectedBundleClient(webContext.get());
         // A good all-around default.
         webContext->setCacheModel(CacheModelDocumentBrowser);
-    }
 
-    if (!qtWebContext) {
-        qtWebContext = QtWebContext::create(webContext.get());
-        s_defaultQtWebContext = qtWebContext.get();
+        s_defaultQtWebContext = QtWebContext::create(webContext.release());
     }
 
-    return qtWebContext.release();
+    return s_defaultQtWebContext;
 }
 
 PassRefPtr<WebPageProxy> QtWebContext::createWebPage(PageClient* client, WebPageGroup* pageGroup)
@@ -168,27 +150,5 @@
     return m_context->createWebPage(client, pageGroup);
 }
 
-QtDownloadManager* QtWebContext::downloadManager()
-{
-    ASSERT(s_downloadManager);
-    return s_downloadManager.get();
-}
-
-QtWebIconDatabaseClient* QtWebContext::iconDatabase()
-{
-    ASSERT(s_iconDatabase);
-    return s_iconDatabase.get();
-}
-
-void QtWebContext::invalidateContext(WebContext* context)
-{
-    UNUSED_PARAM(context);
-    ASSERT(!s_defaultQtWebContext);
-    ASSERT(!s_defaultWebContext || s_defaultWebContext == context);
-    s_downloadManager.clear();
-    s_iconDatabase.clear();
-    s_defaultWebContext = 0;
-}
-
 } // namespace WebKit
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebContext.h (145512 => 145513)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebContext.h	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebContext.h	2013-03-12 11:12:28 UTC (rev 145513)
@@ -21,6 +21,7 @@
 #ifndef QtWebContext_h
 #define QtWebContext_h
 
+#include <QScopedPointer>
 #include <QtGlobal>
 #include <WKContext.h>
 #include <wtf/OwnPtr.h>
@@ -37,25 +38,26 @@
 class WebPageGroup;
 class WebPageProxy;
 
-class QtWebContext : public RefCounted<QtWebContext> {
+class QtWebContext {
 public:
     ~QtWebContext();
 
-    static PassRefPtr<QtWebContext> create(WebContext*);
-    static PassRefPtr<QtWebContext> defaultContext();
+    static QtWebContext* create(PassRefPtr<WebContext>);
+    static QtWebContext* defaultContext();
 
     PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebPageGroup*);
 
     WebContext* context() { return m_context.get(); }
 
-    static QtDownloadManager* downloadManager();
-    static QtWebIconDatabaseClient* iconDatabase();
-    static void invalidateContext(WebContext*);
+    QtDownloadManager* downloadManager() { return m_downloadManager.data(); }
+    QtWebIconDatabaseClient* iconDatabase() { return m_iconDatabase.data(); }
 
 private:
-    explicit QtWebContext(WebContext*);
+    explicit QtWebContext(PassRefPtr<WebContext>);
 
     RefPtr<WebContext> m_context;
+    QScopedPointer<QtDownloadManager> m_downloadManager;
+    QScopedPointer<QtWebIconDatabaseClient> m_iconDatabase;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp (145512 => 145513)


--- trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp	2013-03-12 11:11:14 UTC (rev 145512)
+++ trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp	2013-03-12 11:12:28 UTC (rev 145513)
@@ -81,9 +81,6 @@
 
 void WebContext::platformInvalidateContext()
 {
-#if HAVE(QTQUICK)
-    QtWebContext::invalidateContext(this);
-#endif
 }
 
 String WebContext::platformDefaultDatabaseDirectory() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to