From 869fdeef7922450fee0e568dac356a8f5f021575 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 29 Mar 2022 13:38:13 -0700 Subject: [PATCH] Set all the appropriate WebAttributes. https://redmine.stoutner.com/issues/800 --- src/views/BrowserView.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 319f9e5..74b27cf 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -78,6 +78,18 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Don't allow JavaScript to open windows. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); + // Allow keyboard navigation. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, true); + + // Enable full screen support. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); + + // Require user interaction to play media. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, true); + + // Limit WebRTC to public IP addresses. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, true); + // Set the focus on the WebEngine view. webEngineViewPointer->setFocus(); } @@ -255,10 +267,15 @@ void BrowserView::loadInitialWebsite() void BrowserView::loadUrlFromLineEdit(QString url) const { // Decide if the text is more likely to be a URL or a search. - if (url.contains(".")) // The text is likely a URL. + if (url.startsWith("file://")) // The text is likely a file URL. + { + // Load the URL. + webEngineViewPointer->load(QUrl::fromUserInput(url)); + } + else if (url.contains(".")) // The text is likely a URL. { // Check if the URL does not start with a valid protocol. - if (!url.startsWith("http") && !url.startsWith("file://")) + if (!url.startsWith("http")) { // Add `https://` to the beginning of the URL. url = "https://" + url; -- 2.45.2