[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 | #include "content/shell/browser/shell_download_manager_delegate.h" |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 6 | |
David Vallet | 1168352 | 2017-08-23 03:20:46 | [diff] [blame] | 7 | #include <string> |
8 | |||||
[email protected] | 5c12f4a | 2011-09-30 21:59:04 | [diff] [blame] | 9 | #if defined(OS_WIN) |
10 | #include <windows.h> | ||||
11 | #include <commdlg.h> | ||||
12 | #endif | ||||
13 | |||||
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 14 | #include "base/bind.h" |
Hans Wennborg | 0917de89 | 2020-04-28 20:21:15 | [diff] [blame] | 15 | #include "base/check_op.h" |
[email protected] | e666930 | 2013-03-25 14:31:16 | [diff] [blame] | 16 | #include "base/command_line.h" |
thestig | b7aad54f | 2014-09-05 18:25:39 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
Hans Wennborg | 0917de89 | 2020-04-28 20:21:15 | [diff] [blame] | 18 | #include "base/notreached.h" |
Avi Drissman | 9d3ded9 | 2018-12-25 20:50:21 | [diff] [blame] | 19 | #include "base/stl_util.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 20 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 21 | #include "base/strings/utf_string_conversions.h" |
Gabriel Charette | 5e2e7204 | 2020-02-25 01:04:01 | [diff] [blame] | 22 | #include "base/task/thread_pool.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 23 | #include "build/build_config.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 24 | #include "content/public/browser/browser_context.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 25 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 26 | #include "content/public/browser/browser_thread.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 27 | #include "content/public/browser/download_item_utils.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 28 | #include "content/public/browser/download_manager.h" |
[email protected] | 0b659b3 | 2012-03-26 21:29:32 | [diff] [blame] | 29 | #include "content/public/browser/web_contents.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 30 | #include "content/shell/common/shell_switches.h" |
[email protected] | d96cf75 | 2014-04-09 04:05:28 | [diff] [blame] | 31 | #include "net/base/filename_util.h" |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 32 | |
[email protected] | 517fce72 | 2014-01-15 05:16:14 | [diff] [blame] | 33 | #if defined(OS_WIN) |
[email protected] | 517fce72 | 2014-01-15 05:16:14 | [diff] [blame] | 34 | #include "ui/aura/window.h" |
[email protected] | 7a60cd3a | 2014-03-20 20:54:57 | [diff] [blame] | 35 | #include "ui/aura/window_tree_host.h" |
[email protected] | 517fce72 | 2014-01-15 05:16:14 | [diff] [blame] | 36 | #endif |
37 | |||||
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 38 | namespace content { |
39 | |||||
40 | ShellDownloadManagerDelegate::ShellDownloadManagerDelegate() | ||||
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 41 | : download_manager_(nullptr), suppress_prompting_(false) {} |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 42 | |
Asanka Herath | 1ba0e9f | 2017-04-03 18:48:53 | [diff] [blame] | 43 | ShellDownloadManagerDelegate::~ShellDownloadManagerDelegate() { |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 44 | if (download_manager_) { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 45 | download_manager_->SetDelegate(nullptr); |
46 | download_manager_ = nullptr; | ||||
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 47 | } |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 48 | } |
49 | |||||
50 | |||||
51 | void ShellDownloadManagerDelegate::SetDownloadManager( | ||||
52 | DownloadManager* download_manager) { | ||||
53 | download_manager_ = download_manager; | ||||
54 | } | ||||
55 | |||||
[email protected] | 854e131 | 2012-07-30 17:26:30 | [diff] [blame] | 56 | void ShellDownloadManagerDelegate::Shutdown() { |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 57 | // Revoke any pending callbacks. download_manager_ et. al. are no longer safe |
58 | // to access after this point. | ||||
59 | weak_ptr_factory_.InvalidateWeakPtrs(); | ||||
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 60 | download_manager_ = nullptr; |
[email protected] | 854e131 | 2012-07-30 17:26:30 | [diff] [blame] | 61 | } |
62 | |||||
[email protected] | 4766544 | 2012-07-27 02:31:22 | [diff] [blame] | 63 | bool ShellDownloadManagerDelegate::DetermineDownloadTarget( |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 64 | download::DownloadItem* download, |
danakj | a3cfb833 | 2019-12-10 21:13:33 | [diff] [blame] | 65 | DownloadTargetCallback* callback) { |
mostynb | 4e36389 | 2015-03-23 14:35:05 | [diff] [blame] | 66 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | a558b43a | 2012-08-30 17:09:27 | [diff] [blame] | 67 | // This assignment needs to be here because even at the call to |
68 | // SetDownloadManager, the system is not fully initialized. | ||||
69 | if (default_download_path_.empty()) { | ||||
70 | default_download_path_ = download_manager_->GetBrowserContext()->GetPath(). | ||||
71 | Append(FILE_PATH_LITERAL("Downloads")); | ||||
72 | } | ||||
73 | |||||
[email protected] | 3d833de | 2012-05-30 23:32:06 | [diff] [blame] | 74 | if (!download->GetForcedFilePath().empty()) { |
danakj | a3cfb833 | 2019-12-10 21:13:33 | [diff] [blame] | 75 | std::move(*callback).Run( |
76 | download->GetForcedFilePath(), | ||||
77 | download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, | ||||
78 | download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | ||||
Joe DeBlasio | c427ca03 | 2020-01-17 19:15:43 | [diff] [ |