From 3752a3cbcd0cc0742a5b955e925df18395afdb75 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 18 Jun 2021 11:39:36 +0200 Subject: Add page() and view() back to download-item Restores a QML type but this time derived from the core type. Change-Id: I09ddb6672f7262ae31e4c57f09d019f71abccd41 Reviewed-by: Kirill Burtsev (cherry picked from commit b2ecb708e149fe8914d7d0cbfcf9c300e52a029e) Reviewed-by: Qt Cherry-pick Bot --- src/core/api/qwebenginedownloadrequest.cpp | 14 ++++++++++---- src/core/api/qwebenginedownloadrequest.h | 13 ++++++------- src/core/api/qwebenginepage.cpp | 4 ---- src/core/api/qwebenginepage.h | 2 -- 4 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src/core/api') diff --git a/src/core/api/qwebenginedownloadrequest.cpp b/src/core/api/qwebenginedownloadrequest.cpp index 006fd2e4b..57823a7c9 100644 --- a/src/core/api/qwebenginedownloadrequest.cpp +++ b/src/core/api/qwebenginedownloadrequest.cpp @@ -40,10 +40,13 @@ #include "qwebenginedownloadrequest.h" #include "qwebenginedownloadrequest_p.h" +#include "qwebenginepage.h" + #include "profile_adapter.h" +#include "web_contents_adapter_client.h" #include -#include "QFileInfo" +#include QT_BEGIN_NAMESPACE @@ -662,14 +665,17 @@ QString QWebEngineDownloadRequest::interruptReasonString() const Returns the page the download was requested on. If the download was not triggered by content in a page, \c nullptr is returned. */ -QObject *QWebEngineDownloadRequest::page() const +QWebEnginePage *QWebEngineDownloadRequest::page() const { Q_D(const QWebEngineDownloadRequest); - //TODO: come back here when page is in core - Q_UNREACHABLE(); + if (d->adapterClient->clientType() == QtWebEngineCore::WebContentsAdapterClient::WidgetsClient) + return const_cast(static_cast(d->adapterClient->holdingQObject())); return nullptr; } + +/*! \internal +*/ QWebEngineDownloadRequest::QWebEngineDownloadRequest(QWebEngineDownloadRequestPrivate *p, QObject *parent) : QObject(parent) , d_ptr(p) diff --git a/src/core/api/qwebenginedownloadrequest.h b/src/core/api/qwebenginedownloadrequest.h index 60782390c..f3056a936 100644 --- a/src/core/api/qwebenginedownloadrequest.h +++ b/src/core/api/qwebenginedownloadrequest.h @@ -47,8 +47,8 @@ QT_BEGIN_NAMESPACE -//TODO: class QWebEnginePage; class QWebEngineDownloadRequestPrivate; +class QWebEnginePage; class QWebEngineProfilePrivate; class Q_WEBENGINECORE_EXPORT QWebEngineDownloadRequest : public QObject @@ -66,13 +66,12 @@ public: Q_PROPERTY(bool isFinished READ isFinished NOTIFY isFinishedChanged FINAL) Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged FINAL) Q_PROPERTY(bool isSavePageDownload READ isSavePageDownload CONSTANT FINAL) - //TODO: Q_PROPERTY(QQuickWebEngineView *view READ view CONSTANT REVISION(1,7) FINAL) Q_PROPERTY(QUrl url READ url CONSTANT FINAL) Q_PROPERTY(QString suggestedFileName READ suggestedFileName CONSTANT FINAL) Q_PROPERTY(QString downloadDirectory READ downloadDirectory WRITE setDownloadDirectory NOTIFY downloadDirectoryChanged FINAL) Q_PROPERTY(QString downloadFileName READ downloadFileName WRITE setDownloadFileName NOTIFY downloadFileNameChanged FINAL) - ~QWebEngineDownloadRequest(); + ~QWebEngineDownloadRequest() override; enum DownloadState { DownloadRequested, @@ -141,8 +140,7 @@ public: QString downloadFileName() const; void setDownloadFileName(const QString &fileName); - //TODO: - QObject *page() const; + QWebEnginePage *page() const; public Q_SLOTS: void accept(); @@ -168,9 +166,10 @@ private: Q_DECLARE_PRIVATE(QWebEngineDownloadRequest) friend class QWebEngineProfilePrivate; - friend class QQuickWebEngineProfilePrivate; friend class QWebEnginePage; - QWebEngineDownloadRequest(QWebEngineDownloadRequestPrivate*, QObject *parent = nullptr); + +protected: + QWebEngineDownloadRequest(QWebEngineDownloadRequestPrivate *, QObject *parent = nullptr); QScopedPointer d_ptr; }; diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp index 6b66a0d70..3028c38f5 100644 --- a/src/core/api/qwebenginepage.cpp +++ b/src/core/api/qwebenginepage.cpp @@ -2415,10 +2415,6 @@ void QWebEnginePage::setVisible(bool visible) d->adapter->setVisible(visible); } -QWebEnginePage* QWebEnginePage::fromDownloadRequest(QWebEngineDownloadRequest *request) { - return static_cast(request->d_ptr->adapterClient)->q_ptr; -} - QDataStream &operator<<(QDataStream &stream, const QWebEngineHistory &history) { auto adapter = history.d_func()->adapter(); diff --git a/src/core/api/qwebenginepage.h b/src/core/api/qwebenginepage.h index f2ac8eb6c..3eb4147ac 100644 --- a/src/core/api/qwebenginepage.h +++ b/src/core/api/qwebenginepage.h @@ -324,8 +324,6 @@ public: void acceptAsNewWindow(QWebEngineNewWindowRequest &request); - static QWebEnginePage* fromDownloadRequest(QWebEngineDownloadRequest * request); - Q_SIGNALS: void loadStarted(); void loadProgress(int progress); -- cgit v1.2.3