diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-13 12:51:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 20:50:05 +0200 |
commit | d441d6f39bb846989d95bcf5caf387b42414718d (patch) | |
tree | e367e64a75991c554930278175d403c072de6bb8 /Source/WebKit2/UIProcess/qt/QtWebContext.cpp | |
parent | 0060b2994c07842f4c59de64b5e3e430525c4b90 (diff) | |
download | qtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz |
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit.
Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebKit2/UIProcess/qt/QtWebContext.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/qt/QtWebContext.cpp | 149 |
1 files changed, 66 insertions, 83 deletions
diff --git a/Source/WebKit2/UIProcess/qt/QtWebContext.cpp b/Source/WebKit2/UIProcess/qt/QtWebContext.cpp index 7eb3b7196..4489d74c8 100644 --- a/Source/WebKit2/UIProcess/qt/QtWebContext.cpp +++ b/Source/WebKit2/UIProcess/qt/QtWebContext.cpp @@ -21,24 +21,29 @@ #include "config.h" #include "QtWebContext.h" -#include "MutableArray.h" #include "QtDownloadManager.h" #include "QtWebIconDatabaseClient.h" -#include "WKAPICast.h" -#include "WebContext.h" #include "WebInspectorServer.h" -#include "WebPageProxy.h" +#include "qquickwebview_p_p.h" +#include <QDir> +#include <QStandardPaths> +#include <QStringBuilder> +#include <WKAPICast.h> #include <WKArray.h> +#include <WKContextPrivate.h> #include <WKPage.h> #include <WKString.h> +#include <WKStringQt.h> #include <WKType.h> 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() { @@ -98,117 +103,95 @@ 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) +static void initializeContextInjectedBundleClient(WKContextRef context) { WKContextInjectedBundleClient injectedBundleClient; memset(&injectedBundleClient, 0, sizeof(WKContextInjectedBundleClient)); injectedBundleClient.version = kWKContextInjectedBundleClientCurrentVersion; injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; - WKContextSetInjectedBundleClient(toAPI(context), &injectedBundleClient); + WKContextSetInjectedBundleClient(context, &injectedBundleClient); } -QtWebContext::QtWebContext(WebContext* context) +QtWebContext::QtWebContext(WKContextRef context) : m_context(context) + , m_downloadManager(new QtDownloadManager(context)) + , m_iconDatabase(new QtWebIconDatabaseClient(context)) { } 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(WKContextRef 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) { + WKRetainPtr<WKContextRef> wkContext = adoptWK(WKContextCreate()); // 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()); + // and that the page cache isn't enabled (defaultContext() isn't used there). + initializeContextInjectedBundleClient(wkContext.get()); // A good all-around default. - webContext->setCacheModel(CacheModelDocumentBrowser); - } - - if (!qtWebContext) { - qtWebContext = QtWebContext::create(webContext.get()); - s_defaultQtWebContext = qtWebContext.get(); - } + WKContextSetCacheModel(wkContext.get(), kWKCacheModelDocumentBrowser); - return qtWebContext.release(); -} - -PassRefPtr<WebPageProxy> QtWebContext::createWebPage(PageClient* client, WebPageGroup* pageGroup) -{ - return m_context->createWebPage(client, pageGroup); -} + // Those paths have to be set before the first web process is spawned. + WKContextSetDatabaseDirectory(wkContext.get(), adoptWK(WKStringCreateWithQString(preparedStoragePath(DatabaseStorage))).get()); + WKContextSetLocalStorageDirectory(wkContext.get(), adoptWK(WKStringCreateWithQString(preparedStoragePath(LocalStorage))).get()); + WKContextSetCookieStorageDirectory(wkContext.get(), adoptWK(WKStringCreateWithQString(preparedStoragePath(CookieStorage))).get()); + WKContextSetDiskCacheDirectory(wkContext.get(), adoptWK(WKStringCreateWithQString(preparedStoragePath(DiskCacheStorage))).get()); -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()); -} + s_defaultQtWebContext = QtWebContext::create(wkContext.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()); + return s_defaultQtWebContext; } -QtDownloadManager* QtWebContext::downloadManager() +static QString defaultLocation(QStandardPaths::StandardLocation type) { - ASSERT(s_downloadManager); - return s_downloadManager.get(); + QString path = QStandardPaths::writableLocation(type); + Q_ASSERT(!path.isEmpty()); + return path % QDir::separator() % QStringLiteral(".QtWebKit") % QDir::separator(); } -QtWebIconDatabaseClient* QtWebContext::iconDatabase() +QString QtWebContext::preparedStoragePath(StorageType type) { - ASSERT(s_iconDatabase); - return s_iconDatabase.get(); -} + QString path; + switch (type) { + case DatabaseStorage: + path = defaultLocation(QStandardPaths::DataLocation) % QStringLiteral("Databases"); + QDir::root().mkpath(path); + break; + case LocalStorage: + path = defaultLocation(QStandardPaths::DataLocation) % QStringLiteral("LocalStorage"); + QDir::root().mkpath(path); + break; + case CookieStorage: + path = defaultLocation(QStandardPaths::DataLocation); + QDir::root().mkpath(path); + break; + case DiskCacheStorage: + path = defaultLocation(QStandardPaths::CacheLocation) % QStringLiteral("DiskCache"); + QDir::root().mkpath(path); + break; + case IconDatabaseStorage: + path = defaultLocation(QStandardPaths::DataLocation); + QDir::root().mkpath(path); + path += QStringLiteral("WebpageIcons.db"); + break; + default: + Q_ASSERT(false); + } -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; + return path; } } // namespace WebKit |