summaryrefslogtreecommitdiffstats
path: root/src/webengine/api
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-07-23 17:17:40 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-02 20:52:02 +0000
commit595589197313178551cf7ccd645d2732643875bf (patch)
tree8ed5686b3de206775425eb5c9fcca8dfb3a01320 /src/webengine/api
parent1481e8d87fe89d9e27d9de593767b55a0e84a31f (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/webengine/api')
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp15
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p.h3
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p_p.h2
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp4
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h1
5 files changed, 25 insertions, 0 deletions
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp
index f44351f4c..4dce4ecd9 100644
--- a/src/webengine/api/qquickwebenginedownloaditem.cpp
+++ b/src/webengine/api/qquickwebenginedownloaditem.cpp
@@ -107,6 +107,7 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb
, receivedBytes(0)
, downloadFinished(false)
, downloadPaused(false)
+ , view(nullptr)
{
}
@@ -591,6 +592,20 @@ bool QQuickWebEngineDownloadItem::isPaused() const
return d->downloadPaused;
}
+/*!
+ \qmlproperty bool WebEngineDownloadItem::view
+ \readonly
+ \since QtWebEngine 1.8
+
+ Returns the view the download was requested on. If the download was not triggered by content in a view,
+ \c nullptr is returned.
+*/
+QQuickWebEngineView *QQuickWebEngineDownloadItem::view() const
+{
+ Q_D(const QQuickWebEngineDownloadItem);
+ return d->view;
+}
+
QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate *p, QObject *parent)
: QObject(parent)
, d_ptr(p)
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h
index 88be0dbd1..d19ca4828 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p.h
@@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE
class QQuickWebEngineDownloadItemPrivate;
class QQuickWebEngineProfilePrivate;
+class QQuickWebEngineView;
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineDownloadItem: public QObject {
Q_OBJECT
@@ -134,6 +135,7 @@ public:
Q_PROPERTY(bool isFinished READ isFinished NOTIFY isFinishedChanged REVISION 5 FINAL)
Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged REVISION 5 FINAL)
Q_PROPERTY(bool isSavePageDownload READ isSavePageDownload CONSTANT REVISION 6 FINAL)
+ Q_PROPERTY(QQuickWebEngineView *view READ view CONSTANT REVISION 7 FINAL)
Q_INVOKABLE void accept();
Q_INVOKABLE void cancel();
@@ -155,6 +157,7 @@ public:
bool isFinished() const;
bool isPaused() const;
bool isSavePageDownload() const;
+ QQuickWebEngineView *view() const;
Q_SIGNALS:
void stateChanged();
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
index 631353738..4b89335bd 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
@@ -59,6 +59,7 @@
QT_BEGIN_NAMESPACE
class QQuickWebEngineProfilePrivate;
+class QQuickWebEngineView;
class QQuickWebEngineDownloadItemPrivate {
QQuickWebEngineDownloadItem *q_ptr;
@@ -80,6 +81,7 @@ public:
QString downloadPath;
bool downloadFinished;
bool downloadPaused;
+ QQuickWebEngineView *view;
void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info);
void updateState(QQuickWebEngineDownloadItem::DownloadState newState);
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index f76741212..d11214716 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -222,6 +222,10 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>(
info.savePageFormat);
itemPrivate->type = static_cast<QQuickWebEngineDownloadItem::DownloadType>(info.downloadType);
+ if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::QmlClient)
+ itemPrivate->view = static_cast<QQuickWebEngineViewPrivate *>(info.page)->q_ptr;
+ else
+ itemPrivate->view = nullptr;
QQuickWebEngineDownloadItem *download = new QQuickWebEngineDownloadItem(itemPrivate, q);
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 7f52c7216..7e5d1e64f 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -151,6 +151,7 @@ public:
bool isEnabled() const override;
void setToolTip(const QString &toolTipText) override;
const QObject *holdingQObject() const override;
+ ClientType clientType() override { return QtWebEngineCore::WebContentsAdapterClient::QmlClient; }
QtWebEngineCore::ProfileAdapter *profileAdapter() override;
QtWebEngineCore::WebContentsAdapter *webContentsAdapter() override;