| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
| 11 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 12 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 12 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 13 #include "webkit/fileapi/file_system_context.h" | 13 #include "webkit/fileapi/file_system_context.h" |
| 14 #include "webkit/fileapi/file_system_file_util_proxy.h" | 14 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 15 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 15 #include "webkit/fileapi/file_system_operation_context.h" | 16 #include "webkit/fileapi/file_system_operation_context.h" |
| 16 #include "webkit/fileapi/file_system_path_manager.h" | |
| 17 #include "webkit/fileapi/file_system_quota_util.h" | 17 #include "webkit/fileapi/file_system_quota_util.h" |
| 18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
| 20 #include "webkit/fileapi/file_writer_delegate.h" | 20 #include "webkit/fileapi/file_writer_delegate.h" |
| 21 #include "webkit/fileapi/local_file_util.h" | 21 #include "webkit/fileapi/local_file_util.h" |
| 22 #include "webkit/fileapi/quota_file_util.h" | 22 #include "webkit/fileapi/quota_file_util.h" |
| 23 #include "webkit/quota/quota_types.h" | 23 #include "webkit/quota/quota_types.h" |
| 24 | 24 |
| 25 namespace fileapi { | 25 namespace fileapi { |
| 26 | 26 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 DCHECK(file_system_context()); | 95 DCHECK(file_system_context()); |
| 96 operation_context_.set_src_origin_url(origin_url); | 96 operation_context_.set_src_origin_url(origin_url); |
| 97 operation_context_.set_src_type(type); | 97 operation_context_.set_src_type(type); |
| 98 // TODO(ericu): We don't really need to make this call if !create. | 98 // TODO(ericu): We don't really need to make this call if !create. |
| 99 // Also, in the future we won't need it either way, as long as we do all | 99 // Also, in the future we won't need it either way, as long as we do all |
| 100 // permission+quota checks beforehand. We only need it now because we have to | 100 // permission+quota checks beforehand. We only need it now because we have to |
| 101 // create an unpredictable directory name. Without that, we could lazily | 101 // create an unpredictable directory name. Without that, we could lazily |
| 102 // create the root later on the first filesystem write operation, and just | 102 // create the root later on the first filesystem write operation, and just |
| 103 // return GetFileSystemRootURI() here. | 103 // return GetFileSystemRootURI() here. |
| 104 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( | 104 FileSystemMountPointProvider* mount_point_provider = |
| 105 file_system_context()->GetMountPointProvider(type); |
| 106 if (!mount_point_provider) { |
| 107 DidGetRootPath(false, FilePath(), std::string()); |
| 108 delete this; |
| 109 return; |
| 110 } |
| 111 mount_point_provider->ValidateFileSystemRootAndGetURL( |
| 105 origin_url, type, create, | 112 origin_url, type, create, |
| 106 base::Bind(&FileSystemOperation::DidGetRootPath, | 113 base::Bind(&FileSystemOperation::DidGetRootPath, |
| 107 base::Owned(this))); | 114 base::Owned(this))); |
| 108 } | 115 } |
| 109 | 116 |
| 110 void FileSystemOperation::CreateFile(const GURL& path, | 117 void FileSystemOperation::CreateFile(const GURL& path, |
| 111 bool exclusive) { | 118 bool exclusive) { |
| 112 #ifndef NDEBUG | 119 #ifndef NDEBUG |
| 113 DCHECK(kOperationNone == pending_operation_); | 120 DCHECK(kOperationNone == pending_operation_); |
| 114 pending_operation_ = kOperationCreateFile; | 121 pending_operation_ = kOperationCreateFile; |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 FilePath* virtual_path, FileSystemFileUtil** file_util) { | 776 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 770 if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util)) | 777 if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util)) |
| 771 return false; | 778 return false; |
| 772 | 779 |
| 773 // Any write access is disallowed on the root path. | 780 // Any write access is disallowed on the root path. |
| 774 if (virtual_path->value().length() == 0 || | 781 if (virtual_path->value().length() == 0 || |
| 775 virtual_path->DirName().value() == virtual_path->value()) { | 782 virtual_path->DirName().value() == virtual_path->value()) { |
| 776 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 783 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 777 return false; | 784 return false; |
| 778 } | 785 } |
| 779 if (create && file_system_context()->path_manager()->IsRestrictedFileName( | 786 if (create && |
| 780 *type, virtual_path->BaseName())) { | 787 file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName( |
| 788 virtual_path->BaseName())) { |
| 781 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 789 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 782 return false; | 790 return false; |
| 783 } | 791 } |
| 784 | 792 |
| 785 return true; | 793 return true; |
| 786 } | 794 } |
| 787 | 795 |
| 788 bool FileSystemOperation::VerifyFileSystemPath( | 796 bool FileSystemOperation::VerifyFileSystemPath( |
| 789 const GURL& path, GURL* origin_url, FileSystemType* type, | 797 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 790 FilePath* virtual_path, FileSystemFileUtil** file_util) { | 798 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 791 DCHECK(file_system_context()); | 799 DCHECK(file_system_context()); |
| 792 | 800 |
| 793 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 801 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 794 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 802 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 795 return false; | 803 return false; |
| 796 } | 804 } |
| 797 if (!file_system_context()->path_manager()->IsAccessAllowed( | 805 if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed( |
| 798 *origin_url, *type, *virtual_path)) { | 806 *origin_url, *type, *virtual_path)) { |
| 799 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 807 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 800 return false; | 808 return false; |
| 801 } | 809 } |
| 802 DCHECK(file_util); | 810 DCHECK(file_util); |
| 803 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); | 811 *file_util = file_system_context()->GetFileUtil(*type); |
| 804 DCHECK(*file_util); | 812 DCHECK(*file_util); |
| 805 | 813 |
| 806 return true; | 814 return true; |
| 807 } | 815 } |
| 808 | 816 |
| 809 bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) { | 817 bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) { |
| 810 GURL origin_url; | 818 GURL origin_url; |
| 811 FileSystemType type; | 819 FileSystemType type; |
| 812 FileSystemFileUtil* file_util; | 820 FileSystemFileUtil* file_util; |
| 813 bool result = VerifyFileSystemPathForRead( | 821 bool result = VerifyFileSystemPathForRead( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 841 bool result = VerifyFileSystemPathForWrite( | 849 bool result = VerifyFileSystemPathForWrite( |
| 842 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); | 850 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); |
| 843 operation_context_.set_dest_origin_url(origin_url); | 851 operation_context_.set_dest_origin_url(origin_url); |
| 844 operation_context_.set_dest_type(type); | 852 operation_context_.set_dest_type(type); |
| 845 if (!operation_context_.dest_file_util()) | 853 if (!operation_context_.dest_file_util()) |
| 846 operation_context_.set_dest_file_util(file_util); | 854 operation_context_.set_dest_file_util(file_util); |
| 847 return result; | 855 return result; |
| 848 } | 856 } |
| 849 | 857 |
| 850 } // namespace fileapi | 858 } // namespace fileapi |
| OLD | NEW |