From 2a4a5b2ec17189d4ea8fa783cf219c65560e81f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Mon, 15 Jan 2018 17:57:05 +0100 Subject: Add support for registerProtocolHandler Extend initialization of URLRequestContextGetterQt to create a content::ProtocolHandlerRegistry for each content::BrowserContext and add the registry's URL request interceptor to the front of the interceptor chain. Implement methods in WebContentsDelegateQt to add/remove protocol handlers to/from the ProtocolHandlerRegistry. Add permission request signal and classes for core, quick and widgets. Add widgets autotest. Add signal handlers to quicknanobrowser and simplebrowser. Task-number: QTBUG-62783 Change-Id: I808e7eb9a1cb4d7216686deed4895de14fe46310 Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginepage.cpp | 20 ++++ src/webenginewidgets/api/qwebenginepage.h | 2 + src/webenginewidgets/api/qwebenginepage_p.h | 1 + ...ineregisterprotocolhandlerpermissionrequest.cpp | 115 +++++++++++++++++++++ ...ngineregisterprotocolhandlerpermissionrequest.h | 73 +++++++++++++ src/webenginewidgets/webenginewidgets.pro | 2 + 6 files changed, 213 insertions(+) create mode 100644 src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.cpp create mode 100644 src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.h (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 67d55b20f..ec35ea6ce 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -54,6 +54,7 @@ #include "qwebengineprofile.h" #include "qwebengineprofile_p.h" #include "qwebenginequotapermissionrequest.h" +#include "qwebengineregisterprotocolhandlerpermissionrequest.h" #include "qwebenginescriptcollection_p.h" #include "qwebenginesettings.h" #include "qwebengineview.h" @@ -578,6 +579,13 @@ void QWebEnginePagePrivate::runQuotaPermissionRequest(QSharedPointerquotaPermissionRequested(request); } +void QWebEnginePagePrivate::runRegisterProtocolHandlerPermissionRequest(QSharedPointer controller) +{ + Q_Q(QWebEnginePage); + QWebEngineRegisterProtocolHandlerPermissionRequest request(std::move(controller)); + Q_EMIT q->registerProtocolHandlerPermissionRequested(request); +} + QObject *QWebEnginePagePrivate::accessibilityParentObject() { return view; @@ -749,6 +757,18 @@ QWebEnginePage::QWebEnginePage(QObject* parent) The request object \a request can be used to accept or reject the request. */ +/*! + \fn QWebEnginePage::registerProtocolHandlerPermissionRequested(QWebEngineRegisterProtocolHandlerPermissionRequest request) + \since 5.11 + + This signal is emitted when the web page tries to register a custom protocol + using the \l registerProtocolHandler API. + + The request object \a request can be used to accept or reject the request: + + \snippet webenginewidgets/simplebrowser/webpage.cpp registerProtocolHandlerPermissionRequested +*/ + /*! \fn void QWebEnginePage::pdfPrintingFinished(const QString &filePath, bool success) \since 5.9 diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 7ce72258b..d716765fe 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -66,6 +66,7 @@ class QWebEnginePage; class QWebEnginePagePrivate; class QWebEngineProfile; class QWebEngineQuotaPermissionRequest; +class QWebEngineRegisterProtocolHandlerPermissionRequest; class QWebEngineScriptCollection; class QWebEngineSettings; @@ -338,6 +339,7 @@ Q_SIGNALS: void featurePermissionRequestCanceled(const QUrl &securityOrigin, QWebEnginePage::Feature feature); void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); void quotaPermissionRequested(QWebEngineQuotaPermissionRequest quotaPermissionRequest); + void registerProtocolHandlerPermissionRequested(QWebEngineRegisterProtocolHandlerPermissionRequest request); void authenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator); void proxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator, const QString &proxyHost); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 301028e39..61092fa6a 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -130,6 +130,7 @@ public: void runGeolocationPermissionRequest(const QUrl &securityOrigin) override; void runMouseLockPermissionRequest(const QUrl &securityOrigin) override; void runQuotaPermissionRequest(QSharedPointer) override; + void runRegisterProtocolHandlerPermissionRequest(QSharedPointer) override; QObject *accessibilityParentObject() override; QtWebEngineCore::WebEngineSettings *webEngineSettings() const override; void allowCertificateError(const QSharedPointer &controller) override; diff --git a/src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.cpp b/src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.cpp new file mode 100644 index 000000000..ad1398daf --- /dev/null +++ b/src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengineregisterprotocolhandlerpermissionrequest.h" + +#include "register_protocol_handler_permission_controller.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWebEngineRegisterProtocolHandlerPermissionRequest + \inmodule QtWebEngineWidgets + \since 5.11 + \brief The QWebEngineRegisterProtocolHandlerPermissionRequest type enables + accepting or rejecting requests from the \l registerProtocolHandler API. + + \sa QWebEnginePage::registerProtocolHandlerPermissionRequested +*/ + +static void registerMetaTypes() +{ + qRegisterMetaType(); +} + +Q_CONSTRUCTOR_FUNCTION(registerMetaTypes) + +/*! \fn QWebEngineRegisterProtocolHandlerPermissionRequest::QWebEngineRegisterProtocolHandlerPermissionRequest() + \internal +*/ + +/*! \internal */ +QWebEngineRegisterProtocolHandlerPermissionRequest::QWebEngineRegisterProtocolHandlerPermissionRequest( + QSharedPointer d_ptr) + : d_ptr(std::move(d_ptr)) +{} + +/*! + Rejects the request. + + Subsequent calls to accept() and reject() are ignored. +*/ +void QWebEngineRegisterProtocolHandlerPermissionRequest::reject() +{ + d_ptr->reject(); +} + +/*! + Accepts the request + + Subsequent calls to accept() and reject() are ignored. +*/ +void QWebEngineRegisterProtocolHandlerPermissionRequest::accept() +{ + d_ptr->accept(); +} + +/*! + \property QWebEngineRegisterProtocolHandlerPermissionRequest::origin + \brief The URL template for the protocol handler. + + This is the second parameter from the \l registerProtocolHandler call. +*/ +QUrl QWebEngineRegisterProtocolHandlerPermissionRequest::origin() const +{ + return d_ptr->origin(); +} + +/*! + \property QWebEngineRegisterProtocolHandlerPermissionRequest::protocol + \brief The URL scheme for the protocol handler. + + This is the first parameter from the \l registerProtocolHandler call. +*/ +QString QWebEngineRegisterProtocolHandlerPermissionRequest::protocol() const +{ + return d_ptr->protocol(); +} + +QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.h b/src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.h new file mode 100644 index 000000000..592eabb34 --- /dev/null +++ b/src/webenginewidgets/api/qwebengineregisterprotocolhandlerpermissionrequest.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEREGISTERPROTOCOLHANDLERPERMISSIONREQUEST_H +#define QWEBENGINEREGISTERPROTOCOLHANDLERPERMISSIONREQUEST_H + +#include +#include +#include + +namespace QtWebEngineCore { + class RegisterProtocolHandlerPermissionController; +} + +QT_BEGIN_NAMESPACE + +class QWEBENGINEWIDGETS_EXPORT QWebEngineRegisterProtocolHandlerPermissionRequest { + Q_GADGET + Q_PROPERTY(QUrl origin READ origin CONSTANT FINAL) + Q_PROPERTY(QString protocol READ protocol CONSTANT FINAL) +public: + QWebEngineRegisterProtocolHandlerPermissionRequest() {} + QWebEngineRegisterProtocolHandlerPermissionRequest( + QSharedPointer); + Q_INVOKABLE void accept(); + Q_INVOKABLE void reject(); + QUrl origin() const; + QString protocol() const; + +private: + QSharedPointer d_ptr; +}; + +QT_END_NAMESPACE +Q_DECLARE_METATYPE(QWebEngineRegisterProtocolHandlerPermissionRequest) + +#endif // QWEBENGINEREGISTERPROTOCOLHANDLERPERMISSIONREQUEST_H diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index 37cb7a1f0..c3132b640 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -20,6 +20,7 @@ SOURCES = \ api/qwebenginepage.cpp \ api/qwebengineprofile.cpp \ api/qwebenginequotapermissionrequest.cpp \ + api/qwebengineregisterprotocolhandlerpermissionrequest.cpp \ api/qwebenginescript.cpp \ api/qwebenginescriptcollection.cpp \ api/qwebenginesettings.cpp \ @@ -39,6 +40,7 @@ HEADERS = \ api/qwebengineprofile.h \ api/qwebengineprofile_p.h \ api/qwebenginequotapermissionrequest.h \ + api/qwebengineregisterprotocolhandlerpermissionrequest.h \ api/qwebenginescriptcollection.h \ api/qwebenginescriptcollection_p.h \ api/qwebenginesettings.h \ -- cgit v1.2.3