OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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) | 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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 | 83 |
84 void ShellDownloadManagerDelegate::RestartDownload( | 84 void ShellDownloadManagerDelegate::RestartDownload( |
85 int32 download_id, | 85 int32 download_id, |
86 const FilePath& suggested_path) { | 86 const FilePath& suggested_path) { |
87 DownloadItem* download = | 87 DownloadItem* download = |
88 download_manager_->GetActiveDownloadItem(download_id); | 88 download_manager_->GetActiveDownloadItem(download_id); |
89 if (!download) | 89 if (!download) |
90 return; | 90 return; |
91 | 91 |
92 // Since we have no download UI, show the user a dialog always. | 92 // Since we have no download UI, show the user a dialog always. |
93 download->OnTargetPathDetermined(suggested_path, | 93 ChooseDownloadPath(download, suggested_path); |
Randy Smith (Not in Mondays)
2012/07/10 18:33:09
Any reason not to hoist the code in ChooseDownload
asanka
2012/07/11 20:03:32
I left it out since we might need to override it f
| |
94 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
95 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | |
96 download_manager_->RestartDownload(download_id); | |
97 } | 94 } |
98 | 95 |
99 void ShellDownloadManagerDelegate::ChooseDownloadPath(DownloadItem* item) { | 96 void ShellDownloadManagerDelegate::ChooseDownloadPath( |
97 DownloadItem* item, | |
98 const FilePath& suggested_path) { | |
100 FilePath result; | 99 FilePath result; |
101 #if defined(OS_WIN) && !defined(USE_AURA) | 100 #if defined(OS_WIN) && !defined(USE_AURA) |
102 const FilePath suggested_path(item->GetTargetFilePath()); | |
103 std::wstring file_part = FilePath(suggested_path).BaseName().value(); | 101 std::wstring file_part = FilePath(suggested_path).BaseName().value(); |
104 wchar_t file_name[MAX_PATH]; | 102 wchar_t file_name[MAX_PATH]; |
105 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); | 103 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); |
106 OPENFILENAME save_as; | 104 OPENFILENAME save_as; |
107 ZeroMemory(&save_as, sizeof(save_as)); | 105 ZeroMemory(&save_as, sizeof(save_as)); |
108 save_as.lStructSize = sizeof(OPENFILENAME); | 106 save_as.lStructSize = sizeof(OPENFILENAME); |
109 save_as.hwndOwner = item->GetWebContents()->GetNativeView(); | 107 save_as.hwndOwner = item->GetWebContents()->GetNativeView(); |
110 save_as.lpstrFile = file_name; | 108 save_as.lpstrFile = file_name; |
111 save_as.nMaxFile = arraysize(file_name); | 109 save_as.nMaxFile = arraysize(file_name); |
112 | 110 |
113 std::wstring directory; | 111 std::wstring directory; |
114 if (!suggested_path.empty()) | 112 if (!suggested_path.empty()) |
115 directory = suggested_path.DirName().value(); | 113 directory = suggested_path.DirName().value(); |
116 | 114 |
117 save_as.lpstrInitialDir = directory.c_str(); | 115 save_as.lpstrInitialDir = directory.c_str(); |
118 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | | 116 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | |
119 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; | 117 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; |
120 | 118 |
121 if (GetSaveFileName(&save_as)) | 119 if (GetSaveFileName(&save_as)) |
122 result = FilePath(std::wstring(save_as.lpstrFile)); | 120 result = FilePath(std::wstring(save_as.lpstrFile)); |
123 #else | 121 #else |
124 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
125 #endif | 123 #endif |
126 | 124 |
127 if (result.empty()) { | 125 if (result.empty()) { |
128 download_manager_->FileSelectionCanceled(item->GetId()); | 126 item->Cancel(true); |
129 } else { | 127 } else { |
130 download_manager_->FileSelected(result, item->GetId()); | 128 item->OnTargetPathDetermined(result, |
129 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
130 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | |
131 download_manager_->RestartDownload(download_id); | |
131 } | 132 } |
132 } | 133 } |
133 | 134 |
134 } // namespace content | 135 } // namespace content |
OLD | NEW |