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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 FileInfoOptCallback; | 218 FileInfoOptCallback; |
219 | 219 |
220 // Passes optional file info to the UI thread depending on |result| and |info|. | 220 // Passes optional file info to the UI thread depending on |result| and |info|. |
221 void PassFileInfoToUIThread(const FileInfoOptCallback& callback, | 221 void PassFileInfoToUIThread(const FileInfoOptCallback& callback, |
222 base::File::Error result, | 222 base::File::Error result, |
223 const base::File::Info& info) { | 223 const base::File::Info& info) { |
224 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 224 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
225 std::unique_ptr<base::File::Info> file_info( | 225 std::unique_ptr<base::File::Info> file_info( |
226 result == base::File::FILE_OK ? new base::File::Info(info) : NULL); | 226 result == base::File::FILE_OK ? new base::File::Info(info) : NULL); |
227 content::BrowserThread::PostTask( | 227 content::BrowserThread::PostTask( |
228 content::BrowserThread::UI, | 228 content::BrowserThread::UI, FROM_HERE, |
229 FROM_HERE, | 229 base::BindOnce(callback, base::Passed(&file_info))); |
230 base::Bind(callback, base::Passed(&file_info))); | |
231 } | 230 } |
232 | 231 |
233 // Gets a WebContents instance handle for a platform app hosted in | 232 // Gets a WebContents instance handle for a platform app hosted in |
234 // |render_frame_host|. If not found, then returns NULL. | 233 // |render_frame_host|. If not found, then returns NULL. |
235 content::WebContents* GetWebContentsForRenderFrameHost( | 234 content::WebContents* GetWebContentsForRenderFrameHost( |
236 Profile* profile, | 235 Profile* profile, |
237 content::RenderFrameHost* render_frame_host) { | 236 content::RenderFrameHost* render_frame_host) { |
238 content::WebContents* web_contents = | 237 content::WebContents* web_contents = |
239 content::WebContents::FromRenderFrameHost(render_frame_host); | 238 content::WebContents::FromRenderFrameHost(render_frame_host); |
240 // Check if there is an app window associated with the web contents; if not, | 239 // Check if there is an app window associated with the web contents; if not, |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 error_ = kRequiresFileSystemWriteError; | 573 error_ = kRequiresFileSystemWriteError; |
575 return false; | 574 return false; |
576 } | 575 } |
577 | 576 |
578 if (!app_file_handler_util::ValidateFileEntryAndGetPath( | 577 if (!app_file_handler_util::ValidateFileEntryAndGetPath( |
579 filesystem_name, filesystem_path, | 578 filesystem_name, filesystem_path, |
580 render_frame_host()->GetProcess()->GetID(), &path_, &error_)) | 579 render_frame_host()->GetProcess()->GetID(), &path_, &error_)) |
581 return false; | 580 return false; |
582 | 581 |
583 content::BrowserThread::PostTaskAndReply( | 582 content::BrowserThread::PostTaskAndReply( |
584 content::BrowserThread::FILE, | 583 content::BrowserThread::FILE, FROM_HERE, |
585 FROM_HERE, | 584 base::BindOnce( |
586 base::Bind( | |
587 &FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread, | 585 &FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread, |
588 this), | 586 this), |
589 base::Bind( | 587 base::BindOnce( |
590 &FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse, | 588 &FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse, |
591 this)); | 589 this)); |
592 return true; | 590 return true; |
593 } | 591 } |
594 | 592 |
595 void FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse() { | 593 void FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse() { |
596 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 594 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
597 if (is_directory_ && | 595 if (is_directory_ && |
598 !extension_->permissions_data()->HasAPIPermission( | 596 !extension_->permissions_data()->HasAPIPermission( |
599 APIPermission::kFileSystemDirectory)) { | 597 APIPermission::kFileSystemDirectory)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 ui::SelectFileDialog::Type picker_type) | 641 ui::SelectFileDialog::Type picker_type) |
644 : function_(function) { | 642 : function_(function) { |
645 select_file_dialog_ = ui::SelectFileDialog::Create( | 643 select_file_dialog_ = ui::SelectFileDialog::Create( |
646 this, new ChromeSelectFilePolicy(web_contents)); | 644 this, new ChromeSelectFilePolicy(web_contents)); |
647 gfx::NativeWindow owning_window = web_contents ? | 645 gfx::NativeWindow owning_window = web_contents ? |
648 platform_util::GetTopLevel(web_contents->GetNativeView()) : | 646 platform_util::GetTopLevel(web_contents->GetNativeView()) : |
649 NULL; | 647 NULL; |
650 | 648 |
651 if (g_skip_picker_for_test) { | 649 if (g_skip_picker_for_test) { |
652 if (g_use_suggested_path_for_test) { | 650 if (g_use_suggested_path_for_test) { |
653 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 651 content::BrowserThread::PostTask( |
654 base::Bind( | 652 content::BrowserThread::UI, FROM_HERE, |
| 653 base::BindOnce( |
655 &FileSystemChooseEntryFunction::FilePicker::FileSelected, | 654 &FileSystemChooseEntryFunction::FilePicker::FileSelected, |
656 base::Unretained(this), suggested_name, 1, | 655 base::Unretained(this), suggested_name, 1, |
657 static_cast<void*>(NULL))); | 656 static_cast<void*>(NULL))); |
658 } else if (g_path_to_be_picked_for_test) { | 657 } else if (g_path_to_be_picked_for_test) { |
659 content::BrowserThread::PostTask( | 658 content::BrowserThread::PostTask( |
660 content::BrowserThread::UI, FROM_HERE, | 659 content::BrowserThread::UI, FROM_HERE, |
661 base::Bind( | 660 base::BindOnce( |
662 &FileSystemChooseEntryFunction::FilePicker::FileSelected, | 661 &FileSystemChooseEntryFunction::FilePicker::FileSelected, |
663 base::Unretained(this), *g_path_to_be_picked_for_test, 1, | 662 base::Unretained(this), *g_path_to_be_picked_for_test, 1, |
664 static_cast<void*>(NULL))); | 663 static_cast<void*>(NULL))); |
665 } else if (g_paths_to_be_picked_for_test) { | 664 } else if (g_paths_to_be_picked_for_test) { |
666 content::BrowserThread::PostTask( | 665 content::BrowserThread::PostTask( |
667 content::BrowserThread::UI, | 666 content::BrowserThread::UI, FROM_HERE, |
668 FROM_HERE, | 667 base::BindOnce( |
669 base::Bind( | |
670 &FileSystemChooseEntryFunction::FilePicker::MultiFilesSelected, | 668 &FileSystemChooseEntryFunction::FilePicker::MultiFilesSelected, |
671 base::Unretained(this), | 669 base::Unretained(this), *g_paths_to_be_picked_for_test, |
672 *g_paths_to_be_picked_for_test, | |
673 static_cast<void*>(NULL))); | 670 static_cast<void*>(NULL))); |
674 } else { | 671 } else { |
675 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 672 content::BrowserThread::PostTask( |
676 base::Bind( | 673 content::BrowserThread::UI, FROM_HERE, |
677 &FileSystemChooseEntryFunction::FilePicker:: | 674 base::BindOnce(&FileSystemChooseEntryFunction::FilePicker:: |
678 FileSelectionCanceled, | 675 FileSelectionCanceled, |
679 base::Unretained(this), static_cast<void*>(NULL))); | 676 base::Unretained(this), static_cast<void*>(NULL))); |
680 } | 677 } |
681 return; | 678 return; |
682 } | 679 } |
683 | 680 |
684 select_file_dialog_->SelectFile(picker_type, | 681 select_file_dialog_->SelectFile(picker_type, |
685 base::string16(), | 682 base::string16(), |
686 suggested_name, | 683 suggested_name, |
687 &file_type_info, | 684 &file_type_info, |
688 0, | 685 0, |
689 base::FilePath::StringType(), | 686 base::FilePath::StringType(), |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 } | 860 } |
864 | 861 |
865 DCHECK_EQ(paths.size(), 1u); | 862 DCHECK_EQ(paths.size(), 1u); |
866 bool non_native_path = false; | 863 bool non_native_path = false; |
867 #if defined(OS_CHROMEOS) | 864 #if defined(OS_CHROMEOS) |
868 non_native_path = | 865 non_native_path = |
869 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]); | 866 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]); |
870 #endif | 867 #endif |
871 | 868 |
872 content::BrowserThread::PostTask( | 869 content::BrowserThread::PostTask( |
873 content::BrowserThread::FILE, | 870 content::BrowserThread::FILE, FROM_HERE, |
874 FROM_HERE, | 871 base::BindOnce( |
875 base::Bind( | |
876 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, | 872 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, |
877 this, | 873 this, non_native_path, paths, web_contents)); |
878 non_native_path, | |
879 paths, | |
880 web_contents)); | |
881 return; | 874 return; |
882 } | 875 } |
883 | 876 |
884 OnDirectoryAccessConfirmed(paths); | 877 OnDirectoryAccessConfirmed(paths); |
885 } | 878 } |
886 | 879 |
887 void FileSystemChooseEntryFunction::FileSelectionCanceled() { | 880 void FileSystemChooseEntryFunction::FileSelectionCanceled() { |
888 error_ = kUserCancelled; | 881 error_ = kUserCancelled; |
889 SendResponse(false); | 882 SendResponse(false); |
890 } | 883 } |
891 | 884 |
892 void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread( | 885 void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread( |
893 bool non_native_path, | 886 bool non_native_path, |
894 const std::vector<base::FilePath>& paths, | 887 const std::vector<base::FilePath>& paths, |
895 content::WebContents* web_contents) { | 888 content::WebContents* web_contents) { |
896 const base::FilePath check_path = | 889 const base::FilePath check_path = |
897 non_native_path ? paths[0] : base::MakeAbsoluteFilePath(paths[0]); | 890 non_native_path ? paths[0] : base::MakeAbsoluteFilePath(paths[0]); |
898 if (check_path.empty()) { | 891 if (check_path.empty()) { |
899 content::BrowserThread::PostTask( | 892 content::BrowserThread::PostTask( |
900 content::BrowserThread::UI, | 893 content::BrowserThread::UI, FROM_HERE, |
901 FROM_HERE, | 894 base::BindOnce(&FileSystemChooseEntryFunction::FileSelectionCanceled, |
902 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, | 895 this)); |
903 this)); | |
904 return; | 896 return; |
905 } | 897 } |
906 | 898 |
907 for (size_t i = 0; i < arraysize(kGraylistedPaths); i++) { | 899 for (size_t i = 0; i < arraysize(kGraylistedPaths); i++) { |
908 base::FilePath graylisted_path; | 900 base::FilePath graylisted_path; |
909 if (PathService::Get(kGraylistedPaths[i], &graylisted_path) && | 901 if (PathService::Get(kGraylistedPaths[i], &graylisted_path) && |
910 (check_path == graylisted_path || | 902 (check_path == graylisted_path || |
911 check_path.IsParent(graylisted_path))) { | 903 check_path.IsParent(graylisted_path))) { |
912 if (g_skip_directory_confirmation_for_test) { | 904 if (g_skip_directory_confirmation_for_test) { |
913 if (g_allow_directory_access_for_test) { | 905 if (g_allow_directory_access_for_test) { |
914 break; | 906 break; |
915 } else { | 907 } else { |
916 content::BrowserThread::PostTask( | 908 content::BrowserThread::PostTask( |
917 content::BrowserThread::UI, | 909 content::BrowserThread::UI, FROM_HERE, |
918 FROM_HERE, | 910 base::BindOnce( |
919 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, | 911 &FileSystemChooseEntryFunction::FileSelectionCanceled, this)); |
920 this)); | |
921 } | 912 } |
922 return; | 913 return; |
923 } | 914 } |
924 | 915 |
925 content::BrowserThread::PostTask( | 916 content::BrowserThread::PostTask( |
926 content::BrowserThread::UI, | 917 content::BrowserThread::UI, FROM_HERE, |
927 FROM_HERE, | 918 base::BindOnce( |
928 base::Bind( | |
929 CreateDirectoryAccessConfirmationDialog, | 919 CreateDirectoryAccessConfirmationDialog, |
930 app_file_handler_util::HasFileSystemWritePermission( | 920 app_file_handler_util::HasFileSystemWritePermission( |
931 extension_.get()), | 921 extension_.get()), |
932 base::UTF8ToUTF16(extension_->name()), | 922 base::UTF8ToUTF16(extension_->name()), web_contents, |
933 web_contents, | |
934 base::Bind( | 923 base::Bind( |
935 &FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, | 924 &FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, |
936 this, | 925 this, paths), |
937 paths), | |
938 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, | 926 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, |
939 this))); | 927 this))); |
940 return; | 928 return; |
941 } | 929 } |
942 } | 930 } |
943 | 931 |
944 content::BrowserThread::PostTask( | 932 content::BrowserThread::PostTask( |
945 content::BrowserThread::UI, | 933 content::BrowserThread::UI, FROM_HERE, |
946 FROM_HERE, | 934 base::BindOnce(&FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, |
947 base::Bind(&FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed, | 935 this, paths)); |
948 this, paths)); | |
949 } | 936 } |
950 | 937 |
951 void FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed( | 938 void FileSystemChooseEntryFunction::OnDirectoryAccessConfirmed( |
952 const std::vector<base::FilePath>& paths) { | 939 const std::vector<base::FilePath>& paths) { |
953 if (app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { | 940 if (app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { |
954 PrepareFilesForWritableApp(paths); | 941 PrepareFilesForWritableApp(paths); |
955 return; | 942 return; |
956 } | 943 } |
957 | 944 |
958 // Don't need to check the file, it's for reading. | 945 // Don't need to check the file, it's for reading. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 ->GetFileSystemContext(); | 1137 ->GetFileSystemContext(); |
1151 const storage::FileSystemURL url = context->CreateCrackedFileSystemURL( | 1138 const storage::FileSystemURL url = context->CreateCrackedFileSystemURL( |
1152 site, | 1139 site, |
1153 storage::kFileSystemTypeIsolated, | 1140 storage::kFileSystemTypeIsolated, |
1154 IsolatedContext::GetInstance() | 1141 IsolatedContext::GetInstance() |
1155 ->CreateVirtualRootPath(filesystem_id) | 1142 ->CreateVirtualRootPath(filesystem_id) |
1156 .Append(base::FilePath::FromUTF8Unsafe(filesystem_path))); | 1143 .Append(base::FilePath::FromUTF8Unsafe(filesystem_path))); |
1157 | 1144 |
1158 content::BrowserThread::PostTask( | 1145 content::BrowserThread::PostTask( |
1159 content::BrowserThread::IO, FROM_HERE, | 1146 content::BrowserThread::IO, FROM_HERE, |
1160 base::Bind( | 1147 base::BindOnce( |
1161 base::IgnoreResult( | 1148 base::IgnoreResult( |
1162 &storage::FileSystemOperationRunner::GetMetadata), | 1149 &storage::FileSystemOperationRunner::GetMetadata), |
1163 context->operation_runner()->AsWeakPtr(), url, | 1150 context->operation_runner()->AsWeakPtr(), url, |
1164 storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY, | 1151 storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY, |
1165 base::Bind( | 1152 base::Bind( |
1166 &PassFileInfoToUIThread, | 1153 &PassFileInfoToUIThread, |
1167 base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry, | 1154 base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry, |
1168 this, entry_id, path)))); | 1155 this, entry_id, path)))); |
1169 return true; | 1156 return true; |
1170 } | 1157 } |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); | 1421 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); |
1435 std::vector<api::file_system::Volume> result_volume_list; | 1422 std::vector<api::file_system::Volume> result_volume_list; |
1436 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); | 1423 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); |
1437 | 1424 |
1438 return RespondNow(ArgumentList( | 1425 return RespondNow(ArgumentList( |
1439 api::file_system::GetVolumeList::Results::Create(result_volume_list))); | 1426 api::file_system::GetVolumeList::Results::Create(result_volume_list))); |
1440 } | 1427 } |
1441 #endif | 1428 #endif |
1442 | 1429 |
1443 } // namespace extensions | 1430 } // namespace extensions |
OLD | NEW |