OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shell_download_manager_delegate.h" | 5 #include "content/shell/shell_download_manager_delegate.h" |
6 | 6 |
| 7 #if defined(OS_WIN) |
| 8 #include <windows.h> |
| 9 #include <commdlg.h> |
| 10 #endif |
| 11 |
7 #include "base/bind.h" | 12 #include "base/bind.h" |
8 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/logging.h" |
| 15 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
10 #include "content/browser/browser_context.h" | 17 #include "content/browser/browser_context.h" |
11 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" |
12 #include "content/browser/download/download_manager.h" | 20 #include "content/browser/download/download_manager.h" |
13 #include "content/browser/download/download_state_info.h" | 21 #include "content/browser/download/download_state_info.h" |
14 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
15 | 23 |
16 namespace content { | 24 namespace content { |
17 | 25 |
18 ShellDownloadManagerDelegate::ShellDownloadManagerDelegate() | 26 ShellDownloadManagerDelegate::ShellDownloadManagerDelegate() |
19 : download_manager_(NULL) { | 27 : download_manager_(NULL) { |
20 } | 28 } |
21 | 29 |
(...skipping 18 matching lines...) Expand all Loading... |
40 return true; | 48 return true; |
41 | 49 |
42 FilePath generated_name = net::GenerateFileName( | 50 FilePath generated_name = net::GenerateFileName( |
43 download->GetURL(), | 51 download->GetURL(), |
44 download->content_disposition(), | 52 download->content_disposition(), |
45 download->referrer_charset(), | 53 download->referrer_charset(), |
46 download->suggested_filename(), | 54 download->suggested_filename(), |
47 download->mime_type(), | 55 download->mime_type(), |
48 string16(UTF8ToUTF16("download"))); | 56 string16(UTF8ToUTF16("download"))); |
49 | 57 |
| 58 // Since we have no download UI, show the user a dialog always. |
| 59 state.prompt_user_for_save_location = true; |
| 60 |
50 BrowserThread::PostTask( | 61 BrowserThread::PostTask( |
51 BrowserThread::FILE, | 62 BrowserThread::FILE, |
52 FROM_HERE, | 63 FROM_HERE, |
53 base::Bind( | 64 base::Bind( |
54 &ShellDownloadManagerDelegate::GenerateFilename, | 65 &ShellDownloadManagerDelegate::GenerateFilename, |
55 this, download_id, state, generated_name)); | 66 this, download_id, state, generated_name)); |
56 return false; | 67 return false; |
57 } | 68 } |
58 | 69 |
59 void ShellDownloadManagerDelegate::GenerateFilename( | 70 void ShellDownloadManagerDelegate::GenerateFilename( |
(...skipping 25 matching lines...) Expand all Loading... |
85 if (!download) | 96 if (!download) |
86 return; | 97 return; |
87 download->SetFileCheckResults(state); | 98 download->SetFileCheckResults(state); |
88 download_manager_->RestartDownload(download_id); | 99 download_manager_->RestartDownload(download_id); |
89 } | 100 } |
90 | 101 |
91 void ShellDownloadManagerDelegate::ChooseDownloadPath( | 102 void ShellDownloadManagerDelegate::ChooseDownloadPath( |
92 TabContents* tab_contents, | 103 TabContents* tab_contents, |
93 const FilePath& suggested_path, | 104 const FilePath& suggested_path, |
94 void* data) { | 105 void* data) { |
| 106 FilePath result; |
| 107 #if defined(OS_WIN) |
| 108 std::wstring file_part = FilePath(suggested_path).BaseName().value(); |
| 109 wchar_t file_name[MAX_PATH]; |
| 110 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); |
| 111 OPENFILENAME save_as; |
| 112 ZeroMemory(&save_as, sizeof(save_as)); |
| 113 save_as.lStructSize = sizeof(OPENFILENAME); |
| 114 save_as.hwndOwner = tab_contents->GetNativeView(); |
| 115 save_as.lpstrFile = file_name; |
| 116 save_as.nMaxFile = arraysize(file_name); |
| 117 |
| 118 std::wstring directory; |
| 119 if (!suggested_path.empty()) |
| 120 directory = FilePath(suggested_path).DirName().value(); |
| 121 |
| 122 save_as.lpstrInitialDir = directory.c_str(); |
| 123 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | |
| 124 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; |
| 125 |
| 126 if (GetSaveFileName(&save_as)) |
| 127 result = FilePath(std::wstring(save_as.lpstrFile)); |
| 128 #else |
| 129 NOTIMPLEMENTED(); |
| 130 #endif |
| 131 |
| 132 if (result.empty()) { |
| 133 download_manager_->FileSelectionCanceled(data); |
| 134 } else { |
| 135 download_manager_->FileSelected(result, data); |
| 136 } |
95 } | 137 } |
96 | 138 |
97 bool ShellDownloadManagerDelegate::OverrideIntermediatePath( | 139 bool ShellDownloadManagerDelegate::OverrideIntermediatePath( |
98 DownloadItem* item, | 140 DownloadItem* item, |
99 FilePath* intermediate_path) { | 141 FilePath* intermediate_path) { |
100 return false; | 142 return false; |
101 } | 143 } |
102 | 144 |
103 TabContents* ShellDownloadManagerDelegate:: | 145 TabContents* ShellDownloadManagerDelegate:: |
104 GetAlternativeTabContentsToNotifyForDownload() { | 146 GetAlternativeTabContentsToNotifyForDownload() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void ShellDownloadManagerDelegate::ChooseSavePath( | 200 void ShellDownloadManagerDelegate::ChooseSavePath( |
159 const base::WeakPtr<SavePackage>& save_package, | 201 const base::WeakPtr<SavePackage>& save_package, |
160 const FilePath& suggested_path, | 202 const FilePath& suggested_path, |
161 bool can_save_as_complete) { | 203 bool can_save_as_complete) { |
162 } | 204 } |
163 | 205 |
164 void ShellDownloadManagerDelegate::DownloadProgressUpdated() { | 206 void ShellDownloadManagerDelegate::DownloadProgressUpdated() { |
165 } | 207 } |
166 | 208 |
167 } // namespace content | 209 } // namespace content |
OLD | NEW |