summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/qt/QtWebContext.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-11-07 11:22:47 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2012-11-07 11:22:47 +0100
commitcfd86b747d32ac22246a1aa908eaa720c63a88c1 (patch)
tree24d68c6f61c464ecba1e05670b80390ea3b0e50c /Source/WebKit2/UIProcess/qt/QtWebContext.cpp
parent69d7c744c9de19d152dbe2d8e46eb7dfd4511d1a (diff)
downloadqtwebkit-cfd86b747d32ac22246a1aa908eaa720c63a88c1.tar.gz
Imported WebKit commit 20271caf2e2c016d5cef40184cddeefeac4f1876 (http://svn.webkit.org/repository/webkit/trunk@133733)
New snapshot that contains all previous fixes as well as build fix for latest QtMultimedia API changes.
Diffstat (limited to 'Source/WebKit2/UIProcess/qt/QtWebContext.cpp')
-rw-r--r--Source/WebKit2/UIProcess/qt/QtWebContext.cpp144
1 files changed, 79 insertions, 65 deletions
diff --git a/Source/WebKit2/UIProcess/qt/QtWebContext.cpp b/Source/WebKit2/UIProcess/qt/QtWebContext.cpp
index f8d384cc2..7eb3b7196 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebContext.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtWebContext.cpp
@@ -35,15 +35,10 @@
namespace WebKit {
-static uint64_t generateContextID()
-{
- static uint64_t uniqueContextID = 1;
- return uniqueContextID++;
-}
-
-static HashMap<uint64_t, QtWebContext*> contextMap;
-
-QtWebContext* QtWebContext::s_defaultContext = 0;
+static WebContext* s_defaultWebContext = 0;
+static QtWebContext* s_defaultQtWebContext = 0;
+static OwnPtr<QtDownloadManager> s_downloadManager;
+static OwnPtr<QtWebIconDatabaseClient> s_iconDatabase;
static void initInspectorServer()
{
@@ -87,44 +82,86 @@ static void globalInitialization()
initialized = true;
}
+static void 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());
+}
+
+static void initializeContextInjectedBundleClient(WebContext* context)
+{
+ WKContextInjectedBundleClient injectedBundleClient;
+ memset(&injectedBundleClient, 0, sizeof(WKContextInjectedBundleClient));
+ injectedBundleClient.version = kWKContextInjectedBundleClientCurrentVersion;
+ injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+ WKContextSetInjectedBundleClient(toAPI(context), &injectedBundleClient);
+}
+
QtWebContext::QtWebContext(WebContext* context)
- : m_contextID(generateContextID())
- , m_context(context)
- , m_downloadManager(adoptPtr(new QtDownloadManager(context)))
- , m_iconDatabase(adoptPtr(new QtWebIconDatabaseClient(this)))
+ : m_context(context)
{
- contextMap.set(m_contextID, this);
}
QtWebContext::~QtWebContext()
{
- if (s_defaultContext == this)
- s_defaultContext = 0;
- contextMap.remove(m_contextID);
+ ASSERT(!s_defaultQtWebContext || s_defaultQtWebContext == this);
+ s_defaultQtWebContext = 0;
}
-// Used only by WebKitTestRunner. It avoids calling initialize(), so that we don't register any clients.
+// Used directly only by WebKitTestRunner.
PassRefPtr<QtWebContext> QtWebContext::create(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));
}
PassRefPtr<QtWebContext> QtWebContext::defaultContext()
{
- if (s_defaultContext)
- return PassRefPtr<QtWebContext>(s_defaultContext);
-
- RefPtr<WebContext> context = WebContext::create(String());
- // A good all-around default.
- context->setCacheModel(CacheModelDocumentBrowser);
+ // 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();
+ // 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).
+ initializeContextInjectedBundleClient(webContext.get());
+ // A good all-around default.
+ webContext->setCacheModel(CacheModelDocumentBrowser);
+ }
- RefPtr<QtWebContext> defaultContext = QtWebContext::create(context.get());
- s_defaultContext = defaultContext.get();
- // Make sure that this doesn't get called in WebKitTestRunner (defaultContext isn't used there).
- defaultContext->initializeContextInjectedBundleClient();
+ if (!qtWebContext) {
+ qtWebContext = QtWebContext::create(webContext.get());
+ s_defaultQtWebContext = qtWebContext.get();
+ }
- return defaultContext.release();
+ return qtWebContext.release();
}
PassRefPtr<WebPageProxy> QtWebContext::createWebPage(PageClient* client, WebPageGroup* pageGroup)
@@ -152,49 +189,26 @@ void QtWebContext::postMessageToNavigatorQtObject(WebPageProxy* webPageProxy, co
m_context->postMessageToInjectedBundle(messageName, body.get());
}
-QtWebContext* QtWebContext::contextByID(uint64_t id)
-{
- return contextMap.get(id);
-}
-
-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)
+QtDownloadManager* QtWebContext::downloadManager()
{
- ASSERT(clientInfo);
- return reinterpret_cast<QtWebContext*>(const_cast<void*>(clientInfo));
+ ASSERT(s_downloadManager);
+ return s_downloadManager.get();
}
-void QtWebContext::didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
+QtWebIconDatabaseClient* QtWebContext::iconDatabase()
{
- toQtWebContext(clientInfo)->didReceiveMessageFromInjectedBundle(messageName, messageBody);
+ ASSERT(s_iconDatabase);
+ return s_iconDatabase.get();
}
-void QtWebContext::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
+void QtWebContext::invalidateContext(WebContext* context)
{
- 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());
+ UNUSED_PARAM(context);
+ ASSERT(!s_defaultQtWebContext);
+ ASSERT(!s_defaultWebContext || s_defaultWebContext == context);
+ s_downloadManager.clear();
+ s_iconDatabase.clear();
+ s_defaultWebContext = 0;
}
} // namespace WebKit