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

Side by Side Diff: chrome/browser/file_select_helper.cc

Issue 663473002: Add non-native file handling in FileSelectorHelper class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 6 years, 2 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
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_select_helper.h" 5 #include "chrome/browser/file_select_helper.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/notification_types.h" 25 #include "content/public/browser/notification_types.h"
26 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/render_widget_host_view.h" 27 #include "content/public/browser/render_widget_host_view.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/file_chooser_file_info.h" 29 #include "content/public/common/file_chooser_file_info.h"
30 #include "content/public/common/file_chooser_params.h" 30 #include "content/public/common/file_chooser_params.h"
31 #include "net/base/mime_util.h" 31 #include "net/base/mime_util.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/shell_dialogs/selected_file_info.h" 33 #include "ui/shell_dialogs/selected_file_info.h"
34 34
35 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
37 #include "content/public/browser/site_instance.h"
38 #endif
39
35 using content::BrowserThread; 40 using content::BrowserThread;
36 using content::FileChooserParams; 41 using content::FileChooserParams;
37 using content::RenderViewHost; 42 using content::RenderViewHost;
38 using content::RenderWidgetHost; 43 using content::RenderWidgetHost;
39 using content::WebContents; 44 using content::WebContents;
40 45
41 namespace { 46 namespace {
42 47
43 // There is only one file-selection happening at any given time, 48 // There is only one file-selection happening at any given time,
44 // so we allocate an enumeration ID for that purpose. All IDs from 49 // so we allocate an enumeration ID for that purpose. All IDs from
45 // the renderer must start at 0 and increase. 50 // the renderer must start at 0 and increase.
46 const int kFileSelectEnumerationId = -1; 51 const int kFileSelectEnumerationId = -1;
47 52
48 void NotifyRenderViewHost(
49 RenderViewHost* render_view_host,
50 const std::vector<ui::SelectedFileInfo>& files,
51 FileChooserParams::Mode dialog_mode) {
52 std::vector<content::FileChooserFileInfo> chooser_files;
53 for (size_t i = 0; i < files.size(); ++i) {
54 content::FileChooserFileInfo chooser_file;
55 chooser_file.file_path = files[i].local_path;
56 chooser_file.display_name = files[i].display_name;
57 chooser_files.push_back(chooser_file);
58 }
59 render_view_host->FilesSelectedInChooser(chooser_files, dialog_mode);
60 }
61
62 // Converts a list of FilePaths to a list of ui::SelectedFileInfo. 53 // Converts a list of FilePaths to a list of ui::SelectedFileInfo.
63 std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList( 54 std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList(
64 const std::vector<base::FilePath>& paths) { 55 const std::vector<base::FilePath>& paths) {
65 std::vector<ui::SelectedFileInfo> selected_files; 56 std::vector<ui::SelectedFileInfo> selected_files;
66 for (size_t i = 0; i < paths.size(); ++i) { 57 for (size_t i = 0; i < paths.size(); ++i) {
67 selected_files.push_back( 58 selected_files.push_back(
68 ui::SelectedFileInfo(paths[i], paths[i])); 59 ui::SelectedFileInfo(paths[i], paths[i]));
69 } 60 }
70 return selected_files; 61 return selected_files;
71 } 62 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (!entry->rvh_) 217 if (!entry->rvh_)
227 return; 218 return;
228 if (error) { 219 if (error) {
229 FileSelectionCanceled(NULL); 220 FileSelectionCanceled(NULL);
230 return; 221 return;
231 } 222 }
232 223
233 std::vector<ui::SelectedFileInfo> selected_files = 224 std::vector<ui::SelectedFileInfo> selected_files =
234 FilePathListToSelectedFileInfoList(entry->results_); 225 FilePathListToSelectedFileInfoList(entry->results_);
235 226
236 if (id == kFileSelectEnumerationId) 227 if (id == kFileSelectEnumerationId) {
237 NotifyRenderViewHost(entry->rvh_, selected_files, dialog_mode_); 228 NotifyRenderViewHostAndEnd(selected_files);
238 else 229 } else {
239 entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); 230 entry->rvh_->DirectoryEnumerationFinished(id, entry->results_);
240 231 EnumerateDirectoryEnd();
241 EnumerateDirectoryEnd(); 232 }
242 } 233 }
243 234
244 void FileSelectHelper::NotifyRenderViewHostAndEnd( 235 void FileSelectHelper::NotifyRenderViewHostAndEnd(
245 const std::vector<ui::SelectedFileInfo>& files) { 236 const std::vector<ui::SelectedFileInfo>& files) {
246 if (render_view_host_) 237 std::vector<content::FileChooserFileInfo> chooser_files;
247 NotifyRenderViewHost(render_view_host_, files, dialog_mode_); 238
239 if (!render_view_host_) {
240 RunFileChooserEnd();
241 return;
242 }
243
244 #if defined(OS_CHROMEOS)
245 if (!files.empty()) {
246 // Converts |files| into FileChooserFileInfo with handling of non-native
247 // files.
248 file_manager::util::ConvertSelectedFileInfoListToFileChooserFileInfoList(
249 file_manager::util::GetFileSystemContextForRenderViewHost(
250 profile_, render_view_host_),
251 web_contents_->GetSiteInstance()->GetSiteURL(),
252 files,
253 base::Bind(
254 &FileSelectHelper::ProcessSelectedFilesChromeOSAfterConversion,
255 this));
256 return;
257 }
258 #endif // defined(OS_CHROMEOS)
259
260 for (size_t i = 0; i < files.size(); ++i) {
261 chooser_files[i].file_path = files[i].local_path;
262 chooser_files[i].display_name = files[i].display_name;
Avi (use Gerrit) 2014/10/17 19:38:52 How does this work? chooser_files starts empty, an
hirono 2014/10/20 04:10:48 Yes, this was completely wrong... Fixed.
263 }
264 render_view_host_->FilesSelectedInChooser(chooser_files, dialog_mode_);
248 265
249 // No members should be accessed from here on. 266 // No members should be accessed from here on.
250 RunFileChooserEnd(); 267 RunFileChooserEnd();
251 } 268 }
252 269
270 #if defined(OS_CHROMEOS)
271 void FileSelectHelper::ProcessSelectedFilesChromeOSAfterConversion(
272 scoped_ptr<std::vector<content::FileChooserFileInfo>> list) {
273 if (render_view_host_) {
274 render_view_host_->FilesSelectedInChooser(
275 list ? *list : std::vector<content::FileChooserFileInfo>(),
276 dialog_mode_);
277 }
278
279 // No members should be accessed from here on.
280 RunFileChooserEnd();
281 }
282 #endif // defined(OS_CHROMEOS)
283
253 void FileSelectHelper::DeleteTemporaryFiles() { 284 void FileSelectHelper::DeleteTemporaryFiles() {
254 BrowserThread::PostTask(BrowserThread::FILE, 285 BrowserThread::PostTask(BrowserThread::FILE,
255 FROM_HERE, 286 FROM_HERE,
256 base::Bind(&DeleteFiles, temporary_files_)); 287 base::Bind(&DeleteFiles, temporary_files_));
257 temporary_files_.clear(); 288 temporary_files_.clear();
258 } 289 }
259 290
260 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> 291 scoped_ptr<ui::SelectFileDialog::FileTypeInfo>
261 FileSelectHelper::GetFileTypesFromAcceptType( 292 FileSelectHelper::GetFileTypesFromAcceptType(
262 const std::vector<base::string16>& accept_types) { 293 const std::vector<base::string16>& accept_types) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 // of an extension or a "/" in the case of a MIME type). 559 // of an extension or a "/" in the case of a MIME type).
529 std::string unused; 560 std::string unused;
530 if (accept_type.length() <= 1 || 561 if (accept_type.length() <= 1 ||
531 base::StringToLowerASCII(accept_type) != accept_type || 562 base::StringToLowerASCII(accept_type) != accept_type ||
532 base::TrimWhitespaceASCII(accept_type, base::TRIM_ALL, &unused) != 563 base::TrimWhitespaceASCII(accept_type, base::TRIM_ALL, &unused) !=
533 base::TRIM_NONE) { 564 base::TRIM_NONE) {
534 return false; 565 return false;
535 } 566 }
536 return true; 567 return true;
537 } 568 }
OLDNEW
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698