diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-01-06 14:44:00 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-01-06 14:44:00 +0100 |
commit | 40736c5763bf61337c8c14e16d8587db021a87d4 (patch) | |
tree | b17a9c00042ad89cb1308e2484491799aa14e9f8 /Source/WebKit2/WebProcess/qt | |
download | qtwebkit-40736c5763bf61337c8c14e16d8587db021a87d4.tar.gz |
Imported WebKit commit 2ea9d364d0f6efa8fa64acf19f451504c59be0e4 (http://svn.webkit.org/repository/webkit/trunk@104285)
Diffstat (limited to 'Source/WebKit2/WebProcess/qt')
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtBuiltinBundle.cpp | 137 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtBuiltinBundle.h | 67 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.cpp | 196 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.h | 69 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp | 84 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h | 57 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtNetworkReply.cpp | 116 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/QtNetworkReply.h | 65 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp | 215 | ||||
-rw-r--r-- | Source/WebKit2/WebProcess/qt/WebProcessQt.cpp | 113 |
10 files changed, 1119 insertions, 0 deletions
diff --git a/Source/WebKit2/WebProcess/qt/QtBuiltinBundle.cpp b/Source/WebKit2/WebProcess/qt/QtBuiltinBundle.cpp new file mode 100644 index 000000000..a5a75d0c3 --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtBuiltinBundle.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "QtBuiltinBundle.h" + +#include "QtBuiltinBundlePage.h" +#include "WKArray.h" +#include "WKBundlePage.h" +#include "WKNumber.h" +#include "WKRetainPtr.h" +#include "WKString.h" +#include "WKStringQt.h" +#include <wtf/PassOwnPtr.h> + +namespace WebKit { + +QtBuiltinBundle::~QtBuiltinBundle() +{ + // For OwnPtr's sake. +} + +QtBuiltinBundle& QtBuiltinBundle::shared() +{ + static QtBuiltinBundle& shared = *new QtBuiltinBundle; + return shared; +} + +void QtBuiltinBundle::initialize(WKBundleRef bundle) +{ + m_bundle = bundle; + WKBundleClient client = { + kWKBundleClientCurrentVersion, + this, + didCreatePage, + willDestroyPage, + 0, // didInitializePageGroup + didReceiveMessage + }; + WKBundleSetClient(m_bundle, &client); +} + +void QtBuiltinBundle::didCreatePage(WKBundleRef, WKBundlePageRef page, const void* clientInfo) +{ + static_cast<QtBuiltinBundle*>(const_cast<void*>(clientInfo))->didCreatePage(page); +} + +void QtBuiltinBundle::willDestroyPage(WKBundleRef, WKBundlePageRef page, const void* clientInfo) +{ + static_cast<QtBuiltinBundle*>(const_cast<void*>(clientInfo))->willDestroyPage(page); +} + +void QtBuiltinBundle::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo) +{ + static_cast<QtBuiltinBundle*>(const_cast<void*>(clientInfo))->didReceiveMessage(messageName, messageBody); +} + +void QtBuiltinBundle::didCreatePage(WKBundlePageRef page) +{ + m_pages.add(page, adoptPtr(new QtBuiltinBundlePage(this, page))); +} + +void QtBuiltinBundle::willDestroyPage(WKBundlePageRef page) +{ + m_pages.remove(page); +} + +void QtBuiltinBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody) +{ + if (WKStringIsEqualToUTF8CString(messageName, "MessageToNavigatorQtObject")) + handleMessageToNavigatorQtObject(messageBody); + else if (WKStringIsEqualToUTF8CString(messageName, "SetNavigatorQtObjectEnabled")) + handleSetNavigatorQtObjectEnabled(messageBody); +} + +void QtBuiltinBundle::handleMessageToNavigatorQtObject(WKTypeRef messageBody) +{ + ASSERT(messageBody); + ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID()); + + WKArrayRef body = static_cast<WKArrayRef>(messageBody); + ASSERT(WKArrayGetSize(body) == 2); + ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 0)) == WKBundlePageGetTypeID()); + ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 1)) == WKStringGetTypeID()); + + WKBundlePageRef page = static_cast<WKBundlePageRef>(WKArrayGetItemAtIndex(body, 0)); + WKStringRef contents = static_cast<WKStringRef>(WKArrayGetItemAtIndex(body, 1)); + + QtBuiltinBundlePage* bundlePage = m_pages.get(page); + if (!bundlePage) + return; + bundlePage->didReceiveMessageToNavigatorQtObject(contents); +} + +void QtBuiltinBundle::handleSetNavigatorQtObjectEnabled(WKTypeRef messageBody) +{ + ASSERT(messageBody); + ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID()); + + WKArrayRef body = static_cast<WKArrayRef>(messageBody); + ASSERT(WKArrayGetSize(body) == 2); + ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 0)) == WKBundlePageGetTypeID()); + ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 1)) == WKBooleanGetTypeID()); + + WKBundlePageRef page = static_cast<WKBundlePageRef>(WKArrayGetItemAtIndex(body, 0)); + WKBooleanRef enabled = static_cast<WKBooleanRef>(WKArrayGetItemAtIndex(body, 1)); + + QtBuiltinBundlePage* bundlePage = m_pages.get(page); + if (!bundlePage) + return; + bundlePage->setNavigatorQtObjectEnabled(enabled); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/qt/QtBuiltinBundle.h b/Source/WebKit2/WebProcess/qt/QtBuiltinBundle.h new file mode 100644 index 000000000..498fec7c2 --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtBuiltinBundle.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef QtBuiltinBundle_h +#define QtBuiltinBundle_h + +#include "WKBundle.h" +#include "WKBundlePage.h" +#include <wtf/HashMap.h> +#include <wtf/OwnPtr.h> + +namespace WebKit { + +class QtBuiltinBundlePage; + +class QtBuiltinBundle { +public: + ~QtBuiltinBundle(); + + static QtBuiltinBundle& shared(); + void initialize(WKBundleRef); + + WKBundleRef toRef() const { return m_bundle; } + + // Bundle Client. + static void didCreatePage(WKBundleRef, WKBundlePageRef, const void*); + static void willDestroyPage(WKBundleRef, WKBundlePageRef, const void*); + static void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody, const void*); + + void didCreatePage(WKBundlePageRef); + void willDestroyPage(WKBundlePageRef); + void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody); + +private: + void handleMessageToNavigatorQtObject(WKTypeRef messageBody); + void handleSetNavigatorQtObjectEnabled(WKTypeRef messageBody); + + HashMap<WKBundlePageRef, OwnPtr<QtBuiltinBundlePage> > m_pages; + WKBundleRef m_bundle; +}; + +} // namespace WebKit + +#endif // QtBuiltinBundle_h diff --git a/Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.cpp b/Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.cpp new file mode 100644 index 000000000..2c89556b3 --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "QtBuiltinBundlePage.h" + +#include "QtBuiltinBundle.h" +#include "WKArray.h" +#include "WKBundleFrame.h" +#include "WKRetainPtr.h" +#include "WKString.h" +#include "WKStringPrivate.h" +#include "WKStringQt.h" +#include <JavaScript.h> +#include <JavaScriptCore/JSRetainPtr.h> + +namespace WebKit { + +QtBuiltinBundlePage::QtBuiltinBundlePage(QtBuiltinBundle* bundle, WKBundlePageRef page) + : m_bundle(bundle) + , m_page(page) + , m_navigatorQtObject(0) + , m_navigatorQtObjectEnabled(false) +{ + WKBundlePageLoaderClient loaderClient = { + kWKBundlePageLoaderClientCurrentVersion, + this, + 0, // didStartProvisionalLoadForFrame + 0, // didReceiveServerRedirectForProvisionalLoadForFrame + 0, // didFailProvisionalLoadWithErrorForFrame + 0, // didCommitLoadForFrame + 0, // didFinishDocumentLoadForFrame + 0, // didFinishLoadForFrame + 0, // didFailLoadWithErrorForFrame + 0, // didSameDocumentNavigationForFrame + 0, // didReceiveTitleForFrame + 0, // didFirstLayoutForFrame + 0, // didFirstVisuallyNonEmptyLayoutForFrame + 0, // didRemoveFrameFromHierarchy + 0, // didDisplayInsecureContentForFrame + 0, // didRunInsecureContentForFrame + didClearWindowForFrame, + 0, // didCancelClientRedirectForFrame + 0, // willPerformClientRedirectForFrame + 0, // didHandleOnloadEventsForFrame + 0, // didLayoutForFrame + 0, // didDetectXSSForFrame + }; + WKBundlePageSetPageLoaderClient(m_page, &loaderClient); +} + +QtBuiltinBundlePage::~QtBuiltinBundlePage() +{ + if (!m_navigatorQtObject) + return; + WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); + JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); + JSValueUnprotect(context, m_navigatorQtObject); +} + +void QtBuiltinBundlePage::didClearWindowForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleScriptWorldRef world, const void* clientInfo) +{ + static_cast<QtBuiltinBundlePage*>(const_cast<void*>(clientInfo))->didClearWindowForFrame(frame, world); +} + +static JSValueRef qt_postMessageCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef*) +{ + // FIXME: should it work regardless of the thisObject? + + if (argumentCount < 1 || !JSValueIsString(context, arguments[0])) + return JSValueMakeUndefined(context); + + QtBuiltinBundlePage* bundlePage = reinterpret_cast<QtBuiltinBundlePage*>(JSObjectGetPrivate(thisObject)); + ASSERT(bundlePage); + + // FIXME: needed? + if (!bundlePage->navigatorQtObjectEnabled()) + return JSValueMakeUndefined(context); + + JSRetainPtr<JSStringRef> jsContents = JSValueToStringCopy(context, arguments[0], 0); + WKRetainPtr<WKStringRef> contents(AdoptWK, WKStringCreateWithJSString(jsContents.get())); + bundlePage->postMessageFromNavigatorQtObject(contents.get()); + return JSValueMakeUndefined(context); +} + +void QtBuiltinBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, WKBundleScriptWorldRef world) +{ + if (!WKBundleFrameIsMainFrame(frame) || WKBundleScriptWorldNormalWorld() != world) + return; + JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); + registerNavigatorQtObject(context); +} + +void QtBuiltinBundlePage::postMessageFromNavigatorQtObject(WKStringRef contents) +{ + static WKStringRef messageName = WKStringCreateWithUTF8CString("MessageFromNavigatorQtObject"); + WKTypeRef body[] = { page(), contents }; + WKRetainPtr<WKArrayRef> messageBody(AdoptWK, WKArrayCreate(body, sizeof(body) / sizeof(WKTypeRef))); + WKBundlePostMessage(m_bundle->toRef(), messageName, messageBody.get()); +} + +static JSObjectRef createWrappedMessage(JSGlobalContextRef context, WKStringRef data) +{ + static JSStringRef dataName = JSStringCreateWithUTF8CString("data"); + + JSRetainPtr<JSStringRef> jsData = WKStringCopyJSString(data); + JSObjectRef wrappedMessage = JSObjectMake(context, 0, 0); + JSObjectSetProperty(context, wrappedMessage, dataName, JSValueMakeString(context, jsData.get()), kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); + return wrappedMessage; +} + +void QtBuiltinBundlePage::didReceiveMessageToNavigatorQtObject(WKStringRef contents) +{ + static JSStringRef onmessageName = JSStringCreateWithUTF8CString("onmessage"); + + if (!m_navigatorQtObject) + return; + + WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); + JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); + + JSValueRef onmessageValue = JSObjectGetProperty(context, m_navigatorQtObject, onmessageName, 0); + if (!JSValueIsObject(context, onmessageValue)) + return; + + JSObjectRef onmessageFunction = JSValueToObject(context, onmessageValue, 0); + if (!JSObjectIsFunction(context, onmessageFunction)) + return; + + JSObjectRef wrappedMessage = createWrappedMessage(context, contents); + JSObjectCallAsFunction(context, onmessageFunction, 0, 1, &wrappedMessage, 0); +} + +void QtBuiltinBundlePage::setNavigatorQtObjectEnabled(bool enabled) +{ + if (enabled == m_navigatorQtObjectEnabled) + return; + // Note that this will take effect only after the next page load. + m_navigatorQtObjectEnabled = enabled; +} + +void QtBuiltinBundlePage::registerNavigatorQtObject(JSGlobalContextRef context) +{ + static JSStringRef postMessageName = JSStringCreateWithUTF8CString("postMessage"); + static JSStringRef navigatorName = JSStringCreateWithUTF8CString("navigator"); + static JSStringRef qtName = JSStringCreateWithUTF8CString("qt"); + + if (m_navigatorQtObject) + JSValueUnprotect(context, m_navigatorQtObject); + m_navigatorQtObject = JSObjectMake(context, navigatorQtObjectClass(), this); + JSValueProtect(context, m_navigatorQtObject); + + JSObjectRef postMessage = JSObjectMakeFunctionWithCallback(context, postMessageName, qt_postMessageCallback); + JSObjectSetProperty(context, m_navigatorQtObject, postMessageName, postMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); + + JSValueRef navigatorValue = JSObjectGetProperty(context, JSContextGetGlobalObject(context), navigatorName, 0); + if (!JSValueIsObject(context, navigatorValue)) + return; + JSObjectRef navigatorObject = JSValueToObject(context, navigatorValue, 0); + JSObjectSetProperty(context, navigatorObject, qtName, m_navigatorQtObject, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); +} + +JSClassRef QtBuiltinBundlePage::navigatorQtObjectClass() +{ + static JSClassRef classRef = 0; + if (!classRef) { + const JSClassDefinition navigatorQtObjectClass = kJSClassDefinitionEmpty; + classRef = JSClassCreate(&navigatorQtObjectClass); + } + return classRef; +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.h b/Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.h new file mode 100644 index 000000000..3ffb3f008 --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef QtBuiltinBundlePage_h +#define QtBuiltinBundlePage_h + +#include "JSObjectRef.h" +#include "WKBundlePage.h" +#include "WKBundleScriptWorld.h" + +namespace WebKit { + +class QtBuiltinBundle; + +class QtBuiltinBundlePage { +public: + QtBuiltinBundlePage(QtBuiltinBundle*, WKBundlePageRef); + ~QtBuiltinBundlePage(); + + WKBundlePageRef page() const { return m_page; } + + // Loader Client. + static void didClearWindowForFrame(WKBundlePageRef, WKBundleFrameRef, WKBundleScriptWorldRef, const void*); + + void didClearWindowForFrame(WKBundleFrameRef, WKBundleScriptWorldRef); + + void postMessageFromNavigatorQtObject(WKStringRef message); + void didReceiveMessageToNavigatorQtObject(WKStringRef message); + + bool navigatorQtObjectEnabled() const { return m_navigatorQtObjectEnabled; } + void setNavigatorQtObjectEnabled(bool); + +private: + void registerNavigatorQtObject(JSGlobalContextRef); + + static JSClassRef navigatorQtObjectClass(); + + QtBuiltinBundle* m_bundle; + WKBundlePageRef m_page; + JSObjectRef m_navigatorQtObject; + bool m_navigatorQtObjectEnabled; +}; + +} // namespace WebKit + +#endif // QtBuiltinBundlePage_h diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp new file mode 100644 index 000000000..57b953fea --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "QtNetworkAccessManager.h" + +#include "SharedMemory.h" +#include "WebFrameNetworkingContext.h" +#include "WebPage.h" +#include "WebProcess.h" +#include <QNetworkReply> +#include <QNetworkRequest> + +namespace WebKit { + +QtNetworkAccessManager::QtNetworkAccessManager(WebProcess* webProcess) + : QNetworkAccessManager() + , m_webProcess(webProcess) +{ +} + +QtNetworkAccessManager::QtNetworkAccessManager(QObject* parent) + : QNetworkAccessManager(parent) + , m_webProcess(0) +{ +} + +WebPage* QtNetworkAccessManager::obtainOriginatingWebPage(const QNetworkRequest& request) +{ + QObject* originatingObject = request.originatingObject(); + if (!originatingObject) + return 0; + + QVariant pagePtr = originatingObject->property("PagePointer"); + if (!pagePtr.isValid() || !pagePtr.canConvert<void*>()) + return 0; + + WebPage* webPage = static_cast<WebPage*>(pagePtr.value<void*>()); + Q_ASSERT(webPage); + return webPage; +} + +QNetworkReply* QtNetworkAccessManager::createRequest(Operation operation, const QNetworkRequest& request, QIODevice* outData) +{ + WebPage* webPage = obtainOriginatingWebPage(request); + if (webPage && m_applicationSchemes.contains(webPage, request.url().scheme().toLower())) { + QtNetworkReply* reply = new QtNetworkReply(request, this); + webPage->receivedApplicationSchemeRequest(request, reply); + return reply; + } + + return QNetworkAccessManager::createRequest(operation, request, outData); +} + +void QtNetworkAccessManager::registerApplicationScheme(const WebPage* page, const QString& scheme) +{ + m_applicationSchemes.insert(page, scheme.toLower()); +} + +} + +#include "moc_QtNetworkAccessManager.cpp" diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h new file mode 100644 index 000000000..8d9eb1d0e --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef QtNetworkAccessManager_h +#define QtNetworkAccessManager_h + +#include <QMultiHash> +#include <QNetworkAccessManager> +#include <QString> + +namespace WebKit { + +class WebPage; +class WebProcess; + +class QtNetworkAccessManager : public QNetworkAccessManager { + Q_OBJECT +public: + QtNetworkAccessManager(QObject* parent); + QtNetworkAccessManager(WebProcess*); + void registerApplicationScheme(const WebPage*, const QString& scheme); + +protected: + virtual QNetworkReply* createRequest(Operation, const QNetworkRequest&, QIODevice* outgoingData = 0) OVERRIDE; + static WebPage* obtainOriginatingWebPage(const QNetworkRequest&); + +private: + QMultiHash<const WebPage*, QString> m_applicationSchemes; + WebProcess* m_webProcess; + +}; + +} // namespace WebKit + +#endif // QtNetworkAccessManager_h diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkReply.cpp b/Source/WebKit2/WebProcess/qt/QtNetworkReply.cpp new file mode 100644 index 000000000..fd0f5cb7a --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtNetworkReply.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "QtNetworkReply.h" + +#include "SharedMemory.h" +#include "WebFrameNetworkingContext.h" +#include "WebPage.h" +#include "WebProcess.h" +#include <QNetworkCookie> +#include <QNetworkReply> +#include <QNetworkRequest> + +namespace WebKit { + +QtNetworkReply::QtNetworkReply(const QNetworkRequest& req, QtNetworkAccessManager* parent) + : QNetworkReply(parent) + , m_bytesAvailable(0) + , m_sharedMemorySize(0) +{ + setRequest(req); + setOperation(QNetworkAccessManager::GetOperation); + setUrl(req.url()); + setOpenMode(QIODevice::ReadOnly); + setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QString::fromLocal8Bit("text/html; charset=UTF-16"))); +} + +void QtNetworkReply::setData(const SharedMemory::Handle& handle, qint64 dataSize) +{ + m_sharedMemory = SharedMemory::create(handle, SharedMemory::ReadOnly); + if (!m_sharedMemory) + return; + + m_bytesAvailable = dataSize; + m_sharedMemorySize = dataSize; +} + +void QtNetworkReply::setReplyData(const QtNetworkReplyData& replyData) +{ + if (replyData.m_operation) + setOperation(replyData.m_operation); + if (!replyData.m_contentDisposition.isNull()) + setHeader(QNetworkRequest::ContentDispositionHeader, QString(replyData.m_contentDisposition)); + if (!replyData.m_contentType.isNull()) + setHeader(QNetworkRequest::ContentTypeHeader, QString(replyData.m_contentType)); + if (!replyData.m_location.isNull()) + setHeader(QNetworkRequest::LocationHeader, QString(replyData.m_location)); + if (replyData.m_lastModified) + setHeader(QNetworkRequest::LastModifiedHeader, QDateTime::fromMSecsSinceEpoch(replyData.m_lastModified)); + if (!replyData.m_cookie.isNull()) + setHeader(QNetworkRequest::SetCookieHeader, QVariant::fromValue(QNetworkCookie::parseCookies(QString(replyData.m_cookie).toAscii()))); + if (!replyData.m_userAgent.isNull()) + setHeader(QNetworkRequest::UserAgentHeader, QString(replyData.m_userAgent)); + if (!replyData.m_server.isNull()) + setHeader(QNetworkRequest::ServerHeader, QString(replyData.m_server)); + setHeader(QNetworkRequest::ContentLengthHeader, QVariant::fromValue(replyData.m_contentLength)); + setData(replyData.m_dataHandle, replyData.m_contentLength); +} + +qint64 QtNetworkReply::readData(char* data, qint64 maxlen) +{ + qint64 bytesRead = maxlen < m_bytesAvailable ? maxlen : m_bytesAvailable; + if (qMemCopy(data, static_cast<char*>(m_sharedMemory->data()) + m_sharedMemorySize - m_bytesAvailable, bytesRead)) { + m_bytesAvailable -= bytesRead; + return bytesRead; + } + return 0; +} + +qint64 QtNetworkReply::bytesAvailable() const +{ + return m_bytesAvailable + QNetworkReply::bytesAvailable(); +} + +void QtNetworkReply::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) +{ + QNetworkReply::setHeader(header, value); +} + +void QtNetworkReply::abort() { } +void QtNetworkReply::close() { } +void QtNetworkReply::setReadBufferSize(qint64 size) { } +bool QtNetworkReply::canReadLine () const { return true; } + +void QtNetworkReply::finalize() +{ + QNetworkReply::setFinished(true); + emit readyRead(); + emit finished(); +} + +} // namespace WebKit + diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkReply.h b/Source/WebKit2/WebProcess/qt/QtNetworkReply.h new file mode 100644 index 000000000..8ceb7926e --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/QtNetworkReply.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef QtNetworkReply_h +#define QtNetworkReply_h + +#include "QtNetworkReplyData.h" +#include "SharedMemory.h" +#include <QByteArray> +#include <QDateTime> +#include <QNetworkReply> + +namespace WebKit { + +class QtNetworkAccessManager; + +class QtNetworkReply : public QNetworkReply { +public: + QtNetworkReply(const QNetworkRequest&, QtNetworkAccessManager* parent); + + virtual qint64 readData(char *data, qint64 maxlen); + virtual qint64 bytesAvailable() const; + void setHeader(QNetworkRequest::KnownHeaders, const QVariant &value); + void setData(const SharedMemory::Handle&, qint64 dataSize); + void setReplyData(const QtNetworkReplyData&); + void finalize(); + +protected: + virtual void abort(); + virtual void close(); + virtual void setReadBufferSize(qint64); + virtual bool canReadLine() const; + +private: + qint64 m_bytesAvailable; + QByteArray m_buffer; + RefPtr<SharedMemory> m_sharedMemory; + qint64 m_sharedMemorySize; +}; + +} // namespace WebKit + +#endif // QtNetworkReply_h diff --git a/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp new file mode 100644 index 000000000..c38e38241 --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "RunLoop.h" +#include <runtime/InitializeThreading.h> +#include "WebProcess.h" +#include <wtf/MainThread.h> + +#include <QApplication> +#include <QList> +#include <QNetworkProxyFactory> +#include <QString> +#include <QStringList> +#include <QUrl> +#include <QtGlobal> + +#if USE(ACCELERATED_COMPOSITING) +#include "WebGraphicsLayer.h" +#endif + +#ifndef NDEBUG +#if !OS(WINDOWS) +#include <unistd.h> +#endif +#endif + +#ifndef NDEBUG +#include <QDebug> +#endif + +#if !USE(UNIX_DOMAIN_SOCKETS) +#include <servers/bootstrap.h> + +extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t); +#endif + +using namespace WebCore; + +namespace WebKit { +#ifndef NDEBUG +#if OS(WINDOWS) +static void sleep(unsigned seconds) +{ + ::Sleep(seconds * 1000); +} +#endif +#endif + +class EnvHttpProxyFactory : public QNetworkProxyFactory +{ +public: + EnvHttpProxyFactory() { } + + bool initializeFromEnvironment(); + + QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery& query = QNetworkProxyQuery()); + +private: + QList<QNetworkProxy> m_httpProxy; + QList<QNetworkProxy> m_httpsProxy; +}; + +bool EnvHttpProxyFactory::initializeFromEnvironment() +{ + bool wasSetByEnvironment = false; + + QUrl proxyUrl = QUrl::fromUserInput(QString::fromLocal8Bit(qgetenv("http_proxy"))); + if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) { + int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080; + m_httpProxy << QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort); + wasSetByEnvironment = true; + } else + m_httpProxy << QNetworkProxy::NoProxy; + + proxyUrl = QUrl::fromUserInput(QString::fromLocal8Bit(qgetenv("https_proxy"))); + if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) { + int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080; + m_httpsProxy << QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort); + wasSetByEnvironment = true; + } else + m_httpsProxy << QNetworkProxy::NoProxy; + + return wasSetByEnvironment; +} + +QList<QNetworkProxy> EnvHttpProxyFactory::queryProxy(const QNetworkProxyQuery& query) +{ + QString protocol = query.protocolTag().toLower(); + bool localHost = false; + + if (!query.peerHostName().compare(QLatin1String("localhost"), Qt::CaseInsensitive) || !query.peerHostName().compare(QLatin1String("127.0.0.1"), Qt::CaseInsensitive)) + localHost = true; + if (protocol == QLatin1String("http") && !localHost) + return m_httpProxy; + if (protocol == QLatin1String("https") && !localHost) + return m_httpsProxy; + + QList<QNetworkProxy> proxies; + proxies << QNetworkProxy::NoProxy; + return proxies; +} + +static void initializeProxy() +{ + QList<QNetworkProxy> proxylist = QNetworkProxyFactory::systemProxyForQuery(); + if (proxylist.count() == 1) { + QNetworkProxy proxy = proxylist.first(); + if (proxy == QNetworkProxy::NoProxy || proxy == QNetworkProxy::DefaultProxy) { + EnvHttpProxyFactory* proxyFactory = new EnvHttpProxyFactory(); + if (proxyFactory->initializeFromEnvironment()) { + QNetworkProxyFactory::setApplicationProxyFactory(proxyFactory); + return; + } + } + } + QNetworkProxyFactory::setUseSystemConfiguration(true); +} + +void messageHandler(QtMsgType type, const char* message) +{ + if (type == QtCriticalMsg) { + fprintf(stderr, "%s\n", message); + return; + } + + // Do nothing +} + +Q_DECL_EXPORT int WebProcessMainQt(int argc, char** argv) +{ + // Has to be done before QApplication is constructed in case + // QApplication itself produces debug output. + QByteArray suppressOutput = qgetenv("QT_WEBKIT_SUPPRESS_WEB_PROCESS_OUTPUT"); + if (!suppressOutput.isEmpty() && suppressOutput != "0") + qInstallMsgHandler(messageHandler); + + QApplication::setGraphicsSystem(QLatin1String("raster")); + QApplication* app = new QApplication(argc, argv); +#ifndef NDEBUG + if (qgetenv("QT_WEBKIT2_DEBUG") == "1") { + qDebug() << "Waiting 3 seconds for debugger"; + sleep(3); + } +#endif + + initializeProxy(); + + srandom(time(0)); + + JSC::initializeThreading(); + WTF::initializeMainThread(); + RunLoop::initializeMainRunLoop(); + + // Create the connection. + if (app->arguments().size() <= 1) { + qDebug() << "Error: wrong number of arguments."; + return 1; + } + +#if OS(DARWIN) + QString serviceName = app->arguments().value(1); + + // Get the server port. + mach_port_t identifier; + kern_return_t kr = bootstrap_look_up2(bootstrap_port, serviceName.toUtf8().data(), &identifier, 0, 0); + if (kr) { + printf("bootstrap_look_up2 result: %x", kr); + return 2; + } +#else + bool wasNumber = false; + int identifier = app->arguments().at(1).toInt(&wasNumber, 10); + if (!wasNumber) { + qDebug() << "Error: connection identifier wrong."; + return 1; + } +#endif +#if USE(ACCELERATED_COMPOSITING) + WebGraphicsLayer::initFactory(); +#endif + + WebKit::WebProcess::shared().initialize(identifier, RunLoop::main()); + + RunLoop::run(); + + // FIXME: Do more cleanup here. + + return 0; +} + +} diff --git a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp new file mode 100644 index 000000000..a2beac14b --- /dev/null +++ b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebProcess.h" + +#include "InjectedBundle.h" +#include "QtBuiltinBundle.h" +#include "QtNetworkAccessManager.h" +#include "WKBundleAPICast.h" +#include "WebProcessCreationParameters.h" + +#include <QCoreApplication> +#include <QNetworkAccessManager> +#include <QNetworkCookieJar> +#include <WebCore/CookieJarQt.h> +#include <WebCore/PageCache.h> +#include <WebCore/RuntimeEnabledFeatures.h> + +#if defined(Q_OS_MACX) +#include <dispatch/dispatch.h> +#endif + +using namespace WebCore; + +namespace WebKit { + +static const int DefaultPageCacheCapacity = 20; + +void WebProcess::platformSetCacheModel(CacheModel) +{ + // FIXME: see bug 73918 + pageCache()->setCapacity(DefaultPageCacheCapacity); +} + +void WebProcess::platformClearResourceCaches(ResourceCachesToClear) +{ +} + +#if defined(Q_OS_MACX) +static void parentProcessDiedCallback(void*) +{ + QCoreApplication::quit(); +} +#endif + +void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder* arguments) +{ + m_networkAccessManager = new QtNetworkAccessManager(this); + ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull()); + WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory); + m_networkAccessManager->setCookieJar(jar); + // Do not let QNetworkAccessManager delete the jar. + jar->setParent(0); + +#if defined(Q_OS_MACX) + pid_t ppid = getppid(); + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ppid, DISPATCH_PROC_EXIT, queue); + if (source) { + dispatch_source_set_event_handler_f(source, parentProcessDiedCallback); + dispatch_resume(source); + } +#endif + + // Disable runtime enabled features that have no WebKit2 implementation yet. +#if ENABLE(DEVICE_ORIENTATION) + WebCore::RuntimeEnabledFeatures::setDeviceMotionEnabled(false); + WebCore::RuntimeEnabledFeatures::setDeviceOrientationEnabled(false); +#endif +#if ENABLE(SPEECH_INPUT) + WebCore::RuntimeEnabledFeatures::setSpeechInputEnabled(false); +#endif + + // We'll only install the Qt builtin bundle if we don't have one given by the UI process. + // Currently only WTR provides its own bundle. + if (parameters.injectedBundlePath.isEmpty()) { + m_injectedBundle = InjectedBundle::create(String()); + m_injectedBundle->setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle)); + QtBuiltinBundle::shared().initialize(toAPI(m_injectedBundle.get())); + } +} + +void WebProcess::platformTerminate() +{ + delete m_networkAccessManager; + m_networkAccessManager = 0; + WebCore::SharedCookieJarQt::shared()->destroy(); +} + +} // namespace WebKit |