-
Notifications
You must be signed in to change notification settings - Fork 15k
/
electron_download_manager_delegate.h
83 lines (66 loc) · 2.91 KB
/
electron_download_manager_delegate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_DOWNLOAD_MANAGER_DELEGATE_H_
#define ELECTRON_SHELL_BROWSER_ELECTRON_DOWNLOAD_MANAGER_DELEGATE_H_
#include <vector>
#include "base/memory/weak_ptr.h"
#include "content/public/browser/download_manager_delegate.h"
#include "shell/browser/ui/file_dialog.h"
#include "shell/common/gin_helper/dictionary.h"
#if BUILDFLAG(IS_WIN)
#include "ui/shell_dialogs/execute_select_file_win.h"
#endif // BUILDFLAG(IS_WIN)
namespace content {
class DownloadManager;
}
namespace electron {
class ElectronDownloadManagerDelegate
: public content::DownloadManagerDelegate {
public:
using CreateDownloadPathCallback =
base::RepeatingCallback<void(const base::FilePath&)>;
explicit ElectronDownloadManagerDelegate(content::DownloadManager* manager);
~ElectronDownloadManagerDelegate() override;
// disable copy
ElectronDownloadManagerDelegate(const ElectronDownloadManagerDelegate&) =
delete;
ElectronDownloadManagerDelegate& operator=(
const ElectronDownloadManagerDelegate&) = delete;
// content::DownloadManagerDelegate:
void Shutdown() override;
bool DetermineDownloadTarget(
download::DownloadItem* download,
content::DownloadTargetCallback* callback) override;
bool ShouldOpenDownload(
download::DownloadItem* download,
content::DownloadOpenDelayedCallback callback) override;
void GetNextId(content::DownloadIdCallback callback) override;
private:
// Get the save path set on the associated api::DownloadItem object
void GetItemSavePath(download::DownloadItem* item, base::FilePath* path);
void GetItemSaveDialogOptions(download::DownloadItem* item,
file_dialog::DialogSettings* options);
void OnDownloadPathGenerated(uint32_t download_id,
content::DownloadTargetCallback callback,
const base::FilePath& default_path);
void OnDownloadSaveDialogDone(
uint32_t download_id,
content::DownloadTargetCallback download_callback,
gin_helper::Dictionary result);
base::FilePath last_saved_directory_;
content::DownloadManager* download_manager_;
base::WeakPtrFactory<ElectronDownloadManagerDelegate> weak_ptr_factory_{this};
#if BUILDFLAG(IS_WIN)
// Copied from ui/shell_dialogs/select_file_dialog_win.h
bool GetRegistryDescriptionFromExtension(const std::u16string& file_ext,
std::u16string* reg_description);
std::vector<ui::FileFilterSpec> FormatFilterForExtensions(
const std::vector<std::u16string>& file_ext,
const std::vector<std::u16string>& ext_desc,
bool include_all_files,
bool keep_extension_visible);
#endif // BUILDFLAG(IS_WIN)
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_DOWNLOAD_MANAGER_DELEGATE_H_