Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_dialog.cc
blob1ab190b6e78388d7d38a2a7ed86907cee910bf68
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.
5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_dialog.h"
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 "chrome/common/extensions/api/file_manager_private.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "ui/shell_dialogs/selected_file_info.h"
13 using content::BrowserThread;
15 namespace extensions {
17 namespace {
19 // Computes the routing ID for SelectFileDialogExtension from the |function|.
20 SelectFileDialogExtension::RoutingID GetFileDialogRoutingID(
21 ChromeAsyncExtensionFunction* function) {
22 return SelectFileDialogExtension::GetRoutingIDFromWebContents(
23 function->GetAssociatedWebContents());
26 } // namespace
28 bool FileManagerPrivateCancelDialogFunction::RunAsync() {
29 SelectFileDialogExtension::OnFileSelectionCanceled(
30 GetFileDialogRoutingID(this));
31 SendResponse(true);
32 return true;
35 bool FileManagerPrivateSelectFileFunction::RunAsync() {
36 using extensions::api::file_manager_private::SelectFile::Params;
37 const scoped_ptr<Params> params(Params::Create(*args_));
38 EXTENSION_FUNCTION_VALIDATE(params);
40 std::vector<GURL> file_paths;
41 file_paths.push_back(GURL(params->selected_path));
43 file_manager::util::GetSelectedFileInfoLocalPathOption option =
44 file_manager::util::NO_LOCAL_PATH_RESOLUTION;
45 if (params->should_return_local_path) {
46 option = params->for_opening ?
47 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING :
48 file_manager::util::NEED_LOCAL_PATH_FOR_SAVING;
51 file_manager::util::GetSelectedFileInfo(
52 render_frame_host(),
53 GetProfile(),
54 file_paths,
55 option,
56 base::Bind(
57 &FileManagerPrivateSelectFileFunction::GetSelectedFileInfoResponse,
58 this,
59 params->index));
60 return true;
63 void FileManagerPrivateSelectFileFunction::GetSelectedFileInfoResponse(
64 int index,
65 const std::vector<ui::SelectedFileInfo>& files) {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI);
67 if (files.size() != 1) {
68 SendResponse(false);
69 return;
71 SelectFileDialogExtension::OnFileSelected(GetFileDialogRoutingID(this),
72 files[0], index);
73 SendResponse(true);
76 bool FileManagerPrivateSelectFilesFunction::RunAsync() {
77 using extensions::api::file_manager_private::SelectFiles::Params;
78 const scoped_ptr<Params> params(Params::Create(*args_));
79 EXTENSION_FUNCTION_VALIDATE(params);
81 std::vector<GURL> file_urls;
82 for (size_t i = 0; i < params->selected_paths.size(); ++i)
83 file_urls.push_back(GURL(params->selected_paths[i]));
85 file_manager::util::GetSelectedFileInfo(
86 render_frame_host(),
87 GetProfile(),
88 file_urls,
89 params->should_return_local_path ?
90 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING :
91 file_manager::util::NO_LOCAL_PATH_RESOLUTION,
92 base::Bind(
93 &FileManagerPrivateSelectFilesFunction::GetSelectedFileInfoResponse,
94 this));
95 return true;
98 void FileManagerPrivateSelectFilesFunction::GetSelectedFileInfoResponse(
99 const std::vector<ui::SelectedFileInfo>& files) {
100 DCHECK_CURRENTLY_ON(BrowserThread::UI);
101 if (files.empty()) {
102 SendResponse(false);
103 return;
106 SelectFileDialogExtension::OnMultiFilesSelected(GetFileDialogRoutingID(this),
107 files);
108 SendResponse(true);
111 } // namespace extensions