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
{
19 // Computes the routing ID for SelectFileDialogExtension from the |function|.
20 SelectFileDialogExtension::RoutingID
GetFileDialogRoutingID(
21 ChromeAsyncExtensionFunction
* function
) {
22 return SelectFileDialogExtension::GetRoutingIDFromWebContents(
23 function
->GetAssociatedWebContents());
28 bool FileManagerPrivateCancelDialogFunction::RunAsync() {
29 SelectFileDialogExtension::OnFileSelectionCanceled(
30 GetFileDialogRoutingID(this));
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(
57 &FileManagerPrivateSelectFileFunction::GetSelectedFileInfoResponse
,
63 void FileManagerPrivateSelectFileFunction::GetSelectedFileInfoResponse(
65 const std::vector
<ui::SelectedFileInfo
>& files
) {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
67 if (files
.size() != 1) {
71 SelectFileDialogExtension::OnFileSelected(GetFileDialogRoutingID(this),
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(
89 params
->should_return_local_path
?
90 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING
:
91 file_manager::util::NO_LOCAL_PATH_RESOLUTION
,
93 &FileManagerPrivateSelectFilesFunction::GetSelectedFileInfoResponse
,
98 void FileManagerPrivateSelectFilesFunction::GetSelectedFileInfoResponse(
99 const std::vector
<ui::SelectedFileInfo
>& files
) {
100 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
106 SelectFileDialogExtension::OnMultiFilesSelected(GetFileDialogRoutingID(this),
111 } // namespace extensions