| 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 "chrome/browser/download/download_file_picker.h" | 5 #include "chrome/browser/download/download_file_picker.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/browser/platform_util.h" | 9 #include "chrome/browser/platform_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return FILE_PICKER_DIFFERENT_DIR; | 49 return FILE_PICKER_DIFFERENT_DIR; |
| 50 return FILE_PICKER_DIFFERENT_NAME; | 50 return FILE_PICKER_DIFFERENT_NAME; |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 DownloadFilePicker::DownloadFilePicker( | 55 DownloadFilePicker::DownloadFilePicker( |
| 56 DownloadManager* download_manager, | 56 DownloadManager* download_manager, |
| 57 WebContents* web_contents, | 57 WebContents* web_contents, |
| 58 const FilePath& suggested_path, | 58 const FilePath& suggested_path, |
| 59 void* params) | 59 int32 download_id) |
| 60 : download_manager_(download_manager), | 60 : download_manager_(download_manager), |
| 61 download_id_(download_id), |
| 61 suggested_path_(suggested_path) { | 62 suggested_path_(suggested_path) { |
| 62 DCHECK(download_manager_); | 63 DCHECK(download_manager_); |
| 63 select_file_dialog_ = SelectFileDialog::Create(this); | 64 select_file_dialog_ = SelectFileDialog::Create(this); |
| 64 SelectFileDialog::FileTypeInfo file_type_info; | 65 SelectFileDialog::FileTypeInfo file_type_info; |
| 65 FilePath::StringType extension = suggested_path.Extension(); | 66 FilePath::StringType extension = suggested_path.Extension(); |
| 66 if (!extension.empty()) { | 67 if (!extension.empty()) { |
| 67 extension.erase(extension.begin()); // drop the . | 68 extension.erase(extension.begin()); // drop the . |
| 68 file_type_info.extensions.resize(1); | 69 file_type_info.extensions.resize(1); |
| 69 file_type_info.extensions[0].push_back(extension); | 70 file_type_info.extensions[0].push_back(extension); |
| 70 } | 71 } |
| 71 file_type_info.include_all_files = true; | 72 file_type_info.include_all_files = true; |
| 72 gfx::NativeWindow owning_window = web_contents ? | 73 gfx::NativeWindow owning_window = web_contents ? |
| 73 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; | 74 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; |
| 74 | 75 |
| 75 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 76 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, |
| 76 string16(), | 77 string16(), |
| 77 suggested_path, | 78 suggested_path, |
| 78 &file_type_info, 0, FILE_PATH_LITERAL(""), | 79 &file_type_info, 0, FILE_PATH_LITERAL(""), |
| 79 web_contents, owning_window, params); | 80 web_contents, owning_window, NULL); |
| 80 } | 81 } |
| 81 | 82 |
| 82 DownloadFilePicker::~DownloadFilePicker() { | 83 DownloadFilePicker::~DownloadFilePicker() { |
| 83 } | 84 } |
| 84 | 85 |
| 85 void DownloadFilePicker::ModelChanged(DownloadManager* manager) { | 86 void DownloadFilePicker::ModelChanged(DownloadManager* manager) { |
| 86 } | 87 } |
| 87 | 88 |
| 88 void DownloadFilePicker::ManagerGoingDown(DownloadManager* manager) { | 89 void DownloadFilePicker::ManagerGoingDown(DownloadManager* manager) { |
| 89 DCHECK_EQ(download_manager_, manager); | 90 DCHECK_EQ(download_manager_, manager); |
| 90 download_manager_ = NULL; | 91 download_manager_ = NULL; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void DownloadFilePicker::FileSelected(const FilePath& path, | 94 void DownloadFilePicker::FileSelected(const FilePath& path, |
| 94 int index, | 95 int index, |
| 95 void* params) { | 96 void* params) { |
| 96 FilePickerResult result = ComparePaths(suggested_path_, path); | 97 FilePickerResult result = ComparePaths(suggested_path_, path); |
| 97 RecordFilePickerResult(download_manager_, result); | 98 RecordFilePickerResult(download_manager_, result); |
| 98 if (download_manager_) | 99 if (download_manager_) |
| 99 download_manager_->FileSelected(path, params); | 100 download_manager_->FileSelected(path, download_id_); |
| 100 delete this; | 101 delete this; |
| 101 } | 102 } |
| 102 | 103 |
| 103 void DownloadFilePicker::FileSelectionCanceled(void* params) { | 104 void DownloadFilePicker::FileSelectionCanceled(void* params) { |
| 104 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); | 105 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); |
| 105 if (download_manager_) | 106 if (download_manager_) |
| 106 download_manager_->FileSelectionCanceled(params); | 107 download_manager_->FileSelectionCanceled(download_id_); |
| 107 delete this; | 108 delete this; |
| 108 } | 109 } |
| OLD | NEW |