| 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 "chrome/browser/download/download_file_picker.h" | 5 #include "chrome/browser/download/download_file_picker.h" |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_prefs.h" | 7 #include "chrome/browser/download/download_prefs.h" |
| 8 #include "chrome/browser/platform_util.h" | 8 #include "chrome/browser/platform_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/browser/download/save_package.h" | 10 #include "content/browser/download/save_package.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 | 14 |
| 15 using content::DownloadManager; | 15 using content::DownloadManager; |
| 16 using content::WebContents; |
| 16 | 17 |
| 17 DownloadFilePicker::DownloadFilePicker( | 18 DownloadFilePicker::DownloadFilePicker( |
| 18 DownloadManager* download_manager, | 19 DownloadManager* download_manager, |
| 19 TabContents* tab_contents, | 20 WebContents* web_contents, |
| 20 const FilePath& suggested_path, | 21 const FilePath& suggested_path, |
| 21 void* params) | 22 void* params) |
| 22 : download_manager_(download_manager) { | 23 : download_manager_(download_manager) { |
| 23 select_file_dialog_ = SelectFileDialog::Create(this); | 24 select_file_dialog_ = SelectFileDialog::Create(this); |
| 24 SelectFileDialog::FileTypeInfo file_type_info; | 25 SelectFileDialog::FileTypeInfo file_type_info; |
| 25 FilePath::StringType extension = suggested_path.Extension(); | 26 FilePath::StringType extension = suggested_path.Extension(); |
| 26 if (!extension.empty()) { | 27 if (!extension.empty()) { |
| 27 extension.erase(extension.begin()); // drop the . | 28 extension.erase(extension.begin()); // drop the . |
| 28 file_type_info.extensions.resize(1); | 29 file_type_info.extensions.resize(1); |
| 29 file_type_info.extensions[0].push_back(extension); | 30 file_type_info.extensions[0].push_back(extension); |
| 30 } | 31 } |
| 31 file_type_info.include_all_files = true; | 32 file_type_info.include_all_files = true; |
| 32 gfx::NativeWindow owning_window = tab_contents ? | 33 gfx::NativeWindow owning_window = web_contents ? |
| 33 platform_util::GetTopLevel(tab_contents->GetNativeView()) : NULL; | 34 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; |
| 34 | 35 |
| 35 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 36 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, |
| 36 string16(), | 37 string16(), |
| 37 suggested_path, | 38 suggested_path, |
| 38 &file_type_info, 0, FILE_PATH_LITERAL(""), | 39 &file_type_info, 0, FILE_PATH_LITERAL(""), |
| 39 tab_contents, owning_window, params); | 40 web_contents, owning_window, params); |
| 40 } | 41 } |
| 41 | 42 |
| 42 DownloadFilePicker::~DownloadFilePicker() { | 43 DownloadFilePicker::~DownloadFilePicker() { |
| 43 } | 44 } |
| 44 | 45 |
| 45 void DownloadFilePicker::ModelChanged() { | 46 void DownloadFilePicker::ModelChanged() { |
| 46 } | 47 } |
| 47 | 48 |
| 48 void DownloadFilePicker::ManagerGoingDown() { | 49 void DownloadFilePicker::ManagerGoingDown() { |
| 49 download_manager_ = NULL; | 50 download_manager_ = NULL; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void DownloadFilePicker::FileSelected(const FilePath& path, | 53 void DownloadFilePicker::FileSelected(const FilePath& path, |
| 53 int index, | 54 int index, |
| 54 void* params) { | 55 void* params) { |
| 55 if (download_manager_) | 56 if (download_manager_) |
| 56 download_manager_->FileSelected(path, params); | 57 download_manager_->FileSelected(path, params); |
| 57 delete this; | 58 delete this; |
| 58 } | 59 } |
| 59 | 60 |
| 60 void DownloadFilePicker::FileSelectionCanceled(void* params) { | 61 void DownloadFilePicker::FileSelectionCanceled(void* params) { |
| 61 if (download_manager_) | 62 if (download_manager_) |
| 62 download_manager_->FileSelectionCanceled(params); | 63 download_manager_->FileSelectionCanceled(params); |
| 63 delete this; | 64 delete this; |
| 64 } | 65 } |
| OLD | NEW |