summaryrefslogtreecommitdiffstats
path: root/src/core/api/qwebenginepermission.cpp
diff options
context:
space:
mode:
authorKaloyan Chehlarski <kaloyan.chehlarski@qt.io>2024-07-11 13:45:56 +0200
committerKaloyan Chehlarski <kaloyan.chehlarski@qt.io>2024-07-17 14:32:52 +0000
commit2a84d23c69b0db9a8b050f8e6667972ce337c611 (patch)
tree5260e521d2ffc2c48815a33cd4d016f3ea8adf7b /src/core/api/qwebenginepermission.cpp
parent8ce04357b4ce39b8c4c2243991eae70f78f9b61b (diff)
QWebEnginePermission: Add move constructor and nullptr checks
A move assignment existed for the class, but not a move constructor. Since both of those can leave a QWebEnginePermission object in a state where the d_ptr is null, this change also adds checks to ensure using a moved-from object won't crash the application. Found in API review. Pick-to: 6.8 Change-Id: I977927c18094d06ea63840bb80c88b50c4b19b73 Reviewed-by: Michal Klocek <michal.klocek@qt.io> Reviewed-by: Moss Heim <moss.heim@qt.io>
Diffstat (limited to 'src/core/api/qwebenginepermission.cpp')
-rw-r--r--src/core/api/qwebenginepermission.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/core/api/qwebenginepermission.cpp b/src/core/api/qwebenginepermission.cpp
index 9cef4bf96..0cee6506b 100644
--- a/src/core/api/qwebenginepermission.cpp
+++ b/src/core/api/qwebenginepermission.cpp
@@ -93,6 +93,11 @@ QWebEnginePermission::QWebEnginePermission(const QWebEnginePermission &other)
{
}
+QWebEnginePermission::QWebEnginePermission(QWebEnginePermission &&other)
+ : d_ptr(std::move(other.d_ptr))
+{
+}
+
QWebEnginePermission::~QWebEnginePermission() = default;
QWebEnginePermission &QWebEnginePermission::operator=(const QWebEnginePermission &other)
@@ -109,6 +114,9 @@ bool QWebEnginePermission::equals(const QWebEnginePermission &other) const
if (this == &other)
return true;
+ if (!d_ptr || !other.d_ptr)
+ return false;
+
if (d_ptr->permissionType != other.d_ptr->permissionType || d_ptr->origin != other.d_ptr->origin)
return false;
@@ -140,7 +148,7 @@ bool QWebEnginePermission::equals(const QWebEnginePermission &other) const
*/
QUrl QWebEnginePermission::origin() const
{
- return d_ptr->origin;
+ return d_ptr ? d_ptr->origin : QUrl();
}
/*!
@@ -171,7 +179,7 @@ QUrl QWebEnginePermission::origin() const
*/
QWebEnginePermission::PermissionType QWebEnginePermission::permissionType() const
{
- return d_ptr->permissionType;
+ return d_ptr ? d_ptr->permissionType : PermissionType::Unsupported;
}
/*!
@@ -225,6 +233,8 @@ QWebEnginePermission::State QWebEnginePermission::state() const
*/
bool QWebEnginePermission::isValid() const
{
+ if (!d_ptr)
+ return false;
if (permissionType() == PermissionType::Unsupported)
return false;
if (!isPersistent(permissionType()) && !d_ptr->webContentsAdapter)