[Qt][WK2] Implement custom URL schemes defined in QML.
authorzeno.albisser@nokia.com <zeno.albisser@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2012 20:04:33 +0000 (20:04 +0000)
committerzeno.albisser@nokia.com <zeno.albisser@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2012 20:04:33 +0000 (20:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74931

.:

Add new classes to the export map.

Reviewed by Kenneth Rohde Christiansen.

* Source/qtwebkit-export.map:

Source/WebKit/qt:

Make classes QQuickUrlSchemeDelegate, QQuickNetworkRequest
and QQuickNetworkReply accessible from QML.

Reviewed by Kenneth Rohde Christiansen.

* declarative/experimental/experimental.pri:
* declarative/experimental/plugin.cpp:
* declarative/public.pri:

Source/WebKit2:

Allow creation of custom UrlSchemeDelegates from QML.
A UrlSchemeDelegate contains a handler signal that is triggered
when a url matching the defined scheme is requested.
To allow for this a derivation of QNetworkAccessManager
is necessary.
The request is then handled in QML/JS and a reply
is sent back from the UIProcess to the WebProcess.

Reviewed by Kenneth Rohde Christiansen.

* Shared/qt/QtNetworkReplyData.cpp: Added.
(WebKit::QtNetworkReplyData::QtNetworkReplyData):
(WebKit::QtNetworkReplyData::encode):
(WebKit::QtNetworkReplyData::decode):
* Shared/qt/QtNetworkReplyData.h: Added.
* Shared/qt/QtNetworkRequestData.cpp: Added.
(WebKit::QtNetworkRequestData::QtNetworkRequestData):
(WebKit::QtNetworkRequestData::encode):
(WebKit::QtNetworkRequestData::decode):
* Shared/qt/QtNetworkRequestData.h: Added.
* Target.pri:
* UIProcess/API/qt/qquicknetworkreply.cpp: Added.
(QQuickNetworkReply::QQuickNetworkReply):
(QQuickNetworkReply::contentType):
(QQuickNetworkReply::setContentType):
(QQuickNetworkReply::operation):
(QQuickNetworkReply::setOperation):
(QQuickNetworkReply::contentDisposition):
(QQuickNetworkReply::setContentDisposition):
(QQuickNetworkReply::location):
(QQuickNetworkReply::setLocation):
(QQuickNetworkReply::lastModified):
(QQuickNetworkReply::setLastModified):
(QQuickNetworkReply::cookie):
(QQuickNetworkReply::setCookie):
(QQuickNetworkReply::userAgent):
(QQuickNetworkReply::setUserAgent):
(QQuickNetworkReply::server):
(QQuickNetworkReply::setServer):
(QQuickNetworkReply::data):
(QQuickNetworkReply::setData):
(QQuickNetworkReply::send):
(QQuickNetworkReply::networkRequestData):
(QQuickNetworkReply::setNetworkRequestData):
(QQuickNetworkReply::networkReplyData):
* UIProcess/API/qt/qquicknetworkreply_p.h: Added.
* UIProcess/API/qt/qquicknetworkrequest_p.h: Added.
* UIProcess/API/qt/qquickurlschemedelegate.cpp: Added.
(QQuickUrlSchemeDelegate::QQuickUrlSchemeDelegate):
(QQuickUrlSchemeDelegate::scheme):
(QQuickUrlSchemeDelegate::setScheme):
(QQuickUrlSchemeDelegate::request):
(QQuickUrlSchemeDelegate::reply):
* UIProcess/API/qt/qquickurlschemedelegate_p.h: Added.
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewExperimental::QQuickWebViewExperimental):
(QQuickWebViewExperimental::schemeDelegates_At):
(QQuickWebViewExperimental::schemeDelegates_Append):
(QQuickWebViewExperimental::schemeDelegates_Count):
(QQuickWebViewExperimental::schemeDelegates_Clear):
(QQuickWebViewExperimental::schemeDelegates):
(QQuickWebViewExperimental::invokeApplicationSchemeHandler):
(QQuickWebViewExperimental::sendApplicationSchemeReply):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/qt/QtPageClient.cpp:
(QtPageClient::handleApplicationSchemeRequest):
* UIProcess/qt/QtPageClient.h:
* UIProcess/qt/WebPageProxyQt.cpp:
(WebKit::WebPageProxy::registerApplicationScheme):
(WebKit::WebPageProxy::resolveApplicationSchemeRequest):
(WebKit::WebPageProxy::sendApplicationSchemeReply):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::createNetworkingContext):
* WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp:
* WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::WebPage::registerApplicationScheme):
(WebKit::WebPage::receivedApplicationSchemeRequest):
(WebKit::WebPage::applicationSchemeReply):
* WebProcess/qt/QtNetworkAccessManager.cpp: Added.
(WebKit::QtNetworkAccessManager::QtNetworkAccessManager):
(WebKit::QtNetworkAccessManager::obtainOriginatingWebPage):
(WebKit::QtNetworkAccessManager::createRequest):
(WebKit::QtNetworkAccessManager::registerApplicationScheme):
* WebProcess/qt/QtNetworkAccessManager.h: Added.
* WebProcess/qt/QtNetworkReply.cpp: Added.
(WebKit::QtNetworkReply::QtNetworkReply):
(WebKit::QtNetworkReply::setData):
(WebKit::QtNetworkReply::setReplyData):
(WebKit::QtNetworkReply::readData):
(WebKit::QtNetworkReply::bytesAvailable):
(WebKit::QtNetworkReply::setHeader):
(WebKit::QtNetworkReply::abort):
(WebKit::QtNetworkReply::close):
(WebKit::QtNetworkReply::setReadBufferSize):
(WebKit::QtNetworkReply::canReadLine):
(WebKit::QtNetworkReply::finalize):
* WebProcess/qt/QtNetworkReply.h: Added.
* WebProcess/qt/WebProcessQt.cpp:
(WebKit::WebProcess::platformInitializeWebProcess):

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

35 files changed:
ChangeLog
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/declarative/experimental/experimental.pri
Source/WebKit/qt/declarative/experimental/plugin.cpp
Source/WebKit/qt/declarative/public.pri
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/qt/QtNetworkReplyData.cpp [new file with mode: 0644]
Source/WebKit2/Shared/qt/QtNetworkReplyData.h [new file with mode: 0644]
Source/WebKit2/Shared/qt/QtNetworkRequestData.cpp [new file with mode: 0644]
Source/WebKit2/Shared/qt/QtNetworkRequestData.h [new file with mode: 0644]
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/qt/qquicknetworkreply.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qquicknetworkreply_p.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qquicknetworkrequest_p.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/qt/QtPageClient.cpp
Source/WebKit2/UIProcess/qt/QtPageClient.h
Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp
Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp
Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h [new file with mode: 0644]
Source/WebKit2/WebProcess/qt/QtNetworkReply.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/qt/QtNetworkReply.h [new file with mode: 0644]
Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
Source/qtwebkit-export.map

index 1c29282..e32efe3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-01-05  Zeno Albisser  <zeno@webkit.org>
+
+        [Qt][WK2] Implement custom URL schemes defined in QML.
+        https://bugs.webkit.org/show_bug.cgi?id=74931
+
+        Add new classes to the export map.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * Source/qtwebkit-export.map:
+
 2012-01-05  Fady Samuel  <fsamuel@chromium.org>
 
         Move scalePageBy from eventSender to window.internals
index 4bf3c0f..4860e30 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-05  Zeno Albisser  <zeno@webkit.org>
+
+        [Qt][WK2] Implement custom URL schemes defined in QML.
+        https://bugs.webkit.org/show_bug.cgi?id=74931
+
+        Make classes QQuickUrlSchemeDelegate, QQuickNetworkRequest
+        and QQuickNetworkReply accessible from QML.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * declarative/experimental/experimental.pri:
+        * declarative/experimental/plugin.cpp:
+        * declarative/public.pri:
+
 2012-01-04  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
 
         [Qt] Introduce new qmake variable 'WEBKIT' for signaling dependencies
index 494388a..49f463d 100644 (file)
@@ -36,7 +36,16 @@ RPATHDIR_RELATIVE_TO_DESTDIR = ../../lib
 SOURCES += plugin.cpp
 
 DEFINES += HAVE_WEBKIT2
-INCLUDEPATH += ../../../../WebKit2/UIProcess/API/qt
+
+INCLUDEPATH += \
+    ../../../../WebKit2/UIProcess/API/qt \
+    ../../../../WebKit2/Shared/qt \
+    ../../../../JavaScriptCore \
+    ../../../../JavaScriptCore/wtf \
+    ../../../../JavaScriptCore/wtf/unicode \
+    ../../../../JavaScriptCore/runtime \
+    ../../../../WebKit2/Platform \
+    ../../../../WebKit2/Platform/CoreIPC
 
 target.path = $$[QT_INSTALL_IMPORTS]/$${TARGET.module_name}
 
index d289229..cab0fba 100644 (file)
     Boston, MA 02110-1301, USA.
 */
 
+#include "config.h"
+
+#include "qquicknetworkreply_p.h"
+#include "qquicknetworkrequest_p.h"
 #include "qquickwebpage_p.h"
 #include "qquickwebview_p.h"
 #include "qwebdownloaditem_p.h"
@@ -52,6 +56,11 @@ public:
             QObject::tr("Cannot create separate instance of WebViewExperimental"));
         qmlRegisterUncreatableType<QWebViewportInfo>(uri, 3, 0, "QWebViewportInfo",
             QObject::tr("Cannot create separate instance of QWebViewportInfo"));
+        qmlRegisterType<QQuickUrlSchemeDelegate>(uri, 3, 0, "UrlSchemeDelegate");
+        qmlRegisterUncreatableType<QQuickNetworkRequest>(uri, 3, 0, "NetworkRequest",
+            QObject::tr("NetworkRequest should not be created from QML"));
+        qmlRegisterUncreatableType<QQuickNetworkReply>(uri, 3, 0, "NetworkReply",
+            QObject::tr("NetworkReply should not be created from QML"));
     }
 };
 
index 29bd903..3e2fb47 100644 (file)
@@ -38,6 +38,12 @@ DESTDIR = $${ROOT_BUILD_DIR}/imports/$${TARGET.module_name}
 CONFIG += rpath
 RPATHDIR_RELATIVE_TO_DESTDIR = ../../lib
 
+INCLUDEPATH += \
+    ../../../WebKit2/Shared/qt \
+    ../../../JavaScriptCore \
+    ../../../JavaScriptCore/runtime \
+    ../../../JavaScriptCore/wtf
+
 SOURCES += qdeclarativewebview.cpp plugin.cpp
 HEADERS += qdeclarativewebview_p.h
 
index cbbe420..1fd2d5c 100644 (file)
@@ -1,3 +1,113 @@
+2012-01-05  Zeno Albisser  <zeno@webkit.org>
+
+        [Qt][WK2] Implement custom URL schemes defined in QML.
+        https://bugs.webkit.org/show_bug.cgi?id=74931
+
+        Allow creation of custom UrlSchemeDelegates from QML.
+        A UrlSchemeDelegate contains a handler signal that is triggered
+        when a url matching the defined scheme is requested.
+        To allow for this a derivation of QNetworkAccessManager
+        is necessary.
+        The request is then handled in QML/JS and a reply
+        is sent back from the UIProcess to the WebProcess.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * Shared/qt/QtNetworkReplyData.cpp: Added.
+        (WebKit::QtNetworkReplyData::QtNetworkReplyData):
+        (WebKit::QtNetworkReplyData::encode):
+        (WebKit::QtNetworkReplyData::decode):
+        * Shared/qt/QtNetworkReplyData.h: Added.
+        * Shared/qt/QtNetworkRequestData.cpp: Added.
+        (WebKit::QtNetworkRequestData::QtNetworkRequestData):
+        (WebKit::QtNetworkRequestData::encode):
+        (WebKit::QtNetworkRequestData::decode):
+        * Shared/qt/QtNetworkRequestData.h: Added.
+        * Target.pri:
+        * UIProcess/API/qt/qquicknetworkreply.cpp: Added.
+        (QQuickNetworkReply::QQuickNetworkReply):
+        (QQuickNetworkReply::contentType):
+        (QQuickNetworkReply::setContentType):
+        (QQuickNetworkReply::operation):
+        (QQuickNetworkReply::setOperation):
+        (QQuickNetworkReply::contentDisposition):
+        (QQuickNetworkReply::setContentDisposition):
+        (QQuickNetworkReply::location):
+        (QQuickNetworkReply::setLocation):
+        (QQuickNetworkReply::lastModified):
+        (QQuickNetworkReply::setLastModified):
+        (QQuickNetworkReply::cookie):
+        (QQuickNetworkReply::setCookie):
+        (QQuickNetworkReply::userAgent):
+        (QQuickNetworkReply::setUserAgent):
+        (QQuickNetworkReply::server):
+        (QQuickNetworkReply::setServer):
+        (QQuickNetworkReply::data):
+        (QQuickNetworkReply::setData):
+        (QQuickNetworkReply::send):
+        (QQuickNetworkReply::networkRequestData):
+        (QQuickNetworkReply::setNetworkRequestData):
+        (QQuickNetworkReply::networkReplyData):
+        * UIProcess/API/qt/qquicknetworkreply_p.h: Added.
+        * UIProcess/API/qt/qquicknetworkrequest_p.h: Added.
+        * UIProcess/API/qt/qquickurlschemedelegate.cpp: Added.
+        (QQuickUrlSchemeDelegate::QQuickUrlSchemeDelegate):
+        (QQuickUrlSchemeDelegate::scheme):
+        (QQuickUrlSchemeDelegate::setScheme):
+        (QQuickUrlSchemeDelegate::request):
+        (QQuickUrlSchemeDelegate::reply):
+        * UIProcess/API/qt/qquickurlschemedelegate_p.h: Added.
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewExperimental::QQuickWebViewExperimental):
+        (QQuickWebViewExperimental::schemeDelegates_At):
+        (QQuickWebViewExperimental::schemeDelegates_Append):
+        (QQuickWebViewExperimental::schemeDelegates_Count):
+        (QQuickWebViewExperimental::schemeDelegates_Clear):
+        (QQuickWebViewExperimental::schemeDelegates):
+        (QQuickWebViewExperimental::invokeApplicationSchemeHandler):
+        (QQuickWebViewExperimental::sendApplicationSchemeReply):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/qt/QtPageClient.cpp:
+        (QtPageClient::handleApplicationSchemeRequest):
+        * UIProcess/qt/QtPageClient.h:
+        * UIProcess/qt/WebPageProxyQt.cpp:
+        (WebKit::WebPageProxy::registerApplicationScheme):
+        (WebKit::WebPageProxy::resolveApplicationSchemeRequest):
+        (WebKit::WebPageProxy::sendApplicationSchemeReply):
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::createNetworkingContext):
+        * WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp:
+        * WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/qt/WebPageQt.cpp:
+        (WebKit::WebPage::registerApplicationScheme):
+        (WebKit::WebPage::receivedApplicationSchemeRequest):
+        (WebKit::WebPage::applicationSchemeReply):
+        * WebProcess/qt/QtNetworkAccessManager.cpp: Added.
+        (WebKit::QtNetworkAccessManager::QtNetworkAccessManager):
+        (WebKit::QtNetworkAccessManager::obtainOriginatingWebPage):
+        (WebKit::QtNetworkAccessManager::createRequest):
+        (WebKit::QtNetworkAccessManager::registerApplicationScheme):
+        * WebProcess/qt/QtNetworkAccessManager.h: Added.
+        * WebProcess/qt/QtNetworkReply.cpp: Added.
+        (WebKit::QtNetworkReply::QtNetworkReply):
+        (WebKit::QtNetworkReply::setData):
+        (WebKit::QtNetworkReply::setReplyData):
+        (WebKit::QtNetworkReply::readData):
+        (WebKit::QtNetworkReply::bytesAvailable):
+        (WebKit::QtNetworkReply::setHeader):
+        (WebKit::QtNetworkReply::abort):
+        (WebKit::QtNetworkReply::close):
+        (WebKit::QtNetworkReply::setReadBufferSize):
+        (WebKit::QtNetworkReply::canReadLine):
+        (WebKit::QtNetworkReply::finalize):
+        * WebProcess/qt/QtNetworkReply.h: Added.
+        * WebProcess/qt/WebProcessQt.cpp:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2012-01-05  Fady Samuel  <fsamuel@chromium.org>
 
         Move scalePageBy from eventSender to window.internals
diff --git a/Source/WebKit2/Shared/qt/QtNetworkReplyData.cpp b/Source/WebKit2/Shared/qt/QtNetworkReplyData.cpp
new file mode 100644 (file)
index 0000000..62e5807
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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 "QtNetworkReplyData.h"
+
+#include "ArgumentCodersQt.h"
+#include "KURL.h"
+#include "Noncopyable.h"
+#include "SharedMemory.h"
+#include "WebCoreArgumentCoders.h"
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+QtNetworkReplyData::QtNetworkReplyData()
+    : m_contentLength(0)
+    , m_lastModified(0)
+{ }
+
+void QtNetworkReplyData::encode(CoreIPC::ArgumentEncoder* encoder) const
+{
+    encoder->encode(m_urlString);
+    encoder->encodeEnum(m_operation);
+    encoder->encode(m_contentDisposition);
+    encoder->encode(m_contentType);
+    encoder->encodeUInt64(m_contentLength);
+    encoder->encode(m_location);
+    encoder->encodeUInt64(m_lastModified);
+    encoder->encode(m_cookie);
+    encoder->encode(m_userAgent);
+    encoder->encode(m_server);
+    encoder->encode(m_replyUuid);
+    encoder->encode(m_dataHandle);
+}
+
+bool QtNetworkReplyData::decode(CoreIPC::ArgumentDecoder* decoder, QtNetworkReplyData& destination)
+{
+    if (!decoder->decode(destination.m_urlString))
+        return false;
+    if (!decoder->decodeEnum(destination.m_operation))
+        return false;
+    if (!decoder->decode(destination.m_contentDisposition))
+        return false;
+    if (!decoder->decode(destination.m_contentType))
+        return false;
+    if (!decoder->decodeUInt64(destination.m_contentLength))
+        return false;
+    if (!decoder->decode(destination.m_location))
+        return false;
+    if (!decoder->decodeUInt64(destination.m_lastModified))
+        return false;
+    if (!decoder->decode(destination.m_cookie))
+        return false;
+    if (!decoder->decode(destination.m_userAgent))
+        return false;
+    if (!decoder->decode(destination.m_server))
+        return false;
+    if (!decoder->decode(destination.m_replyUuid))
+        return false;
+    if (!decoder->decode(destination.m_dataHandle))
+        return false;
+    return true;
+}
+
+} // namespace WebKit
+
+
diff --git a/Source/WebKit2/Shared/qt/QtNetworkReplyData.h b/Source/WebKit2/Shared/qt/QtNetworkReplyData.h
new file mode 100644 (file)
index 0000000..d74b422
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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 QtNetworkReplyData_h
+#define QtNetworkReplyData_h
+
+#include "Noncopyable.h"
+#include "RefCounted.h"
+#include "SharedMemory.h"
+#include <QNetworkAccessManager>
+#include <wtf/text/WTFString.h>
+
+namespace CoreIPC {
+class ArgumentEncoder;
+class ArgumentDecoder;
+};
+
+namespace WebKit {
+
+struct QtNetworkReplyData : public WTF::RefCounted<QtNetworkReplyData> {
+    WTF_MAKE_NONCOPYABLE(QtNetworkReplyData);
+public:
+    QtNetworkReplyData();
+
+    void encode(CoreIPC::ArgumentEncoder*) const;
+    static bool decode(CoreIPC::ArgumentDecoder*, QtNetworkReplyData&);
+
+    WTF::String m_urlString;
+
+    QNetworkAccessManager::Operation m_operation;
+    WTF::String m_contentDisposition;
+    WTF::String m_contentType;
+    uint64_t m_contentLength;
+    WTF::String m_location;
+    uint64_t m_lastModified;
+    WTF::String m_cookie;
+    WTF::String m_userAgent;
+    WTF::String m_server;
+    String m_replyUuid;
+
+    SharedMemory::Handle m_dataHandle;
+};
+
+} // namespace WebKit
+
+#endif // QtNetworkReplyData_h
diff --git a/Source/WebKit2/Shared/qt/QtNetworkRequestData.cpp b/Source/WebKit2/Shared/qt/QtNetworkRequestData.cpp
new file mode 100644 (file)
index 0000000..c6ea6e3
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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 replyroduce 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 "QtNetworkRequestData.h"
+
+#include "ArgumentCodersQt.h"
+#include "Platform.h"
+#include "WebCoreArgumentCoders.h"
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QUuid>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+QtNetworkRequestData::QtNetworkRequestData()
+{ }
+
+QtNetworkRequestData::QtNetworkRequestData(const QNetworkRequest& request, QNetworkReply* reply)
+{
+    m_scheme = request.url().scheme();
+    m_urlString = request.url().toString();
+    m_replyUuid = QUuid::createUuid().toString();
+}
+
+QtNetworkRequestData::QtNetworkRequestData(const QtNetworkRequestData& origin)
+    : RefCounted<QtNetworkRequestData>(),
+    m_scheme(origin.m_scheme),
+    m_urlString(origin.m_urlString),
+    m_replyUuid(origin.m_replyUuid)
+{
+}
+
+void QtNetworkRequestData::encode(CoreIPC::ArgumentEncoder* encoder) const
+{
+    encoder->encode(m_scheme);
+    encoder->encode(m_urlString);
+    encoder->encode(m_replyUuid);
+}
+
+bool QtNetworkRequestData::decode(CoreIPC::ArgumentDecoder* decoder, QtNetworkRequestData& destination)
+{
+    if (!decoder->decode(destination.m_scheme))
+        return false;
+    if (!decoder->decode(destination.m_urlString))
+        return false;
+    if (!decoder->decode(destination.m_replyUuid))
+        return false;
+    return true;
+}
+
+} // namespace WebKit
+
diff --git a/Source/WebKit2/Shared/qt/QtNetworkRequestData.h b/Source/WebKit2/Shared/qt/QtNetworkRequestData.h
new file mode 100644 (file)
index 0000000..1567964
--- /dev/null
@@ -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 replyroduce 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 QtNetworkRequestData_h
+#define QtNetworkRequestData_h
+
+#include "RefCounted.h"
+#include <wtf/text/WTFString.h>
+
+namespace CoreIPC {
+class ArgumentEncoder;
+class ArgumentDecoder;
+};
+
+class QNetworkRequest;
+class QNetworkReply;
+
+namespace WebKit {
+
+struct QtNetworkRequestData : public WTF::RefCounted<QtNetworkRequestData> {
+    QtNetworkRequestData();
+    QtNetworkRequestData(const QNetworkRequest&, QNetworkReply*);
+    QtNetworkRequestData(const QtNetworkRequestData&);
+
+    void encode(CoreIPC::ArgumentEncoder*) const;
+    static bool decode(CoreIPC::ArgumentDecoder*, QtNetworkRequestData&);
+
+    String m_scheme;
+    String m_urlString;
+    String m_replyUuid;
+};
+
+} // namespace WebKit
+
+#endif // QtNetworkRequestData_h
index 9857bfd..733469e 100644 (file)
@@ -127,6 +127,8 @@ HEADERS += \
     Shared/qt/ArgumentCodersQt.h \
     Shared/qt/PlatformCertificateInfo.h \
     Shared/qt/WebEventFactoryQt.h \
+    Shared/qt/QtNetworkReplyData.h \
+    Shared/qt/QtNetworkRequestData.h \
     UIProcess/API/C/WKAPICast.h \
     UIProcess/API/C/WKAuthenticationChallenge.h \
     UIProcess/API/C/WKAuthenticationDecisionListener.h \
@@ -178,6 +180,9 @@ HEADERS += \
     UIProcess/API/qt/qwebnavigationhistory_p_p.h \
     UIProcess/API/qt/qquickwebview_p.h \
     UIProcess/API/qt/qquickwebview_p_p.h \
+    UIProcess/API/qt/qquicknetworkreply_p.h \
+    UIProcess/API/qt/qquicknetworkrequest_p.h \
+    UIProcess/API/qt/qquickurlschemedelegate_p.h \
     UIProcess/API/qt/qwebviewportinfo_p.h \
     UIProcess/Authentication/AuthenticationChallengeProxy.h \
     UIProcess/Authentication/AuthenticationDecisionListener.h \
@@ -353,7 +358,9 @@ HEADERS += \
     WebProcess/WebConnectionToUIProcess.h \
     WebProcess/WebProcess.h \
     WebProcess/qt/QtBuiltinBundle.h \
-    WebProcess/qt/QtBuiltinBundlePage.h
+    WebProcess/qt/QtBuiltinBundlePage.h \
+    WebProcess/qt/QtNetworkAccessManager.h \
+    WebProcess/qt/QtNetworkReply.h
 
 SOURCES += \
     Platform/CoreIPC/ArgumentCoders.cpp \
@@ -460,6 +467,8 @@ SOURCES += \
     Shared/qt/NativeWebWheelEventQt.cpp \
     Shared/qt/WebCoreArgumentCodersQt.cpp \
     Shared/qt/WebEventFactoryQt.cpp \
+    Shared/qt/QtNetworkReplyData.cpp \
+    Shared/qt/QtNetworkRequestData.cpp \
     Shared/qt/WebURLRequestQt.cpp \
     Shared/qt/WebURLResponseQt.cpp \
     UIProcess/API/C/WKAuthenticationChallenge.cpp \
@@ -499,6 +508,8 @@ SOURCES += \
     UIProcess/API/qt/qwebnavigationhistory.cpp \
     UIProcess/API/qt/qquickwebview.cpp \
     UIProcess/API/qt/qwebiconimageprovider.cpp \
+    UIProcess/API/qt/qquicknetworkreply.cpp \
+    UIProcess/API/qt/qquickurlschemedelegate.cpp \
     UIProcess/API/qt/qwebpreferences.cpp \
     UIProcess/API/qt/qwebviewportinfo.cpp \
     UIProcess/Authentication/AuthenticationChallengeProxy.cpp \
@@ -708,6 +719,8 @@ SOURCES += \
     WebProcess/WebProcess.cpp \
     WebProcess/qt/QtBuiltinBundle.cpp \
     WebProcess/qt/QtBuiltinBundlePage.cpp \
+    WebProcess/qt/QtNetworkAccessManager.cpp \
+    WebProcess/qt/QtNetworkReply.cpp \
     WebProcess/qt/WebProcessMainQt.cpp \
     WebProcess/qt/WebProcessQt.cpp
 
diff --git a/Source/WebKit2/UIProcess/API/qt/qquicknetworkreply.cpp b/Source/WebKit2/UIProcess/API/qt/qquicknetworkreply.cpp
new file mode 100644 (file)
index 0000000..4e88103
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org>
+ *
+ * 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 "qquicknetworkreply_p.h"
+
+#include "QtNetworkReplyData.h"
+#include "QtNetworkRequestData.h"
+#include "qquickwebview_p.h"
+#include <QDateTime>
+
+using namespace WebKit;
+
+QQuickNetworkReply::QQuickNetworkReply(QObject* parent)
+    : QObject(parent)
+    , m_networkReplyData(adoptRef(new WebKit::QtNetworkReplyData))
+{
+    Q_ASSERT(parent);
+}
+
+QString QQuickNetworkReply::contentType() const
+{
+    return m_networkReplyData->m_contentType;
+}
+
+void QQuickNetworkReply::setContentType(const QString& contentType)
+{
+    m_networkReplyData->m_contentType = contentType;
+}
+
+QNetworkAccessManager::Operation QQuickNetworkReply::operation() const
+{
+    return m_networkReplyData->m_operation;
+}
+
+void QQuickNetworkReply::setOperation(QNetworkAccessManager::Operation operation)
+{
+    m_networkReplyData->m_operation = operation;
+}
+
+QString QQuickNetworkReply::contentDisposition() const
+{
+    return m_networkReplyData->m_contentDisposition;
+}
+
+void QQuickNetworkReply::setContentDisposition(const QString& disposition)
+{
+    m_networkReplyData->m_contentDisposition = disposition;
+}
+
+QString QQuickNetworkReply::location() const
+{
+    return m_networkReplyData->m_location;
+}
+
+void QQuickNetworkReply::setLocation(const QString& location)
+{
+    m_networkReplyData->m_location = location;
+}
+
+QString QQuickNetworkReply::lastModified() const
+{
+    return QDateTime::fromMSecsSinceEpoch(m_networkReplyData->m_lastModified).toString(Qt::ISODate);
+}
+
+void QQuickNetworkReply::setLastModified(const QString& lastModified)
+{
+    m_networkReplyData->m_lastModified = QDateTime::fromString(lastModified, Qt::ISODate).toMSecsSinceEpoch();
+}
+
+QString QQuickNetworkReply::cookie() const
+{
+    return m_networkReplyData->m_cookie;
+}
+
+void QQuickNetworkReply::setCookie(const QString& cookie)
+{
+    m_networkReplyData->m_cookie = cookie;
+}
+
+QString QQuickNetworkReply::userAgent() const
+{
+    return m_networkReplyData->m_userAgent;
+}
+
+void QQuickNetworkReply::setUserAgent(const QString& userAgent)
+{
+    m_networkReplyData->m_userAgent = userAgent;
+}
+
+QString QQuickNetworkReply::server() const
+{
+    return m_networkReplyData->m_server;
+}
+
+void QQuickNetworkReply::setServer(const QString& server)
+{
+    m_networkReplyData->m_server = server;
+}
+
+QString QQuickNetworkReply::data() const
+{
+    if (m_networkReplyData->m_dataHandle.isNull())
+        return QString();
+    RefPtr<SharedMemory> sm = SharedMemory::create(m_networkReplyData->m_dataHandle, SharedMemory::ReadOnly);
+    if (!sm)
+        return QString();
+
+    uint64_t stringLength = m_networkReplyData->m_contentLength / sizeof(UChar);
+    return QString(reinterpret_cast<const QChar*>(sm->data()), stringLength);
+}
+
+void QQuickNetworkReply::setData(const QString& data)
+{
+    // This function can be called several times. In this case the previous SharedMemory handles
+    // will be overwritten and the previously allocated SharedMemory will die with the last handle.
+    m_networkReplyData->m_contentLength = 0;
+
+    if (data.isNull())
+        return;
+    const UChar* ucharData = reinterpret_cast<const UChar*>(data.constData());
+    uint64_t smLength = sizeof(UChar) * data.length();
+
+    RefPtr<SharedMemory> sm = SharedMemory::create(smLength);
+    if (!sm)
+        return;
+    // The size of the allocated shared memory can be bigger than requested.
+    // Usually the size will be rounded up to the next multiple of a page size.
+    memcpy(sm->data(), ucharData, smLength);
+
+    if (!sm->createHandle(m_networkReplyData->m_dataHandle, SharedMemory::ReadOnly))
+        return;
+    m_networkReplyData->m_contentLength = smLength;
+}
+
+void QQuickNetworkReply::send()
+{
+    QObject* schemeParent = parent()->parent();
+    if (!schemeParent)
+        return;
+    QQuickWebViewExperimental* webViewExperimental = qobject_cast<QQuickWebViewExperimental*>(schemeParent->parent());
+    if (!webViewExperimental)
+        return;
+    webViewExperimental->sendApplicationSchemeReply(this);
+}
+
+WTF::RefPtr<WebKit::QtNetworkRequestData> QQuickNetworkReply::networkRequestData() const
+{
+    return m_networkRequestData;
+}
+
+void QQuickNetworkReply::setNetworkRequestData(WTF::RefPtr<WebKit::QtNetworkRequestData> data)
+{
+    m_networkRequestData = data;
+    m_networkReplyData->m_replyUuid = data->m_replyUuid;
+}
+
+WTF::RefPtr<WebKit::QtNetworkReplyData> QQuickNetworkReply::networkReplyData() const
+{
+    return m_networkReplyData;
+}
+
+#include "moc_qquicknetworkreply_p.cpp"
diff --git a/Source/WebKit2/UIProcess/API/qt/qquicknetworkreply_p.h b/Source/WebKit2/UIProcess/API/qt/qquicknetworkreply_p.h
new file mode 100644 (file)
index 0000000..ffe45f3
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org>
+ *
+ * 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.
+ *
+ */
+
+#ifndef qquicknetworkreply_p_h
+#define qquicknetworkreply_p_h
+
+#include "QtNetworkReplyData.h"
+#include "QtNetworkRequestData.h"
+#include "qwebkitglobal.h"
+#include <QNetworkAccessManager>
+#include <QObject>
+#include <QtDeclarative/qdeclarativelist.h>
+#include <QtQuick/qquickitem.h>
+
+class QWEBKIT_EXPORT QQuickNetworkReply : public QObject {
+    Q_OBJECT
+    Q_PROPERTY(QString contentType READ contentType WRITE setContentType)
+    Q_PROPERTY(QString data READ data WRITE setData)
+    Q_ENUMS(QNetworkAccessManager::Operation)
+
+public:
+    QQuickNetworkReply(QObject* parent);
+    QString contentType() const;
+    void setContentType(const QString&);
+    QNetworkAccessManager::Operation operation() const;
+    void setOperation(QNetworkAccessManager::Operation);
+    QString contentDisposition() const;
+    void setContentDisposition(const QString&);
+    QString location() const;
+    void setLocation(const QString&);
+    QString lastModified() const;
+    void setLastModified(const QString&);
+    QString cookie() const;
+    void setCookie(const QString&);
+    QString userAgent() const;
+    void setUserAgent(const QString&);
+    QString server() const;
+    void setServer(const QString&);
+
+    QString data() const;
+    void setData(const QString& data);
+
+    WTF::RefPtr<WebKit::QtNetworkRequestData> networkRequestData() const;
+    void setNetworkRequestData(WTF::RefPtr<WebKit::QtNetworkRequestData> data);
+    WTF::RefPtr<WebKit::QtNetworkReplyData> networkReplyData() const;
+
+public Q_SLOTS:
+    void send();
+
+private:
+    WTF::RefPtr<WebKit::QtNetworkRequestData> m_networkRequestData;
+    WTF::RefPtr<WebKit::QtNetworkReplyData> m_networkReplyData;
+};
+
+QML_DECLARE_TYPE(QQuickNetworkReply)
+
+#endif // qquicknetworkreply_p_h
+
diff --git a/Source/WebKit2/UIProcess/API/qt/qquicknetworkrequest_p.h b/Source/WebKit2/UIProcess/API/qt/qquicknetworkrequest_p.h
new file mode 100644 (file)
index 0000000..113114c
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org>
+ *
+ * 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.
+ *
+ */
+
+#ifndef qquicknetworkrequest_p_h
+#define qquicknetworkrequest_p_h
+
+#include "qwebkitglobal.h"
+#include <QObject>
+#include <QtDeclarative/qdeclarativelist.h>
+#include <QtQuick/qquickitem.h>
+
+class QWEBKIT_EXPORT QQuickNetworkRequest : public QObject {
+    Q_OBJECT
+    Q_PROPERTY(QString url READ url)
+
+public:
+    QQuickNetworkRequest(QObject* parent)
+        : QObject(parent)
+    {
+        Q_ASSERT(parent);
+    }
+
+    QString url() const { return m_url; }
+    void setUrl(const QString& url) { m_url = url; }
+
+private:
+    QString m_url;
+};
+
+QML_DECLARE_TYPE(QQuickNetworkRequest)
+
+#endif // qquicknetworkrequest_p_h
+
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp b/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp
new file mode 100644 (file)
index 0000000..e5d6304
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org>
+ *
+ * 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 "qquickurlschemedelegate_p.h"
+
+#include "qquicknetworkreply_p.h"
+#include "qquicknetworkrequest_p.h"
+
+QQuickUrlSchemeDelegate::QQuickUrlSchemeDelegate(QObject* parent)
+    : QObject(parent)
+    , m_request(new QQuickNetworkRequest(this))
+    , m_reply(new QQuickNetworkReply(this))
+{ }
+
+QString QQuickUrlSchemeDelegate::scheme() const
+{
+    return m_scheme;
+}
+
+void QQuickUrlSchemeDelegate::setScheme(const QString& scheme)
+{
+    m_scheme = scheme;
+    emit schemeChanged();
+}
+
+QQuickNetworkRequest* QQuickUrlSchemeDelegate::request() const
+{
+    return m_request;
+}
+
+QQuickNetworkReply* QQuickUrlSchemeDelegate::reply() const
+{
+    return m_reply;
+}
+
+#include "moc_qquickurlschemedelegate_p.cpp"
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h b/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h
new file mode 100644 (file)
index 0000000..6ee6027
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2011 Zeno Albisser <zeno@webkit.org>
+ *
+ * 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.
+ *
+ */
+
+#ifndef qquickurlschemedelegate_p_h
+#define qquickurlschemedelegate_p_h
+
+#include "qwebkitglobal.h"
+#include <QObject>
+#include <QtQuick/qquickitem.h>
+
+class QQuickNetworkRequest;
+class QQuickNetworkReply;
+
+class QWEBKIT_EXPORT QQuickUrlSchemeDelegate : public QObject {
+    Q_OBJECT
+    Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged)
+    Q_PROPERTY(QQuickNetworkRequest* request READ request)
+    Q_PROPERTY(QQuickNetworkReply* reply READ reply)
+
+public:
+    QQuickUrlSchemeDelegate(QObject* parent = 0);
+    QString scheme() const;
+    void setScheme(const QString& scheme);
+    QQuickNetworkRequest* request() const;
+    QQuickNetworkReply* reply() const;
+
+Q_SIGNALS:
+    void schemeChanged();
+    void receivedRequest();
+
+private:
+    QString m_scheme;
+    QQuickNetworkRequest* m_request;
+    QQuickNetworkReply* m_reply;
+};
+
+QML_DECLARE_TYPE(QQuickUrlSchemeDelegate)
+
+#endif // qquickurlschemedelegate_p_h
+
+
index 23bcabb..7bbef91 100644 (file)
@@ -33,6 +33,7 @@
 #include "WebPageGroup.h"
 #include "WebPreferences.h"
 
+#include "qquicknetworkreply_p.h"
 #include "qquickwebpage_p_p.h"
 #include "qquickwebview_p_p.h"
 #include "qwebdownloaditem_p_p.h"
@@ -595,6 +596,7 @@ QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView)
     : QObject(webView)
     , q_ptr(webView)
     , d_ptr(webView->d_ptr.data())
+    , schemeParent(new QObject(this))
     , m_viewportInfo(new QWebViewportInfo(webView->d_ptr.data(), this))
 {
 }
@@ -698,6 +700,69 @@ bool QQuickWebViewExperimental::useTraditionalDesktopBehaviour() const
     return d->useTraditionalDesktopBehaviour;
 }
 
+QQuickUrlSchemeDelegate* QQuickWebViewExperimental::schemeDelegates_At(QDeclarativeListProperty<QQuickUrlSchemeDelegate>* property, int index)
+{
+    const QObjectList children = property->object->children();
+    if (index < children.count())
+        return static_cast<QQuickUrlSchemeDelegate*>(children.at(index));
+    return 0;
+}
+
+void QQuickWebViewExperimental::schemeDelegates_Append(QDeclarativeListProperty<QQuickUrlSchemeDelegate>* property, QQuickUrlSchemeDelegate *scheme)
+{
+    QObject* schemeParent = property->object;
+    scheme->setParent(schemeParent);
+    QQuickWebViewExperimental* webViewExperimental = qobject_cast<QQuickWebViewExperimental*>(property->object->parent());
+    if (!webViewExperimental)
+        return;
+    QQuickWebViewPrivate* d = webViewExperimental->d_func();
+    d->webPageProxy->registerApplicationScheme(scheme->scheme());
+}
+
+int QQuickWebViewExperimental::schemeDelegates_Count(QDeclarativeListProperty<QQuickUrlSchemeDelegate>* property)
+{
+    return property->object->children().count();
+}
+
+void QQuickWebViewExperimental::schemeDelegates_Clear(QDeclarativeListProperty<QQuickUrlSchemeDelegate>* property)
+{
+    const QObjectList children = property->object->children();
+    for (int index = 0; index < children.count(); index++) {
+        QObject* child = children.at(index);
+        child->setParent(0);
+        delete child;
+    }
+}
+
+QDeclarativeListProperty<QQuickUrlSchemeDelegate> QQuickWebViewExperimental::schemeDelegates()
+{
+    return QDeclarativeListProperty<QQuickUrlSchemeDelegate>(schemeParent, 0,
+            QQuickWebViewExperimental::schemeDelegates_Append,
+            QQuickWebViewExperimental::schemeDelegates_Count,
+            QQuickWebViewExperimental::schemeDelegates_At,
+            QQuickWebViewExperimental::schemeDelegates_Clear);
+}
+
+void QQuickWebViewExperimental::invokeApplicationSchemeHandler(PassRefPtr<QtNetworkRequestData> request)
+{
+    const QObjectList children = schemeParent->children();
+    for (int index = 0; index < children.count(); index++) {
+        QQuickUrlSchemeDelegate* delegate = qobject_cast<QQuickUrlSchemeDelegate*>(children.at(index));
+        if (!delegate)
+            continue;
+        if (!delegate->scheme().compare(QString(request->m_scheme), Qt::CaseInsensitive)) {
+            delegate->reply()->setNetworkRequestData(request);
+            emit delegate->receivedRequest();
+            return;
+        }
+    }
+}
+
+void QQuickWebViewExperimental::sendApplicationSchemeReply(QQuickNetworkReply* reply)
+{
+    d_ptr->webPageProxy->sendApplicationSchemeReply(reply);
+}
+
 void QQuickWebViewExperimental::goForwardTo(int index)
 {
     d_ptr->navigationHistory->d->goForwardTo(index);
index f1b4cbb..e5d3f1e 100644 (file)
@@ -21,7 +21,9 @@
 #ifndef qquickwebview_p_h
 #define qquickwebview_p_h
 
+#include "qquickurlschemedelegate_p.h"
 #include "qwebkitglobal.h"
+#include <QtDeclarative/qdeclarativelist.h>
 #include <QtQuick/qquickitem.h>
 
 class QWebNavigationRequest;
@@ -35,11 +37,20 @@ class QWebNavigationHistory;
 class QWebPreferences;
 class QWebPermissionRequest;
 class QWebViewportInfo;
+class QQuickNetworkReply;
 
 namespace WTR {
 class PlatformWebView;
 }
 
+namespace WebKit {
+class QtNetworkRequestData;
+}
+
+namespace WTF {
+template<class T> class PassRefPtr;
+}
+
 typedef const struct OpaqueWKContext* WKContextRef;
 typedef const struct OpaqueWKPageGroup* WKPageGroupRef;
 typedef const struct OpaqueWKPage* WKPageRef;
@@ -178,6 +189,7 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
     Q_PROPERTY(bool useTraditionalDesktopBehaviour READ useTraditionalDesktopBehaviour WRITE setUseTraditionalDesktopBehaviour)
     Q_PROPERTY(QWebViewportInfo* viewportInfo READ viewportInfo CONSTANT FINAL)
+    Q_PROPERTY(QDeclarativeListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates)
     Q_ENUMS(NavigationRequestAction)
 
 public:
@@ -204,6 +216,14 @@ public:
     QWebNavigationHistory* navigationHistory() const;
     QQuickWebPage* page();
 
+    static QQuickUrlSchemeDelegate* schemeDelegates_At(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*, int index);
+    static void schemeDelegates_Append(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*, QQuickUrlSchemeDelegate*);
+    static int schemeDelegates_Count(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*);
+    static void schemeDelegates_Clear(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*);
+    QDeclarativeListProperty<QQuickUrlSchemeDelegate> schemeDelegates();
+    void invokeApplicationSchemeHandler(WTF::PassRefPtr<WebKit::QtNetworkRequestData>);
+    void sendApplicationSchemeReply(QQuickNetworkReply*);
+
 public Q_SLOTS:
     void setUseTraditionalDesktopBehaviour(bool enable);
     void goBackTo(int index);
@@ -222,6 +242,7 @@ Q_SIGNALS:
 private:
     QQuickWebView* q_ptr;
     QQuickWebViewPrivate* d_ptr;
+    QObject* schemeParent;
     QWebViewportInfo* m_viewportInfo;
 
     friend class QtWebPageUIClient;
index cee7514..42a18f3 100644 (file)
@@ -36,6 +36,9 @@
 #if ENABLE(TOUCH_EVENTS)
 #include "NativeWebTouchEvent.h"
 #endif
+#if PLATFORM(QT)
+#include "QtNetworkRequestData.h"
+#endif
 #include "NotificationPermissionRequestManagerProxy.h"
 #include "PlatformProcessIdentifier.h"
 #include "SandboxExtension.h"
@@ -92,6 +95,10 @@ namespace WebCore {
     struct WindowFeatures;
 }
 
+#if PLATFORM(QT)
+class QQuickNetworkReply;
+#endif
+
 #if PLATFORM(MAC)
 #ifdef __OBJC__
 @class WKView;
@@ -303,6 +310,11 @@ public:
     
     bool maintainsInactiveSelection() const { return m_maintainsInactiveSelection; }
     void setMaintainsInactiveSelection(bool);
+#if PLATFORM(QT)
+    void registerApplicationScheme(const String& scheme);
+    void resolveApplicationSchemeRequest(QtNetworkRequestData);
+    void sendApplicationSchemeReply(const QQuickNetworkReply*);
+#endif
 
 #if PLATFORM(QT)
     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
@@ -984,6 +996,10 @@ private:
     static WKPageDebugPaintFlags s_debugPaintFlags;
 
     bool m_shouldSendEventsSynchronously;
+
+#if PLATFORM(QT)
+    WTF::HashSet<RefPtr<QtNetworkRequestData> > m_applicationSchemeRequests;
+#endif
 };
 
 } // namespace WebKit
index 0bf1fbd..5c2133a 100644 (file)
@@ -123,6 +123,10 @@ messages -> WebPageProxy {
     DidReceiveContentLengthForResource(uint64_t frameID, uint64_t resourceIdentifier, uint64_t contentLength)
     DidFinishLoadForResource(uint64_t frameID, uint64_t resourceIdentifier)
     DidFailLoadForResource(uint64_t frameID, uint64_t resourceIdentifier, WebCore::ResourceError error)
+#if PLATFORM(QT)
+    ResolveApplicationSchemeRequest(WebKit::QtNetworkRequestData request)
+#endif
+
 
     # Custom representations
     DidFinishLoadingDataForCustomRepresentation(WTF::String suggestedFilename, CoreIPC::DataReference data)
index 4153505..b173776 100644 (file)
@@ -100,6 +100,13 @@ void QtPageClient::handleDownloadRequest(DownloadProxy* download)
     QQuickWebViewPrivate::get(m_webView)->handleDownloadRequest(download);
 }
 
+void QtPageClient::handleApplicationSchemeRequest(PassRefPtr<QtNetworkRequestData> requestData)
+{
+    if (!m_webView || !m_webView->experimental())
+        return;
+    m_webView->experimental()->invokeApplicationSchemeHandler(requestData.get());
+}
+
 void QtPageClient::setCursor(const WebCore::Cursor& cursor)
 {
     // FIXME: This is a temporary fix until we get cursor support in QML items.
index 6e72603..a3149b6 100644 (file)
@@ -53,6 +53,7 @@ public:
     virtual void didRelaunchProcess();
     virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
     virtual void handleDownloadRequest(DownloadProxy*);
+    virtual void handleApplicationSchemeRequest(PassRefPtr<QtNetworkRequestData>);
 
     virtual void displayView();
     virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
index 4582e16..ac9fde4 100644 (file)
@@ -27,6 +27,9 @@
 #include "WebPageProxy.h"
 
 #include "PageClient.h"
+#include "QtNetworkReplyData.h"
+#include "QtPageClient.h"
+#include "qquicknetworkreply_p.h"
 #include "WebPageMessages.h"
 #include "WebProcessProxy.h"
 #include <WebCore/Editor.h>
@@ -77,4 +80,26 @@ void WebPageProxy::cancelComposition()
     process()->send(Messages::WebPage::CancelComposition(), m_pageID);
 }
 
+void WebPageProxy::registerApplicationScheme(const String& scheme)
+{
+    process()->send(Messages::WebPage::RegisterApplicationScheme(scheme), m_pageID);
+}
+
+void WebPageProxy::resolveApplicationSchemeRequest(QtNetworkRequestData request)
+{
+    RefPtr<QtNetworkRequestData> requestData = adoptRef(new QtNetworkRequestData(request));
+    m_applicationSchemeRequests.add(requestData);
+    static_cast<QtPageClient*>(m_pageClient)->handleApplicationSchemeRequest(requestData);
+}
+
+void WebPageProxy::sendApplicationSchemeReply(const QQuickNetworkReply* reply)
+{
+    RefPtr<QtNetworkRequestData> requestData = reply->networkRequestData();
+    if (m_applicationSchemeRequests.contains(requestData)) {
+        RefPtr<QtNetworkReplyData> replyData = reply->networkReplyData();
+        process()->send(Messages::WebPage::ApplicationSchemeReply(*replyData), pageID());
+        m_applicationSchemeRequests.remove(requestData);
+    }
+}
+
 } // namespace WebKit
index 7c544d6..3d0e222 100644 (file)
@@ -1438,7 +1438,14 @@ void WebFrameLoaderClient::didChangeScrollOffset()
 
 PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
 {
-    return WebFrameNetworkingContext::create(m_frame);
+    RefPtr<WebFrameNetworkingContext> context = WebFrameNetworkingContext::create(m_frame);
+#if PLATFORM(QT)
+    // We encapsulate the WebPage pointer as a property of the originating QObject.
+    QObject* originatingObject = context->originatingObject();
+    ASSERT(originatingObject);
+    originatingObject->setProperty("PagePointer", QVariant::fromValue(static_cast<void*>(m_frame->page())));
+#endif
+    return context.release();
 }
 
 } // namespace WebKit
index 4908b68..7ec6264 100644 (file)
@@ -33,12 +33,12 @@ namespace WebCore {
 class WebFrameNetworkingContext : public FrameNetworkingContext {
 public:
     static PassRefPtr<WebFrameNetworkingContext> create(WebKit::WebFrame*);
+    virtual QObject* originatingObject() const;
 
 private:
     WebFrameNetworkingContext(WebKit::WebFrame*);
     virtual ~WebFrameNetworkingContext();
 
-    virtual QObject* originatingObject() const;
     virtual QNetworkAccessManager* networkAccessManager() const;
     virtual bool mimeSniffingEnabled() const;
     virtual bool thirdPartyCookiePolicyPermission(const QUrl&) const;
index 3573dd6..40072cf 100644 (file)
 
 #if PLATFORM(QT)
 #include "ArgumentCodersQt.h"
+#include "QtNetworkAccessManager.h"
+#include "QtNetworkReply.h"
+#include "QtNetworkReplyData.h"
+#include "QtNetworkRequestData.h"
+#include <QNetworkReply>
+#include <QNetworkRequest>
 #endif
 
 #if PLATFORM(GTK)
@@ -468,6 +474,11 @@ public:
 
     void contextMenuShowing() { m_isShowingContextMenu = true; }
 
+#if PLATFORM(QT)
+    void registerApplicationScheme(const String& scheme);
+    void applicationSchemeReply(const QtNetworkReplyData&);
+    void receivedApplicationSchemeRequest(const QNetworkRequest&, QtNetworkReply*);
+#endif
     void wheelEvent(const WebWheelEvent&);
 #if ENABLE(GESTURE_EVENTS)
     void gestureEvent(const WebGestureEvent&);
@@ -727,6 +738,9 @@ private:
 #if PLATFORM(WIN)
     bool m_gestureReachedScrollingLimit;
 #endif
+#if PLATFORM(QT)
+    HashMap<String, QtNetworkReply*> m_applicationSchemeReplies;
+#endif
 };
 
 } // namespace WebKit
index 45ed7cc..5a3bb45 100644 (file)
@@ -60,6 +60,11 @@ messages -> WebPage {
     Reload(bool reloadFromOrigin)
     StopLoading()
 
+#if PLATFORM(QT)
+    ApplicationSchemeReply(WebKit::QtNetworkReplyData reply)
+    RegisterApplicationScheme(WTF::String scheme)
+#endif
+
     StopLoadingFrame(uint64_t frameID)
     
     RestoreSession(WebKit::SessionState state)
index 318da23..55080d0 100644 (file)
@@ -30,6 +30,8 @@
 #include "NotImplemented.h"
 #include "WebEditorClient.h"
 #include "WebEvent.h"
+#include "WebPageProxyMessages.h"
+#include "WebProcess.h"
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
 #include <WebCore/KeyboardEvent.h>
@@ -388,4 +390,29 @@ void WebPage::cancelComposition()
     // FIXME: static_cast<WebEditorClient*>(targetFrame->editor()->client())->sendSelectionChangedMessage();
 }
 
+void WebPage::registerApplicationScheme(const String& scheme)
+{
+    QtNetworkAccessManager* qnam = qobject_cast<QtNetworkAccessManager*>(WebProcess::shared().networkAccessManager());
+    if (!qnam)
+        return;
+    qnam->registerApplicationScheme(this, QString(scheme));
+}
+
+void WebPage::receivedApplicationSchemeRequest(const QNetworkRequest& request, QtNetworkReply* reply)
+{
+    QtNetworkRequestData requestData(request, reply);
+    m_applicationSchemeReplies.add(requestData.m_replyUuid, reply);
+    send(Messages::WebPageProxy::ResolveApplicationSchemeRequest(requestData));
+}
+
+void WebPage::applicationSchemeReply(const QtNetworkReplyData& replyData)
+{
+    if (!m_applicationSchemeReplies.contains(replyData.m_replyUuid))
+        return;
+
+    QtNetworkReply* networkReply = m_applicationSchemeReplies.take(replyData.m_replyUuid);
+    networkReply->setReplyData(replyData);
+    networkReply->finalize();
+}
+
 } // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp
new file mode 100644 (file)
index 0000000..57b953f
--- /dev/null
@@ -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 (file)
index 0000000..8d9eb1d
--- /dev/null
@@ -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 (file)
index 0000000..fd0f5cb
--- /dev/null
@@ -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 (file)
index 0000000..8ceb792
--- /dev/null
@@ -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
index d949206..a2beac1 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "InjectedBundle.h"
 #include "QtBuiltinBundle.h"
+#include "QtNetworkAccessManager.h"
 #include "WKBundleAPICast.h"
 #include "WebProcessCreationParameters.h"
 
@@ -67,7 +68,7 @@ static void parentProcessDiedCallback(void*)
 
 void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder* arguments)
 {
-    m_networkAccessManager = new QNetworkAccessManager;
+    m_networkAccessManager = new QtNetworkAccessManager(this);
     ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull());
     WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory);
     m_networkAccessManager->setCookieJar(jar);
index 4958c85..3af8492 100644 (file)
@@ -148,6 +148,12 @@ qwk_1.0 {
         *QWebNavigationRequest;
         non-virtual?thunk?to?QWebNavigationRequest*;
         QWebNavigationRequest::*;
+        *QQuickUrlSchemeDelegate;
+        QQuickUrlSchemeDelegate::*;
+        *QQuickNetworkRequest;
+        QQuickNetworkRequest::*;
+        *QQuickNetworkReply;
+        QQuickNetworkReply::*;
 
 
         # WebKit 2 C API mangled in C++