summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/simplebrowser
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webenginewidgets/simplebrowser')
-rw-r--r--examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc27
-rw-r--r--examples/webenginewidgets/simplebrowser/tabwidget.cpp5
-rw-r--r--examples/webenginewidgets/simplebrowser/webpage.cpp7
3 files changed, 36 insertions, 3 deletions
diff --git a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
index dd7a8b998..a312da3ad 100644
--- a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
+++ b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
@@ -103,6 +103,25 @@
\skipto TabWidget::setupView
\printuntil /^\}/
+ \section1 Closing Tabs
+
+ When the user closes a tab, we first trigger the \l {QWebEnginePage::}{RequestClose} web action
+ on the corresponding \c WebView:
+
+ \quotefromfile webenginewidgets/simplebrowser/tabwidget.cpp
+ \skipto QTabBar::tabCloseRequested
+ \printuntil }
+
+ This allows any JavaScript \c beforeunload event listeners to fire, which may
+ prompt the user with a dialog to confirm that they want to close the page.
+ In this case, the user can reject the close request and leave the tab open,
+ otherwise the \l {QWebEnginePage::}{windowCloseRequested} signal is emitted and we close the
+ tab:
+
+ \quotefromfile webenginewidgets/simplebrowser/tabwidget.cpp
+ \skipto QWebEnginePage::windowCloseRequested
+ \printuntil }
+
\section1 Implementing WebView Functionality
The \c WebView is derived from QWebEngineView to support the following
@@ -204,13 +223,17 @@
The \c handleProxyAuthenticationRequired signal handler implements the very same
steps for the authentication of HTTP proxies.
- In case of SSL errors, we just need to return a boolean value indicating
- whether the certificate should be ignored.
+ In case of SSL errors, we check whether they come from the main frame, or
+ from a resource inside the page. Resource errors automatically trigger a
+ certificate rejection, since a user won't have enough context to make a
+ decision. For all other cases, we trigger a dialog where the user can
+ allow or reject the certificate.
\quotefromfile webenginewidgets/simplebrowser/webpage.cpp
\skipto WebPage::handleCertificateError(
\printuntil }
\printuntil }
+ \printuntil }
\section1 Opening a Web Page
diff --git a/examples/webenginewidgets/simplebrowser/tabwidget.cpp b/examples/webenginewidgets/simplebrowser/tabwidget.cpp
index f9037a8e1..acdf49510 100644
--- a/examples/webenginewidgets/simplebrowser/tabwidget.cpp
+++ b/examples/webenginewidgets/simplebrowser/tabwidget.cpp
@@ -21,7 +21,10 @@ TabWidget::TabWidget(QWebEngineProfile *profile, QWidget *parent)
tabBar->setMovable(true);
tabBar->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tabBar, &QTabBar::customContextMenuRequested, this, &TabWidget::handleContextMenuRequested);
- connect(tabBar, &QTabBar::tabCloseRequested, this, &TabWidget::closeTab);
+ connect(tabBar, &QTabBar::tabCloseRequested, [this](int index) {
+ if (WebView *view = webView(index))
+ view->page()->triggerAction(QWebEnginePage::WebAction::RequestClose);
+ });
connect(tabBar, &QTabBar::tabBarDoubleClicked, [this](int index) {
if (index == -1)
createTab();
diff --git a/examples/webenginewidgets/simplebrowser/webpage.cpp b/examples/webenginewidgets/simplebrowser/webpage.cpp
index 807cdf0ff..6fc9aeaf9 100644
--- a/examples/webenginewidgets/simplebrowser/webpage.cpp
+++ b/examples/webenginewidgets/simplebrowser/webpage.cpp
@@ -19,6 +19,13 @@ WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
void WebPage::handleCertificateError(QWebEngineCertificateError error)
{
+ // Automatically block certificate errors from page resources without prompting the user.
+ // This mirrors the behavior found in other major browsers.
+ if (!error.isMainFrame()) {
+ error.rejectCertificate();
+ return;
+ }
+
error.defer();
QTimer::singleShot(0, this,
[this, error]() mutable { emit createCertificateErrorDialog(error); });