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/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/render_messages.h" | |
16 #include "chrome/common/render_messages_params.h" | |
17 #include "content/browser/renderer_host/render_view_host.h" | 15 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/renderer_host/render_widget_host_view.h" | 16 #include "content/browser/renderer_host/render_widget_host_view.h" |
19 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
20 #include "content/common/notification_details.h" | 18 #include "content/common/notification_details.h" |
21 #include "content/common/notification_source.h" | 19 #include "content/common/notification_source.h" |
| 20 #include "content/common/view_messages.h" |
22 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
23 #include "net/base/mime_util.h" | 22 #include "net/base/mime_util.h" |
24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
25 | 24 |
26 FileSelectHelper::FileSelectHelper(Profile* profile) | 25 FileSelectHelper::FileSelectHelper(Profile* profile) |
27 : profile_(profile), | 26 : profile_(profile), |
28 render_view_host_(NULL), | 27 render_view_host_(NULL), |
29 select_file_dialog_(), | 28 select_file_dialog_(), |
30 dialog_type_(SelectFileDialog::SELECT_OPEN_FILE) { | 29 dialog_type_(SelectFileDialog::SELECT_OPEN_FILE) { |
31 } | 30 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 render_view_host_ = render_view_host; | 198 render_view_host_ = render_view_host; |
200 notification_registrar_.RemoveAll(); | 199 notification_registrar_.RemoveAll(); |
201 notification_registrar_.Add(this, | 200 notification_registrar_.Add(this, |
202 NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 201 NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
203 Source<RenderViewHost>(render_view_host)); | 202 Source<RenderViewHost>(render_view_host)); |
204 | 203 |
205 if (!select_file_dialog_.get()) | 204 if (!select_file_dialog_.get()) |
206 select_file_dialog_ = SelectFileDialog::Create(this); | 205 select_file_dialog_ = SelectFileDialog::Create(this); |
207 | 206 |
208 switch (params.mode) { | 207 switch (params.mode) { |
209 case ViewHostMsg_RunFileChooser_Params::Open: | 208 case ViewHostMsg_RunFileChooser_Mode::Open: |
210 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; | 209 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; |
211 break; | 210 break; |
212 case ViewHostMsg_RunFileChooser_Params::OpenMultiple: | 211 case ViewHostMsg_RunFileChooser_Mode::OpenMultiple: |
213 dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE; | 212 dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE; |
214 break; | 213 break; |
215 case ViewHostMsg_RunFileChooser_Params::OpenFolder: | 214 case ViewHostMsg_RunFileChooser_Mode::OpenFolder: |
216 dialog_type_ = SelectFileDialog::SELECT_FOLDER; | 215 dialog_type_ = SelectFileDialog::SELECT_FOLDER; |
217 break; | 216 break; |
218 case ViewHostMsg_RunFileChooser_Params::Save: | 217 case ViewHostMsg_RunFileChooser_Mode::Save: |
219 dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; | 218 dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; |
220 break; | 219 break; |
221 default: | 220 default: |
222 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning. | 221 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning. |
223 NOTREACHED(); | 222 NOTREACHED(); |
224 } | 223 } |
225 scoped_ptr<SelectFileDialog::FileTypeInfo> file_types( | 224 scoped_ptr<SelectFileDialog::FileTypeInfo> file_types( |
226 GetFileTypesFromAcceptType(params.accept_types)); | 225 GetFileTypesFromAcceptType(params.accept_types)); |
227 FilePath default_file_name = params.default_file_name; | 226 FilePath default_file_name = params.default_file_name; |
228 if (default_file_name.empty()) | 227 if (default_file_name.empty()) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return handled; | 264 return handled; |
266 } | 265 } |
267 | 266 |
268 void FileSelectObserver::OnRunFileChooser( | 267 void FileSelectObserver::OnRunFileChooser( |
269 const ViewHostMsg_RunFileChooser_Params& params) { | 268 const ViewHostMsg_RunFileChooser_Params& params) { |
270 if (!file_select_helper_.get()) | 269 if (!file_select_helper_.get()) |
271 file_select_helper_.reset(new FileSelectHelper(tab_contents()->profile())); | 270 file_select_helper_.reset(new FileSelectHelper(tab_contents()->profile())); |
272 file_select_helper_->RunFileChooser(tab_contents()->render_view_host(), | 271 file_select_helper_->RunFileChooser(tab_contents()->render_view_host(), |
273 params); | 272 params); |
274 } | 273 } |
OLD | NEW |