#ifndef WEBVIEW_H_ #define WEBVIEW_H_ #include #include #include #include #include #include #include class QNetworkReply; 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 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: explicit WebView(QWidget* parent = nullptr); void setIgnoreSslErrors(bool on); bool wasAbortedDownload() { bool r = _abortedDownload; _abortedDownload = false; return r; } protected: QWebEngineView *createWindow(QWebEnginePage::WebWindowType) override; void contextMenuEvent(QContextMenuEvent *ev) override; protected slots: void windowCloseRequested(); void onDownloadRequested(QWebEngineDownloadItem* item); void downloadDeniedMessage(); private: QStack _urls; QTimer *_timer; bool _abortedDownload; CustomPage *_customPage{nullptr}; }; #endif