2015-06-22 11:43:49 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_DOWNLOAD_MANAGER_DELEGATE_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_ELECTRON_DOWNLOAD_MANAGER_DELEGATE_H_
|
2015-06-22 11:43:49 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2015-06-22 11:43:49 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "content/public/browser/download_manager_delegate.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/file_dialog.h"
|
2019-09-08 15:10:18 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2015-06-22 11:43:49 +00:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class DownloadManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class ElectronDownloadManagerDelegate
|
|
|
|
: public content::DownloadManagerDelegate {
|
|
|
|
public:
|
|
|
|
using CreateDownloadPathCallback =
|
2021-05-06 22:01:04 +00:00
|
|
|
base::RepeatingCallback<void(const base::FilePath&)>;
|
2015-06-22 11:43:49 +00:00
|
|
|
|
|
|
|
explicit ElectronDownloadManagerDelegate(content::DownloadManager* manager);
|
2018-04-17 23:03:51 +00:00
|
|
|
~ElectronDownloadManagerDelegate() override;
|
2015-06-22 11:43:49 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ElectronDownloadManagerDelegate(const ElectronDownloadManagerDelegate&) =
|
|
|
|
delete;
|
|
|
|
ElectronDownloadManagerDelegate& operator=(
|
|
|
|
const ElectronDownloadManagerDelegate&) = delete;
|
|
|
|
|
2015-06-22 11:43:49 +00:00
|
|
|
// content::DownloadManagerDelegate:
|
|
|
|
void Shutdown() override;
|
|
|
|
bool DetermineDownloadTarget(
|
2018-04-10 15:29:26 +00:00
|
|
|
download::DownloadItem* download,
|
2024-01-25 17:46:30 +00:00
|
|
|
download::DownloadTargetCallback* callback) override;
|
2015-06-22 11:43:49 +00:00
|
|
|
bool ShouldOpenDownload(
|
2018-04-10 15:29:26 +00:00
|
|
|
download::DownloadItem* download,
|
2019-12-13 20:13:12 +00:00
|
|
|
content::DownloadOpenDelayedCallback callback) override;
|
|
|
|
void GetNextId(content::DownloadIdCallback callback) override;
|
2015-06-22 11:43:49 +00:00
|
|
|
|
|
|
|
private:
|
2016-08-25 21:34:48 +00:00
|
|
|
// Get the save path set on the associated api::DownloadItem object
|
2018-04-10 15:29:26 +00:00
|
|
|
void GetItemSavePath(download::DownloadItem* item, base::FilePath* path);
|
2018-11-08 14:51:06 +00:00
|
|
|
void GetItemSaveDialogOptions(download::DownloadItem* item,
|
2020-10-27 15:18:36 +00:00
|
|
|
file_dialog::DialogSettings* options);
|
2016-08-25 21:34:48 +00:00
|
|
|
|
2019-01-31 02:06:55 +00:00
|
|
|
void OnDownloadPathGenerated(uint32_t download_id,
|
2024-01-25 17:46:30 +00:00
|
|
|
download::DownloadTargetCallback callback,
|
2019-01-31 02:06:55 +00:00
|
|
|
const base::FilePath& default_path);
|
|
|
|
|
|
|
|
void OnDownloadSaveDialogDone(
|
|
|
|
uint32_t download_id,
|
2024-01-25 17:46:30 +00:00
|
|
|
download::DownloadTargetCallback download_callback,
|
2019-09-08 15:10:18 +00:00
|
|
|
gin_helper::Dictionary result);
|
2019-01-31 02:06:55 +00:00
|
|
|
|
2021-02-18 23:27:29 +00:00
|
|
|
base::FilePath last_saved_directory_;
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<content::DownloadManager> download_manager_;
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<ElectronDownloadManagerDelegate> weak_ptr_factory_{this};
|
2015-06-22 11:43:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_DOWNLOAD_MANAGER_DELEGATE_H_
|