From b58b4c59f1beb5679f6d0edae5497bbc9eadbff3 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 12 Jul 2021 11:52:15 +0200 Subject: Get rid of private methods of QWebEngineNewWindowRequest Change-Id: I40072b45ceffa1a2c92027a4c01239974b8ac498 Reviewed-by: Michal Klocek (cherry picked from commit 5be01d2ffd3dbc2b023dd1ffb75d376019ee934e) Reviewed-by: Qt Cherry-pick Bot --- src/core/api/CMakeLists.txt | 2 +- src/core/api/qwebenginenewwindowrequest.cpp | 33 +--------- src/core/api/qwebenginenewwindowrequest.h | 10 +-- src/core/api/qwebenginenewwindowrequest_p.h | 84 ++++++++++++++++++++++++++ src/core/api/qwebenginepage.cpp | 9 +-- src/webenginequick/api/qquickwebengineview.cpp | 10 +-- 6 files changed, 100 insertions(+), 48 deletions(-) create mode 100644 src/core/api/qwebenginenewwindowrequest_p.h (limited to 'src') diff --git a/src/core/api/CMakeLists.txt b/src/core/api/CMakeLists.txt index 6d9e614d2..2a0c1ebf7 100644 --- a/src/core/api/CMakeLists.txt +++ b/src/core/api/CMakeLists.txt @@ -27,7 +27,7 @@ qt_internal_add_module(WebEngineCore qwebengineloadinginfo.cpp qwebengineloadinginfo.h qwebenginemessagepumpscheduler.cpp qwebenginemessagepumpscheduler_p.h qwebenginenavigationrequest.cpp qwebenginenavigationrequest.h - qwebenginenewwindowrequest.cpp qwebenginenewwindowrequest.h + qwebenginenewwindowrequest.cpp qwebenginenewwindowrequest.h qwebenginenewwindowrequest_p.h qwebenginenotification.cpp qwebenginenotification.h qwebenginepage.cpp qwebenginepage.h qwebenginepage_p.h qwebengineprofile.cpp qwebengineprofile.h qwebengineprofile_p.h diff --git a/src/core/api/qwebenginenewwindowrequest.cpp b/src/core/api/qwebenginenewwindowrequest.cpp index 5899c0dc3..7d2762e1c 100644 --- a/src/core/api/qwebenginenewwindowrequest.cpp +++ b/src/core/api/qwebenginenewwindowrequest.cpp @@ -38,21 +38,12 @@ ****************************************************************************/ #include "qwebenginenewwindowrequest.h" +#include "qwebenginenewwindowrequest_p.h" #include "web_contents_adapter.h" QT_BEGIN_NAMESPACE -struct QWebEngineNewWindowRequestPrivate -{ - QWebEngineNewWindowRequest::DestinationType destination; - QRect requestedGeometry; - QUrl requestedUrl; - QSharedPointer adapter; - bool isUserInitiated; - bool isRequestHandled = false; -}; - /*! \class QWebEngineNewWindowRequest \brief A utility type for the QWebEnginePage::newWindowRequested() signal. @@ -181,26 +172,4 @@ bool QWebEngineNewWindowRequest::isUserInitiated() const return d_ptr->isUserInitiated; } -/*! \internal -*/ -QSharedPointer QWebEngineNewWindowRequest::adapter() -{ - return d_ptr->adapter; -} - -/*! \internal -*/ -bool QWebEngineNewWindowRequest::isHandled() const -{ - return d_ptr->isRequestHandled; -} - -/*! \internal -*/ -void QWebEngineNewWindowRequest::setHandled() -{ - d_ptr->isRequestHandled = true; - d_ptr->adapter.reset(); -} - QT_END_NAMESPACE diff --git a/src/core/api/qwebenginenewwindowrequest.h b/src/core/api/qwebenginenewwindowrequest.h index dd7256a03..4066f1a65 100644 --- a/src/core/api/qwebenginenewwindowrequest.h +++ b/src/core/api/qwebenginenewwindowrequest.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef QWEBENGINENEWWINDOWREQUEST_P_H -#define QWEBENGINENEWWINDOWREQUEST_P_H +#ifndef QWEBENGINENEWWINDOWREQUEST_H +#define QWEBENGINENEWWINDOWREQUEST_H #include #include @@ -83,10 +83,6 @@ protected: QSharedPointer, QObject * = nullptr); - QSharedPointer adapter(); - bool isHandled() const; - void setHandled(); - QScopedPointer d_ptr; friend class QWebEnginePage; friend class QWebEnginePagePrivate; @@ -96,4 +92,4 @@ protected: QT_END_NAMESPACE -#endif // QWEBENGINENEWWINDOWREQUEST_P_H +#endif // QWEBENGINENEWWINDOWREQUEST_H diff --git a/src/core/api/qwebenginenewwindowrequest_p.h b/src/core/api/qwebenginenewwindowrequest_p.h new file mode 100644 index 000000000..ec69dc84c --- /dev/null +++ b/src/core/api/qwebenginenewwindowrequest_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINENEWWINDOWREQUEST_P_H +#define QWEBENGINENEWWINDOWREQUEST_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qwebenginenewwindowrequest.h" + +#include +#include +#include + +namespace QtWebEngineCore { +class WebContentsAdapter; +} + +QT_BEGIN_NAMESPACE + +struct QWebEngineNewWindowRequestPrivate +{ + void setHandled() + { + isRequestHandled = true; + adapter.reset(); + } + + QWebEngineNewWindowRequest::DestinationType destination; + QRect requestedGeometry; + QUrl requestedUrl; + QSharedPointer adapter; + bool isUserInitiated; + bool isRequestHandled = false; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINENEWWINDOWREQUEST_P_H diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp index df2eb7a65..9943def62 100644 --- a/src/core/api/qwebenginepage.cpp +++ b/src/core/api/qwebenginepage.cpp @@ -48,6 +48,7 @@ #include "qwebengineloadinginfo.h" #include "qwebenginenavigationrequest.h" #include "qwebenginenewwindowrequest.h" +#include "qwebenginenewwindowrequest_p.h" #include "qwebengineprofile.h" #include "qwebengineprofile_p.h" #include "qwebenginequotarequest.h" @@ -378,7 +379,7 @@ QWebEnginePagePrivate::adoptNewWindow(QSharedPointer newWebC Q_EMIT q->newWindowRequested(request); - if (request.isHandled()) + if (request.d_ptr->isRequestHandled) return newWebContents; return nullptr; } @@ -2250,9 +2251,9 @@ QSizeF QWebEnginePage::contentsSize() const void QWebEnginePage::acceptAsNewWindow(QWebEngineNewWindowRequest &request) { Q_D(QWebEnginePage); - auto adapter = request.adapter(); + auto adapter = request.d_ptr->adapter; QUrl url = request.requestedUrl(); - if ((!adapter && !url.isValid()) || request.isHandled()) { + if ((!adapter && !url.isValid()) || request.d_ptr->isRequestHandled) { qWarning("Trying to open an empty request, it was either already used or was invalidated." "\nYou must complete the request synchronously within the newWindowRequested signal handler." " If a view hasn't been adopted before returning, the request will be invalidated."); @@ -2268,7 +2269,7 @@ void QWebEnginePage::acceptAsNewWindow(QWebEngineNewWindowRequest &request) if (!geometry.isEmpty()) emit geometryChangeRequested(geometry); - request.setHandled(); + request.d_ptr->setHandled(); } /*! diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp index 23d89440d..cfd17e5aa 100644 --- a/src/webenginequick/api/qquickwebengineview.cpp +++ b/src/webenginequick/api/qquickwebengineview.cpp @@ -64,6 +64,7 @@ #include "qwebenginescriptcollection.h" #include #include +#include #include #include "qwebengineregisterprotocolhandlerrequest.h" #if QT_CONFIG(webenginequick_testsupport) @@ -527,7 +528,7 @@ QQuickWebEngineViewPrivate::adoptNewWindow(QSharedPointer ne Q_EMIT q->newViewRequested(&request); - if (request.isHandled()) + if (request.d_ptr->isRequestHandled) return newWebContents; return nullptr; } @@ -1666,19 +1667,20 @@ void QQuickWebEngineView::itemChange(ItemChange change, const ItemChangeData &va void QQuickWebEngineView::acceptAsNewView(QWebEngineNewWindowRequest *request) { Q_D(QQuickWebEngineView); - if (!request || (!request->adapter() && !request->requestedUrl().isValid()) || request->isHandled()) { + if (!request || (!request->d_ptr->adapter && !request->requestedUrl().isValid()) + || request->d_ptr->isRequestHandled) { qWarning("Trying to open an empty request, it was either already used or was invalidated." "\nYou must complete the request synchronously within the newViewRequested signal handler." " If a view hasn't been adopted before returning, the request will be invalidated."); return; } - if (auto adapter = request->adapter()) + if (auto adapter = request->d_ptr->adapter) d->adoptWebContents(adapter.data()); else setUrl(request->requestedUrl()); - request->setHandled(); + request->d_ptr->setHandled(); } #if QT_CONFIG(draganddrop) -- cgit v1.2.3