diff options
author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2023-09-29 13:18:39 +0200 |
---|---|---|
committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2023-10-01 22:25:52 +0200 |
commit | b8ee80acdadefff927ed2c2884e0e67c9c2fc9a9 (patch) | |
tree | fac6188a607a34c6aa89a4790a11e1e87c778e0d | |
parent | 3cbb895954e0d22efc20700a1e66413a8a483124 (diff) |
Support filePath argument of save() when saving non-HTML files
Currently the filePath argument of QWebEnginePage::save() is ignored
when the user tries to download anything but HTML; and the requested
download path is the Downloads folder of the OS.
Fix this and adjust the corresponding test case with checking path
and file name of the download request.
Pick-to: 6.6
Task-number: QTBUG-117624
Change-Id: Ia1d3afc898b1aad223aab772b775724a50e88bd3
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 18 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_save.qml | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 36551bc29..7ce5bdf4d 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -102,23 +102,34 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem * return true; } + QString suggestedFilePath; + QString suggestedFilename; bool isSavePageDownload = false; WebContentsAdapterClient *adapterClient = nullptr; if (content::WebContents *webContents = content::DownloadItemUtils::GetWebContents(item)) { WebContentsDelegateQt *contentsDelegate = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate()); adapterClient = contentsDelegate->adapterClient(); - if (contentsDelegate->savePageInfo()) { + if (SavePageInfo *spi = contentsDelegate->savePageInfo()) { // We end up here when saving non text-based files (MHTML, PDF or images) + suggestedFilePath = spi->requestedFilePath; + const QFileInfo fileInfo(suggestedFilePath); + if (fileInfo.isRelative()) { + const QDir downloadDir(m_profileAdapter->downloadPath()); + suggestedFilePath = downloadDir.absoluteFilePath(suggestedFilePath); + } + suggestedFilename = fileInfo.fileName(); isSavePageDownload = true; // Clear the delegate's SavePageInfo. It's only valid for the page currently being saved. contentsDelegate->setSavePageInfo(nullptr); } } - QString suggestedFilename = toQt(item->GetSuggestedFilename()); QString mimeTypeString = toQt(item->GetMimeType()); if (suggestedFilename.isEmpty()) + suggestedFilename = toQt(item->GetSuggestedFilename()); + + if (suggestedFilename.isEmpty()) suggestedFilename = toQt(net::HttpContentDisposition(item->GetContentDisposition(), net::kCharsetLatin1).filename()); if (suggestedFilename.isEmpty()) @@ -139,7 +150,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem * QDir defaultDownloadDirectory(m_profileAdapter->downloadPath()); - QString suggestedFilePath = m_profileAdapter->determineDownloadPath(defaultDownloadDirectory.absolutePath(), suggestedFilename, item->GetStartTime().ToTimeT()); + if (suggestedFilePath.isEmpty()) + suggestedFilePath = m_profileAdapter->determineDownloadPath(defaultDownloadDirectory.absolutePath(), suggestedFilename, item->GetStartTime().ToTimeT()); item->AddObserver(this); QList<ProfileAdapterClient*> clients = m_profileAdapter->clients(); diff --git a/tests/auto/quick/qmltests/data/tst_save.qml b/tests/auto/quick/qmltests/data/tst_save.qml index f07a5f212..08d99022a 100644 --- a/tests/auto/quick/qmltests/data/tst_save.qml +++ b/tests/auto/quick/qmltests/data/tst_save.qml @@ -137,6 +137,8 @@ TestWebEngineView { downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) compare(downloadUrl, webEngineView.url) + compare(downloadDir, fileDir) + compare(downloadFileName, fileName) compare(isSavePageDownload, true) compare(downloadState[0], WebEngineDownloadRequest.DownloadRequested) } |