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/ui/chrome_select_file_policy.h" | 10 #include "chrome/browser/ui/chrome_select_file_policy.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return FILE_PICKER_DIFFERENT_DIR; | 52 return FILE_PICKER_DIFFERENT_DIR; |
53 return FILE_PICKER_DIFFERENT_NAME; | 53 return FILE_PICKER_DIFFERENT_NAME; |
54 } | 54 } |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 DownloadFilePicker::DownloadFilePicker() : download_id_(0) { | 58 DownloadFilePicker::DownloadFilePicker() : download_id_(0) { |
59 } | 59 } |
60 | 60 |
61 void DownloadFilePicker::Init(DownloadManager* download_manager, | 61 void DownloadFilePicker::Init(DownloadManager* download_manager, |
62 DownloadItem* item) { | 62 DownloadItem* item, |
| 63 const FilePath& suggested_path, |
| 64 const FileSelectedCallback& callback) { |
63 download_manager_ = download_manager; | 65 download_manager_ = download_manager; |
64 download_id_ = item->GetId(); | 66 download_id_ = item->GetId(); |
65 InitSuggestedPath(item); | 67 file_selected_callback_ = callback; |
| 68 InitSuggestedPath(item, suggested_path); |
66 | 69 |
67 DCHECK(download_manager_); | 70 DCHECK(download_manager_); |
68 WebContents* web_contents = item->GetWebContents(); | 71 WebContents* web_contents = item->GetWebContents(); |
69 select_file_dialog_ = SelectFileDialog::Create( | 72 select_file_dialog_ = SelectFileDialog::Create( |
70 this, new ChromeSelectFilePolicy(web_contents)); | 73 this, new ChromeSelectFilePolicy(web_contents)); |
71 SelectFileDialog::FileTypeInfo file_type_info; | 74 SelectFileDialog::FileTypeInfo file_type_info; |
72 FilePath::StringType extension = suggested_path_.Extension(); | 75 FilePath::StringType extension = suggested_path_.Extension(); |
73 if (!extension.empty()) { | 76 if (!extension.empty()) { |
74 extension.erase(extension.begin()); // drop the . | 77 extension.erase(extension.begin()); // drop the . |
75 file_type_info.extensions.resize(1); | 78 file_type_info.extensions.resize(1); |
(...skipping 10 matching lines...) Expand all Loading... |
86 &file_type_info, | 89 &file_type_info, |
87 0, | 90 0, |
88 FILE_PATH_LITERAL(""), | 91 FILE_PATH_LITERAL(""), |
89 owning_window, | 92 owning_window, |
90 NULL); | 93 NULL); |
91 } | 94 } |
92 | 95 |
93 DownloadFilePicker::~DownloadFilePicker() { | 96 DownloadFilePicker::~DownloadFilePicker() { |
94 } | 97 } |
95 | 98 |
96 void DownloadFilePicker::InitSuggestedPath(DownloadItem* item) { | 99 void DownloadFilePicker::InitSuggestedPath(DownloadItem* item, |
97 set_suggested_path(item->GetTargetFilePath()); | 100 const FilePath& suggested_path) { |
| 101 set_suggested_path(suggested_path); |
| 102 } |
| 103 |
| 104 void DownloadFilePicker::OnFileSelected(const FilePath& path) { |
| 105 file_selected_callback_.Run(path); |
| 106 delete this; |
98 } | 107 } |
99 | 108 |
100 void DownloadFilePicker::RecordFileSelected(const FilePath& path) { | 109 void DownloadFilePicker::RecordFileSelected(const FilePath& path) { |
101 FilePickerResult result = ComparePaths(suggested_path_, path); | 110 FilePickerResult result = ComparePaths(suggested_path_, path); |
102 RecordFilePickerResult(download_manager_, result); | 111 RecordFilePickerResult(download_manager_, result); |
103 } | 112 } |
104 | 113 |
105 void DownloadFilePicker::FileSelected(const FilePath& path, | 114 void DownloadFilePicker::FileSelected(const FilePath& path, |
106 int index, | 115 int index, |
107 void* params) { | 116 void* params) { |
108 RecordFileSelected(path); | 117 RecordFileSelected(path); |
109 | 118 OnFileSelected(path); |
110 if (download_manager_) | |
111 download_manager_->FileSelected(path, download_id_); | |
112 delete this; | |
113 } | 119 } |
114 | 120 |
115 void DownloadFilePicker::FileSelectionCanceled(void* params) { | 121 void DownloadFilePicker::FileSelectionCanceled(void* params) { |
116 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); | 122 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); |
117 if (download_manager_) | 123 OnFileSelected(FilePath()); |
118 download_manager_->FileSelectionCanceled(download_id_); | |
119 delete this; | |
120 } | 124 } |
OLD | NEW |