From 2c3b026349349729141ca46bd9d292327da2dfe2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 13 Nov 2025 13:48:37 +0100 Subject: Port to QtWebEngine (thx Junie), bump to C++20 --- src/webview.h | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'src/webview.h') diff --git a/src/webview.h b/src/webview.h index 9d7e28d..43e293e 100644 --- a/src/webview.h +++ b/src/webview.h @@ -2,8 +2,12 @@ #define WEBVIEW_H_ #include -#include -#include +#include +#include +#include +#include +#include +#include class QNetworkReply; class QTimer; @@ -12,11 +16,29 @@ class QTimer; * Make sure pages that want to load in a new tab are actually loaded in the same page, * and remember the previous URL in case the "new tab" requests to be closed. */ -class WebView : public QWebView +class CustomPage : public QWebEnginePage +{ + Q_OBJECT +public: + explicit CustomPage(QObject *parent = nullptr) : QWebEnginePage(parent) {} + void setIgnoreSslErrors(bool on) { _ignoreSslErrors = on; } +protected: + bool certificateError(const QWebEngineCertificateError &error) override { + if (_ignoreSslErrors) { + return true; + } + return QWebEnginePage::certificateError(error); + } +private: + bool _ignoreSslErrors{false}; +}; + +class WebView : public QWebEngineView { Q_OBJECT public: - WebView(QWidget* parent = NULL); + explicit WebView(QWidget* parent = nullptr); + void setIgnoreSslErrors(bool on); bool wasAbortedDownload() { bool r = _abortedDownload; _abortedDownload = false; @@ -24,18 +46,19 @@ public: } protected: - QWebView *createWindow(QWebPage::WebWindowType); + QWebEngineView *createWindow(QWebEnginePage::WebWindowType) override; + void contextMenuEvent(QContextMenuEvent *ev) override; protected slots: - void windowCloseRequested(); - void unsupportedContent(QNetworkReply*); - void downloadRequest(QNetworkRequest); - void downloadDeniedMessage(); + void windowCloseRequested(); + void onDownloadRequested(QWebEngineDownloadItem* item); + void downloadDeniedMessage(); private: - QStack _urls; - QTimer *_timer; - bool _abortedDownload; + QStack _urls; + QTimer *_timer; + bool _abortedDownload; + CustomPage *_customPage{nullptr}; }; #endif -- cgit v1.2.3-55-g7522