diff options
-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) } |