summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_delegate_qt.cpp
diff options
context:
space:
mode:
authorViktor Engelmann <viktor.engelmann@qt.io>2017-07-03 15:51:51 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-18 18:06:55 +0000
commit49c0ce8403e5caeb864f66553f122c68a7c975fb (patch)
treea3b4c1f89754c316fe1fb5cce4392dd05f1db4e7 /src/core/web_contents_delegate_qt.cpp
parent8365186b3fdc2f1eca7e015147688d23bfdf81e9 (diff)
Add Setting to allow passing unknown URL schemes to QDesktopServices
A new enum UnknownUrlSchemePolicy was added to WebEngineSettings, QWebEngineSettings and QQuickWebEngineSettings. WebContentsDelegate now has a new attribute of that type, which can be read and written through the public APIs Q(Quick)WebEngineSettings::unknownUrlSchemeNavigationPolicy and Q(Quick)WebEngineSettings::setUnknownUrlSchemeNavigationPolicy. This way, one can control, whether URLs with unknown schemes are passed to QDesktopServices. WebContentsAdapterClient::navigationRequested is called on these requests, so this allows more fine-grained control over the schemes and origins, that are allowed. Task-number: QTBUG-58627 Change-Id: Ie81d9503456d63ea1ed5606483254acf437cd8f7 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r--src/core/web_contents_delegate_qt.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index ad0e7ad6d..31180a1c1 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -499,14 +499,45 @@ void WebContentsDelegateQt::requestGeolocationPermission(const QUrl &requestingO
extern WebContentsAdapterClient::NavigationType pageTransitionToNavigationType(ui::PageTransition transition);
-void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransition page_transition, bool is_main_frame)
+void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransition page_transition, bool is_main_frame, bool has_user_gesture)
{
- int navigationRequestAction = WebContentsAdapterClient::AcceptRequest;
- m_viewClient->navigationRequested(pageTransitionToNavigationType(page_transition), url, navigationRequestAction, is_main_frame);
+ WebEngineSettings *settings = m_viewClient->webEngineSettings();
+ bool navigationAllowedByPolicy = false;
+ bool navigationRequestAccepted = true;
+
+ switch (settings->unknownUrlSchemePolicy()) {
+ case WebEngineSettings::DisallowUnknownUrlSchemes:
+ break;
+ case WebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction:
+ navigationAllowedByPolicy = has_user_gesture;
+ break;
+ case WebEngineSettings::AllowAllUnknownUrlSchemes:
+ navigationAllowedByPolicy = true;
+ break;
+ default:
+ Q_UNREACHABLE();
+ }
+
+ if (navigationAllowedByPolicy) {
+ int navigationRequestAction = WebContentsAdapterClient::AcceptRequest;
+ m_viewClient->navigationRequested(pageTransitionToNavigationType(page_transition), url, navigationRequestAction, is_main_frame);
+ navigationRequestAccepted = navigationRequestAction == WebContentsAdapterClient::AcceptRequest;
#ifndef QT_NO_DESKTOPSERVICES
- if (navigationRequestAction == WebContentsAdapterClient::AcceptRequest)
- QDesktopServices::openUrl(url);
+ if (navigationRequestAccepted)
+ QDesktopServices::openUrl(url);
#endif
+ }
+
+ if (!navigationAllowedByPolicy || !navigationRequestAccepted) {
+ if (!navigationAllowedByPolicy)
+ didFailLoad(url, 420, QStringLiteral("Launching external protocol forbidden by WebEngineSettings::UnknownUrlSchemePolicy"));
+ else
+ didFailLoad(url, 420, QStringLiteral("Launching external protocol suppressed by WebContentsAdapterClient::navigationRequested"));
+ if (settings->testAttribute(WebEngineSettings::ErrorPageEnabled)) {
+ EmitLoadStarted(toQt(GURL(content::kUnreachableWebDataURL)), true);
+ m_viewClient->webContentsAdapter()->load(toQt(GURL(content::kUnreachableWebDataURL)));
+ }
+ }
}
void WebContentsDelegateQt::ShowValidationMessage(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view, const base::string16 &main_text, const base::string16 &sub_text)