Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_dialog.cc

Issue 141473004: Random cleanup for c/b/cros/extensions/file_manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extensions/extension_function_dispatcher.h"
9 #include "chrome/browser/ui/views/select_file_dialog_extension.h" 8 #include "chrome/browser/ui/views/select_file_dialog_extension.h"
10 #include "chrome/common/extensions/api/file_browser_private.h" 9 #include "chrome/common/extensions/api/file_browser_private.h"
11 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h"
13 #include "ui/shell_dialogs/selected_file_info.h" 11 #include "ui/shell_dialogs/selected_file_info.h"
14 12
15 using content::BrowserThread; 13 using content::BrowserThread;
16 14
17 namespace extensions { 15 namespace extensions {
18 16
19 namespace { 17 namespace {
20 18
21 // Returns the WebContents of the tab associated with the dispatcher. Returns 19 // Computes the routing ID for SelectFileDialogExtension from the |function|.
22 // NULL on error.
23 content::WebContents* GetWebContents(ExtensionFunctionDispatcher* dispatcher) {
24 if (!dispatcher) {
25 LOG(WARNING) << "No dispatcher";
26 return NULL;
27 }
28 if (!dispatcher->delegate()) {
29 LOG(WARNING) << "No delegate";
30 return NULL;
31 }
32 content::WebContents* web_contents =
33 dispatcher->delegate()->GetAssociatedWebContents();
34 if (!web_contents) {
35 LOG(WARNING) << "No associated tab contents";
36 return NULL;
37 }
38 return web_contents;
39 }
40
41 // Computes the routing ID for SelectFileDialogExtension from the |dispatcher|.
42 SelectFileDialogExtension::RoutingID GetFileDialogRoutingID( 20 SelectFileDialogExtension::RoutingID GetFileDialogRoutingID(
43 ExtensionFunctionDispatcher* dispatcher) { 21 ChromeAsyncExtensionFunction* function) {
44 return SelectFileDialogExtension::GetRoutingIDFromWebContents( 22 return SelectFileDialogExtension::GetRoutingIDFromWebContents(
45 GetWebContents(dispatcher)); 23 function->GetAssociatedWebContents());
46 } 24 }
47 25
48 } // namespace 26 } // namespace
49 27
50 bool FileBrowserPrivateCancelDialogFunction::RunImpl() { 28 bool FileBrowserPrivateCancelDialogFunction::RunImpl() {
51 const SelectFileDialogExtension::RoutingID routing_id = 29 SelectFileDialogExtension::OnFileSelectionCanceled(
52 GetFileDialogRoutingID(dispatcher()); 30 GetFileDialogRoutingID(this));
53 SelectFileDialogExtension::OnFileSelectionCanceled(routing_id);
54 SendResponse(true); 31 SendResponse(true);
55 return true; 32 return true;
56 } 33 }
57 34
58 bool FileBrowserPrivateSelectFileFunction::RunImpl() { 35 bool FileBrowserPrivateSelectFileFunction::RunImpl() {
59 using extensions::api::file_browser_private::SelectFile::Params; 36 using extensions::api::file_browser_private::SelectFile::Params;
60 const scoped_ptr<Params> params(Params::Create(*args_)); 37 const scoped_ptr<Params> params(Params::Create(*args_));
61 EXTENSION_FUNCTION_VALIDATE(params); 38 EXTENSION_FUNCTION_VALIDATE(params);
62 39
63 std::vector<GURL> file_paths; 40 std::vector<GURL> file_paths;
(...skipping 20 matching lines...) Expand all
84 } 61 }
85 62
86 void FileBrowserPrivateSelectFileFunction::GetSelectedFileInfoResponse( 63 void FileBrowserPrivateSelectFileFunction::GetSelectedFileInfoResponse(
87 int index, 64 int index,
88 const std::vector<ui::SelectedFileInfo>& files) { 65 const std::vector<ui::SelectedFileInfo>& files) {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
90 if (files.size() != 1) { 67 if (files.size() != 1) {
91 SendResponse(false); 68 SendResponse(false);
92 return; 69 return;
93 } 70 }
94 const SelectFileDialogExtension::RoutingID routing_id = 71 SelectFileDialogExtension::OnFileSelected(GetFileDialogRoutingID(this),
95 GetFileDialogRoutingID(dispatcher()); 72 files[0], index);
96 SelectFileDialogExtension::OnFileSelected(routing_id, files[0], index);
97 SendResponse(true); 73 SendResponse(true);
98 } 74 }
99 75
100 bool FileBrowserPrivateSelectFilesFunction::RunImpl() { 76 bool FileBrowserPrivateSelectFilesFunction::RunImpl() {
101 using extensions::api::file_browser_private::SelectFiles::Params; 77 using extensions::api::file_browser_private::SelectFiles::Params;
102 const scoped_ptr<Params> params(Params::Create(*args_)); 78 const scoped_ptr<Params> params(Params::Create(*args_));
103 EXTENSION_FUNCTION_VALIDATE(params); 79 EXTENSION_FUNCTION_VALIDATE(params);
104 80
105 const size_t len = params->selected_paths.size();
106 std::vector<GURL> file_urls; 81 std::vector<GURL> file_urls;
107 file_urls.reserve(len); 82 for (size_t i = 0; i < params->selected_paths.size(); ++i)
108 for (size_t i = 0; i < len; ++i) {
109 file_urls.push_back(GURL(params->selected_paths[i])); 83 file_urls.push_back(GURL(params->selected_paths[i]));
110 }
111 84
112 file_manager::util::GetSelectedFileInfo( 85 file_manager::util::GetSelectedFileInfo(
113 render_view_host(), 86 render_view_host(),
114 GetProfile(), 87 GetProfile(),
115 file_urls, 88 file_urls,
116 params->should_return_local_path ? 89 params->should_return_local_path ?
117 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING : 90 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING :
118 file_manager::util::NO_LOCAL_PATH_RESOLUTION, 91 file_manager::util::NO_LOCAL_PATH_RESOLUTION,
119 base::Bind( 92 base::Bind(
120 &FileBrowserPrivateSelectFilesFunction::GetSelectedFileInfoResponse, 93 &FileBrowserPrivateSelectFilesFunction::GetSelectedFileInfoResponse,
121 this)); 94 this));
122 return true; 95 return true;
123 } 96 }
124 97
125 void FileBrowserPrivateSelectFilesFunction::GetSelectedFileInfoResponse( 98 void FileBrowserPrivateSelectFilesFunction::GetSelectedFileInfoResponse(
126 const std::vector<ui::SelectedFileInfo>& files) { 99 const std::vector<ui::SelectedFileInfo>& files) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 const SelectFileDialogExtension::RoutingID routing_id = 101 SelectFileDialogExtension::OnMultiFilesSelected(GetFileDialogRoutingID(this),
129 GetFileDialogRoutingID(dispatcher()); 102 files);
130 SelectFileDialogExtension::OnMultiFilesSelected(routing_id, files);
131 SendResponse(true); 103 SendResponse(true);
132 } 104 }
133 105
134 } // namespace extensions 106 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698