summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/download_manager_delegate_qt.cpp23
-rw-r--r--src/core/profile_adapter_client.h3
-rw-r--r--src/core/web_contents_adapter_client.h6
-rw-r--r--src/core/web_contents_delegate_qt.h1
-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
-rw-r--r--src/webengine/plugin/plugin.cpp2
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.cpp12
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.h3
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem_p.h1
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp7
-rw-r--r--tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp4
16 files changed, 84 insertions, 4 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 813657365..4ed77688e 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -168,6 +168,11 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem*
item->AddObserver(this);
QList<ProfileAdapterClient*> clients = m_profileAdapter->clients();
if (!clients.isEmpty()) {
+ content::WebContents *webContents = content::DownloadItemUtils::GetWebContents(item);
+ WebContentsAdapterClient *adapterClient = nullptr;
+ if (webContents)
+ adapterClient = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate())->adapterClient();
+
ProfileAdapterClient::DownloadItemInfo info = {
item->GetId(),
toQt(item->GetURL()),
@@ -181,7 +186,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem*
false /* paused */,
false /* done */,
downloadType,
- item->GetLastReason()
+ item->GetLastReason(),
+ adapterClient
};
for (ProfileAdapterClient *client : qAsConst(clients)) {
@@ -263,6 +269,10 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
// Clear the delegate's SavePageInfo. It's only valid for the page currently being saved.
contentsDelegate->setSavePageInfo(SavePageInfo());
+ WebContentsAdapterClient *adapterClient = nullptr;
+ if (web_contents)
+ adapterClient = static_cast<WebContentsDelegateQt *>(web_contents->GetDelegate())->adapterClient();
+
ProfileAdapterClient::DownloadItemInfo info = {
m_currentId + 1,
toQt(web_contents->GetURL()),
@@ -276,7 +286,8 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
false, /* paused */
false, /* done */
ProfileAdapterClient::SavePage,
- ProfileAdapterClient::NoReason
+ ProfileAdapterClient::NoReason,
+ adapterClient
};
for (ProfileAdapterClient *client : qAsConst(clients)) {
@@ -323,6 +334,11 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(download::DownloadItem *downlo
{
QList<ProfileAdapterClient*> clients = m_profileAdapter->clients();
if (!clients.isEmpty()) {
+ WebContentsAdapterClient *adapterClient = nullptr;
+ content::WebContents *webContents = content::DownloadItemUtils::GetWebContents(download);
+ if (webContents)
+ adapterClient = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate())->adapterClient();
+
ProfileAdapterClient::DownloadItemInfo info = {
download->GetId(),
toQt(download->GetURL()),
@@ -336,7 +352,8 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(download::DownloadItem *downlo
download->IsPaused(),
download->IsDone(),
0 /* downloadType (unused) */,
- download->GetLastReason()
+ download->GetLastReason(),
+ adapterClient
};
for (ProfileAdapterClient *client : qAsConst(clients)) {
diff --git a/src/core/profile_adapter_client.h b/src/core/profile_adapter_client.h
index 65b0aed6a..06051fab6 100644
--- a/src/core/profile_adapter_client.h
+++ b/src/core/profile_adapter_client.h
@@ -57,6 +57,8 @@
namespace QtWebEngineCore {
+class WebContentsAdapterClient;
+
class QWEBENGINECORE_PRIVATE_EXPORT ProfileAdapterClient
{
public:
@@ -133,6 +135,7 @@ public:
bool done;
int downloadType;
int downloadInterruptReason;
+ WebContentsAdapterClient *page;
};
virtual ~ProfileAdapterClient() { }
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 2419a1259..851a6122f 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -394,6 +394,11 @@ public:
KilledTerminationStatus
};
+ enum ClientType {
+ QmlClient,
+ WidgetsClient
+ };
+
enum MediaRequestFlag {
MediaNone = 0,
MediaAudioCapture = 0x01,
@@ -466,6 +471,7 @@ public:
virtual bool isEnabled() const = 0;
virtual const QObject *holdingQObject() const = 0;
virtual void setToolTip(const QString& toolTipText) = 0;
+ virtual ClientType clientType() = 0;
virtual ProfileAdapter *profileAdapter() = 0;
virtual WebContentsAdapter* webContentsAdapter() = 0;
diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h
index b2ca4e491..674e75fcd 100644
--- a/src/core/web_contents_delegate_qt.h
+++ b/src/core/web_contents_delegate_qt.h
@@ -154,6 +154,7 @@ public:
WebEngineSettings *webEngineSettings() const;
WebContentsAdapter *webContentsAdapter() const;
+ WebContentsAdapterClient *adapterClient() const { return m_viewClient; }
private:
QWeakPointer<WebContentsAdapter> createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture);
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;
diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp
index 76bee50be..84a12c930 100644
--- a/src/webengine/plugin/plugin.cpp
+++ b/src/webengine/plugin/plugin.cpp
@@ -112,6 +112,8 @@ public:
tr("Cannot create a separate instance of WebEngineDownloadItem"));
qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 6>(uri, 1, 7, "WebEngineDownloadItem",
tr("Cannot create a separate instance of WebEngineDownloadItem"));
+ qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 7>(uri, 1, 8, "WebEngineDownloadItem",
+ tr("Cannot create a separate instance of WebEngineDownloadItem"));
qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest>(uri, 1, 1, "WebEngineNewViewRequest", msgUncreatableType("WebEngineNewViewRequest"));
qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest, 1>(uri, 1, 5, "WebEngineNewViewRequest", tr("Cannot create separate instance of WebEngineNewViewRequest"));
qmlRegisterUncreatableType<QQuickWebEngineSettings>(uri, 1, 1, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
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);
diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
index 31b66ebe2..68c549540 100644
--- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
+++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
@@ -443,6 +443,7 @@ void tst_QWebEngineDownloadItem::downloadLink()
QCOMPARE(item->path(), suggestedPath);
QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
QCOMPARE(item->url(), downloadUrl);
+ QCOMPARE(item->page(), m_page);
connect(item, &QWebEngineDownloadItem::finished, [&, item]() {
QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted);
@@ -456,6 +457,7 @@ void tst_QWebEngineDownloadItem::downloadLink()
QCOMPARE(item->path(), downloadPath);
QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
QCOMPARE(item->url(), downloadUrl);
+ QCOMPARE(item->page(), m_page);
finishedCount++;
});
@@ -636,6 +638,7 @@ void tst_QWebEngineDownloadItem::downloadPage()
QCOMPARE(item->path(), downloadPath);
QCOMPARE(item->savePageFormat(), savePageFormat);
QCOMPARE(item->url(), downloadUrl);
+ QCOMPARE(item->page(), m_page);
// no need to call item->accept()
connect(item, &QWebEngineDownloadItem::finished, [&, item]() {
@@ -650,6 +653,7 @@ void tst_QWebEngineDownloadItem::downloadPage()
QCOMPARE(item->path(), downloadPath);
QCOMPARE(item->savePageFormat(), savePageFormat);
QCOMPARE(item->url(), downloadUrl);
+ QCOMPARE(item->page(), m_page);
finishedCount++;
});