diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 77469a8ea91807ba6936e714a0bf988c8d39c669..0eabd340c51365ba6adf928d7c82a872b4cca5d6 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -65,7 +65,7 @@ DownloadManagerDelegateQt::DownloadManagerDelegateQt(BrowserContextAdapter *cont : m_contextAdapter(contextAdapter) , m_currentId(0) , m_weakPtrFactory(this) - , m_downloadType(BrowserContextAdapterClient::Attachment) + , m_nextDownloadIsUserRequested(false) { Q_ASSERT(m_contextAdapter); } @@ -107,10 +107,17 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i QString suggestedFilename = toQt(item->GetSuggestedFilename()); QString mimeTypeString = toQt(item->GetMimeType()); - bool isAttachment = net::HttpContentDisposition(item->GetContentDisposition(), std::string()).is_attachment(); - - if (!isAttachment || !BrowserContextAdapterClient::UserRequested) - m_downloadType = BrowserContextAdapterClient::DownloadAttribute; + int downloadType = 0; + if (m_nextDownloadIsUserRequested) { + downloadType = BrowserContextAdapterClient::UserRequested; + m_nextDownloadIsUserRequested = false; + } else { + bool isAttachment = net::HttpContentDisposition(item->GetContentDisposition(), std::string()).is_attachment(); + if (isAttachment) + downloadType = BrowserContextAdapterClient::Attachment; + else + downloadType = BrowserContextAdapterClient::DownloadAttribute; + } if (suggestedFilename.isEmpty()) suggestedFilename = toQt(net::HttpContentDisposition(item->GetContentDisposition(), std::string()).filename()); @@ -155,7 +162,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i suggestedFilePath, BrowserContextAdapterClient::UnknownSavePageFormat, false /* accepted */, - m_downloadType, + downloadType, item->GetLastReason() }; @@ -283,7 +290,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa QString(), BrowserContextAdapterClient::UnknownSavePageFormat, true /* accepted */, - m_downloadType, + 0 /* downloadType (unused) */, download->GetLastReason() }; diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h index cd21d330c84d42db7a8a05538b8522bdc4b95ab9..d23a78b0b13ee9f28a5713de9ee5b3b6e714d9d6 100644 --- a/src/core/download_manager_delegate_qt.h +++ b/src/core/download_manager_delegate_qt.h @@ -84,7 +84,7 @@ public: void cancelDownload(quint32 downloadId); - void setDownloadType(int downloadType) { m_downloadType = downloadType; } + void markNextDownloadAsUserRequested() { m_nextDownloadIsUserRequested = true; } // Inherited from content::DownloadItem::Observer void OnDownloadUpdated(content::DownloadItem *download) override; @@ -97,7 +97,7 @@ private: uint64_t m_currentId; base::WeakPtrFactory<DownloadManagerDelegateQt> m_weakPtrFactory; - int m_downloadType; + bool m_nextDownloadIsUserRequested; friend class DownloadManagerDelegateInstance; DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegateQt); diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index ff4f09f0efde8a50dcd5c94221c1e91c07c410bc..b301622d48241dbb09f8f7f62768154e80434427 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -942,7 +942,7 @@ void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileN if (!dlm) return; - dlmd->setDownloadType(BrowserContextAdapterClient::UserRequested); + dlmd->markNextDownloadAsUserRequested(); dlm->SetDelegate(dlmd); GURL gurl = toGurl(url); diff --git a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp index c25e82d41a6bd7b2f19c9034b7a694f5a1a9613b..aba5bdeb1128797462159677f7f2edbc0b4c38cb 100644 --- a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp +++ b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp @@ -86,7 +86,7 @@ void tst_QWebEngineDownloads::downloadLink_data() /* fileDisposition */ << QByteArrayLiteral("") /* fileHasReferer */ << true /* fileAction */ << FileIsDownloaded - /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute; + /* downloadType */ << QWebEngineDownloadItem::UserRequested; // SaveLink should always trigger a download, also for text files. QTest::newRow("save link to text file") @@ -99,7 +99,7 @@ void tst_QWebEngineDownloads::downloadLink_data() /* fileDisposition */ << QByteArrayLiteral("") /* fileHasReferer */ << true /* fileAction */ << FileIsDownloaded - /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute; + /* downloadType */ << QWebEngineDownloadItem::UserRequested; // ... adding the "download" attribute should have no effect. QTest::newRow("save link to text file (attribute)") @@ -112,7 +112,7 @@ void tst_QWebEngineDownloads::downloadLink_data() /* fileDisposition */ << QByteArrayLiteral("") /* fileHasReferer */ << true /* fileAction */ << FileIsDownloaded - /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute; + /* downloadType */ << QWebEngineDownloadItem::UserRequested; // ... adding the "attachment" content disposition should also have no effect. QTest::newRow("save link to text file (attachment)") @@ -508,7 +508,7 @@ void tst_QWebEngineDownloads::downloadTwoLinks() QCOMPARE(item->totalBytes(), -1); QCOMPARE(item->receivedBytes(), 0); QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->type(), QWebEngineDownloadItem::DownloadAttribute); + QCOMPARE(item->type(), QWebEngineDownloadItem::Attachment); QCOMPARE(item->mimeType(), QStringLiteral("text/plain")); QCOMPARE(item->path(), standardDir + QByteArrayLiteral("/file2")); QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);