diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-02-16 11:04:13 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-02-21 14:06:38 +0000 |
commit | 91bf3b3f87c0275ac4e7b1805a74ce931522adda (patch) | |
tree | ff60df7d0816275a0336cf2ae52ac9d88f422198 /src/core | |
parent | 025952a9673264c3557f6f7c195eebc11892e80a (diff) |
Fixup merge of downloadType from 5.10.1
In 5.11 we deprecated downloadType and at the same time ripped out most
of the faulty logic. Later we partially fixed the logic in 5.10.1, but
kept the 5.11 version during the merge. This restores the improved logic
from 5.10.1, while keeping the property deprecated since it is still
misleading at times.
Change-Id: I12ee09a2b212506f7ba1a336c9c2e88aa3b1de24
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/browser_context_adapter_client.h | 9 | ||||
-rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 19 | ||||
-rw-r--r-- | src/core/download_manager_delegate_qt.h | 3 | ||||
-rw-r--r-- | src/core/web_contents_adapter.cpp | 4 |
4 files changed, 31 insertions, 4 deletions
diff --git a/src/core/browser_context_adapter_client.h b/src/core/browser_context_adapter_client.h index 32a56bfce..02bee8ed6 100644 --- a/src/core/browser_context_adapter_client.h +++ b/src/core/browser_context_adapter_client.h @@ -69,6 +69,13 @@ public: MimeHtmlSaveFormat }; + enum DownloadType { + Attachment = 0, + DownloadAttribute, + UserRequested, + SavePage + }; + // Keep in sync with content::DownloadInterruptReason enum DownloadInterruptReason { NoReason = 0, @@ -113,7 +120,7 @@ public: bool accepted; bool paused; bool done; - bool isSavePageDownload; + int downloadType; int downloadInterruptReason; }; diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 191bb2267..40df9b3a8 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -65,6 +65,7 @@ DownloadManagerDelegateQt::DownloadManagerDelegateQt(BrowserContextAdapter *cont : m_contextAdapter(contextAdapter) , m_currentId(0) , m_weakPtrFactory(this) + , m_nextDownloadIsUserRequested(false) { Q_ASSERT(m_contextAdapter); } @@ -122,6 +123,18 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i QString suggestedFilename = toQt(item->GetSuggestedFilename()); QString mimeTypeString = toQt(item->GetMimeType()); + 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()); @@ -167,7 +180,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i false /* accepted */, false /* paused */, false /* done */, - false /* isSavePageDownload */, + downloadType, item->GetLastReason() }; @@ -262,7 +275,7 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content acceptedByDefault, false, /* paused */ false, /* done */ - true /* isSavePageDownload */, + BrowserContextAdapterClient::SavePage, BrowserContextAdapterClient::NoReason }; @@ -302,7 +315,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa true /* accepted */, download->IsPaused(), download->IsDone(), - download->IsSavePackageDownload(), + 0 /* downloadType (unused) */, download->GetLastReason() }; diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h index dd8ebf6c4..df43211ed 100644 --- a/src/core/download_manager_delegate_qt.h +++ b/src/core/download_manager_delegate_qt.h @@ -86,6 +86,8 @@ public: void pauseDownload(quint32 downloadId); void resumeDownload(quint32 downloadId); + void markNextDownloadAsUserRequested() { m_nextDownloadIsUserRequested = true; } + // Inherited from content::DownloadItem::Observer void OnDownloadUpdated(content::DownloadItem *download) override; void OnDownloadDestroyed(content::DownloadItem *download) override; @@ -97,6 +99,7 @@ private: uint64_t m_currentId; base::WeakPtrFactory<DownloadManagerDelegateQt> m_weakPtrFactory; + 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 5b7e437bf..c7b2e6e93 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -979,10 +979,14 @@ void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileN Q_D(WebContentsAdapter); content::BrowserContext *bctx = webContents()->GetBrowserContext(); content::DownloadManager *dlm = content::BrowserContext::GetDownloadManager(bctx); + DownloadManagerDelegateQt *dlmd = d->browserContextAdapter->downloadManagerDelegate(); if (!dlm) return; + dlmd->markNextDownloadAsUserRequested(); + dlm->SetDelegate(dlmd); + net::NetworkTrafficAnnotationTag traffic_annotation = net::DefineNetworkTrafficAnnotation( "WebContentsAdapter::download", R"( |