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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 10696188: Adds the optional suggestedName to the chooseFile fileSystem API call. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 | « no previous file | chrome/common/extensions/api/file_system.idl » ('j') | 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/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Handles showing a dialog to the user to ask for the filename for a file to 237 // Handles showing a dialog to the user to ask for the filename for a file to
238 // save or open. 238 // save or open.
239 class FileSystemChooseFileFunction::FilePicker 239 class FileSystemChooseFileFunction::FilePicker
240 : public SelectFileDialog::Listener { 240 : public SelectFileDialog::Listener {
241 public: 241 public:
242 FilePicker(FileSystemChooseFileFunction* function, 242 FilePicker(FileSystemChooseFileFunction* function,
243 content::WebContents* web_contents, 243 content::WebContents* web_contents,
244 const FilePath& suggested_path, 244 const FilePath& suggested_path,
245 SelectFileDialog::Type picker_type, 245 SelectFileDialog::Type picker_type,
246 EntryType entry_type) 246 EntryType entry_type)
247 : suggested_path_(suggested_path), 247 : suggested_path_(suggested_path),
benwells 2012/07/12 08:23:33 Nit: change suggested_path here to suggested_name.
thorogood 2012/07/12 08:40:20 Done, and I've changed it in a few other places in
248 entry_type_(entry_type), 248 entry_type_(entry_type),
249 function_(function) { 249 function_(function) {
250 select_file_dialog_ = SelectFileDialog::Create( 250 select_file_dialog_ = SelectFileDialog::Create(
251 this, new ChromeSelectFilePolicy(web_contents)); 251 this, new ChromeSelectFilePolicy(web_contents));
252 SelectFileDialog::FileTypeInfo file_type_info; 252 SelectFileDialog::FileTypeInfo file_type_info;
253 FilePath::StringType extension = suggested_path.Extension(); 253 FilePath::StringType extension = suggested_path.Extension();
254 if (!extension.empty()) { 254 if (!extension.empty()) {
255 extension.erase(extension.begin()); // drop the . 255 extension.erase(extension.begin()); // drop the .
256 file_type_info.extensions.resize(1); 256 file_type_info.extensions.resize(1);
257 file_type_info.extensions[0].push_back(extension); 257 file_type_info.extensions[0].push_back(extension);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 365
366 void FileSystemChooseFileFunction::FileSelectionCanceled() { 366 void FileSystemChooseFileFunction::FileSelectionCanceled() {
367 error_ = kUserCancelled; 367 error_ = kUserCancelled;
368 SendResponse(false); 368 SendResponse(false);
369 } 369 }
370 370
371 bool FileSystemChooseFileFunction::RunImpl() { 371 bool FileSystemChooseFileFunction::RunImpl() {
372 scoped_ptr<ChooseFile::Params> params(ChooseFile::Params::Create(*args_)); 372 scoped_ptr<ChooseFile::Params> params(ChooseFile::Params::Create(*args_));
373 EXTENSION_FUNCTION_VALIDATE(params.get()); 373 EXTENSION_FUNCTION_VALIDATE(params.get());
374 374
375 FilePath suggested_path;
benwells 2012/07/12 08:23:33 Nit: suggested_name
thorogood 2012/07/12 08:40:20 Done.
375 EntryType entry_type = READ_ONLY; 376 EntryType entry_type = READ_ONLY;
376 SelectFileDialog::Type picker_type = SelectFileDialog::SELECT_OPEN_FILE; 377 SelectFileDialog::Type picker_type = SelectFileDialog::SELECT_OPEN_FILE;
378
377 file_system::ChooseFileOptions* options = params->options.get(); 379 file_system::ChooseFileOptions* options = params->options.get();
378 if (options && options->type.get()) { 380 if (options) {
379 if (*options->type == kOpenWritableFileOption) { 381 if (options->type.get()) {
380 entry_type = WRITABLE; 382 if (*options->type == kOpenWritableFileOption) {
381 } else if (*options->type == kSaveFileOption) { 383 entry_type = WRITABLE;
382 entry_type = WRITABLE; 384 } else if (*options->type == kSaveFileOption) {
383 picker_type = SelectFileDialog::SELECT_SAVEAS_FILE; 385 entry_type = WRITABLE;
384 } else if (*options->type != kOpenFileOption) { 386 picker_type = SelectFileDialog::SELECT_SAVEAS_FILE;
385 error_ = kUnknownChooseFileType; 387 } else if (*options->type != kOpenFileOption) {
386 return false; 388 error_ = kUnknownChooseFileType;
389 return false;
390 }
391 }
392
393 if (options->suggested_name.get()) {
394 suggested_path = FilePath::FromUTF8Unsafe(*options->suggested_name.get())
benwells 2012/07/12 08:23:33 We should just use BaseName, so if an extension tr
thorogood 2012/07/12 08:40:20 Done. BaseName may still return an absolute path i
387 } 395 }
388 } 396 }
389 397
390 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { 398 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) {
391 error_ = kRequiresFileSystemWriteError; 399 error_ = kRequiresFileSystemWriteError;
392 return false; 400 return false;
393 } 401 }
394 402
395 return ShowPicker(FilePath(), picker_type, entry_type); 403 return ShowPicker(suggested_path, picker_type, entry_type);
396 } 404 }
397 405
398 } // namespace extensions 406 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/file_system.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698