| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/extensions/api/file_system/file_entry_picker.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string16.h" |
| 13 #include "chrome/browser/platform_util.h" |
| 14 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/shell_dialogs/selected_file_info.h" |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 FileEntryPicker::FileEntryPicker( |
| 22 content::WebContents* web_contents, |
| 23 const base::FilePath& suggested_name, |
| 24 const ui::SelectFileDialog::FileTypeInfo& file_type_info, |
| 25 ui::SelectFileDialog::Type picker_type, |
| 26 FilesSelectedCallback files_selected_callback, |
| 27 base::OnceClosure file_selection_canceled_callback) |
| 28 : files_selected_callback_(std::move(files_selected_callback)), |
| 29 file_selection_canceled_callback_( |
| 30 std::move(file_selection_canceled_callback)) { |
| 31 CHECK(web_contents); |
| 32 gfx::NativeWindow owning_window = |
| 33 platform_util::GetTopLevel(web_contents->GetNativeView()); |
| 34 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 35 this, base::MakeUnique<ChromeSelectFilePolicy>(web_contents).release()); |
| 36 select_file_dialog_->SelectFile( |
| 37 picker_type, base::string16(), suggested_name, &file_type_info, 0, |
| 38 base::FilePath::StringType(), owning_window, nullptr); |
| 39 } |
| 40 |
| 41 FileEntryPicker::~FileEntryPicker() {} |
| 42 |
| 43 void FileEntryPicker::FileSelected(const base::FilePath& path, |
| 44 int index, |
| 45 void* params) { |
| 46 MultiFilesSelected({path}, params); |
| 47 } |
| 48 |
| 49 void FileEntryPicker::FileSelectedWithExtraInfo( |
| 50 const ui::SelectedFileInfo& file, |
| 51 int index, |
| 52 void* params) { |
| 53 // Normally, file.local_path is used because it is a native path to the |
| 54 // local read-only cached file in the case of remote file system like |
| 55 // Chrome OS's Google Drive integration. Here, however, |file.file_path| is |
| 56 // necessary because we need to create a FileEntry denoting the remote file, |
| 57 // not its cache. On other platforms than Chrome OS, they are the same. |
| 58 // |
| 59 // TODO(kinaba): remove this, once after the file picker implements proper |
| 60 // switch of the path treatment depending on the |allowed_paths|. |
| 61 FileSelected(file.file_path, index, params); |
| 62 } |
| 63 |
| 64 void FileEntryPicker::MultiFilesSelected( |
| 65 const std::vector<base::FilePath>& files, |
| 66 void* params) { |
| 67 std::move(files_selected_callback_).Run(files); |
| 68 delete this; |
| 69 } |
| 70 |
| 71 void FileEntryPicker::MultiFilesSelectedWithExtraInfo( |
| 72 const std::vector<ui::SelectedFileInfo>& files, |
| 73 void* params) { |
| 74 std::vector<base::FilePath> paths; |
| 75 for (const auto& file : files) |
| 76 paths.push_back(file.file_path); |
| 77 MultiFilesSelected(paths, params); |
| 78 } |
| 79 |
| 80 void FileEntryPicker::FileSelectionCanceled(void* params) { |
| 81 std::move(file_selection_canceled_callback_).Run(); |
| 82 delete this; |
| 83 } |
| 84 |
| 85 } // namespace extensions |
| OLD | NEW |