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

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: 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 if (!render_view_host_) {
247 NotifyRenderViewHost(render_view_host_, files, dialog_mode_); 238 RunFileChooserEnd();
239 return;
240 }
241
242 #if defined(OS_CHROMEOS)
243 if (!files.empty()) {
244 // Converts |files| into FileChooserFileInfo with handling of non-native
245 // files.
246 file_manager::util::ConvertSelectedFileInfoListToFileChooserFileInfoList(
247 file_manager::util::GetFileSystemContextForRenderViewHost(
248 profile_, render_view_host_),
249 web_contents_->GetSiteInstance()->GetSiteURL(),
250 files,
251 base::Bind(
252 &FileSelectHelper::ProcessSelectedFilesChromeOSAfterConversion,
253 this));
254 return;
255 }
256 #endif // defined(OS_CHROMEOS)
257
258 std::vector<content::FileChooserFileInfo> chooser_files;
259 for (const auto& file : files) {
260 content::FileChooserFileInfo chooser_file;
261 chooser_file.file_path = file.local_path;
262 chooser_file.display_name = file.display_name;
263 chooser_files.push_back(chooser_file);
264 }
265 render_view_host_->FilesSelectedInChooser(chooser_files, dialog_mode_);
248 266
249 // No members should be accessed from here on. 267 // No members should be accessed from here on.
250 RunFileChooserEnd(); 268 RunFileChooserEnd();
251 } 269 }
252 270
271 #if defined(OS_CHROMEOS)
272 void FileSelectHelper::ProcessSelectedFilesChromeOSAfterConversion(
273 scoped_ptr<std::vector<content::FileChooserFileInfo>> list) {
274 if (render_view_host_) {
275 render_view_host_->FilesSelectedInChooser(
276 list ? *list : std::vector<content::FileChooserFileInfo>(),
Lei Zhang 2014/10/20 19:07:50 In a later CL, maybe make GetFileSystemContextForR
hirono 2014/10/21 01:41:13 Got it. Thanks!
277 dialog_mode_);
278 }
279
280 // No members should be accessed from here on.
281 RunFileChooserEnd();
282 }
283 #endif // defined(OS_CHROMEOS)
284
253 void FileSelectHelper::DeleteTemporaryFiles() { 285 void FileSelectHelper::DeleteTemporaryFiles() {
254 BrowserThread::PostTask(BrowserThread::FILE, 286 BrowserThread::PostTask(BrowserThread::FILE,
255 FROM_HERE, 287 FROM_HERE,
256 base::Bind(&DeleteFiles, temporary_files_)); 288 base::Bind(&DeleteFiles, temporary_files_));
257 temporary_files_.clear(); 289 temporary_files_.clear();
258 } 290 }
259 291
260 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> 292 scoped_ptr<ui::SelectFileDialog::FileTypeInfo>
261 FileSelectHelper::GetFileTypesFromAcceptType( 293 FileSelectHelper::GetFileTypesFromAcceptType(
262 const std::vector<base::string16>& accept_types) { 294 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). 560 // of an extension or a "/" in the case of a MIME type).
529 std::string unused; 561 std::string unused;
530 if (accept_type.length() <= 1 || 562 if (accept_type.length() <= 1 ||
531 base::StringToLowerASCII(accept_type) != accept_type || 563 base::StringToLowerASCII(accept_type) != accept_type ||
532 base::TrimWhitespaceASCII(accept_type, base::TRIM_ALL, &unused) != 564 base::TrimWhitespaceASCII(accept_type, base::TRIM_ALL, &unused) !=
533 base::TRIM_NONE) { 565 base::TRIM_NONE) {
534 return false; 566 return false;
535 } 567 }
536 return true; 568 return true;
537 } 569 }
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