summaryrefslogtreecommitdiffstats
path: root/src/webview.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/webview.h')
-rw-r--r--src/webview.h47
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