OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_dialog.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_dialog.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 7 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
8 #include "chrome/browser/ui/views/select_file_dialog_extension.h" | 8 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
9 #include "chrome/common/extensions/api/file_browser_private.h" | 9 #include "chrome/common/extensions/api/file_manager_private.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "ui/shell_dialogs/selected_file_info.h" | 11 #include "ui/shell_dialogs/selected_file_info.h" |
12 | 12 |
13 using content::BrowserThread; | 13 using content::BrowserThread; |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Computes the routing ID for SelectFileDialogExtension from the |function|. | 19 // Computes the routing ID for SelectFileDialogExtension from the |function|. |
20 SelectFileDialogExtension::RoutingID GetFileDialogRoutingID( | 20 SelectFileDialogExtension::RoutingID GetFileDialogRoutingID( |
21 ChromeAsyncExtensionFunction* function) { | 21 ChromeAsyncExtensionFunction* function) { |
22 return SelectFileDialogExtension::GetRoutingIDFromWebContents( | 22 return SelectFileDialogExtension::GetRoutingIDFromWebContents( |
23 function->GetAssociatedWebContents()); | 23 function->GetAssociatedWebContents()); |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 bool FileBrowserPrivateCancelDialogFunction::RunAsync() { | 28 bool FileManagerPrivateCancelDialogFunction::RunAsync() { |
29 SelectFileDialogExtension::OnFileSelectionCanceled( | 29 SelectFileDialogExtension::OnFileSelectionCanceled( |
30 GetFileDialogRoutingID(this)); | 30 GetFileDialogRoutingID(this)); |
31 SendResponse(true); | 31 SendResponse(true); |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 bool FileBrowserPrivateSelectFileFunction::RunAsync() { | 35 bool FileManagerPrivateSelectFileFunction::RunAsync() { |
36 using extensions::api::file_browser_private::SelectFile::Params; | 36 using extensions::api::file_manager_private::SelectFile::Params; |
37 const scoped_ptr<Params> params(Params::Create(*args_)); | 37 const scoped_ptr<Params> params(Params::Create(*args_)); |
38 EXTENSION_FUNCTION_VALIDATE(params); | 38 EXTENSION_FUNCTION_VALIDATE(params); |
39 | 39 |
40 std::vector<GURL> file_paths; | 40 std::vector<GURL> file_paths; |
41 file_paths.push_back(GURL(params->selected_path)); | 41 file_paths.push_back(GURL(params->selected_path)); |
42 | 42 |
43 file_manager::util::GetSelectedFileInfoLocalPathOption option = | 43 file_manager::util::GetSelectedFileInfoLocalPathOption option = |
44 file_manager::util::NO_LOCAL_PATH_RESOLUTION; | 44 file_manager::util::NO_LOCAL_PATH_RESOLUTION; |
45 if (params->should_return_local_path) { | 45 if (params->should_return_local_path) { |
46 option = params->for_opening ? | 46 option = params->for_opening ? |
47 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING : | 47 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING : |
48 file_manager::util::NEED_LOCAL_PATH_FOR_SAVING; | 48 file_manager::util::NEED_LOCAL_PATH_FOR_SAVING; |
49 } | 49 } |
50 | 50 |
51 file_manager::util::GetSelectedFileInfo( | 51 file_manager::util::GetSelectedFileInfo( |
52 render_view_host(), | 52 render_view_host(), |
53 GetProfile(), | 53 GetProfile(), |
54 file_paths, | 54 file_paths, |
55 option, | 55 option, |
56 base::Bind( | 56 base::Bind( |
57 &FileBrowserPrivateSelectFileFunction::GetSelectedFileInfoResponse, | 57 &FileManagerPrivateSelectFileFunction::GetSelectedFileInfoResponse, |
58 this, | 58 this, |
59 params->index)); | 59 params->index)); |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 void FileBrowserPrivateSelectFileFunction::GetSelectedFileInfoResponse( | 63 void FileManagerPrivateSelectFileFunction::GetSelectedFileInfoResponse( |
64 int index, | 64 int index, |
65 const std::vector<ui::SelectedFileInfo>& files) { | 65 const std::vector<ui::SelectedFileInfo>& files) { |
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
67 if (files.size() != 1) { | 67 if (files.size() != 1) { |
68 SendResponse(false); | 68 SendResponse(false); |
69 return; | 69 return; |
70 } | 70 } |
71 SelectFileDialogExtension::OnFileSelected(GetFileDialogRoutingID(this), | 71 SelectFileDialogExtension::OnFileSelected(GetFileDialogRoutingID(this), |
72 files[0], index); | 72 files[0], index); |
73 SendResponse(true); | 73 SendResponse(true); |
74 } | 74 } |
75 | 75 |
76 bool FileBrowserPrivateSelectFilesFunction::RunAsync() { | 76 bool FileManagerPrivateSelectFilesFunction::RunAsync() { |
77 using extensions::api::file_browser_private::SelectFiles::Params; | 77 using extensions::api::file_manager_private::SelectFiles::Params; |
78 const scoped_ptr<Params> params(Params::Create(*args_)); | 78 const scoped_ptr<Params> params(Params::Create(*args_)); |
79 EXTENSION_FUNCTION_VALIDATE(params); | 79 EXTENSION_FUNCTION_VALIDATE(params); |
80 | 80 |
81 std::vector<GURL> file_urls; | 81 std::vector<GURL> file_urls; |
82 for (size_t i = 0; i < params->selected_paths.size(); ++i) | 82 for (size_t i = 0; i < params->selected_paths.size(); ++i) |
83 file_urls.push_back(GURL(params->selected_paths[i])); | 83 file_urls.push_back(GURL(params->selected_paths[i])); |
84 | 84 |
85 file_manager::util::GetSelectedFileInfo( | 85 file_manager::util::GetSelectedFileInfo( |
86 render_view_host(), | 86 render_view_host(), |
87 GetProfile(), | 87 GetProfile(), |
88 file_urls, | 88 file_urls, |
89 params->should_return_local_path ? | 89 params->should_return_local_path ? |
90 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING : | 90 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING : |
91 file_manager::util::NO_LOCAL_PATH_RESOLUTION, | 91 file_manager::util::NO_LOCAL_PATH_RESOLUTION, |
92 base::Bind( | 92 base::Bind( |
93 &FileBrowserPrivateSelectFilesFunction::GetSelectedFileInfoResponse, | 93 &FileManagerPrivateSelectFilesFunction::GetSelectedFileInfoResponse, |
94 this)); | 94 this)); |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 void FileBrowserPrivateSelectFilesFunction::GetSelectedFileInfoResponse( | 98 void FileManagerPrivateSelectFilesFunction::GetSelectedFileInfoResponse( |
99 const std::vector<ui::SelectedFileInfo>& files) { | 99 const std::vector<ui::SelectedFileInfo>& files) { |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
101 SelectFileDialogExtension::OnMultiFilesSelected(GetFileDialogRoutingID(this), | 101 SelectFileDialogExtension::OnMultiFilesSelected(GetFileDialogRoutingID(this), |
102 files); | 102 files); |
103 SendResponse(true); | 103 SendResponse(true); |
104 } | 104 } |
105 | 105 |
106 } // namespace extensions | 106 } // namespace extensions |
OLD | NEW |