diff options
author | Liang Qi <liang.qi@qt.io> | 2019-09-12 10:00:03 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2019-09-12 20:19:28 +0200 |
commit | 2f71cdff2cda7903fd0b5ff0033d790877e40181 (patch) | |
tree | 0255e40f5366123bedefcbc9ad7d482f2e8198a2 /src/webenginewidgets/api/qwebenginecertificateerror.cpp | |
parent | d91b839d67bcfa1cfeb3d095b6885c97c53b9812 (diff) | |
parent | 5b0bbd7345b698faab0116b821802fb4a30c0fa4 (diff) | |
download | qtwebengine-wip/qt6.tar.gz |
Merge "Merge remote-tracking branch 'origin/5.14' into wip/qt6"wip/qt6
Diffstat (limited to 'src/webenginewidgets/api/qwebenginecertificateerror.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginecertificateerror.cpp | 109 |
1 files changed, 102 insertions, 7 deletions
diff --git a/src/webenginewidgets/api/qwebenginecertificateerror.cpp b/src/webenginewidgets/api/qwebenginecertificateerror.cpp index f04b73615..a61d98f94 100644 --- a/src/webenginewidgets/api/qwebenginecertificateerror.cpp +++ b/src/webenginewidgets/api/qwebenginecertificateerror.cpp @@ -39,6 +39,8 @@ #include "qwebenginecertificateerror.h" +#include "certificate_error_controller.h" + QT_BEGIN_NAMESPACE /*! @@ -51,14 +53,38 @@ QT_BEGIN_NAMESPACE QWebEnginePage::certificateError(). */ -class QWebEngineCertificateErrorPrivate { +class QWebEngineCertificateErrorPrivate : public QSharedData { public: QWebEngineCertificateErrorPrivate(int error, QUrl url, bool overridable, QString errorDescription); + ~QWebEngineCertificateErrorPrivate() { + if (deferred && !answered) + rejectCertificate(); + } + + void resolveError(bool accept) { + if (answered) + return; + answered = true; + if (overridable) { + if (auto ctl = controller.lock()) + ctl->accept(accept); + } + } + + void ignoreCertificateError() { resolveError(true); } + void rejectCertificate() { resolveError(false); } + QWebEngineCertificateError::Error error; QUrl url; bool overridable; QString errorDescription; + QList<QSslCertificate> chain; + + bool answered = false, deferred = false; + QWeakPointer<CertificateErrorController> controller; + + Q_DISABLE_COPY(QWebEngineCertificateErrorPrivate) }; QWebEngineCertificateErrorPrivate::QWebEngineCertificateErrorPrivate(int error, QUrl url, bool overridable, QString errorDescription) @@ -68,17 +94,31 @@ QWebEngineCertificateErrorPrivate::QWebEngineCertificateErrorPrivate(int error, , errorDescription(errorDescription) { } - /*! \internal */ QWebEngineCertificateError::QWebEngineCertificateError(int error, QUrl url, bool overridable, QString errorDescription) - : d_ptr(new QWebEngineCertificateErrorPrivate(error, url, overridable, errorDescription)) + : d(new QWebEngineCertificateErrorPrivate(error, url, overridable, errorDescription)) { } /*! \internal */ +QWebEngineCertificateError::QWebEngineCertificateError(const QSharedPointer<CertificateErrorController> &controller) + : d(new QWebEngineCertificateErrorPrivate(controller->error(), controller->url(), + controller->overridable(), controller->errorString())) +{ + d->controller = controller; + d->chain = controller->chain(); +} + +QWebEngineCertificateError::QWebEngineCertificateError(const QWebEngineCertificateError &other) = default; + +QWebEngineCertificateError& QWebEngineCertificateError::operator=(const QWebEngineCertificateError &other) = default; + +/*! \internal +*/ QWebEngineCertificateError::~QWebEngineCertificateError() { + } /*! @@ -116,7 +156,6 @@ QWebEngineCertificateError::~QWebEngineCertificateError() */ bool QWebEngineCertificateError::isOverridable() const { - const Q_D(QWebEngineCertificateError); return d->overridable; } @@ -127,7 +166,6 @@ bool QWebEngineCertificateError::isOverridable() const */ QUrl QWebEngineCertificateError::url() const { - const Q_D(QWebEngineCertificateError); return d->url; } @@ -138,7 +176,6 @@ QUrl QWebEngineCertificateError::url() const */ QWebEngineCertificateError::Error QWebEngineCertificateError::error() const { - const Q_D(QWebEngineCertificateError); return d->error; } @@ -149,8 +186,66 @@ QWebEngineCertificateError::Error QWebEngineCertificateError::error() const */ QString QWebEngineCertificateError::errorDescription() const { - const Q_D(QWebEngineCertificateError); return d->errorDescription; } +/*! + Marks the certificate error for delayed handling. + + This function should be called when there is a need to postpone the decision whether to ignore a + certificate error, for example, while waiting for user input. When called, the function pauses the + URL request until ignoreCertificateError() or rejectCertificate() is called. + + \note It is only possible to defer overridable certificate errors. + + \sa isOverridable(), deferred() +*/ +void QWebEngineCertificateError::defer() +{ + if (isOverridable()) + d->deferred = true; +} + +/*! + Returns whether the decision for error handling was delayed and the URL load was halted. +*/ +bool QWebEngineCertificateError::deferred() const +{ + return d->deferred; +} + +/*! + Ignores the certificate error and continues the loading of the requested URL. +*/ +void QWebEngineCertificateError::ignoreCertificateError() +{ + d->ignoreCertificateError(); +} + +/*! + Rejects the certificate and aborts the loading of the requested URL. +*/ +void QWebEngineCertificateError::rejectCertificate() +{ + d->rejectCertificate(); +} + +/*! + Returns \c true if the error was explicitly rejected or accepted. +*/ +bool QWebEngineCertificateError::answered() const +{ + return d->answered; +} + +/*! + Returns the peer's chain of digital certificates + + Chain starts with the peer's immediate certificate and ending with the CA's certificate. +*/ +QList<QSslCertificate> QWebEngineCertificateError::chain() const +{ + return d->chain; +} + QT_END_NAMESPACE |