Skip to content

Instantly share code, notes, and snippets.

@zenoalbisser
Created December 15, 2011 15:24
Show Gist options
  • Save zenoalbisser/1481473 to your computer and use it in GitHub Desktop.
Save zenoalbisser/1481473 to your computer and use it in GitHub Desktop.
commit bdcafe55f3a8bec03d2aa85fcd28f5859150c95f
Author: Zeno Albisser <zeno@webkit.org>
Date: Mon Dec 5 20:38:47 2011 +0100
bla
diff --git a/Source/WebKit/qt/declarative/experimental/plugin.cpp b/Source/WebKit/qt/declarative/experimental/plugin.cpp
index 86312e1..92892e9 100644
--- a/Source/WebKit/qt/declarative/experimental/plugin.cpp
+++ b/Source/WebKit/qt/declarative/experimental/plugin.cpp
@@ -45,6 +45,9 @@ public:
qmlRegisterExtendedType<QQuickWebView, QQuickWebViewExperimentalExtension>(uri, 3, 0, "WebView");
qmlRegisterUncreatableType<QQuickWebViewExperimental>(uri, 3, 0, "QQuickWebViewExperimental",
QObject::tr("Cannot create separate instance of QQuickWebViewExperimental"));
+ qmlRegisterType<UrlScheme>(uri, 3, 0, "UrlScheme");
+ qmlRegisterUncreatableType<NetworkRequest>(uri, 3, 0, "NetworkRequest", QObject::tr("NetworkRequest should not be created from QML"));
+ qmlRegisterUncreatableType<NetworkReply>(uri, 3, 0, "NetworkReply", QObject::tr("NetworkReply should not be created from QML"));
}
};
diff --git a/Source/WebKit2/Shared/qt/NetworkReplyData.h b/Source/WebKit2/Shared/qt/NetworkReplyData.h
new file mode 100644
index 0000000..2ab9668
--- /dev/null
+++ b/Source/WebKit2/Shared/qt/NetworkReplyData.h
@@ -0,0 +1,107 @@
+/*
+ * 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 NetworkReplyData_h
+#define NetworkReplyData_h
+
+#include "WebCoreArgumentCoders.h"
+#include <wtf/text/WTFString.h>
+#include "KURL.h"
+
+#include <QNetworkRequest>
+
+namespace WebKit {
+
+struct NetworkReplyData {
+ NetworkReplyData()
+ { }
+
+ void encode(CoreIPC::ArgumentEncoder* encoder) const
+ {
+ encoder->encode(m_url);
+ 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_data);
+ }
+
+ static bool decode(CoreIPC::ArgumentDecoder* decoder, NetworkReplyData& destination)
+ {
+ if (!decoder->decode(destination.m_url))
+ 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_data))
+ return false;
+ return true;
+ }
+
+ WTF::String m_url;
+
+ enum Operation {
+ Head,
+ Get,
+ Put,
+ Post,
+ Delete
+ } 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;
+
+ WTF::String m_data;
+};
+
+} // namespace WebKit
+
+#endif // NetworkReplyData_h
diff --git a/Source/WebKit2/Shared/qt/NetworkRequestData.h b/Source/WebKit2/Shared/qt/NetworkRequestData.h
new file mode 100644
index 0000000..3898bbb
--- /dev/null
+++ b/Source/WebKit2/Shared/qt/NetworkRequestData.h
@@ -0,0 +1,72 @@
+/*
+ * 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 NetworkRequestData_h
+#define NetworkRequestData_h
+
+#include "WebCoreArgumentCoders.h"
+#include <wtf/text/WTFString.h>
+#include "KURL.h"
+
+#include <QNetworkRequest>
+#include <QNetworkReply>
+
+namespace WebKit {
+
+struct NetworkRequestData {
+ NetworkRequestData() { }
+ NetworkRequestData(const QNetworkRequest& req, QNetworkReply* rep)
+ {
+ m_scheme = req.url().scheme();
+ m_url = req.url().toString();
+ m_reply = (uint64_t)(rep); //this is not really a good idea!!!
+ }
+
+ void encode(CoreIPC::ArgumentEncoder* encoder) const
+ {
+ encoder->encode(m_scheme);
+ encoder->encode(m_url);
+ encoder->encodeUInt64(m_reply);
+ }
+
+ static bool decode(CoreIPC::ArgumentDecoder* decoder, NetworkRequestData& destination)
+ {
+ if (!decoder->decode(destination.m_scheme))
+ return false;
+ if (!decoder->decode(destination.m_url))
+ return false;
+ if (!decoder->decodeUInt64(destination.m_reply))
+ return false;
+ return true;
+ }
+
+ String m_scheme;
+ String m_url;
+ uint64_t m_reply;
+};
+
+} // namespace WebKit
+
+#endif // NetworkRequestData_h
diff --git a/Source/WebKit2/Target.pri b/Source/WebKit2/Target.pri
index be2813b..745f3dbb 100644
--- a/Source/WebKit2/Target.pri
+++ b/Source/WebKit2/Target.pri
@@ -182,6 +182,8 @@ HEADERS += \
UIProcess/API/qt/qquickwebpage_p_p.h \
UIProcess/API/qt/qquickwebview_p.h \
UIProcess/API/qt/qquickwebview_p_p.h \
+ UIProcess/API/qt/NetworkReply.h \
+ UIProcess/API/qt/NetworkRequest.h \
UIProcess/Authentication/AuthenticationChallengeProxy.h \
UIProcess/Authentication/AuthenticationDecisionListener.h \
UIProcess/Authentication/WebCredential.h \
@@ -342,6 +344,7 @@ HEADERS += \
WebProcess/WebCoreSupport/WebPopupMenu.h \
WebProcess/WebCoreSupport/WebSearchPopupMenu.h \
WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h \
+ WebProcess/WebCoreSupport/qt/PageGuard.h \
WebProcess/WebPage/DrawingArea.h \
WebProcess/WebPage/DrawingAreaImpl.h \
WebProcess/WebPage/FindController.h \
@@ -356,7 +359,10 @@ 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 \
+ WebProcess/qt/QtNetworkRequest.h
SOURCES += \
Platform/CoreIPC/ArgumentCoders.cpp \
@@ -500,6 +506,7 @@ SOURCES += \
UIProcess/API/qt/qwebnavigationrequest.cpp \
UIProcess/API/qt/qquickwebpage.cpp \
UIProcess/API/qt/qquickwebview.cpp \
+ UIProcess/API/qt/NetworkReply.cpp \
UIProcess/API/qt/qwebpreferences.cpp \
UIProcess/Authentication/AuthenticationChallengeProxy.cpp \
UIProcess/Authentication/AuthenticationDecisionListener.cpp \
@@ -684,6 +691,7 @@ SOURCES += \
WebProcess/WebCoreSupport/qt/WebErrorsQt.cpp \
WebProcess/WebCoreSupport/qt/WebDragClientQt.cpp \
WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp \
+ WebProcess/WebCoreSupport/qt/PageGuard.cpp \
WebProcess/WebCoreSupport/qt/WebPopupMenuQt.cpp \
WebProcess/WebPage/DecoderAdapter.cpp \
WebProcess/WebPage/DrawingArea.cpp \
@@ -709,6 +717,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/NetworkReply.cpp b/Source/WebKit2/UIProcess/API/qt/NetworkReply.cpp
new file mode 100644
index 0000000..aa3215d
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/qt/NetworkReply.cpp
@@ -0,0 +1,77 @@
+/*
+ * 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 "qwebkitglobal.h"
+#include "NetworkReply.h"
+#include "NetworkReplyData.h"
+#include "NetworkRequestData.h"
+#include "qquickwebview_p.h"
+
+NetworkReply::NetworkReply(QObject* parent)
+ : QObject(parent)
+ , m_networkRequestData(0)
+ , m_networkReplyData(new WebKit::NetworkReplyData) { }
+
+QString NetworkReply::contentType() const
+{
+ return m_networkReplyData->m_contentType;
+}
+void NetworkReply::setContentType(const QString& contentType)
+{
+ m_networkReplyData->m_contentType = contentType;
+}
+
+QString NetworkReply::data() const
+{
+ return m_networkReplyData->m_data;
+}
+
+void NetworkReply::setData(const QString& data)
+{
+ m_networkReplyData->m_data = data;
+}
+
+void NetworkReply::send()
+{
+ QObject* schemeParent = parent()->parent();
+ if (!schemeParent)
+ return;
+ QQuickWebViewExperimental* experimentalWebView = qobject_cast<QQuickWebViewExperimental*>(schemeParent->parent());
+ if (!experimentalWebView)
+ return;
+ experimentalWebView->sendCustomSchemeReply(this);
+}
+
+WebKit::NetworkRequestData* NetworkReply::networkRequestData() const
+{
+ return m_networkRequestData;
+}
+
+void NetworkReply::setNetworkRequestData(WebKit::NetworkRequestData* data)
+{
+ m_networkRequestData = data;
+}
+
+WebKit::NetworkReplyData* NetworkReply::networkReplyData() const
+{
+ return m_networkReplyData;
+}
+
diff --git a/Source/WebKit2/UIProcess/API/qt/NetworkReply.h b/Source/WebKit2/UIProcess/API/qt/NetworkReply.h
new file mode 100644
index 0000000..413332b
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/qt/NetworkReply.h
@@ -0,0 +1,61 @@
+/*
+ * 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 NetworkReply_h
+#define NetworkReply_h
+
+#include "qwebkitglobal.h"
+#include <QtDeclarative/qdeclarativelist.h>
+#include <QtQuick/qquickitem.h>
+
+#include <QObject>
+
+namespace WebKit {
+ class NetworkRequestData;
+ class NetworkReplyData;
+}
+
+class QWEBKIT_EXPORT NetworkReply : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString contentType READ contentType WRITE setContentType)
+ Q_PROPERTY(QString data READ data WRITE setData)
+
+public:
+ NetworkReply(QObject* parent = 0);
+ QString contentType() const;
+ void setContentType(const QString& contentType);
+ QString data() const;
+ void setData(const QString& data);
+
+ WebKit::NetworkRequestData* networkRequestData() const;
+ void setNetworkRequestData(WebKit::NetworkRequestData* data);
+ WebKit::NetworkReplyData* networkReplyData() const;
+
+public Q_SLOTS:
+ void send();
+
+private:
+ WebKit::NetworkRequestData* m_networkRequestData;
+ WebKit::NetworkReplyData* m_networkReplyData;
+};
+
+QML_DECLARE_TYPE(NetworkReply)
+
+#endif // NetworkReply.h
diff --git a/Source/WebKit2/UIProcess/API/qt/NetworkRequest.h b/Source/WebKit2/UIProcess/API/qt/NetworkRequest.h
new file mode 100644
index 0000000..a80bcf2
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/qt/NetworkRequest.h
@@ -0,0 +1,46 @@
+/*
+ * 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 NetworkRequest_h
+#define NetworkRequest_h
+
+#include "qwebkitglobal.h"
+#include <QtDeclarative/qdeclarativelist.h>
+#include <QtQuick/qquickitem.h>
+
+#include <QObject>
+
+class QWEBKIT_EXPORT NetworkRequest : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString url READ url)
+
+public:
+ NetworkRequest(QObject* parent = 0)
+ : QObject(parent) { }
+ QString url() const { return m_url; }
+ void setUrl(const QString& url) { m_url = url; }
+
+private:
+ QString m_url;
+};
+
+QML_DECLARE_TYPE(NetworkRequest)
+
+#endif // NetworkRequest.h
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
index 3086042..74b3b49 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
@@ -432,6 +432,7 @@ QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView)
: QObject(webView)
, q_ptr(webView)
, d_ptr(webView->d_ptr.data())
+ , schemeParent(new QObject(this))
{
}
@@ -500,6 +501,69 @@ bool QQuickWebViewExperimental::useTraditionalDesktopBehaviour() const
return d->useTraditionalDesktopBehaviour;
}
+UrlScheme *QQuickWebViewExperimental::schemeDelegates_at(QDeclarativeListProperty<UrlScheme> *prop, int index)
+{
+ const QObjectList children = prop->object->children();
+ if (index < children.count())
+ return static_cast<UrlScheme*>(children.at(index));
+ else
+ return 0;
+}
+
+void QQuickWebViewExperimental::schemeDelegates_append(QDeclarativeListProperty<UrlScheme> *prop, UrlScheme *scheme)
+{
+ QObject* schemeParent = prop->object;
+ scheme->setParent(schemeParent);
+ QQuickWebViewExperimental* webView = qobject_cast<QQuickWebViewExperimental*>(prop->object->parent());
+ if (!webView)
+ return;
+ QQuickWebViewPrivate* d = webView->d_func();
+ d->pageProxy->registerCustomScheme(scheme->scheme());
+}
+
+int QQuickWebViewExperimental::schemeDelegates_count(QDeclarativeListProperty<UrlScheme> *prop)
+{
+ return prop->object->children().count();
+}
+
+void QQuickWebViewExperimental::schemeDelegates_clear(QDeclarativeListProperty<UrlScheme> *prop)
+{
+ const QObjectList children = prop->object->children();
+ for (int index = 0; index < children.count(); index++) {
+ QObject* child = children.at(index);
+ child->setParent(0);
+ delete child;
+ }
+}
+
+QDeclarativeListProperty<UrlScheme> QQuickWebViewExperimental::schemeDelegates()
+{
+ return QDeclarativeListProperty<UrlScheme>(schemeParent, 0, QQuickWebViewExperimental::schemeDelegates_append,
+ QQuickWebViewExperimental::schemeDelegates_count,
+ QQuickWebViewExperimental::schemeDelegates_at,
+ QQuickWebViewExperimental::schemeDelegates_clear);
+}
+
+void QQuickWebViewExperimental::invokeCustomSchemeHandler(NetworkRequestData* request)
+{
+ const QObjectList children = schemeParent->children();
+ for (int index = 0; index < children.count(); index++) {
+ UrlScheme* urlScheme = qobject_cast<UrlScheme*>(children.at(index));
+ if (!urlScheme)
+ continue;
+ if (urlScheme->scheme() == QString(request->m_scheme)) {
+ urlScheme->reply()->setNetworkRequestData(request);
+ emit urlScheme->receivedRequest();
+ return;
+ }
+ }
+}
+
+void QQuickWebViewExperimental::sendCustomSchemeReply(NetworkReply* reply)
+{
+ d_func()->pageProxy->sendCustomSchemeReply(reply);
+}
+
QQuickWebView::QQuickWebView(QQuickItem* parent)
: QQuickItem(parent)
, d_ptr(new QQuickWebViewPrivate(this))
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
index 099504f..30ee545 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
@@ -22,6 +22,9 @@
#define qquickwebview_p_h
#include "qwebkitglobal.h"
+#include "NetworkReply.h"
+#include "NetworkRequest.h"
+#include <QtDeclarative/qdeclarativelist.h>
#include <QtQuick/qquickitem.h>
class QWebNavigationRequest;
@@ -47,6 +50,34 @@ class QPainter;
class QUrl;
QT_END_NAMESPACE
+class QWEBKIT_EXPORT UrlScheme : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged)
+ Q_PROPERTY(NetworkRequest* request READ request)
+ Q_PROPERTY(NetworkReply* reply READ reply)
+
+public:
+ UrlScheme()
+ : m_request(new NetworkRequest(this))
+ , m_reply(new NetworkReply(this))
+ { }
+ QString scheme() const { return m_scheme; }
+ void setScheme(const QString& scheme) { m_scheme = scheme; emit schemeChanged(); }
+ NetworkRequest* request() const { return m_request; }
+ NetworkReply* reply() const { return m_reply; }
+
+Q_SIGNALS:
+ void schemeChanged();
+ void receivedRequest();
+
+private:
+ QString m_scheme;
+ NetworkRequest* m_request;
+ NetworkReply* m_reply;
+};
+
+QML_DECLARE_TYPE(UrlScheme)
+
class QWEBKIT_EXPORT QQuickWebView : public QQuickItem {
Q_OBJECT
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
@@ -173,6 +204,7 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
Q_PROPERTY(QDeclarativeComponent* confirmDialog READ confirmDialog WRITE setConfirmDialog NOTIFY confirmDialogChanged)
Q_PROPERTY(QDeclarativeComponent* promptDialog READ promptDialog WRITE setPromptDialog NOTIFY promptDialogChanged)
Q_PROPERTY(bool useTraditionalDesktopBehaviour READ useTraditionalDesktopBehaviour WRITE setUseTraditionalDesktopBehaviour)
+ Q_PROPERTY(QDeclarativeListProperty<UrlScheme> schemeDelegates READ schemeDelegates)
public:
QQuickWebViewExperimental(QQuickWebView* webView);
@@ -187,6 +219,14 @@ public:
bool useTraditionalDesktopBehaviour() const;
+ static UrlScheme* schemeDelegates_at(QDeclarativeListProperty<UrlScheme>*, int index);
+ static void schemeDelegates_append(QDeclarativeListProperty<UrlScheme>*, UrlScheme*);
+ static int schemeDelegates_count(QDeclarativeListProperty<UrlScheme>*);
+ static void schemeDelegates_clear(QDeclarativeListProperty<UrlScheme>*);
+ QDeclarativeListProperty<UrlScheme> schemeDelegates();
+ void invokeCustomSchemeHandler(WebKit::NetworkRequestData*);
+ void sendCustomSchemeReply(NetworkReply*);
+
public Q_SLOTS:
void setUseTraditionalDesktopBehaviour(bool enable);
@@ -200,6 +240,7 @@ Q_SIGNALS:
private:
QQuickWebView* q_ptr;
QQuickWebViewPrivate* d_ptr;
+ QObject* schemeParent;
friend class QtWebPageProxy;
friend class QtWebPageUIClient;
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.cpp b/Source/WebKit2/UIProcess/WebPageProxy.cpp
index eff6611..9423e9e 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.cpp
+++ b/Source/WebKit2/UIProcess/WebPageProxy.cpp
@@ -37,6 +37,10 @@
#include "NativeWebKeyboardEvent.h"
#include "NativeWebMouseEvent.h"
#include "NativeWebWheelEvent.h"
+#include "NetworkReply.h"
+#include "NetworkReplyData.h"
+#include "NetworkRequest.h"
+#include "NetworkRequestData.h"
#include "NotificationPermissionRequest.h"
#include "NotificationPermissionRequestManager.h"
#include "PageClient.h"
@@ -147,6 +151,8 @@ WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> p
, m_pageGroup(pageGroup)
, m_mainFrame(0)
, m_userAgent(standardUserAgent())
+ , m_customSchemeReceivedCallback(0)
+ , m_customSchemeReceivedCallbackData(0)
, m_geolocationPermissionRequestManager(this)
, m_notificationPermissionRequestManager(this)
, m_estimatedProgress(0)
@@ -793,7 +799,32 @@ void WebPageProxy::setMaintainsInactiveSelection(bool newValue)
{
m_maintainsInactiveSelection = newValue;
}
-
+
+void WebPageProxy::registerCustomSchemeReceivedCallback(CustomSchemeCallbackFunction fn, void* data)
+{
+ m_customSchemeReceivedCallback = fn;
+ m_customSchemeReceivedCallbackData = data;
+}
+
+void WebPageProxy::registerCustomScheme(const String& scheme)
+{
+ process()->send(Messages::WebPage::RegisterCustomScheme(scheme), m_pageID);
+}
+
+void WebPageProxy::resolveCustomSchemeRequest(NetworkRequestData req)
+{
+ m_customSchemeReceivedCallback(m_customSchemeReceivedCallbackData, req);
+}
+
+void WebPageProxy::sendCustomSchemeReply(const NetworkReply* reply)
+{
+ WebKit::NetworkRequestData* requestData = reply->networkRequestData();
+ WebKit::NetworkReplyData* replyData = reply->networkReplyData();
+ WebKit::SharedMemory::Handle handle;
+ int dataSize = 0;
+ process()->send(Messages::WebPage::CustomSchemeReply(*requestData, *replyData, handle, dataSize), pageID());
+}
+
void WebPageProxy::executeEditCommand(const String& commandName)
{
if (!isValid())
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h
index 47fcd6c..824ab4d 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.h
+++ b/Source/WebKit2/UIProcess/WebPageProxy.h
@@ -36,6 +36,7 @@
#if ENABLE(TOUCH_EVENTS)
#include "NativeWebTouchEvent.h"
#endif
+#include "NetworkRequestData.h"
#include "NotificationPermissionRequestManagerProxy.h"
#include "PlatformProcessIdentifier.h"
#include "SandboxExtension.h"
@@ -92,6 +93,8 @@ namespace WebCore {
struct WindowFeatures;
}
+class NetworkReply;
+
#if PLATFORM(MAC)
#ifdef __OBJC__
@class WKView;
@@ -196,6 +199,8 @@ private:
CallbackFunction m_callback;
};
+typedef void (*CustomSchemeCallbackFunction)(void*, NetworkRequestData);
+
class WebPageProxy : public APIObject, public WebPopupMenuProxy::Client {
public:
static const Type APIType = TypePage;
@@ -303,6 +308,10 @@ public:
bool maintainsInactiveSelection() const { return m_maintainsInactiveSelection; }
void setMaintainsInactiveSelection(bool);
+ void registerCustomSchemeReceivedCallback(CustomSchemeCallbackFunction fn, void* data);
+ void registerCustomScheme(const String& scheme);
+ void resolveCustomSchemeRequest(NetworkRequestData req);
+ void sendCustomSchemeReply(const NetworkReply*);
#if PLATFORM(MAC)
void updateWindowIsVisible(bool windowIsVisible);
@@ -864,6 +873,8 @@ private:
HashMap<uint64_t, RefPtr<ScriptValueCallback> > m_scriptValueCallbacks;
HashMap<uint64_t, RefPtr<ComputedPagesCallback> > m_computedPagesCallbacks;
HashMap<uint64_t, RefPtr<ValidateCommandCallback> > m_validateCommandCallbacks;
+ CustomSchemeCallbackFunction m_customSchemeReceivedCallback;
+ void* m_customSchemeReceivedCallbackData;
HashSet<WebEditCommandProxy*> m_editCommandSet;
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.messages.in b/Source/WebKit2/UIProcess/WebPageProxy.messages.in
index 5e3d698..a17d81a 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.messages.in
+++ b/Source/WebKit2/UIProcess/WebPageProxy.messages.in
@@ -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)
+ ResolveCustomSchemeRequest(WebKit::NetworkRequestData request)
+#endif
+
# Custom representations
DidFinishLoadingDataForCustomRepresentation(WTF::String suggestedFilename, CoreIPC::DataReference data)
diff --git a/Source/WebKit2/UIProcess/WebProcessProxy.h b/Source/WebKit2/UIProcess/WebProcessProxy.h
index 129e0ea..5165f7c 100644
--- a/Source/WebKit2/UIProcess/WebProcessProxy.h
+++ b/Source/WebKit2/UIProcess/WebProcessProxy.h
@@ -131,7 +131,6 @@ private:
// CoreIPC message handlers.
void addBackForwardItem(uint64_t itemID, const String& originalURLString, const String& urlString, const String& title, const CoreIPC::DataReference& backForwardData);
void didDestroyFrame(uint64_t);
-
void shouldTerminate(bool& shouldTerminate);
#if ENABLE(PLUGIN_PROCESS)
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
index 036011e2a..0e3d301 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
@@ -113,6 +113,30 @@ void QtWebPageProxy::hideContextMenu()
activeMenu->hide();
}
+void QtWebPageProxy::registerCustomScheme(const QString& scheme)
+{
+ m_webPageProxy->registerCustomScheme(scheme);
+ m_webPageProxy->registerCustomSchemeReceivedCallback(&QtWebPageProxy::customSchemeReceivedCallBack, static_cast<void*>(this));
+}
+
+void QtWebPageProxy::customSchemeReceivedCallBack(void* client, NetworkRequestData request)
+{
+ QtWebPageProxy* webPageProxy = static_cast<QtWebPageProxy*>(client);
+ NetworkRequestData* requestData = new NetworkRequestData(request);
+ webPageProxy->m_customSchemeRequests.insert(requestData);
+ webPageProxy->m_qmlWebView->experimental()->invokeCustomSchemeHandler(requestData);
+}
+
+void QtWebPageProxy::sendCustomSchemeReply(const NetworkReply* reply)
+{
+ WebKit::NetworkRequestData* requestData = static_cast<WebKit::NetworkRequestData*>(reply->networkRequestData());
+ if (m_customSchemeRequests.contains(requestData)) {
+ m_webPageProxy->sendCustomSchemeReply(reply);
+ m_customSchemeRequests.remove(requestData);
+ delete requestData;
+ }
+}
+
void QtWebPageProxy::setViewNeedsDisplay(const WebCore::IntRect&)
{
m_qmlWebPage->update();
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h b/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h
index ed487aa..94a7736 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageProxy.h
@@ -42,6 +42,7 @@ class QtWebPageEventHandler;
class QWebDownloadItem;
class QWebPreferences;
class QWKHistory;
+class NetworkReply;
namespace WebKit {
class QtWebContext;
@@ -154,6 +155,10 @@ public:
QtWebPageEventHandler* eventHandler() { return m_eventHandler; }
+ void registerCustomScheme(const QString& scheme);
+ static void customSchemeReceivedCallBack(void* client, NetworkRequestData);
+ void sendCustomSchemeReply(const NetworkReply*);
+
public Q_SLOTS:
void didReceiveDownloadResponse(QWebDownloadItem* downloadItem);
@@ -182,6 +187,7 @@ private:
QSharedPointer<QMenu> activeMenu;
QtWebPageEventHandler* m_eventHandler;
+ QSet<NetworkRequestData*> m_customSchemeRequests;
};
#endif /* QtWebPageProxy_h */
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
index 4dd5699..f5dc37e 100644
--- a/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
+++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
@@ -1438,7 +1438,9 @@ void WebFrameLoaderClient::didChangeScrollOffset()
PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
{
- return WebFrameNetworkingContext::create(m_frame->coreFrame());
+ PassRefPtr<WebFrameNetworkingContext> context = WebFrameNetworkingContext::create(m_frame->coreFrame());
+ context->setOriginatingObject(new PageGuard(m_frame->page()));
+ return context;
}
} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/qt/PageGuard.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/qt/PageGuard.cpp
new file mode 100644
index 0000000..9b63c5f
--- /dev/null
+++ b/Source/WebKit2/WebProcess/WebCoreSupport/qt/PageGuard.cpp
@@ -0,0 +1,11 @@
+#include "PageGuard.h"
+
+PageGuard::PageGuard(void* page)
+ : m_page(page) { }
+
+void* PageGuard::page() const
+{
+ return m_page;
+}
+
+
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/qt/PageGuard.h b/Source/WebKit2/WebProcess/WebCoreSupport/qt/PageGuard.h
new file mode 100644
index 0000000..578bbe7
--- /dev/null
+++ b/Source/WebKit2/WebProcess/WebCoreSupport/qt/PageGuard.h
@@ -0,0 +1,36 @@
+/*
+ * 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 PageGuard_h
+#define PageGuard_h
+
+#include <QObject>
+
+class PageGuard : public QObject
+{
+ Q_OBJECT
+public:
+ PageGuard(void* page);
+ void* page() const;
+private:
+ void* m_page;
+};
+
+#endif // PageGuard_h
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp
index a6f3aab..9ebefde 100644
--- a/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp
+++ b/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.cpp
@@ -38,11 +38,21 @@ PassRefPtr<WebFrameNetworkingContext> WebFrameNetworkingContext::create(Frame* f
return adoptRef(new WebFrameNetworkingContext(frame));
}
+void WebFrameNetworkingContext::setOriginatingObject(QObject* origin)
+{
+ m_originatingObject = origin;
+}
+
QObject* WebFrameNetworkingContext::originatingObject() const
{
return m_originatingObject;
}
+void* WebFrameNetworkingContext::originPage() const
+{
+ return m_originPage;
+}
+
QNetworkAccessManager* WebFrameNetworkingContext::networkAccessManager() const
{
return WebKit::WebProcess::shared().networkAccessManager();
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h b/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h
index 10c341a..e282c83 100644
--- a/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h
+++ b/Source/WebKit2/WebProcess/WebCoreSupport/qt/WebFrameNetworkingContext.h
@@ -20,6 +20,7 @@
#ifndef WebFrameNetworkingContext_h
#define WebFrameNetworkingContext_h
+#include "PageGuard.h"
#include <WebCore/FrameNetworkingContext.h>
namespace WebCore {
@@ -27,16 +28,19 @@ namespace WebCore {
class WebFrameNetworkingContext : public FrameNetworkingContext {
public:
static PassRefPtr<WebFrameNetworkingContext> create(Frame*);
+ void setOriginatingObject(QObject*);
private:
WebFrameNetworkingContext(Frame*);
virtual QObject* originatingObject() const;
+ virtual void* originPage() const;
virtual QNetworkAccessManager* networkAccessManager() const;
virtual bool mimeSniffingEnabled() const;
virtual bool thirdPartyCookiePolicyPermission(const QUrl&) const;
QObject* m_originatingObject;
+ void* m_originPage;
bool m_mimeSniffingEnabled;
};
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
index 148fee7..d7af029 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
@@ -36,10 +36,13 @@
#include "MessageID.h"
#include "NetscapePlugin.h"
#include "NotificationPermissionRequestManager.h"
+#include "NetworkReplyData.h"
+#include "NetworkRequestData.h"
#include "PageOverlay.h"
#include "PluginProxy.h"
#include "PluginView.h"
#include "PrintInfo.h"
+#include "QtNetworkAccessManager.h"
#include "RunLoop.h"
#include "SessionState.h"
#include "ShareableBitmap.h"
@@ -623,6 +626,38 @@ void WebPage::loadPlainTextString(const String& string)
loadData(sharedBuffer, "text/plain", "utf-16", blankURL(), KURL());
}
+void WebPage::registerCustomScheme(const String& scheme)
+{
+ QtNetworkAccessManager* qnam = qobject_cast<QtNetworkAccessManager*>(WebProcess::shared().networkAccessManager());
+ if (!qnam)
+ return;
+ qnam->registerApplicationScheme(QString(scheme));
+}
+
+void WebPage::receivedCustomSchemeRequest(const QNetworkRequest& request, QtNetworkReply* reply)
+{
+ qDebug() << "receivedCustomSchemeRequest!!!";
+
+ NetworkRequestData requestData(request, reply);
+ requestData.m_url = request.url().toString();
+ send(Messages::WebPageProxy::ResolveCustomSchemeRequest(requestData));
+}
+
+void WebPage::customSchemeReply(NetworkRequestData request, NetworkReplyData reply, const WebKit::SharedMemory::Handle& handle, int size)
+{
+ qDebug() << "And all of a sudden... we are in WebPage::CustomSchemaData";
+// RefPtr<SharedMemory> sharedMemory = SharedMemory::create(handle, SharedMemory::ReadOnly);
+// if (!sharedMemory)
+// return;
+
+// QByteArray buffer = QByteArray::fromRawData((const char*)sharedMemory->data(), size);
+
+ QtNetworkReply* networkReply = (QtNetworkReply*)request.m_reply;
+ //reply->setData(handle, size);
+ networkReply->setData(reply.m_data);
+ networkReply->finalize();
+}
+
void WebPage::linkClicked(const String& url, const WebMouseEvent& event)
{
Frame* frame = m_page->mainFrame();
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h
index 8756b41..cc14f1d 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebPage.h
+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h
@@ -41,6 +41,8 @@
#include "InjectedBundlePageResourceLoadClient.h"
#include "InjectedBundlePageUIClient.h"
#include "MessageSender.h"
+#include "NetworkRequestData.h"
+#include "NetworkReplyData.h"
#include "Plugin.h"
#include "SandboxExtension.h"
#include "ShareableBitmap.h"
@@ -60,6 +62,10 @@
#if PLATFORM(QT)
#include "ArgumentCodersQt.h"
+#include "QtNetworkAccessManager.h"
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include "QtNetworkReply.h"
#endif
#if PLATFORM(GTK)
@@ -462,6 +468,12 @@ public:
void contextMenuShowing() { m_isShowingContextMenu = true; }
+ void registerCustomScheme(const String& scheme);
+ void customSchemeReply(NetworkRequestData request, NetworkReplyData reply, const WebKit::SharedMemory::Handle& handle, int size);
+//#if PLATFORM(QT)
+ void receivedCustomSchemeRequest(const QNetworkRequest&, QtNetworkReply*);
+//#endif
+
private:
WebPage(uint64_t pageID, const WebPageCreationParameters&);
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
index 3786191..0b04f2a 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
@@ -64,6 +64,9 @@ messages -> WebPage {
Reload(bool reloadFromOrigin)
StopLoading()
+ CustomSchemeReply(WebKit::NetworkRequestData request, WebKit::NetworkReplyData reply, WebKit::SharedMemory::Handle handle, uint32_t size)
+ RegisterCustomScheme(WTF::String scheme)
+
StopLoadingFrame(uint64_t frameID)
RestoreSession(WebKit::SessionState state)
diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp
new file mode 100644
index 0000000..e0be192
--- /dev/null
+++ b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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 "WebProcess.h"
+#include "WebPage.h"
+#include "WebFrameNetworkingContext.h"
+
+#include <QNetworkRequest>
+#include <QNetworkReply>
+
+#include <QDebug>
+
+namespace WebKit {
+
+QtNetworkAccessManager::QtNetworkAccessManager(WebProcess* webProcess)
+ : QNetworkAccessManager()
+ , m_webProcess(webProcess)
+{
+}
+
+QtNetworkAccessManager::QtNetworkAccessManager(QObject * parent)
+ : QNetworkAccessManager(parent)
+ , m_webProcess(0)
+{
+}
+
+QNetworkReply* QtNetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice* outgoingData)
+{
+ const QString& scheme = req.url().scheme();
+ if (m_applicationSchemes.contains(scheme)) { //we should have this on a per/page base... not on a application global one.
+ QObject* origin = req.originatingObject();
+ PageGuard* pageGuard = qobject_cast<PageGuard*>(origin);
+ if (pageGuard) {
+ WebPage* webPage = static_cast<WebPage*>(pageGuard->page());
+ QtNetworkReply* reply = new QtNetworkReply(req, this);
+ webPage->receivedCustomSchemeRequest(req, reply);
+ return reply;
+ }
+ }
+
+ return QNetworkAccessManager::createRequest(op, req, outgoingData);
+}
+
+void QtNetworkAccessManager::registerApplicationScheme(const QString& scheme) {
+ qDebug() << "QtNetworkAccessManager::registerApplicationScheme" << scheme;
+ m_applicationSchemes.append(scheme);
+}
+
+}
diff --git a/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h
new file mode 100644
index 0000000..e94a5fb
--- /dev/null
+++ b/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.h
@@ -0,0 +1,56 @@
+/*
+ * 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 <QNetworkAccessManager>
+#include <QStringList>
+#include <QTimer>
+#include <QDebug>
+
+namespace WebKit {
+
+class WebProcess;
+
+class QtNetworkAccessManager : public QNetworkAccessManager {
+ Q_OBJECT
+public:
+ QtNetworkAccessManager(QObject * parent = 0);
+ QtNetworkAccessManager(WebProcess*);
+ void registerApplicationScheme(const QString& scheme);
+
+protected:
+ virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest & req, QIODevice* outgoingData = 0);
+
+private:
+ QStringList 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 0000000..3435d97
--- /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 "WebProcess.h"
+#include "WebPage.h"
+#include "WebFrameNetworkingContext.h"
+
+#include <QNetworkRequest>
+#include <QNetworkReply>
+
+#include <QDebug>
+
+namespace WebKit {
+
+QtNetworkReply::QtNetworkReply(const QNetworkRequest& req, QtNetworkAccessManager* parent)
+ : QNetworkReply((QObject*)parent)
+ , m_bytesAvailable(0)
+{
+ setRequest(req);
+ setOperation(QNetworkAccessManager::GetOperation);
+ setUrl(req.url());
+ setOpenMode(QIODevice::ReadOnly);
+ setHeader(QNetworkRequest::ContentLengthHeader, QVariant(10));
+ setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QString::fromLocal8Bit("text/html; charset=UTF-8")));
+}
+
+void QtNetworkReply::setData(const WTF::String& data)
+{
+ // FIXME: Do this with taking proper encoding into account
+ qDebug() << "QtNetworkReply::setData()" << QString(data);
+ m_buffer = QString(data).toLocal8Bit();
+ m_bytesAvailable = m_buffer.size();
+}
+
+void QtNetworkReply::setData(const QByteArray& data)
+{
+ m_buffer = data;
+}
+
+void QtNetworkReply::setData(const SharedMemory::Handle& handle, qint64 size)
+{
+ RefPtr<SharedMemory> sharedMemory = SharedMemory::create(handle, SharedMemory::ReadOnly);
+ if (!sharedMemory) {
+ qDebug() << "cannot create shared memory :(";
+ return;
+ }
+
+ qDebug() << "filling m_buffer with size:" << size;
+ m_buffer = QByteArray::fromRawData((const char*)sharedMemory->data(),size);
+ m_bytesAvailable = size;
+}
+
+qint64 QtNetworkReply::readData(char *data, qint64 maxlen)
+{
+ qDebug() << "::readData m_bytesAvailable:" << m_bytesAvailable;
+ if(qMemCopy(data, m_buffer.constData(), m_bytesAvailable))
+ return m_bytesAvailable;
+ else
+ return 0;
+}
+
+qint64 QtNetworkReply::bytesAvailable() const
+{
+ qDebug() << "::bytesAvailable" << m_bytesAvailable;
+ return m_bytesAvailable;
+}
+
+void QtNetworkReply::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
+{
+ QNetworkReply::setHeader(header,value);
+}
+
+void QtNetworkReply::abort() { }
+
+// reimplemented from QNetworkReply / QIODevice
+void QtNetworkReply::close() { }
+void QtNetworkReply::setReadBufferSize(qint64 size) { }
+bool QtNetworkReply::canReadLine () const { return true; }
+
+
+void QtNetworkReply::finalize()
+{
+ qDebug() << "::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 0000000..aa1c814
--- /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 "SharedMemory.h"
+
+#include <QNetworkReply>
+#include <QByteArray>
+
+namespace WebKit {
+
+class QtNetworkAccessManager;
+
+class QtNetworkReply : public QNetworkReply {
+public:
+ QtNetworkReply(const QNetworkRequest& req, QtNetworkAccessManager* parent);
+
+ virtual qint64 readData(char *data, qint64 maxlen);
+ virtual qint64 bytesAvailable() const;
+ void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
+ void setData(const QByteArray&);
+ void setData(const WTF::String&);
+ void setData(const SharedMemory::Handle& handle, qint64 size);
+ void finalize();
+
+protected:
+ virtual void abort();
+
+ // reimplemented from QNetworkReply / QIODevice
+ virtual void close();
+ virtual void setReadBufferSize(qint64 size);
+ virtual bool canReadLine () const;
+
+private:
+ qint64 m_bytesAvailable;
+ QByteArray m_buffer;
+};
+
+} // namespace WebKit
+
+#endif // QtNetworkReply_h
diff --git a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
index d949206..1be5f80 100644
--- a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
+++ b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
@@ -30,6 +30,7 @@
#include "QtBuiltinBundle.h"
#include "WKBundleAPICast.h"
#include "WebProcessCreationParameters.h"
+#include "QtNetworkAccessManager.h"
#include <QCoreApplication>
#include <QNetworkAccessManager>
@@ -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);
diff --git a/Source/qtwebkit-export.map b/Source/qtwebkit-export.map
index 4b6e75f..4d84a12 100644
--- a/Source/qtwebkit-export.map
+++ b/Source/qtwebkit-export.map
@@ -133,6 +133,12 @@ qwk_1.0 {
*QWebNavigationRequest;
non-virtual?thunk?to?QWebNavigationRequest*;
QWebNavigationRequest::*;
+ *UrlScheme;
+ UrlScheme::*;
+ *NetworkRequest;
+ NetworkRequest::*;
+ *NetworkReply;
+ NetworkReply::*;
# WebKit 2 C API mangled in C++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment