Implementation of DownloadManagerDelegateEfl class
authorPawel Niemirski <p.niemirski@samsung.com>
Thu, 22 Oct 2015 12:33:33 +0000 (14:33 +0200)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
The patch implements DownloadManagerDelegateEfl::DetermineDownloadTarget,
which allows to use Chromium downloads.

We are checking whether the external download manager is available,
in order for it to be considered, before using Chromium fallback
download code.

Right now, PathService class is used to determine where downloads
should be saved on given platform based on mime type.

Original beta/m47 patch:
- http://web.sec.samsung.net/gerrit/#/c/96713/

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=14817

Reviewed by: a1.gomes

Change-Id: Ia1362cad11044dab4de4e1ee7eb908ebeee3c995
Signed-off-by: Pawel Niemirski <p.niemirski@samsung.com>
(cherry picked from commit d0bde5a4fdf6f0591bf194478e1b7f3b5997bd00)

tizen_src/ewk/efl_integration/browser/download_manager_delegate_efl.cc
tizen_src/ewk/efl_integration/browser/download_manager_delegate_efl.h
tizen_src/ewk/efl_integration/context_menu_controller_efl.cc

index fab4dd3..598730e 100644 (file)
@@ -5,16 +5,66 @@
 #include "browser/download_manager_delegate_efl.h"
 
 #include "base/files/file_path.h"
+#include "base/path_service.h"
+#include "components/mime_util/mime_util.h"
+#include "content/common/paths_efl.h"
 #include "content/public/browser/download_danger_type.h"
 #include "content/public/browser/download_item.h"
+#include "ewk/efl_integration/browser_context_efl.h"
+#include "ewk/efl_integration/eweb_view.h"
 
+bool DownloadManagerDelegateEfl::TriggerExternalDownloadManager(
+    content::DownloadItem* item) const {
+  content::BrowserContextEfl* browser_context =
+      static_cast<content::BrowserContextEfl*>(item->GetBrowserContext());
+  if (browser_context) {
+    auto start_download_callback =
+        browser_context->WebContext()->DidStartDownloadCallback();
+    if (start_download_callback) {
+      DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+      start_download_callback->TriggerCallback(item->GetURL().spec());
+      return true;
+    }
+  }
+  return false;
+}
 
-bool DownloadManagerDelegateEfl::DetermineDownloadTarget(content::DownloadItem* item,
-                                                         const content::DownloadTargetCallback& callback) {
-  callback.Run(item->GetForcedFilePath(),
+base::FilePath DownloadManagerDelegateEfl::GetPlatformDownloadPath(
+    content::DownloadItem* item) const {
+  base::FilePath path;
+  if (mime_util::IsSupportedImageMimeType(item->GetMimeType())) {
+    if (!PathService::Get(PathsEfl::DIR_DOWNLOAD_IMAGE, &path)) {
+      LOG(ERROR) << "Could not get image directory.";
+      return base::FilePath();
+    }
+  } else {
+    if (!PathService::Get(PathsEfl::DIR_DOWNLOADS, &path)) {
+      LOG(ERROR) << "Could not get download directory.";
+      return base::FilePath();
+    }
+  }
+
+  return path.Append(item->GetSuggestedFilename());
+}
+
+void DownloadManagerDelegateEfl::CancelDownload(
+    const content::DownloadTargetCallback& callback) const {
+  callback.Run(base::FilePath(), /* Empty file path for cancellation */
                content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
                content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
-               item->GetForcedFilePath());
+               base::FilePath());
+}
+
+bool DownloadManagerDelegateEfl::DetermineDownloadTarget(content::DownloadItem* item,
+                                                         const content::DownloadTargetCallback& callback) {
+  if (TriggerExternalDownloadManager(item)) {
+    CancelDownload(callback);
+  } else {
+    callback.Run(GetPlatformDownloadPath(item),
+                 content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+                 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+                 GetPlatformDownloadPath(item));
+  }
   return true;
 }
 
index 9a12500..9a4fa88 100644 (file)
@@ -7,8 +7,7 @@
 
 #include "content/public/browser/download_manager_delegate.h"
 
-// EFL WebView does not use Chromium downloads, so implement methods here to
-// unconditionally cancel the download.
+// This is the EFL side helper for the download system.
 class DownloadManagerDelegateEfl : public content::DownloadManagerDelegate {
 public:
     virtual ~DownloadManagerDelegateEfl() { }
@@ -24,6 +23,14 @@ public:
         content::DownloadItem*,
         const content::DownloadOpenDelayedCallback&) override;
     virtual void GetNextId(const content::DownloadIdCallback&) override;
+private:
+    // If the external download manager is available, trigger download
+    // with it and return true, otherwise return false.
+    bool TriggerExternalDownloadManager(content::DownloadItem* item) const;
+
+    base::FilePath GetPlatformDownloadPath(content::DownloadItem* item) const;
+
+    void CancelDownload(const content::DownloadTargetCallback&) const;
 };
 
 #endif // DOWNLOAD_MANAGER_DELEGATE_EFL_H
index 2ef7584..c121789 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "base/files/file_path.h"
 #include "base/path_service.h"
+#include "base/strings/utf_string_conversions.h"
 #include "ui/base/clipboard/clipboard_helper_efl.h"
 #include "common/web_contents_utils.h"
 #include "context_menu_controller_efl.h"
@@ -590,6 +591,7 @@ base::FilePath ContextMenuControllerEfl::DownloadFile(const GURL url,
     }
   }
 
+  dl_params->set_suggested_name(base::UTF8ToUTF16(fileName.value()));
   dl_params->set_file_path(fullPath);
   dl_params->set_prompt(true);
   dl_params->set_callback(callback);