OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/browser/shell_download_manager_delegate.h" | 5 #include "content/shell/browser/shell_download_manager_delegate.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <commdlg.h> | 9 #include <commdlg.h> |
10 #endif | 10 #endif |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" |
18 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/download_manager.h" | 22 #include "content/public/browser/download_manager.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/shell/common/shell_switches.h" | 24 #include "content/shell/common/shell_switches.h" |
23 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
24 | 26 |
25 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
26 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
27 #include "ui/aura/window_tree_host.h" | 29 #include "ui/aura/window_tree_host.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 97 } |
96 | 98 |
97 bool ShellDownloadManagerDelegate::ShouldOpenDownload( | 99 bool ShellDownloadManagerDelegate::ShouldOpenDownload( |
98 DownloadItem* item, | 100 DownloadItem* item, |
99 const DownloadOpenDelayedCallback& callback) { | 101 const DownloadOpenDelayedCallback& callback) { |
100 return true; | 102 return true; |
101 } | 103 } |
102 | 104 |
103 void ShellDownloadManagerDelegate::GetNextId( | 105 void ShellDownloadManagerDelegate::GetNextId( |
104 const DownloadIdCallback& callback) { | 106 const DownloadIdCallback& callback) { |
105 static uint32 next_id = DownloadItem::kInvalidId + 1; | 107 static uint32_t next_id = DownloadItem::kInvalidId + 1; |
106 callback.Run(next_id++); | 108 callback.Run(next_id++); |
107 } | 109 } |
108 | 110 |
109 // static | 111 // static |
110 void ShellDownloadManagerDelegate::GenerateFilename( | 112 void ShellDownloadManagerDelegate::GenerateFilename( |
111 const GURL& url, | 113 const GURL& url, |
112 const std::string& content_disposition, | 114 const std::string& content_disposition, |
113 const std::string& suggested_filename, | 115 const std::string& suggested_filename, |
114 const std::string& mime_type, | 116 const std::string& mime_type, |
115 const base::FilePath& suggested_directory, | 117 const base::FilePath& suggested_directory, |
116 const FilenameDeterminedCallback& callback) { | 118 const FilenameDeterminedCallback& callback) { |
117 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 119 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
118 base::FilePath generated_name = net::GenerateFileName(url, | 120 base::FilePath generated_name = net::GenerateFileName(url, |
119 content_disposition, | 121 content_disposition, |
120 std::string(), | 122 std::string(), |
121 suggested_filename, | 123 suggested_filename, |
122 mime_type, | 124 mime_type, |
123 "download"); | 125 "download"); |
124 | 126 |
125 if (!base::PathExists(suggested_directory)) | 127 if (!base::PathExists(suggested_directory)) |
126 base::CreateDirectory(suggested_directory); | 128 base::CreateDirectory(suggested_directory); |
127 | 129 |
128 base::FilePath suggested_path(suggested_directory.Append(generated_name)); | 130 base::FilePath suggested_path(suggested_directory.Append(generated_name)); |
129 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
130 BrowserThread::UI, FROM_HERE, base::Bind(callback, suggested_path)); | 132 BrowserThread::UI, FROM_HERE, base::Bind(callback, suggested_path)); |
131 } | 133 } |
132 | 134 |
133 void ShellDownloadManagerDelegate::OnDownloadPathGenerated( | 135 void ShellDownloadManagerDelegate::OnDownloadPathGenerated( |
134 uint32 download_id, | 136 uint32_t download_id, |
135 const DownloadTargetCallback& callback, | 137 const DownloadTargetCallback& callback, |
136 const base::FilePath& suggested_path) { | 138 const base::FilePath& suggested_path) { |
137 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
138 if (suppress_prompting_) { | 140 if (suppress_prompting_) { |
139 // Testing exit. | 141 // Testing exit. |
140 callback.Run(suggested_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 142 callback.Run(suggested_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
141 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 143 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
142 suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload"))); | 144 suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload"))); |
143 return; | 145 return; |
144 } | 146 } |
145 | 147 |
146 ChooseDownloadPath(download_id, callback, suggested_path); | 148 ChooseDownloadPath(download_id, callback, suggested_path); |
147 } | 149 } |
148 | 150 |
149 void ShellDownloadManagerDelegate::ChooseDownloadPath( | 151 void ShellDownloadManagerDelegate::ChooseDownloadPath( |
150 uint32 download_id, | 152 uint32_t download_id, |
151 const DownloadTargetCallback& callback, | 153 const DownloadTargetCallback& callback, |
152 const base::FilePath& suggested_path) { | 154 const base::FilePath& suggested_path) { |
153 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
154 DownloadItem* item = download_manager_->GetDownload(download_id); | 156 DownloadItem* item = download_manager_->GetDownload(download_id); |
155 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) | 157 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) |
156 return; | 158 return; |
157 | 159 |
158 base::FilePath result; | 160 base::FilePath result; |
159 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
160 std::wstring file_part = base::FilePath(suggested_path).BaseName().value(); | 162 std::wstring file_part = base::FilePath(suggested_path).BaseName().value(); |
(...skipping 25 matching lines...) Expand all Loading... |
186 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); | 188 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result); |
187 } | 189 } |
188 | 190 |
189 void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting( | 191 void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting( |
190 const base::FilePath& default_download_path) { | 192 const base::FilePath& default_download_path) { |
191 default_download_path_ = default_download_path; | 193 default_download_path_ = default_download_path; |
192 suppress_prompting_ = true; | 194 suppress_prompting_ = true; |
193 } | 195 } |
194 | 196 |
195 } // namespace content | 197 } // namespace content |
OLD | NEW |