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 --- examples/webengine/quicknanobrowser/BrowserWindow.qml | 5 +++++ examples/webenginewidgets/simplebrowser/webpage.cpp | 17 +++++++++++++++++ examples/webenginewidgets/simplebrowser/webpage.h | 2 ++ 3 files changed, 24 insertions(+) (limited to 'examples') diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml index be1e42c73..15a8d96fe 100644 --- a/examples/webengine/quicknanobrowser/BrowserWindow.qml +++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml @@ -445,6 +445,11 @@ ApplicationWindow { request.reject(); } + onRegisterProtocolHandlerPermissionRequested: { + print("accepting registerProtocolHandler permission request for " + request.protocol + " from " + request.origin); + request.accept(); + } + onRenderProcessTerminated: { var status = ""; switch (terminationStatus) { diff --git a/examples/webenginewidgets/simplebrowser/webpage.cpp b/examples/webenginewidgets/simplebrowser/webpage.cpp index 903956419..ef55fd33d 100644 --- a/examples/webenginewidgets/simplebrowser/webpage.cpp +++ b/examples/webenginewidgets/simplebrowser/webpage.cpp @@ -63,6 +63,7 @@ WebPage::WebPage(QWebEngineProfile *profile, QObject *parent) { connect(this, &QWebEnginePage::authenticationRequired, this, &WebPage::handleAuthenticationRequired); connect(this, &QWebEnginePage::proxyAuthenticationRequired, this, &WebPage::handleProxyAuthenticationRequired); + connect(this, &QWebEnginePage::registerProtocolHandlerPermissionRequested, this, &WebPage::handleRegisterProtocolHandlerPermissionRequested); } bool WebPage::certificateError(const QWebEngineCertificateError &error) @@ -141,3 +142,19 @@ void WebPage::handleProxyAuthenticationRequired(const QUrl &, QAuthenticator *au *auth = QAuthenticator(); } } + +//! [registerProtocolHandlerPermissionRequested] +void WebPage::handleRegisterProtocolHandlerPermissionRequested(QWebEngineRegisterProtocolHandlerPermissionRequest request) +{ + auto answer = QMessageBox::question( + view()->window(), + tr("Permission Request"), + tr("Allow %1 to open all %2 links?") + .arg(request.origin().host()) + .arg(request.protocol())); + if (answer == QMessageBox::Yes) + request.accept(); + else + request.reject(); +} +//! [registerProtocolHandlerPermissionRequested] diff --git a/examples/webenginewidgets/simplebrowser/webpage.h b/examples/webenginewidgets/simplebrowser/webpage.h index 797943249..d44c79358 100644 --- a/examples/webenginewidgets/simplebrowser/webpage.h +++ b/examples/webenginewidgets/simplebrowser/webpage.h @@ -52,6 +52,7 @@ #define WEBPAGE_H #include +#include class WebPage : public QWebEnginePage { @@ -66,6 +67,7 @@ protected: private slots: void handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth); void handleProxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth, const QString &proxyHost); + void handleRegisterProtocolHandlerPermissionRequested(QWebEngineRegisterProtocolHandlerPermissionRequest request); }; #endif // WEBPAGE_H -- cgit v1.2.3