diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-07-23 17:17:40 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-02 20:52:02 +0000 |
commit | 595589197313178551cf7ccd645d2732643875bf (patch) | |
tree | 8ed5686b3de206775425eb5c9fcca8dfb3a01320 /src/webenginewidgets | |
parent | 1481e8d87fe89d9e27d9de593767b55a0e84a31f (diff) |
Add QWebEngineDownloadItem page/view accessor
To be able to determine where a download was triggered.
[ChangeLog][DownloadItem] Added a page/view accessor to tell were
the download was triggered.
Change-Id: I21843a545a3e0eb66f5e5fa8a50e77564f2118a7
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.cpp | 12 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.h | 3 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 7 |
5 files changed, 23 insertions, 1 deletions
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index 631c028c3..fc27e104d 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -169,6 +169,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr , downloadPaused(false) , totalBytes(-1) , receivedBytes(0) + , page(0) { } @@ -630,6 +631,17 @@ QString QWebEngineDownloadItem::interruptReasonString() const static_cast<ProfileAdapterClient::DownloadInterruptReason>(interruptReason())); } +/*! + \since 5.12 + Returns the page the download was requested on. If the download was not triggered by content in a page, + \c nullptr is returned. +*/ +QWebEnginePage *QWebEngineDownloadItem::page() const +{ + Q_D(const QWebEngineDownloadItem); + return d->page; +} + QWebEngineDownloadItem::QWebEngineDownloadItem(QWebEngineDownloadItemPrivate *p, QObject *parent) : QObject(parent) , d_ptr(p) diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h index 073b97170..981a3c374 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem.h @@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE +class QWebEnginePage; class QWebEngineDownloadItemPrivate; class QWebEngineProfilePrivate; @@ -128,6 +129,8 @@ public: QString interruptReasonString() const; bool isSavePageDownload() const; + QWebEnginePage *page() const; + public Q_SLOTS: void accept(); void cancel(); diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h index 514beacc7..bdcda5be6 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h @@ -81,6 +81,7 @@ public: qint64 totalBytes; qint64 receivedBytes; + QWebEnginePage *page; void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info); }; diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index fbaf0b579..e2329e8f8 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -147,6 +147,7 @@ public: bool isEnabled() const override; void setToolTip(const QString &toolTipText) override; const QObject *holdingQObject() const override; + ClientType clientType() override { return QtWebEngineCore::WebContentsAdapterClient::WidgetsClient; } QtWebEngineCore::ProfileAdapter *profileAdapter() override; QtWebEngineCore::WebContentsAdapter *webContentsAdapter() override; diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index a7a7ea19b..4523a425a 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -38,12 +38,13 @@ ****************************************************************************/ #include "qwebengineprofile.h" +#include "qwebengineprofile_p.h" #include "qwebenginecookiestore.h" #include "qwebenginedownloaditem.h" #include "qwebenginedownloaditem_p.h" #include "qwebenginepage.h" -#include "qwebengineprofile_p.h" +#include "qwebenginepage_p.h" #include "qwebenginesettings.h" #include "qwebenginescriptcollection_p.h" #include "qtwebenginecoreglobal.h" @@ -202,6 +203,10 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) itemPrivate->mimeType = info.mimeType; itemPrivate->savePageFormat = static_cast<QWebEngineDownloadItem::SavePageFormat>(info.savePageFormat); itemPrivate->type = static_cast<QWebEngineDownloadItem::DownloadType>(info.downloadType); + if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::WidgetsClient) + itemPrivate->page = static_cast<QWebEnginePagePrivate *>(info.page)->q_ptr; + else + itemPrivate->page = nullptr; QWebEngineDownloadItem *download = new QWebEngineDownloadItem(itemPrivate, q); |