Commit 275bfbee authored by hirono's avatar hirono Committed by Commit bot

Add non-native file handling in FileSelectorHelper class.

In chrome OS, the file chooser dialog box may return paths that does not point to a native file. The CL lets FileSelectorHelper handle for the non-native paths and generate FileChooserFileInfo that refers non-native files.

BUG=126902
TEST=manually test to upload drive/local files

Review URL: https://codereview.chromium.org/663473002

Cr-Commit-Position: refs/heads/master@{#300399}
parent d2d1b62f
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/shell_dialogs/selected_file_info.h" #include "ui/shell_dialogs/selected_file_info.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "content/public/browser/site_instance.h"
#endif
using content::BrowserThread; using content::BrowserThread;
using content::FileChooserParams; using content::FileChooserParams;
using content::RenderViewHost; using content::RenderViewHost;
...@@ -45,20 +50,6 @@ namespace { ...@@ -45,20 +50,6 @@ namespace {
// the renderer must start at 0 and increase. // the renderer must start at 0 and increase.
const int kFileSelectEnumerationId = -1; const int kFileSelectEnumerationId = -1;
void NotifyRenderViewHost(
RenderViewHost* render_view_host,
const std::vector<ui::SelectedFileInfo>& files,
FileChooserParams::Mode dialog_mode) {
std::vector<content::FileChooserFileInfo> chooser_files;
for (size_t i = 0; i < files.size(); ++i) {
content::FileChooserFileInfo chooser_file;
chooser_file.file_path = files[i].local_path;
chooser_file.display_name = files[i].display_name;
chooser_files.push_back(chooser_file);
}
render_view_host->FilesSelectedInChooser(chooser_files, dialog_mode);
}
// Converts a list of FilePaths to a list of ui::SelectedFileInfo. // Converts a list of FilePaths to a list of ui::SelectedFileInfo.
std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList( std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList(
const std::vector<base::FilePath>& paths) { const std::vector<base::FilePath>& paths) {
...@@ -233,22 +224,63 @@ void FileSelectHelper::OnListDone(int id, int error) { ...@@ -233,22 +224,63 @@ void FileSelectHelper::OnListDone(int id, int error) {
std::vector<ui::SelectedFileInfo> selected_files = std::vector<ui::SelectedFileInfo> selected_files =
FilePathListToSelectedFileInfoList(entry->results_); FilePathListToSelectedFileInfoList(entry->results_);
if (id == kFileSelectEnumerationId) if (id == kFileSelectEnumerationId) {
NotifyRenderViewHost(entry->rvh_, selected_files, dialog_mode_); NotifyRenderViewHostAndEnd(selected_files);
else } else {
entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); entry->rvh_->DirectoryEnumerationFinished(id, entry->results_);
EnumerateDirectoryEnd();
EnumerateDirectoryEnd(); }
} }
void FileSelectHelper::NotifyRenderViewHostAndEnd( void FileSelectHelper::NotifyRenderViewHostAndEnd(
const std::vector<ui::SelectedFileInfo>& files) { const std::vector<ui::SelectedFileInfo>& files) {
if (render_view_host_) if (!render_view_host_) {
NotifyRenderViewHost(render_view_host_, files, dialog_mode_); RunFileChooserEnd();
return;
}
#if defined(OS_CHROMEOS)
if (!files.empty()) {
// Converts |files| into FileChooserFileInfo with handling of non-native
// files.
file_manager::util::ConvertSelectedFileInfoListToFileChooserFileInfoList(
file_manager::util::GetFileSystemContextForRenderViewHost(
profile_, render_view_host_),
web_contents_->GetSiteInstance()->GetSiteURL(),
files,
base::Bind(
&FileSelectHelper::ProcessSelectedFilesChromeOSAfterConversion,
this));
return;
}
#endif // defined(OS_CHROMEOS)
std::vector<content::FileChooserFileInfo> chooser_files;
for (const auto& file : files) {
content::FileChooserFileInfo chooser_file;
chooser_file.file_path = file.local_path;
chooser_file.display_name = file.display_name;
chooser_files.push_back(chooser_file);
}
render_view_host_->FilesSelectedInChooser(chooser_files, dialog_mode_);
// No members should be accessed from here on.
RunFileChooserEnd();
}
#if defined(OS_CHROMEOS)
void FileSelectHelper::ProcessSelectedFilesChromeOSAfterConversion(
scoped_ptr<std::vector<content::FileChooserFileInfo>> list) {
if (render_view_host_) {
render_view_host_->FilesSelectedInChooser(
list ? *list : std::vector<content::FileChooserFileInfo>(),
dialog_mode_);
}
// No members should be accessed from here on. // No members should be accessed from here on.
RunFileChooserEnd(); RunFileChooserEnd();
} }
#endif // defined(OS_CHROMEOS)
void FileSelectHelper::DeleteTemporaryFiles() { void FileSelectHelper::DeleteTemporaryFiles() {
BrowserThread::PostTask(BrowserThread::FILE, BrowserThread::PostTask(BrowserThread::FILE,
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
class Profile; class Profile;
namespace content { namespace content {
struct FileChooserFileInfo;
class RenderViewHost; class RenderViewHost;
class WebContents; class WebContents;
} }
...@@ -144,6 +145,11 @@ class FileSelectHelper ...@@ -144,6 +145,11 @@ class FileSelectHelper
// file chooser. // file chooser.
void NotifyRenderViewHostAndEnd( void NotifyRenderViewHostAndEnd(
const std::vector<ui::SelectedFileInfo>& files); const std::vector<ui::SelectedFileInfo>& files);
#if defined(OS_CHROMEOS)
// Sends the result to the render process, and call |RunFileChooserEnd|.
void ProcessSelectedFilesChromeOSAfterConversion(
scoped_ptr<std::vector<content::FileChooserFileInfo>> list);
#endif // defined(OS_CHROMEOS)
// Schedules the deletion of the files in |temporary_files_| and clears the // Schedules the deletion of the files in |temporary_files_| and clears the
// vector. // vector.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment