| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/select_file_dialog.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
| 12 #include "chrome/browser/prefs/pref_service.h" | |
| 13 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 15 #include "chrome/common/pref_names.h" | |
| 16 #include "grit/generated_resources.h" | |
| 17 #include "ui/base/dialogs/selected_file_info.h" | |
| 18 #include "ui/base/dialogs/select_file_policy.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 | |
| 21 using content::WebContents; | |
| 22 | |
| 23 SelectFileDialog::FileTypeInfo::FileTypeInfo() : include_all_files(false) {} | |
| 24 | |
| 25 SelectFileDialog::FileTypeInfo::~FileTypeInfo() {} | |
| 26 | |
| 27 void SelectFileDialog::Listener::FileSelectedWithExtraInfo( | |
| 28 const ui::SelectedFileInfo& file, | |
| 29 int index, | |
| 30 void* params) { | |
| 31 FileSelected(file.path, index, params); | |
| 32 } | |
| 33 | |
| 34 void SelectFileDialog::Listener::MultiFilesSelectedWithExtraInfo( | |
| 35 const std::vector<ui::SelectedFileInfo>& files, | |
| 36 void* params) { | |
| 37 std::vector<FilePath> file_paths; | |
| 38 for (size_t i = 0; i < files.size(); ++i) | |
| 39 file_paths.push_back(files[i].path); | |
| 40 | |
| 41 MultiFilesSelected(file_paths, params); | |
| 42 } | |
| 43 | |
| 44 SelectFileDialog::SelectFileDialog(Listener* listener, | |
| 45 ui::SelectFilePolicy* policy) | |
| 46 : listener_(listener), | |
| 47 select_file_policy_(policy) { | |
| 48 DCHECK(listener_); | |
| 49 } | |
| 50 | |
| 51 SelectFileDialog::~SelectFileDialog() {} | |
| 52 | |
| 53 void SelectFileDialog::SelectFile(Type type, | |
| 54 const string16& title, | |
| 55 const FilePath& default_path, | |
| 56 const FileTypeInfo* file_types, | |
| 57 int file_type_index, | |
| 58 const FilePath::StringType& default_extension, | |
| 59 gfx::NativeWindow owning_window, | |
| 60 void* params) { | |
| 61 DCHECK(listener_); | |
| 62 | |
| 63 if (select_file_policy_.get() && | |
| 64 !select_file_policy_->CanOpenSelectFileDialog()) { | |
| 65 select_file_policy_->SelectFileDenied(); | |
| 66 | |
| 67 // Inform the listener that no file was selected. | |
| 68 // Post a task rather than calling FileSelectionCanceled directly to ensure | |
| 69 // that the listener is called asynchronously. | |
| 70 MessageLoop::current()->PostTask( | |
| 71 FROM_HERE, base::Bind(&SelectFileDialog::CancelFileSelection, this, | |
| 72 params)); | |
| 73 return; | |
| 74 } | |
| 75 | |
| 76 // Call the platform specific implementation of the file selection dialog. | |
| 77 SelectFileImpl(type, title, default_path, file_types, file_type_index, | |
| 78 default_extension, owning_window, params); | |
| 79 } | |
| 80 | |
| 81 bool SelectFileDialog::HasMultipleFileTypeChoices() { | |
| 82 return HasMultipleFileTypeChoicesImpl(); | |
| 83 } | |
| 84 | |
| 85 void SelectFileDialog::CancelFileSelection(void* params) { | |
| 86 if (listener_) | |
| 87 listener_->FileSelectionCanceled(params); | |
| 88 } | |
| OLD | NEW |