summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-05 10:48:38 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-19 14:49:08 +0000
commitd3f80fb0b71e3020e4e8173e2002dc93efdc5f60 (patch)
tree1a019dbd7330479a278cce5908975ee940af38ef /src/webenginewidgets
parente263449d32e9392985c1587f2a0b4e0e77e605a2 (diff)
Experimental custom URL scheme API
Introduces API for custom URL scheme as an experimental API in widgets. A QML api is not included yet. Change-Id: Ice4542e5238feb961a4c9c60a809455e31dc1ec6 Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp48
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.h3
-rw-r--r--src/webenginewidgets/api/qwebengineprofile_p.h7
-rw-r--r--src/webenginewidgets/api/qwebengineurlrequestjob.cpp67
-rw-r--r--src/webenginewidgets/api/qwebengineurlrequestjob_p.h69
-rw-r--r--src/webenginewidgets/api/qwebengineurlschemehandler.cpp83
-rw-r--r--src/webenginewidgets/api/qwebengineurlschemehandler_p.h72
-rw-r--r--src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h66
-rw-r--r--src/webenginewidgets/webenginewidgets.pro5
9 files changed, 419 insertions, 1 deletions
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 6427d3811..3de2fe521 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -41,6 +41,7 @@
#include "qwebenginepage.h"
#include "qwebengineprofile_p.h"
#include "qwebenginesettings.h"
+#include "qwebengineurlschemehandler_p_p.h"
#include "browser_context_adapter.h"
#include "web_engine_visited_links_manager.h"
@@ -453,4 +454,51 @@ QWebEngineSettings *QWebEngineProfile::settings() const
return d->settings();
}
+QWebEngineUrlSchemeHandler *QWebEngineProfilePrivate::urlSchemeHandler(const QByteArray &protocol)
+{
+ if (m_urlSchemeHandlers.contains(protocol))
+ return m_urlSchemeHandlers.value(protocol);
+ return 0;
+}
+
+static bool checkInternalScheme(const QByteArray &scheme)
+{
+ static QSet<QByteArray> internalSchemes;
+ if (internalSchemes.isEmpty()) {
+ internalSchemes << QByteArrayLiteral("qrc") << QByteArrayLiteral("data") << QByteArrayLiteral("blob")
+ << QByteArrayLiteral("http") << QByteArrayLiteral("ftp") << QByteArrayLiteral("javascript");
+ }
+ return internalSchemes.contains(scheme);
+}
+
+void QWebEngineProfilePrivate::installUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler)
+{
+ Q_ASSERT(handler);
+ QByteArray scheme = handler->scheme();
+ if (checkInternalScheme(scheme)) {
+ qWarning() << "Can not install a URL scheme handler overriding internal scheme: " << scheme;
+ return;
+ }
+
+ m_urlSchemeHandlers.insert(scheme, handler);
+ browserContext()->customUrlSchemeHandlers().append(handler->d_func());
+ browserContext()->updateCustomUrlSchemeHandlers();
+}
+
+void QWebEngineProfilePrivate::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler)
+{
+ int count = m_urlSchemeHandlers.remove(handler->scheme());
+ if (!count)
+ return;
+ browserContext()->customUrlSchemeHandlers().removeOne(handler->d_func());
+ browserContext()->updateCustomUrlSchemeHandlers();
+}
+
+void QWebEngineProfilePrivate::clearUrlSchemeHandlers()
+{
+ m_urlSchemeHandlers.clear();
+ browserContext()->customUrlSchemeHandlers().clear();
+ browserContext()->updateCustomUrlSchemeHandlers();
+}
+
QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h
index ac875c050..a2523edad 100644
--- a/src/webenginewidgets/api/qwebengineprofile.h
+++ b/src/webenginewidgets/api/qwebengineprofile.h
@@ -104,10 +104,11 @@ Q_SIGNALS:
void downloadRequested(QWebEngineDownloadItem *download);
private:
- Q_DECLARE_PRIVATE(QWebEngineProfile);
+ Q_DECLARE_PRIVATE(QWebEngineProfile)
QWebEngineProfile(QWebEngineProfilePrivate *);
friend class QWebEnginePagePrivate;
+ friend class QWebEngineUrlSchemeHandler;
QScopedPointer<QWebEngineProfilePrivate> d_ptr;
};
diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h
index b56e1b3b2..1fc2297c7 100644
--- a/src/webenginewidgets/api/qwebengineprofile_p.h
+++ b/src/webenginewidgets/api/qwebengineprofile_p.h
@@ -39,6 +39,7 @@
#include "browser_context_adapter_client.h"
#include "qwebengineprofile.h"
+#include "qwebengineurlschemehandler_p.h"
#include <QMap>
#include <QPointer>
@@ -63,12 +64,18 @@ public:
void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE;
void downloadUpdated(const DownloadItemInfo &info) Q_DECL_OVERRIDE;
+ QWebEngineUrlSchemeHandler *urlSchemeHandler(const QByteArray &);
+ void installUrlSchemeHandler(QWebEngineUrlSchemeHandler *);
+ void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *);
+ void clearUrlSchemeHandlers();
+
private:
QWebEngineProfile *q_ptr;
QWebEngineSettings *m_settings;
BrowserContextAdapter *m_browserContext;
QExplicitlySharedDataPointer<BrowserContextAdapter> m_browserContextRef;
QMap<quint32, QPointer<QWebEngineDownloadItem> > m_ongoingDownloads;
+ QMap<QByteArray, QPointer<QWebEngineUrlSchemeHandler> > m_urlSchemeHandlers;
};
QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebengineurlrequestjob.cpp b/src/webenginewidgets/api/qwebengineurlrequestjob.cpp
new file mode 100644
index 000000000..e937a5bba
--- /dev/null
+++ b/src/webenginewidgets/api/qwebengineurlrequestjob.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwebengineurlrequestjob_p.h"
+
+#include "qwebengineprofile.h"
+
+#include "url_request_custom_job_delegate.h"
+
+QT_BEGIN_NAMESPACE
+
+QWebEngineUrlRequestJob::QWebEngineUrlRequestJob(URLRequestCustomJobDelegate * p)
+ : QObject(p) // owned by the jobdelegate and deleted when the job is done
+ , d_ptr(p)
+{
+}
+
+QWebEngineUrlRequestJob::~QWebEngineUrlRequestJob()
+{
+}
+
+QUrl QWebEngineUrlRequestJob::requestUrl() const
+{
+ return d_ptr->url();
+}
+
+void QWebEngineUrlRequestJob::setReply(const QByteArray &contentType, QIODevice *device)
+{
+ d_ptr->setReply(contentType, device);
+}
+
+
+
+QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebengineurlrequestjob_p.h b/src/webenginewidgets/api/qwebengineurlrequestjob_p.h
new file mode 100644
index 000000000..3aea80d2f
--- /dev/null
+++ b/src/webenginewidgets/api/qwebengineurlrequestjob_p.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWEBENGINEURLREQUESTJOB_H
+#define QWEBENGINEURLREQUESTJOB_H
+
+#include "qtwebenginewidgetsglobal.h"
+
+#include <QtCore/QByteArray>
+#include <QtCore/QObject>
+#include <QtCore/QUrl>
+
+class URLRequestCustomJobDelegate;
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+
+class QWEBENGINEWIDGETS_EXPORT QWebEngineUrlRequestJob : public QObject {
+ Q_OBJECT
+public:
+ ~QWebEngineUrlRequestJob();
+
+ QUrl requestUrl() const;
+ void setReply(const QByteArray &contentType, QIODevice *device);
+
+private:
+ QWebEngineUrlRequestJob(URLRequestCustomJobDelegate *);
+ friend class QWebEngineUrlSchemeHandlerPrivate;
+
+ URLRequestCustomJobDelegate* d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINEURLREQUESTJOB_H
diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler.cpp b/src/webenginewidgets/api/qwebengineurlschemehandler.cpp
new file mode 100644
index 000000000..b52912b7c
--- /dev/null
+++ b/src/webenginewidgets/api/qwebengineurlschemehandler.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwebengineurlschemehandler_p.h"
+#include "qwebengineurlschemehandler_p_p.h"
+
+#include "qwebengineprofile.h"
+#include "qwebengineprofile_p.h"
+#include "qwebengineurlrequestjob_p.h"
+
+#include <QSharedPointer>
+
+QT_BEGIN_NAMESPACE
+
+QWebEngineUrlSchemeHandlerPrivate::QWebEngineUrlSchemeHandlerPrivate(const QByteArray &scheme, QWebEngineUrlSchemeHandler *q, QWebEngineProfile *profile)
+ : CustomUrlSchemeHandler(scheme)
+ , q_ptr(q)
+ , m_profile(profile)
+{
+}
+
+QWebEngineUrlSchemeHandlerPrivate::~QWebEngineUrlSchemeHandlerPrivate()
+{
+}
+
+bool QWebEngineUrlSchemeHandlerPrivate::handleJob(URLRequestCustomJobDelegate *job)
+{
+ QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(job);
+ q_ptr->requestStarted(requestJob);
+ return true;
+}
+
+QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile)
+ : QObject(profile)
+ , d_ptr(new QWebEngineUrlSchemeHandlerPrivate(scheme, this, profile))
+{
+ profile->d_func()->installUrlSchemeHandler(this);
+}
+
+QWebEngineUrlSchemeHandler::~QWebEngineUrlSchemeHandler()
+{
+ d_ptr->m_profile->d_func()->removeUrlSchemeHandler(this);
+}
+
+QByteArray QWebEngineUrlSchemeHandler::scheme() const
+{
+ return d_ptr->scheme();
+}
+
+QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler_p.h b/src/webenginewidgets/api/qwebengineurlschemehandler_p.h
new file mode 100644
index 000000000..0455128c7
--- /dev/null
+++ b/src/webenginewidgets/api/qwebengineurlschemehandler_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWEBENGINEURLSCHEMEHANDLER_H
+#define QWEBENGINEURLSCHEMEHANDLER_H
+
+#include "qtwebenginewidgetsglobal.h"
+
+#include <QtCore/QByteArray>
+#include <QtCore/QIODevice>
+#include <QtCore/QObject>
+#include <QtCore/QScopedPointer>
+#include <QtCore/QUrl>
+
+QT_BEGIN_NAMESPACE
+
+class QWebEngineProfile;
+class QWebEngineUrlRequestJob;
+class QWebEngineUrlSchemeHandlerPrivate;
+
+class QWEBENGINEWIDGETS_EXPORT QWebEngineUrlSchemeHandler : public QObject {
+ Q_OBJECT
+public:
+ QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile);
+ virtual ~QWebEngineUrlSchemeHandler();
+
+ QByteArray scheme() const;
+
+ virtual void requestStarted(QWebEngineUrlRequestJob*) = 0;
+
+private:
+ Q_DECLARE_PRIVATE(QWebEngineUrlSchemeHandler)
+ friend class QWebEngineProfilePrivate;
+ QScopedPointer<QWebEngineUrlSchemeHandlerPrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINEURLSCHEMEHANDLER_H
diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h b/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h
new file mode 100644
index 000000000..e880bf000
--- /dev/null
+++ b/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWEBENGINEURLSCHEMEHANDLER_P_H
+#define QWEBENGINEURLSCHEMEHANDLER_P_H
+
+#include "qwebengineurlschemehandler_p.h"
+
+#include "custom_url_scheme_handler.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWebEngineProfile;
+class QWebEngineUrlRequestJob;
+class QWebEngineUrlSchemeHandler;
+
+class QWebEngineUrlSchemeHandlerPrivate : public CustomUrlSchemeHandler {
+public:
+ Q_DECLARE_PUBLIC(QWebEngineUrlSchemeHandler)
+
+ QWebEngineUrlSchemeHandlerPrivate(const QByteArray &, QWebEngineUrlSchemeHandler *, QWebEngineProfile *);
+ virtual ~QWebEngineUrlSchemeHandlerPrivate();
+
+ virtual bool handleJob(URLRequestCustomJobDelegate*) Q_DECL_OVERRIDE;
+
+private:
+ QWebEngineUrlSchemeHandler *q_ptr;
+ QWebEngineProfile* m_profile;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINEURLSCHEMEHANDLER_P_H
diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro
index 82908bfd0..7fa630702 100644
--- a/src/webenginewidgets/webenginewidgets.pro
+++ b/src/webenginewidgets/webenginewidgets.pro
@@ -18,6 +18,8 @@ SOURCES = \
api/qwebenginepage.cpp \
api/qwebengineprofile.cpp \
api/qwebenginesettings.cpp \
+ api/qwebengineurlrequestjob.cpp \
+ api/qwebengineurlschemehandler.cpp \
api/qwebengineview.cpp \
render_widget_host_view_qt_delegate_widget.cpp
@@ -32,6 +34,9 @@ HEADERS = \
api/qwebengineprofile.h \
api/qwebengineprofile_p.h \
api/qwebenginesettings.h \
+ api/qwebengineurlrequestjob_p.h \
+ api/qwebengineurlschemehandler_p.h \
+ api/qwebengineurlschemehandler_p_p.h \
api/qwebengineview.h \
api/qwebengineview_p.h \
render_widget_host_view_qt_delegate_widget.h