[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #ifndef CONTENT_SHELL_BROWSER_SHELL_DOWNLOAD_MANAGER_DELEGATE_H_ |
| 6 | #define CONTENT_SHELL_BROWSER_SHELL_DOWNLOAD_MANAGER_DELEGATE_H_ |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 7 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
[email protected] | 1bd0ef1 | 2011-10-20 05:24:17 | [diff] [blame] | 14 | #include "content/public/browser/download_manager_delegate.h" |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 15 | |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 16 | namespace content { |
| 17 | |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 18 | class DownloadManager; |
| 19 | |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 20 | class ShellDownloadManagerDelegate : public DownloadManagerDelegate { |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 21 | public: |
| 22 | ShellDownloadManagerDelegate(); |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 23 | ~ShellDownloadManagerDelegate() override; |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 24 | |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 25 | void SetDownloadManager(DownloadManager* manager); |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 26 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 27 | void Shutdown() override; |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 28 | bool DetermineDownloadTarget(download::DownloadItem* download, |
danakj | a3cfb833 | 2019-12-10 21:13:33 | [diff] [blame] | 29 | DownloadTargetCallback* callback) override; |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 30 | bool ShouldOpenDownload(download::DownloadItem* item, |
danakj | 8c70a44 | 2019-12-10 22:48:24 | [diff] [blame] | 31 | DownloadOpenDelayedCallback callback) override; |
danakj | a6dd6f5 | 2019-12-10 19:04:52 | [diff] [blame] | 32 | void GetNextId(DownloadIdCallback callback) override; |
[email protected] | a558b43a | 2012-08-30 17:09:27 | [diff] [blame] | 33 | |
| 34 | // Inhibits prompting and sets the default download path. |
| 35 | void SetDownloadBehaviorForTesting( |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 36 | const base::FilePath& default_download_path); |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | friend class base::RefCountedThreadSafe<ShellDownloadManagerDelegate>; |
| 40 | |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 41 | using FilenameDeterminedCallback = |
| 42 | base::OnceCallback<void(const base::FilePath&)>; |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 43 | |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 44 | static void GenerateFilename(const GURL& url, |
| 45 | const std::string& content_disposition, |
| 46 | const std::string& suggested_filename, |
| 47 | const std::string& mime_type, |
| 48 | const base::FilePath& suggested_directory, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 49 | FilenameDeterminedCallback callback); |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 50 | void OnDownloadPathGenerated(uint32_t download_id, |
danakj | a3cfb833 | 2019-12-10 21:13:33 | [diff] [blame] | 51 | DownloadTargetCallback callback, |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 52 | const base::FilePath& suggested_path); |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 53 | void ChooseDownloadPath(uint32_t download_id, |
danakj | a3cfb833 | 2019-12-10 21:13:33 | [diff] [blame] | 54 | DownloadTargetCallback callback, |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 55 | const base::FilePath& suggested_path); |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 56 | |
| 57 | DownloadManager* download_manager_; |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 58 | base::FilePath default_download_path_; |
[email protected] | a558b43a | 2012-08-30 17:09:27 | [diff] [blame] | 59 | bool suppress_prompting_; |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 60 | base::WeakPtrFactory<ShellDownloadManagerDelegate> weak_ptr_factory_{this}; |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(ShellDownloadManagerDelegate); |
| 63 | }; |
| 64 | |
| 65 | } // namespace content |
| 66 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 67 | #endif // CONTENT_SHELL_BROWSER_SHELL_DOWNLOAD_MANAGER_DELEGATE_H_ |