Skip to content

Commit ba79e85

Browse files
author
Ulf Hermann
committed
Turn webEngineCertificateError into a well-behaved value type
Allow a nullptr as the controller and add an "Ok" value to the enum to signify "no error". This is in line with the "OK" value in Chromium's net_errors.h. Furthermore, add a public default ctor to allow QMetaType to create it. Task-number: QTBUG-108649 Fixes: QTBUG-135032 Pick-to: 6.9 6.8 Change-Id: Id06db78f273805ba117eefaa0ada3eac2f538962 Reviewed-by: Michal Klocek <[email protected]>
1 parent f88fa0c commit ba79e85

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/core/api/qwebenginecertificateerror.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ QWebEngineCertificateError::~QWebEngineCertificateError() = default;
4242
QSslError::SslError values are not used directly, because the Qt error
4343
categories cannot be mapped to the Chromium error categories.
4444
45+
\value Ok There was no actual certificate error.
4546
\value SslPinnedKeyNotInCertificateChain The certificate did not match the built-in public keys
4647
pinned for the host name.
4748
\value CertificateCommonNameInvalid The certificate's common name did not match the host name.
@@ -74,7 +75,9 @@ QWebEngineCertificateError::~QWebEngineCertificateError() = default;
7475
*/
7576
bool QWebEngineCertificateError::isOverridable() const
7677
{
77-
return d->overridable();
78+
if (Q_LIKELY(d))
79+
return d->overridable();
80+
return false;
7881
}
7982

8083
/*!
@@ -84,7 +87,9 @@ bool QWebEngineCertificateError::isOverridable() const
8487
*/
8588
QUrl QWebEngineCertificateError::url() const
8689
{
87-
return d->url();
90+
if (Q_LIKELY(d))
91+
return d->url();
92+
return QUrl();
8893
}
8994

9095
/*!
@@ -97,7 +102,9 @@ QUrl QWebEngineCertificateError::url() const
97102
*/
98103
bool QWebEngineCertificateError::isMainFrame() const
99104
{
100-
return d->isMainFrame();
105+
if (Q_LIKELY(d))
106+
return d->isMainFrame();
107+
return false;
101108
}
102109

103110
/*!
@@ -107,7 +114,9 @@ bool QWebEngineCertificateError::isMainFrame() const
107114
*/
108115
QWebEngineCertificateError::Type QWebEngineCertificateError::type() const
109116
{
110-
return d->error();
117+
if (Q_LIKELY(d))
118+
return d->error();
119+
return Ok;
111120
}
112121

113122
/*!
@@ -117,7 +126,9 @@ QWebEngineCertificateError::Type QWebEngineCertificateError::type() const
117126
*/
118127
QString QWebEngineCertificateError::description() const
119128
{
120-
return d->errorString();
129+
if (Q_LIKELY(d))
130+
return d->errorString();
131+
return QString();
121132
}
122133

123134
/*!
@@ -135,7 +146,8 @@ QString QWebEngineCertificateError::description() const
135146
*/
136147
void QWebEngineCertificateError::defer()
137148
{
138-
d->defer();
149+
if (Q_LIKELY(d))
150+
d->defer();
139151
}
140152

141153
/*!
@@ -145,7 +157,8 @@ void QWebEngineCertificateError::defer()
145157
*/
146158
void QWebEngineCertificateError::acceptCertificate()
147159
{
148-
d->ignoreCertificateError();
160+
if (Q_LIKELY(d))
161+
d->ignoreCertificateError();
149162
}
150163

151164
/*!
@@ -155,7 +168,8 @@ void QWebEngineCertificateError::acceptCertificate()
155168
*/
156169
void QWebEngineCertificateError::rejectCertificate()
157170
{
158-
d->rejectCertificate();
171+
if (Q_LIKELY(d))
172+
d->rejectCertificate();
159173
}
160174

161175
/*!
@@ -167,7 +181,9 @@ void QWebEngineCertificateError::rejectCertificate()
167181
*/
168182
QList<QSslCertificate> QWebEngineCertificateError::certificateChain() const
169183
{
170-
return d->certificateChain();
184+
if (Q_LIKELY(d))
185+
return d->certificateChain();
186+
return QList<QSslCertificate>();
171187
}
172188

173189
QT_END_NAMESPACE

src/core/api/qwebenginecertificateerror.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ class Q_WEBENGINECORE_EXPORT QWebEngineCertificateError
2727
Q_PROPERTY(bool isMainFrame READ isMainFrame CONSTANT FINAL REVISION(6, 8))
2828

2929
public:
30+
QWebEngineCertificateError() = default;
3031
QWebEngineCertificateError(const QWebEngineCertificateError &other);
3132
QWebEngineCertificateError &operator=(const QWebEngineCertificateError &other);
3233
~QWebEngineCertificateError();
3334

3435
// Keep this identical to NET_ERROR in net_error_list.h, or add mapping layer.
3536
enum Type {
37+
Ok = 0, // No actual error. See net_errors.h for that one
38+
3639
SslPinnedKeyNotInCertificateChain = -150,
3740
CertificateCommonNameInvalid = -200,
3841
CertificateDateInvalid = -201,

tests/auto/quick/publicapi/tst_publicapi.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static const QStringList expectedAPI = QStringList()
140140
<< "QWebEngineCertificateError.CertificateSymantecLegacy --> Type"
141141
<< "QWebEngineCertificateError.SslObsoleteVersion --> Type"
142142
<< "QWebEngineCertificateError.SslPinnedKeyNotInCertificateChain --> Type"
143+
<< "QWebEngineCertificateError.Ok --> Type"
143144
<< "QWebEngineCertificateError.defer() --> void"
144145
<< "QWebEngineCertificateError.description --> QString"
145146
<< "QWebEngineCertificateError.type --> QWebEngineCertificateError::Type"

0 commit comments

Comments
 (0)