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 "ui/base/dialogs/select_file_dialog_win.h" | 5 #include "ui/base/dialogs/select_file_dialog_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <commdlg.h> | 8 #include <commdlg.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/i18n/case_conversion.h" | 17 #include "base/i18n/case_conversion.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/message_loop_proxy.h" |
19 #include "base/string_split.h" | 20 #include "base/string_split.h" |
20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "base/win/metro.h" | 23 #include "base/win/metro.h" |
23 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
24 #include "base/win/scoped_comptr.h" | 25 #include "base/win/scoped_comptr.h" |
25 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
26 #include "grit/ui_strings.h" | 27 #include "grit/ui_strings.h" |
27 #include "ui/base/dialogs/base_shell_dialog_win.h" | 28 #include "ui/base/dialogs/base_shell_dialog_win.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 const std::wstring& default_extension, | 417 const std::wstring& default_extension, |
417 RunState run_state, | 418 RunState run_state, |
418 HWND owner, | 419 HWND owner, |
419 void* params) | 420 void* params) |
420 : type(type), | 421 : type(type), |
421 title(title), | 422 title(title), |
422 default_path(default_path), | 423 default_path(default_path), |
423 file_type_index(file_type_index), | 424 file_type_index(file_type_index), |
424 default_extension(default_extension), | 425 default_extension(default_extension), |
425 run_state(run_state), | 426 run_state(run_state), |
| 427 ui_proxy(MessageLoopForUI::current()->message_loop_proxy()), |
426 owner(owner), | 428 owner(owner), |
427 params(params) { | 429 params(params) { |
428 if (file_types) { | 430 if (file_types) { |
429 this->file_types = *file_types; | 431 this->file_types = *file_types; |
430 } else { | 432 } else { |
431 this->file_types.include_all_files = true; | 433 this->file_types.include_all_files = true; |
432 } | 434 } |
433 } | 435 } |
434 SelectFileDialog::Type type; | 436 SelectFileDialog::Type type; |
435 std::wstring title; | 437 std::wstring title; |
436 FilePath default_path; | 438 FilePath default_path; |
437 FileTypeInfo file_types; | 439 FileTypeInfo file_types; |
438 int file_type_index; | 440 int file_type_index; |
439 std::wstring default_extension; | 441 std::wstring default_extension; |
440 RunState run_state; | 442 RunState run_state; |
| 443 scoped_refptr<base::MessageLoopProxy> ui_proxy; |
441 HWND owner; | 444 HWND owner; |
442 void* params; | 445 void* params; |
443 }; | 446 }; |
444 | 447 |
445 // Shows the file selection dialog modal to |owner| and calls the result | 448 // Shows the file selection dialog modal to |owner| and calls the result |
446 // back on the ui thread. Run on the dialog thread. | 449 // back on the ui thread. Run on the dialog thread. |
447 void ExecuteSelectFile(const ExecuteSelectParams& params); | 450 void ExecuteSelectFile(const ExecuteSelectParams& params); |
448 | 451 |
449 // Notifies the listener that a folder was chosen. Run on the ui thread. | 452 // Notifies the listener that a folder was chosen. Run on the ui thread. |
450 void FileSelected(const FilePath& path, int index, | 453 void FileSelected(const FilePath& path, int index, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if (success) | 577 if (success) |
575 path = FilePath(path_as_wstring); | 578 path = FilePath(path_as_wstring); |
576 DisableOwner(params.run_state.owner); | 579 DisableOwner(params.run_state.owner); |
577 } else if (params.type == SELECT_OPEN_FILE) { | 580 } else if (params.type == SELECT_OPEN_FILE) { |
578 success = RunOpenFileDialog(params.title, filter, | 581 success = RunOpenFileDialog(params.title, filter, |
579 params.run_state.owner, &path); | 582 params.run_state.owner, &path); |
580 } else if (params.type == SELECT_OPEN_MULTI_FILE) { | 583 } else if (params.type == SELECT_OPEN_MULTI_FILE) { |
581 std::vector<FilePath> paths; | 584 std::vector<FilePath> paths; |
582 if (RunOpenMultiFileDialog(params.title, filter, | 585 if (RunOpenMultiFileDialog(params.title, filter, |
583 params.run_state.owner, &paths)) { | 586 params.run_state.owner, &paths)) { |
584 params.run_state.dialog_thread->message_loop()->PostTask( | 587 params.ui_proxy->PostTask( |
585 FROM_HERE, | 588 FROM_HERE, |
586 base::Bind(&SelectFileDialogImpl::MultiFilesSelected, this, paths, | 589 base::Bind(&SelectFileDialogImpl::MultiFilesSelected, this, paths, |
587 params.params, params.run_state)); | 590 params.params, params.run_state)); |
588 return; | 591 return; |
589 } | 592 } |
590 } | 593 } |
591 | 594 |
592 if (success) { | 595 if (success) { |
593 params.run_state.dialog_thread->message_loop()->PostTask( | 596 params.ui_proxy->PostTask( |
594 FROM_HERE, | 597 FROM_HERE, |
595 base::Bind(&SelectFileDialogImpl::FileSelected, this, path, | 598 base::Bind(&SelectFileDialogImpl::FileSelected, this, path, |
596 filter_index, params.params, params.run_state)); | 599 filter_index, params.params, params.run_state)); |
597 } else { | 600 } else { |
598 params.run_state.dialog_thread->message_loop()->PostTask( | 601 params.ui_proxy->PostTask( |
599 FROM_HERE, | 602 FROM_HERE, |
600 base::Bind(&SelectFileDialogImpl::FileNotSelected, this, params.params, | 603 base::Bind(&SelectFileDialogImpl::FileNotSelected, this, params.params, |
601 params.run_state)); | 604 params.run_state)); |
602 } | 605 } |
603 } | 606 } |
604 | 607 |
605 void SelectFileDialogImpl::FileSelected(const FilePath& selected_folder, | 608 void SelectFileDialogImpl::FileSelected(const FilePath& selected_folder, |
606 int index, | 609 int index, |
607 void* params, | 610 void* params, |
608 RunState run_state) { | 611 RunState run_state) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 return return_value; | 847 return return_value; |
845 } | 848 } |
846 | 849 |
847 SelectFileDialog* CreateWinSelectFileDialog( | 850 SelectFileDialog* CreateWinSelectFileDialog( |
848 SelectFileDialog::Listener* listener, | 851 SelectFileDialog::Listener* listener, |
849 SelectFilePolicy* policy) { | 852 SelectFilePolicy* policy) { |
850 return new SelectFileDialogImpl(listener, policy); | 853 return new SelectFileDialogImpl(listener, policy); |
851 } | 854 } |
852 | 855 |
853 } // namespace ui | 856 } // namespace ui |
OLD | NEW |