1 // Copyright 2013 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/chromeos/extensions/file_manager/private_api_dialog.h" 6 7 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 8 #include "chrome/browser/ui/views/select_file_dialog_extension.h" 9 #include "content/public/browser/browser_thread.h" 10 #include "ui/shell_dialogs/selected_file_info.h" 11 12 using content::BrowserThread; 13 14 namespace file_manager { 15 16 CancelFileDialogFunction::CancelFileDialogFunction() { 17 } 18 19 CancelFileDialogFunction::~CancelFileDialogFunction() { 20 } 21 22 bool CancelFileDialogFunction::RunImpl() { 23 int32 tab_id = util::GetTabId(dispatcher()); 24 SelectFileDialogExtension::OnFileSelectionCanceled(tab_id); 25 SendResponse(true); 26 return true; 27 } 28 29 SelectFileFunction::SelectFileFunction() { 30 } 31 32 SelectFileFunction::~SelectFileFunction() { 33 } 34 35 bool SelectFileFunction::RunImpl() { 36 if (args_->GetSize() != 4) { 37 return false; 38 } 39 std::string file_url; 40 args_->GetString(0, &file_url); 41 std::vector<GURL> file_paths; 42 file_paths.push_back(GURL(file_url)); 43 bool for_opening = false; 44 args_->GetBoolean(2, &for_opening); 45 bool need_local_path = false; 46 args_->GetBoolean(3, &need_local_path); 47 48 util::GetSelectedFileInfoLocalPathOption option = 49 util::NO_LOCAL_PATH_RESOLUTION; 50 if (need_local_path) { 51 option = for_opening ? 52 util::NEED_LOCAL_PATH_FOR_OPENING : util::NEED_LOCAL_PATH_FOR_SAVING; 53 } 54 55 util::GetSelectedFileInfo( 56 render_view_host(), 57 profile(), 58 file_paths, 59 option, 60 base::Bind(&SelectFileFunction::GetSelectedFileInfoResponse, this)); 61 return true; 62 } 63 64 void SelectFileFunction::GetSelectedFileInfoResponse( 65 const std::vector<ui::SelectedFileInfo>& files) { 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 if (files.size() != 1) { 68 SendResponse(false); 69 return; 70 } 71 int index; 72 args_->GetInteger(1, &index); 73 int32 tab_id = util::GetTabId(dispatcher()); 74 SelectFileDialogExtension::OnFileSelected(tab_id, files[0], index); 75 SendResponse(true); 76 } 77 78 SelectFilesFunction::SelectFilesFunction() { 79 } 80 81 SelectFilesFunction::~SelectFilesFunction() { 82 } 83 84 bool SelectFilesFunction::RunImpl() { 85 if (args_->GetSize() != 2) { 86 return false; 87 } 88 89 ListValue* path_list = NULL; 90 args_->GetList(0, &path_list); 91 DCHECK(path_list); 92 93 std::string virtual_path; 94 size_t len = path_list->GetSize(); 95 std::vector<GURL> file_urls; 96 file_urls.reserve(len); 97 for (size_t i = 0; i < len; ++i) { 98 path_list->GetString(i, &virtual_path); 99 file_urls.push_back(GURL(virtual_path)); 100 } 101 102 bool need_local_path = false; 103 args_->GetBoolean(1, &need_local_path); 104 105 util::GetSelectedFileInfo( 106 render_view_host(), 107 profile(), 108 file_urls, 109 need_local_path ? 110 util::NEED_LOCAL_PATH_FOR_OPENING : util::NO_LOCAL_PATH_RESOLUTION, 111 base::Bind(&SelectFilesFunction::GetSelectedFileInfoResponse, this)); 112 return true; 113 } 114 115 void SelectFilesFunction::GetSelectedFileInfoResponse( 116 const std::vector<ui::SelectedFileInfo>& files) { 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 118 int32 tab_id = util::GetTabId(dispatcher()); 119 SelectFileDialogExtension::OnMultiFilesSelected(tab_id, files); 120 SendResponse(true); 121 } 122 123 } // namespace file_manager 124