diff options
| author | Simon Rettberg | 2025-11-13 13:48:37 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-11-13 14:00:03 +0100 |
| commit | 2c3b026349349729141ca46bd9d292327da2dfe2 (patch) | |
| tree | af0650430c311a319bda68c89b4fd39036a9ec2c /src/webview.h | |
| parent | Fix: error page not showing HTTP error codes, but "Unknown Error" (diff) | |
| download | slxbrowser-2c3b026349349729141ca46bd9d292327da2dfe2.tar.gz slxbrowser-2c3b026349349729141ca46bd9d292327da2dfe2.tar.xz slxbrowser-2c3b026349349729141ca46bd9d292327da2dfe2.zip | |
Diffstat (limited to 'src/webview.h')
| -rw-r--r-- | src/webview.h | 47 |
1 files changed, 35 insertions, 12 deletions
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 <QStack> -#include <QWebView> -#include <QNetworkRequest> +#include <QUrl> +#include <QtWebEngineWidgets/QWebEngineView> +#include <QtWebEngineWidgets/QWebEnginePage> +#include <QtWebEngineWidgets/QWebEngineProfile> +#include <QtWebEngineWidgets/QWebEngineDownloadItem> +#include <QtWebEngineWidgets/QWebEngineCertificateError> 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<QUrl> _urls; - QTimer *_timer; - bool _abortedDownload; + QStack<QUrl> _urls; + QTimer *_timer; + bool _abortedDownload; + CustomPage *_customPage{nullptr}; }; #endif |
