| OLD | NEW |
| 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 "apps/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "apps/app_window_registry.h" | 8 #include "apps/app_window_registry.h" |
| 9 #include "apps/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 error_path.BaseName().AsUTF8Unsafe().c_str()); | 291 error_path.BaseName().AsUTF8Unsafe().c_str()); |
| 292 SendResponse(false); | 292 SendResponse(false); |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool FileSystemGetWritableEntryFunction::RunAsync() { | 295 bool FileSystemGetWritableEntryFunction::RunAsync() { |
| 296 std::string filesystem_name; | 296 std::string filesystem_name; |
| 297 std::string filesystem_path; | 297 std::string filesystem_path; |
| 298 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 298 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 299 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 299 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 300 | 300 |
| 301 if (!app_file_handler_util::HasFileSystemWritePermission(extension_)) { | 301 if (!app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { |
| 302 error_ = kRequiresFileSystemWriteError; | 302 error_ = kRequiresFileSystemWriteError; |
| 303 return false; | 303 return false; |
| 304 } | 304 } |
| 305 | 305 |
| 306 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, | 306 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, |
| 307 filesystem_path, | 307 filesystem_path, |
| 308 render_view_host_, | 308 render_view_host_, |
| 309 &path_, | 309 &path_, |
| 310 &error_)) | 310 &error_)) |
| 311 return false; | 311 return false; |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 this)); | 680 this)); |
| 681 } | 681 } |
| 682 return; | 682 return; |
| 683 } | 683 } |
| 684 | 684 |
| 685 content::BrowserThread::PostTask( | 685 content::BrowserThread::PostTask( |
| 686 content::BrowserThread::UI, | 686 content::BrowserThread::UI, |
| 687 FROM_HERE, | 687 FROM_HERE, |
| 688 base::Bind( | 688 base::Bind( |
| 689 CreateDirectoryAccessConfirmationDialog, | 689 CreateDirectoryAccessConfirmationDialog, |
| 690 app_file_handler_util::HasFileSystemWritePermission(extension_), | 690 app_file_handler_util::HasFileSystemWritePermission( |
| 691 extension_.get()), |
| 691 base::UTF8ToUTF16(extension_->name()), | 692 base::UTF8ToUTF16(extension_->name()), |
| 692 web_contents, | 693 web_contents, |
| 693 base::Bind( | 694 base::Bind( |
| 694 &FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, | 695 &FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, |
| 695 this, | 696 this, |
| 696 paths), | 697 paths), |
| 697 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, | 698 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, |
| 698 this))); | 699 this))); |
| 699 return; | 700 return; |
| 700 } | 701 } |
| 701 } | 702 } |
| 702 | 703 |
| 703 content::BrowserThread::PostTask( | 704 content::BrowserThread::PostTask( |
| 704 content::BrowserThread::UI, | 705 content::BrowserThread::UI, |
| 705 FROM_HERE, | 706 FROM_HERE, |
| 706 base::Bind(&FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, | 707 base::Bind(&FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, |
| 707 this, paths)); | 708 this, paths)); |
| 708 } | 709 } |
| 709 | 710 |
| 710 void FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed( | 711 void FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed( |
| 711 const std::vector<base::FilePath>& paths) { | 712 const std::vector<base::FilePath>& paths) { |
| 712 if (app_file_handler_util::HasFileSystemWritePermission(extension_)) { | 713 if (app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { |
| 713 PrepareFilesForWritableApp(paths); | 714 PrepareFilesForWritableApp(paths); |
| 714 return; | 715 return; |
| 715 } | 716 } |
| 716 | 717 |
| 717 // Don't need to check the file, it's for reading. | 718 // Don't need to check the file, it's for reading. |
| 718 RegisterFileSystemsAndSendResponse(paths); | 719 RegisterFileSystemsAndSendResponse(paths); |
| 719 } | 720 } |
| 720 | 721 |
| 721 void FileSystemChooseEntryFunction::BuildFileTypeInfo( | 722 void FileSystemChooseEntryFunction::BuildFileTypeInfo( |
| 722 ui::SelectFileDialog::FileTypeInfo* file_type_info, | 723 ui::SelectFileDialog::FileTypeInfo* file_type_info, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 ui::SelectFileDialog::Type picker_type = | 788 ui::SelectFileDialog::Type picker_type = |
| 788 ui::SelectFileDialog::SELECT_OPEN_FILE; | 789 ui::SelectFileDialog::SELECT_OPEN_FILE; |
| 789 | 790 |
| 790 file_system::ChooseEntryOptions* options = params->options.get(); | 791 file_system::ChooseEntryOptions* options = params->options.get(); |
| 791 if (options) { | 792 if (options) { |
| 792 multiple_ = options->accepts_multiple; | 793 multiple_ = options->accepts_multiple; |
| 793 if (multiple_) | 794 if (multiple_) |
| 794 picker_type = ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE; | 795 picker_type = ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE; |
| 795 | 796 |
| 796 if (options->type == file_system::CHOOSE_ENTRY_TYPE_OPENWRITABLEFILE && | 797 if (options->type == file_system::CHOOSE_ENTRY_TYPE_OPENWRITABLEFILE && |
| 797 !app_file_handler_util::HasFileSystemWritePermission(extension_)) { | 798 !app_file_handler_util::HasFileSystemWritePermission( |
| 799 extension_.get())) { |
| 798 error_ = kRequiresFileSystemWriteError; | 800 error_ = kRequiresFileSystemWriteError; |
| 799 return false; | 801 return false; |
| 800 } else if (options->type == file_system::CHOOSE_ENTRY_TYPE_SAVEFILE) { | 802 } else if (options->type == file_system::CHOOSE_ENTRY_TYPE_SAVEFILE) { |
| 801 if (!app_file_handler_util::HasFileSystemWritePermission(extension_)) { | 803 if (!app_file_handler_util::HasFileSystemWritePermission( |
| 804 extension_.get())) { |
| 802 error_ = kRequiresFileSystemWriteError; | 805 error_ = kRequiresFileSystemWriteError; |
| 803 return false; | 806 return false; |
| 804 } | 807 } |
| 805 if (multiple_) { | 808 if (multiple_) { |
| 806 error_ = kMultipleUnsupportedError; | 809 error_ = kMultipleUnsupportedError; |
| 807 return false; | 810 return false; |
| 808 } | 811 } |
| 809 picker_type = ui::SelectFileDialog::SELECT_SAVEAS_FILE; | 812 picker_type = ui::SelectFileDialog::SELECT_SAVEAS_FILE; |
| 810 } else if (options->type == file_system::CHOOSE_ENTRY_TYPE_OPENDIRECTORY) { | 813 } else if (options->type == file_system::CHOOSE_ENTRY_TYPE_OPENDIRECTORY) { |
| 811 is_directory_ = true; | 814 is_directory_ = true; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 return false; | 945 return false; |
| 943 } | 946 } |
| 944 | 947 |
| 945 bool FileSystemGetObservedEntriesFunction::RunSync() { | 948 bool FileSystemGetObservedEntriesFunction::RunSync() { |
| 946 NOTIMPLEMENTED(); | 949 NOTIMPLEMENTED(); |
| 947 error_ = kUnknownIdError; | 950 error_ = kUnknownIdError; |
| 948 return false; | 951 return false; |
| 949 } | 952 } |
| 950 | 953 |
| 951 } // namespace extensions | 954 } // namespace extensions |
| OLD | NEW |