From 66def056d0f0fc8794f622fcfd61f974fce2a3b1 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 25 Aug 2014 15:37:49 +0200 Subject: Add Qt WebEngine Widgets API for allowing certificate errors This adds API for overriding some certificate errors. Once overridden any identical error for the same hostname and certificate will use the same override. Similar API for QtWebEngine QML should be added in a later patch. Change-Id: I144147b86d9b592e3f87346a1e48890acee0c670 Reviewed-by: Jocelyn Turcotte --- examples/webenginewidgets/browser/webview.cpp | 15 +++++++++++++++ examples/webenginewidgets/browser/webview.h | 1 + 2 files changed, 16 insertions(+) (limited to 'examples/webenginewidgets/browser') diff --git a/examples/webenginewidgets/browser/webview.cpp b/examples/webenginewidgets/browser/webview.cpp index e32ab71d6..ce0f7c418 100644 --- a/examples/webenginewidgets/browser/webview.cpp +++ b/examples/webenginewidgets/browser/webview.cpp @@ -129,6 +129,21 @@ bool WebPage::acceptNavigationRequest(QWebEngineFrame *frame, const QNetworkRequ } #endif +bool WebPage::certificateError(const QWebEngineCertificateError &error) +{ + if (error.isOverridable()) { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Warning); + msgBox.setText(error.errorDescription()); + msgBox.setInformativeText(tr("If you wish so, you may continue with an unverified certicate. Accepting an unverified certicate means you may not be connected with the host you tried to connect to.\nDo you wish to override the security check and continue?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + return msgBox.exec() == QMessageBox::Yes; + } + QMessageBox::critical(view(), tr("Certificate Error"), error.errorDescription(), QMessageBox::Ok, QMessageBox::NoButton); + return false; +} + class PopupWindow : public QWidget { Q_OBJECT public: diff --git a/examples/webenginewidgets/browser/webview.h b/examples/webenginewidgets/browser/webview.h index 352954c8d..2238abbd5 100644 --- a/examples/webenginewidgets/browser/webview.h +++ b/examples/webenginewidgets/browser/webview.h @@ -72,6 +72,7 @@ protected: #if !defined(QT_NO_UITOOLS) QObject *createPlugin(const QString &classId, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); #endif + virtual bool certificateError(const QWebEngineCertificateError &error) Q_DECL_OVERRIDE; private slots: #if defined(QWEBENGINEPAGE_UNSUPPORTEDCONTENT) -- cgit v1.2.3