#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;
}
#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() { }
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