diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-18 11:39:36 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-21 17:49:31 +0200 |
commit | b2ecb708e149fe8914d7d0cbfcf9c300e52a029e (patch) | |
tree | f9fdc60b8e07d19e69c2cd044649f17b491e33f7 /src/webenginequick | |
parent | 56186b555b98ed682e88c105a16e47023410f58e (diff) |
Add page() and view() back to download-item
Restores a QML type but this time derived from the core type.
Pick-to: 6.2
Change-Id: I09ddb6672f7262ae31e4c57f09d019f71abccd41
Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Diffstat (limited to 'src/webenginequick')
-rw-r--r-- | src/webenginequick/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebenginedownloadrequest.cpp | 66 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebenginedownloadrequest_p.h | 78 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile.cpp | 14 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile.h | 6 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile_p.h | 4 | ||||
-rw-r--r-- | src/webenginequick/plugin/plugin.cpp | 4 |
7 files changed, 160 insertions, 13 deletions
diff --git a/src/webenginequick/CMakeLists.txt b/src/webenginequick/CMakeLists.txt index a1ed1eae0..7ebd758f4 100644 --- a/src/webenginequick/CMakeLists.txt +++ b/src/webenginequick/CMakeLists.txt @@ -15,6 +15,7 @@ qt_internal_add_module(WebEngineQuick api/qquickwebengineaction_p_p.h api/qquickwebengineclientcertificateselection.cpp api/qquickwebengineclientcertificateselection_p.h api/qquickwebenginedialogrequests.cpp api/qquickwebenginedialogrequests_p.h + api/qquickwebenginedownloadrequest.cpp api/qquickwebenginedownloadrequest_p.h api/qquickwebenginefaviconprovider.cpp api/qquickwebenginefaviconprovider_p_p.h api/qquickwebengineprofile.cpp api/qquickwebengineprofile.h api/qquickwebengineprofile_p.h diff --git a/src/webenginequick/api/qquickwebenginedownloadrequest.cpp b/src/webenginequick/api/qquickwebenginedownloadrequest.cpp new file mode 100644 index 000000000..bd3383004 --- /dev/null +++ b/src/webenginequick/api/qquickwebenginedownloadrequest.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "qquickwebenginedownloadrequest_p.h" +#include "QtWebEngineCore/private/qwebenginedownloadrequest_p.h" + +#include "web_contents_adapter_client.h" + +QT_BEGIN_NAMESPACE + +/*! + \internal +*/ +QQuickWebEngineDownloadRequest::QQuickWebEngineDownloadRequest(QWebEngineDownloadRequestPrivate *p, QObject *parent) + : QWebEngineDownloadRequest(p, parent) +{ +} + +/*! + \internal + Returns the WebEngineView the download was requested on. If the download was not triggered by content in a WebEngineView, + \c nullptr is returned. +*/ +QQuickWebEngineView *QQuickWebEngineDownloadRequest::view() const +{ + Q_ASSERT(d_ptr->adapterClient->clientType() == QtWebEngineCore::WebContentsAdapterClient::QmlClient); + return const_cast<QQuickWebEngineView *>(static_cast<const QQuickWebEngineView *>(d_ptr->adapterClient->holdingQObject())); +} + +QT_END_NAMESPACE diff --git a/src/webenginequick/api/qquickwebenginedownloadrequest_p.h b/src/webenginequick/api/qquickwebenginedownloadrequest_p.h new file mode 100644 index 000000000..971c9882b --- /dev/null +++ b/src/webenginequick/api/qquickwebenginedownloadrequest_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 QQUICKWEBENGINEDOWNLOADREQUEST_P_H +#define QQUICKWEBENGINEDOWNLOADREQUEST_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 <QtWebEngineQuick/private/qtwebenginequickglobal_p.h> +#include <QtWebEngineQuick/private/qquickwebengineview_p.h> + +#include <QtWebEngineCore/qwebenginedownloadrequest.h> + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineProfilePrivate; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineDownloadRequest : public QWebEngineDownloadRequest +{ + Q_OBJECT +public: + Q_PROPERTY(QQuickWebEngineView *view READ view CONSTANT FINAL) + + QQuickWebEngineView *view() const; +private: + Q_DISABLE_COPY(QQuickWebEngineDownloadRequest) + friend class QQuickWebEngineProfilePrivate; + QQuickWebEngineDownloadRequest(QWebEngineDownloadRequestPrivate *, QObject *parent = nullptr); +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEDOWNLOADREQUEST_P_H diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp index c95a838af..a2f970c29 100644 --- a/src/webenginequick/api/qquickwebengineprofile.cpp +++ b/src/webenginequick/api/qquickwebengineprofile.cpp @@ -39,6 +39,7 @@ #include "qquickwebengineprofile.h" #include "qquickwebengineprofile_p.h" +#include "qquickwebenginedownloadrequest_p.h" #include "qquickwebenginesettings_p.h" #include "qquickwebenginescriptcollection.h" #include "qquickwebengineview_p_p.h" @@ -51,6 +52,7 @@ #include <QtWebEngineCore/qwebenginenotification.h> #include <QtWebEngineCore/private/qwebenginedownloadrequest_p.h> #include <QtWebEngineCore/qwebengineurlscheme.h> + #include <QFileInfo> #include <QDir> #include <QQmlEngine> @@ -126,7 +128,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QQuickWebEngineProfile::downloadRequested(QWebEngineDownloadRequest *download) + \fn QQuickWebEngineProfile::downloadRequested(QQuickWebEngineDownloadRequest *download) This signal is emitted whenever a download has been triggered. The \a download argument holds the state of the download. @@ -139,7 +141,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QQuickWebEngineProfile::downloadFinished(QWebEngineDownloadRequest *download) + \fn QQuickWebEngineProfile::downloadFinished(QQuickWebEngineDownloadRequest *download) This signal is emitted whenever downloading stops, because it finished successfully, was cancelled, or was interrupted (for example, because connectivity was lost). @@ -253,10 +255,10 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) else itemPrivate->adapterClient = nullptr; - QWebEngineDownloadRequest *download = new QWebEngineDownloadRequest(itemPrivate, q); + QQuickWebEngineDownloadRequest *download = new QQuickWebEngineDownloadRequest(itemPrivate, q); m_ongoingDownloads.insert(info.id, download); - QObject::connect(download, &QWebEngineDownloadRequest::destroyed, q, [id = info.id, this] () { downloadDestroyed(id); }); + QObject::connect(download, &QObject::destroyed, q, [id = info.id, this] () { downloadDestroyed(id); }); QQmlEngine::setObjectOwnership(download, QQmlEngine::JavaScriptOwnership); Q_EMIT q->downloadRequested(download); @@ -281,14 +283,14 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info Q_Q(QQuickWebEngineProfile); - QWebEngineDownloadRequest* download = m_ongoingDownloads.value(info.id).data(); + QQuickWebEngineDownloadRequest* download = m_ongoingDownloads.value(info.id).data(); if (!download) { downloadDestroyed(info.id); return; } - download->d_func()->update(info); + download->d_ptr->update(info); if (info.state != ProfileAdapterClient::DownloadInProgress) { Q_EMIT q->downloadFinished(download); diff --git a/src/webenginequick/api/qquickwebengineprofile.h b/src/webenginequick/api/qquickwebengineprofile.h index b833aa300..8147f0432 100644 --- a/src/webenginequick/api/qquickwebengineprofile.h +++ b/src/webenginequick/api/qquickwebengineprofile.h @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE -class QWebEngineDownloadRequest; +class QQuickWebEngineDownloadRequest; class QWebEngineScript; class QQuickWebEngineSettings; class QWebEngineClientCertificateStore; @@ -167,8 +167,8 @@ Q_SIGNALS: Q_REVISION(1,3) void spellCheckEnabledChanged(); Q_REVISION(1,5) void useForGlobalCertificateVerificationChanged(); Q_REVISION(1,5) void downloadPathChanged(); - void downloadRequested(QWebEngineDownloadRequest *download); - void downloadFinished(QWebEngineDownloadRequest *download); + void downloadRequested(QQuickWebEngineDownloadRequest *download); + void downloadFinished(QQuickWebEngineDownloadRequest *download); Q_REVISION(1,5) void presentNotification(QWebEngineNotification *notification); diff --git a/src/webenginequick/api/qquickwebengineprofile_p.h b/src/webenginequick/api/qquickwebengineprofile_p.h index b9b52a693..8c2b14fda 100644 --- a/src/webenginequick/api/qquickwebengineprofile_p.h +++ b/src/webenginequick/api/qquickwebengineprofile_p.h @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -class QWebEngineDownloadRequest; +class QQuickWebEngineDownloadRequest; class QQuickWebEngineSettings; class QQuickWebEngineViewPrivate; class QQuickWebEngineScriptCollection; @@ -95,7 +95,7 @@ private: QQuickWebEngineProfile *q_ptr; QScopedPointer<QQuickWebEngineSettings> m_settings; QPointer<QtWebEngineCore::ProfileAdapter> m_profileAdapter; - QMap<quint32, QPointer<QWebEngineDownloadRequest> > m_ongoingDownloads; + QMap<quint32, QPointer<QQuickWebEngineDownloadRequest> > m_ongoingDownloads; QScopedPointer<QQuickWebEngineScriptCollection> m_scriptCollection; }; diff --git a/src/webenginequick/plugin/plugin.cpp b/src/webenginequick/plugin/plugin.cpp index a76ffbb48..8f2dc6015 100644 --- a/src/webenginequick/plugin/plugin.cpp +++ b/src/webenginequick/plugin/plugin.cpp @@ -42,6 +42,7 @@ #include <QtWebEngineQuick/private/qquickwebengineclientcertificateselection_p.h> #include <QtWebEngineQuick/private/qquickwebenginedialogrequests_p.h> +#include <QtWebEngineQuick/private/qquickwebenginedownloadrequest_p.h> #include <QtWebEngineQuick/private/qquickwebenginefaviconprovider_p_p.h> #include <QtWebEngineQuick/private/qquickwebenginesettings_p.h> #include <QtWebEngineQuick/private/qquickwebenginesingleton_p.h> @@ -59,7 +60,6 @@ #include <QtWebEngineCore/qwebenginequotarequest.h> #include <QtWebEngineCore/qwebengineregisterprotocolhandlerrequest.h> #include <QtWebEngineCore/qwebenginecontextmenurequest.h> -#include <QtWebEngineCore/qwebenginedownloadrequest.h> #include <QtWebEngineCore/qwebenginescript.h> QT_BEGIN_NAMESPACE @@ -111,7 +111,7 @@ public: uri, 1, 1, "WebEngineScript", msgUncreatableType("WebEngineScript")); // for enums qRegisterMetaType<QWebEngineCertificateError>(); qmlRegisterUncreatableType<QWebEngineCertificateError>(uri, 1, 1, "WebEngineCertificateError", msgUncreatableType("WebEngineCertificateError")); - qmlRegisterUncreatableType<QWebEngineDownloadRequest>(uri, 1, 1, "WebEngineDownloadRequest", + qmlRegisterUncreatableType<QQuickWebEngineDownloadRequest>(uri, 1, 1, "WebEngineDownloadRequest", msgUncreatableType("WebEngineDownloadRequest")); qmlRegisterUncreatableType<QWebEngineNewWindowRequest>(uri, 1, 1, "WebEngineNewViewRequest", msgUncreatableType("WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineSettings>(uri, 1, 1, "WebEngineSettings", msgUncreatableType("WebEngineSettings")); |