Chromium Code Reviews| Index: chrome/browser/extensions/api/file_system/file_system_api.cc |
| diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc |
| index 871125e0030030d2aab9d8263ef184ef5e896dbb..ffddc20ae795cfa3c0caf4fdb6e4e2b68cf96e95 100644 |
| --- a/chrome/browser/extensions/api/file_system/file_system_api.cc |
| +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc |
| @@ -241,16 +241,16 @@ class FileSystemChooseFileFunction::FilePicker |
| public: |
| FilePicker(FileSystemChooseFileFunction* function, |
| content::WebContents* web_contents, |
| - const FilePath& suggested_path, |
| + const FilePath& suggested_name, |
| SelectFileDialog::Type picker_type, |
| EntryType entry_type) |
| - : suggested_path_(suggested_path), |
| + : suggested_name_(suggested_name), |
| entry_type_(entry_type), |
| function_(function) { |
| select_file_dialog_ = SelectFileDialog::Create( |
| this, new ChromeSelectFilePolicy(web_contents)); |
| SelectFileDialog::FileTypeInfo file_type_info; |
| - FilePath::StringType extension = suggested_path.Extension(); |
| + FilePath::StringType extension = suggested_name.Extension(); |
| if (!extension.empty()) { |
| extension.erase(extension.begin()); // drop the . |
| file_type_info.extensions.resize(1); |
| @@ -279,7 +279,7 @@ class FileSystemChooseFileFunction::FilePicker |
| select_file_dialog_->SelectFile(picker_type, |
| string16(), |
| - suggested_path, |
| + suggested_name, |
| &file_type_info, 0, FILE_PATH_LITERAL(""), |
| owning_window, NULL); |
| } |
| @@ -300,7 +300,7 @@ class FileSystemChooseFileFunction::FilePicker |
| delete this; |
| } |
| - FilePath suggested_path_; |
| + FilePath suggested_name_; |
| EntryType entry_type_; |
| @@ -311,7 +311,7 @@ class FileSystemChooseFileFunction::FilePicker |
| }; |
| bool FileSystemChooseFileFunction::ShowPicker( |
| - const FilePath& suggested_path, |
| + const FilePath& suggested_name, |
| SelectFileDialog::Type picker_type, |
| EntryType entry_type) { |
| ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
| @@ -327,7 +327,7 @@ bool FileSystemChooseFileFunction::ShowPicker( |
| // its destruction (and subsequent sending of the function response) until the |
| // user has selected a file or cancelled the picker. At that point, the picker |
| // will delete itself, which will also free the function instance. |
| - new FilePicker(this, shell_window->web_contents(), suggested_path, |
| + new FilePicker(this, shell_window->web_contents(), suggested_name, |
| picker_type, entry_type); |
| return true; |
| } |
| @@ -372,18 +372,35 @@ bool FileSystemChooseFileFunction::RunImpl() { |
| scoped_ptr<ChooseFile::Params> params(ChooseFile::Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + FilePath suggested_name; |
| EntryType entry_type = READ_ONLY; |
| SelectFileDialog::Type picker_type = SelectFileDialog::SELECT_OPEN_FILE; |
| + |
| file_system::ChooseFileOptions* options = params->options.get(); |
| - if (options && options->type.get()) { |
| - if (*options->type == kOpenWritableFileOption) { |
| - entry_type = WRITABLE; |
| - } else if (*options->type == kSaveFileOption) { |
| - entry_type = WRITABLE; |
| - picker_type = SelectFileDialog::SELECT_SAVEAS_FILE; |
| - } else if (*options->type != kOpenFileOption) { |
| - error_ = kUnknownChooseFileType; |
| - return false; |
| + if (options) { |
| + if (options->type.get()) { |
| + if (*options->type == kOpenWritableFileOption) { |
| + entry_type = WRITABLE; |
| + } else if (*options->type == kSaveFileOption) { |
| + entry_type = WRITABLE; |
| + picker_type = SelectFileDialog::SELECT_SAVEAS_FILE; |
| + } else if (*options->type != kOpenFileOption) { |
| + error_ = kUnknownChooseFileType; |
| + return false; |
| + } |
| + } |
| + |
| + if (options->suggested_name.get()) { |
| + suggested_name = FilePath::FromUTF8Unsafe( |
| + *options->suggested_name.get()); |
| + |
| + // Don't allow any path components; shorten to the base name. This should |
| + // result in a relative path, but in some cases may not be. Clear the |
|
benwells
2012/07/12 08:48:01
nit: ...cases may not.
thorogood
2012/07/13 01:15:22
Done.
|
| + // suggestion for safety if this is the case. |
| + suggested_name = suggested_name.BaseName(); |
| + if (suggested_name.IsAbsolute()) { |
| + suggested_name = FilePath(); |
| + } |
| } |
| } |
| @@ -392,7 +409,7 @@ bool FileSystemChooseFileFunction::RunImpl() { |
| return false; |
| } |
| - return ShowPicker(FilePath(), picker_type, entry_type); |
| + return ShowPicker(suggested_name, picker_type, entry_type); |
| } |
| } // namespace extensions |