From eda8fbdf0d6249f4f89e3456092cbe790b27b1fb Mon Sep 17 00:00:00 2001
From: Andras Becsi <andras.becsi@digia.com>
Date: Fri, 6 Feb 2015 11:59:01 +0100
Subject: [PATCH] Reverse the logic for download cancellation

Since we require downloads to be explicitly accepted
we should have 'accepted' as a member in the download
info instead of 'cancelled'.

Change-Id: Ia8ff4a4b29f3c8631f4cb1c410ece5f11d9cdc93
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
---
 src/core/browser_context_adapter_client.h      |  2 +-
 src/core/download_manager_delegate_qt.cpp      | 11 +++++------
 src/webengine/api/qquickwebengineprofile.cpp   |  4 ++--
 src/webenginewidgets/api/qwebengineprofile.cpp |  4 ++--
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/core/browser_context_adapter_client.h b/src/core/browser_context_adapter_client.h
index ff65f0c8f..a9e7eb726 100644
--- a/src/core/browser_context_adapter_client.h
+++ b/src/core/browser_context_adapter_client.h
@@ -64,7 +64,7 @@ public:
         const qint64 receivedBytes;
 
         QString path;
-        bool cancelled;
+        bool accepted;
     };
 
     virtual ~BrowserContextAdapterClient() { }
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 73a0976da..3ef8cc9af 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -126,7 +126,6 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
 
     item->AddObserver(this);
     if (m_contextAdapter->client()) {
-        bool cancelled = false;
         BrowserContextAdapterClient::DownloadItemInfo info = {
             item->GetId(),
             toQt(item->GetURL()),
@@ -134,18 +133,18 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
             item->GetTotalBytes(),
             item->GetReceivedBytes(),
             suggestedFilePath,
-            cancelled
+            false /* accepted */
         };
         m_contextAdapter->client()->downloadRequested(info);
 
         suggestedFile.setFile(info.path);
 
-        if (!info.cancelled && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) {
+        if (info.accepted && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) {
             qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data());
-            cancelled = true;
+            info.accepted = false;
         }
 
-        if (info.cancelled) {
+        if (!info.accepted) {
             cancelDownload(callback);
             return true;
         }
@@ -180,7 +179,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
             download->GetTotalBytes(),
             download->GetReceivedBytes(),
             QString(),
-            false
+            true /* accepted */
         };
         m_contextAdapter->client()->downloadUpdated(info);
     }
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index cac309291..5905fb3d9 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -100,8 +100,8 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
 
     QQuickWebEngineDownloadItem::DownloadState state = download->state();
     info.path = download->path();
-    info.cancelled = state == QQuickWebEngineDownloadItem::DownloadCancelled
-                      || state == QQuickWebEngineDownloadItem::DownloadRequested;
+    info.accepted = state != QQuickWebEngineDownloadItem::DownloadCancelled
+                      && state != QQuickWebEngineDownloadItem::DownloadRequested;
 }
 
 void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info)
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 64876bf1a..afe0774c0 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -152,11 +152,11 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
     QWebEngineDownloadItem::DownloadState state = download->state();
 
     info.path = download->path();
-    info.cancelled = state == QWebEngineDownloadItem::DownloadCancelled;
+    info.accepted = state != QWebEngineDownloadItem::DownloadCancelled;
 
     if (state == QWebEngineDownloadItem::DownloadRequested) {
         // Delete unaccepted downloads.
-        info.cancelled = true;
+        info.accepted = false;
         m_ongoingDownloads.remove(info.id);
         delete download;
     }
-- 
GitLab