summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2023-02-24 14:57:52 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-01 19:36:48 +0000
commit01be7f108c0d501f532b197f091baaaaba211ee6 (patch)
treed7d3ceccfd754e87f573e2955fb946ccac1d5844
parent12be7ebfb9da83282e8b13b09aa636e0e700f659 (diff)
Fix initialization of QWebEngineDownloadRequest::totalBytes for Widgets
QQuickWebEngineProfile already initializes totalBytes. Also clean up QWebEngineDownloadRequestPrivate and fix typo in documentation. Fixes: QTBUG-104869 Change-Id: I8c4b79c076ddc63180960e22a9488b45ff6c4402 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 496647f7647571ca3cdf81b10ba418de0f06f34d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/core/api/qwebenginedownloadrequest.cpp19
-rw-r--r--src/core/api/qwebenginedownloadrequest_p.h29
-rw-r--r--src/core/api/qwebengineprofile.cpp5
-rw-r--r--src/core/download_manager_delegate_qt.cpp2
-rw-r--r--src/webenginequick/api/qquickwebengineprofile.cpp4
-rw-r--r--tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp4
6 files changed, 30 insertions, 33 deletions
diff --git a/src/core/api/qwebenginedownloadrequest.cpp b/src/core/api/qwebenginedownloadrequest.cpp
index 97f6051b4..e51fe7c0f 100644
--- a/src/core/api/qwebenginedownloadrequest.cpp
+++ b/src/core/api/qwebenginedownloadrequest.cpp
@@ -123,20 +123,9 @@ static inline QWebEngineDownloadRequest::DownloadInterruptReason toDownloadInter
QWebEnginePage::download, QWebEnginePage::save
*/
-QWebEngineDownloadRequestPrivate::QWebEngineDownloadRequestPrivate(QtWebEngineCore::ProfileAdapter *adapter, const QUrl &url)
- : downloadFinished(false)
- , downloadId(-1)
- , downloadState(QWebEngineDownloadRequest::DownloadCancelled)
- , savePageFormat(QWebEngineDownloadRequest::MimeHtmlSaveFormat)
- , interruptReason(QWebEngineDownloadRequest::NoReason)
- , downloadUrl(url)
- , downloadPaused(false)
- , isCustomFileName(false)
- , totalBytes(-1)
- , receivedBytes(0)
- , isSavePageDownload(false)
- , profileAdapter(adapter)
- , adapterClient(nullptr)
+QWebEngineDownloadRequestPrivate::QWebEngineDownloadRequestPrivate(
+ QtWebEngineCore::ProfileAdapter *adapter)
+ : profileAdapter(adapter)
{
}
@@ -391,7 +380,7 @@ QWebEngineDownloadRequest::DownloadState QWebEngineDownloadRequest::state() cons
}
/*!
- Returns the the total amount of data to download in bytes.
+ Returns the total amount of data to download in bytes.
\c -1 means the size is unknown.
*/
diff --git a/src/core/api/qwebenginedownloadrequest_p.h b/src/core/api/qwebenginedownloadrequest_p.h
index 814af59cb..26afbc4ad 100644
--- a/src/core/api/qwebenginedownloadrequest_p.h
+++ b/src/core/api/qwebenginedownloadrequest_p.h
@@ -31,32 +31,35 @@ QT_BEGIN_NAMESPACE
class Q_WEBENGINECORE_PRIVATE_EXPORT QWebEngineDownloadRequestPrivate
{
public:
- QWebEngineDownloadRequestPrivate(QtWebEngineCore::ProfileAdapter *adapter, const QUrl &url);
+ QWebEngineDownloadRequestPrivate(QtWebEngineCore::ProfileAdapter *adapter);
~QWebEngineDownloadRequestPrivate();
void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info);
void setFinished();
- bool downloadFinished;
- quint32 downloadId;
+ bool downloadFinished = false;
+ quint32 downloadId = -1;
qint64 startTime;
- QWebEngineDownloadRequest::DownloadState downloadState;
- QWebEngineDownloadRequest::SavePageFormat savePageFormat;
- QWebEngineDownloadRequest::DownloadInterruptReason interruptReason;
+ QWebEngineDownloadRequest::DownloadState downloadState =
+ QWebEngineDownloadRequest::DownloadCancelled;
+ QWebEngineDownloadRequest::SavePageFormat savePageFormat =
+ QWebEngineDownloadRequest::MimeHtmlSaveFormat;
+ QWebEngineDownloadRequest::DownloadInterruptReason interruptReason =
+ QWebEngineDownloadRequest::NoReason;
QString downloadPath;
- const QUrl downloadUrl;
+ QUrl downloadUrl;
QString mimeType;
- bool downloadPaused;
+ bool downloadPaused = false;
QString suggestedFileName;
QString downloadDirectory;
QString downloadFileName;
- bool isCustomFileName;
- qint64 totalBytes;
- qint64 receivedBytes;
- bool isSavePageDownload;
+ bool isCustomFileName = false;
+ qint64 totalBytes = -1;
+ qint64 receivedBytes = 0;
+ bool isSavePageDownload = false;
QWebEngineDownloadRequest *q_ptr;
QPointer<QtWebEngineCore::ProfileAdapter> profileAdapter;
- QtWebEngineCore::WebContentsAdapterClient *adapterClient;
+ QtWebEngineCore::WebContentsAdapterClient *adapterClient = nullptr;
Q_DECLARE_PUBLIC(QWebEngineDownloadRequest)
};
diff --git a/src/core/api/qwebengineprofile.cpp b/src/core/api/qwebengineprofile.cpp
index 4eacc8dc7..445df4b52 100644
--- a/src/core/api/qwebengineprofile.cpp
+++ b/src/core/api/qwebengineprofile.cpp
@@ -186,11 +186,14 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
Q_Q(QWebEngineProfile);
Q_ASSERT(!m_ongoingDownloads.contains(info.id));
- QWebEngineDownloadRequestPrivate *itemPrivate = new QWebEngineDownloadRequestPrivate(m_profileAdapter, info.url);
+ QWebEngineDownloadRequestPrivate *itemPrivate =
+ new QWebEngineDownloadRequestPrivate(m_profileAdapter);
itemPrivate->downloadId = info.id;
itemPrivate->downloadState = info.accepted ? QWebEngineDownloadRequest::DownloadInProgress
: QWebEngineDownloadRequest::DownloadRequested;
itemPrivate->startTime = info.startTime;
+ itemPrivate->downloadUrl = info.url;
+ itemPrivate->totalBytes = info.totalBytes;
itemPrivate->downloadDirectory = QFileInfo(info.path).path();
itemPrivate->downloadFileName = QFileInfo(info.path).fileName();
itemPrivate->suggestedFileName = info.suggestedFileName;
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 69803c16b..d093c4e26 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -254,7 +254,7 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
++m_currentId,
toQt(web_contents->GetURL()),
download::DownloadItem::IN_PROGRESS,
- 0, /* totalBytes */
+ -1, /* totalBytes */
0, /* receivedBytes */
QStringLiteral("application/x-mimearchive"),
suggestedFilePath,
diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp
index 1cfaab3f5..3c7989cf0 100644
--- a/src/webenginequick/api/qquickwebengineprofile.cpp
+++ b/src/webenginequick/api/qquickwebengineprofile.cpp
@@ -209,10 +209,12 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
Q_Q(QQuickWebEngineProfile);
Q_ASSERT(!m_ongoingDownloads.contains(info.id));
- QWebEngineDownloadRequestPrivate *itemPrivate = new QWebEngineDownloadRequestPrivate(m_profileAdapter, info.url);
+ QWebEngineDownloadRequestPrivate *itemPrivate =
+ new QWebEngineDownloadRequestPrivate(m_profileAdapter);
itemPrivate->downloadId = info.id;
itemPrivate->downloadState = QWebEngineDownloadRequest::DownloadRequested;
itemPrivate->startTime = info.startTime;
+ itemPrivate->downloadUrl = info.url;
itemPrivate->totalBytes = info.totalBytes;
itemPrivate->mimeType = info.mimeType;
itemPrivate->downloadDirectory = QFileInfo(info.path).path();
diff --git a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
index 1c2268b31..c81a27b3a 100644
--- a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
+++ b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
@@ -415,7 +415,7 @@ void tst_QWebEngineDownloadRequest::downloadLink()
ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) {
QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested);
QCOMPARE(item->isFinished(), false);
- QCOMPARE(item->totalBytes(), -1);
+ QCOMPARE(item->totalBytes(), fileContents.size());
QCOMPARE(item->receivedBytes(), 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason);
QCOMPARE(item->isSavePageDownload(), false);
@@ -526,7 +526,7 @@ void tst_QWebEngineDownloadRequest::downloadTwoLinks()
ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) {
QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested);
QCOMPARE(item->isFinished(), false);
- QCOMPARE(item->totalBytes(), -1);
+ QCOMPARE(item->totalBytes(), 5); // strlen("fileN")
QCOMPARE(item->receivedBytes(), 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason);
QCOMPARE(item->savePageFormat(), QWebEngineDownloadRequest::UnknownSaveFormat);