summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2017-08-14 10:25:56 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2018-01-19 11:17:43 +0000
commitf2d938962fe9a029ec0baf37ca7f478051125780 (patch)
tree9ce93d8076ff3f7f51ac06bfe02f7548e4dfffb8 /src
parent04337275e4b66ba5853c24a79d7f61ebb2e7a247 (diff)
Fix QWebEngineDownloadItem::type()
Task-number: QTBUG-62640 Change-Id: I2b16f24533b38c20a7071319723382ba240e35f3 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'src')
-rw-r--r--src/core/download_manager_delegate_qt.cpp21
-rw-r--r--src/core/download_manager_delegate_qt.h4
-rw-r--r--src/core/web_contents_adapter.cpp2
3 files changed, 17 insertions, 10 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 77469a8ea..0eabd340c 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 cd21d330c..d23a78b0b 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 ff4f09f0e..b301622d4 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);