| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sandboxed_file_system_operation.h" | 5 #include "webkit/fileapi/sandboxed_file_system_operation.h" |
| 6 | 6 |
| 7 #include "net/url_request/url_request_context.h" | 7 #include "net/url_request/url_request_context.h" |
| 8 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 8 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 9 #include "webkit/fileapi/file_system_path_manager.h" | 9 #include "webkit/fileapi/file_system_path_manager.h" |
| 10 #include "webkit/fileapi/file_system_quota_manager.h" | 10 #include "webkit/fileapi/file_system_quota_manager.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 file_system_context_->path_manager()->GetFileSystemRootPath( | 33 file_system_context_->path_manager()->GetFileSystemRootPath( |
| 34 origin_url, type, create, | 34 origin_url, type, create, |
| 35 callback_factory_.NewCallback( | 35 callback_factory_.NewCallback( |
| 36 &SandboxedFileSystemOperation::DidGetRootPath)); | 36 &SandboxedFileSystemOperation::DidGetRootPath)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void SandboxedFileSystemOperation::CreateFile( | 39 void SandboxedFileSystemOperation::CreateFile( |
| 40 const FilePath& path, bool exclusive) { | 40 const FilePath& path, bool exclusive) { |
| 41 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) | 41 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { |
| 42 delete this; |
| 42 return; | 43 return; |
| 44 } |
| 43 FileSystemOperation::CreateFile(path, exclusive); | 45 FileSystemOperation::CreateFile(path, exclusive); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void SandboxedFileSystemOperation::CreateDirectory( | 48 void SandboxedFileSystemOperation::CreateDirectory( |
| 47 const FilePath& path, bool exclusive, bool recursive) { | 49 const FilePath& path, bool exclusive, bool recursive) { |
| 48 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) | 50 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { |
| 51 delete this; |
| 49 return; | 52 return; |
| 53 } |
| 50 FileSystemOperation::CreateDirectory(path, exclusive, recursive); | 54 FileSystemOperation::CreateDirectory(path, exclusive, recursive); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void SandboxedFileSystemOperation::Copy( | 57 void SandboxedFileSystemOperation::Copy( |
| 54 const FilePath& src_path, const FilePath& dest_path) { | 58 const FilePath& src_path, const FilePath& dest_path) { |
| 55 if (!VerifyFileSystemPathForRead(src_path) || | 59 if (!VerifyFileSystemPathForRead(src_path) || |
| 56 !VerifyFileSystemPathForWrite(dest_path, true /* create */, | 60 !VerifyFileSystemPathForWrite(dest_path, true /* create */, |
| 57 FileSystemQuotaManager::kUnknownSize)) | 61 FileSystemQuotaManager::kUnknownSize)) { |
| 62 delete this; |
| 58 return; | 63 return; |
| 64 } |
| 59 FileSystemOperation::Copy(src_path, dest_path); | 65 FileSystemOperation::Copy(src_path, dest_path); |
| 60 } | 66 } |
| 61 | 67 |
| 62 void SandboxedFileSystemOperation::Move( | 68 void SandboxedFileSystemOperation::Move( |
| 63 const FilePath& src_path, const FilePath& dest_path) { | 69 const FilePath& src_path, const FilePath& dest_path) { |
| 64 if (!VerifyFileSystemPathForRead(src_path) || | 70 if (!VerifyFileSystemPathForRead(src_path) || |
| 65 !VerifyFileSystemPathForWrite(dest_path, true /* create */, | 71 !VerifyFileSystemPathForWrite(dest_path, true /* create */, |
| 66 FileSystemQuotaManager::kUnknownSize)) | 72 FileSystemQuotaManager::kUnknownSize)) { |
| 73 delete this; |
| 67 return; | 74 return; |
| 75 } |
| 68 FileSystemOperation::Move(src_path, dest_path); | 76 FileSystemOperation::Move(src_path, dest_path); |
| 69 } | 77 } |
| 70 | 78 |
| 71 void SandboxedFileSystemOperation::DirectoryExists(const FilePath& path) { | 79 void SandboxedFileSystemOperation::DirectoryExists(const FilePath& path) { |
| 72 if (!VerifyFileSystemPathForRead(path)) | 80 if (!VerifyFileSystemPathForRead(path)) { |
| 81 delete this; |
| 73 return; | 82 return; |
| 83 } |
| 74 FileSystemOperation::DirectoryExists(path); | 84 FileSystemOperation::DirectoryExists(path); |
| 75 } | 85 } |
| 76 | 86 |
| 77 void SandboxedFileSystemOperation::FileExists(const FilePath& path) { | 87 void SandboxedFileSystemOperation::FileExists(const FilePath& path) { |
| 78 if (!VerifyFileSystemPathForRead(path)) | 88 if (!VerifyFileSystemPathForRead(path)) { |
| 89 delete this; |
| 79 return; | 90 return; |
| 91 } |
| 80 FileSystemOperation::FileExists(path); | 92 FileSystemOperation::FileExists(path); |
| 81 } | 93 } |
| 82 | 94 |
| 83 void SandboxedFileSystemOperation::GetMetadata(const FilePath& path) { | 95 void SandboxedFileSystemOperation::GetMetadata(const FilePath& path) { |
| 84 if (!VerifyFileSystemPathForRead(path)) | 96 if (!VerifyFileSystemPathForRead(path)) { |
| 97 delete this; |
| 85 return; | 98 return; |
| 99 } |
| 86 FileSystemOperation::GetMetadata(path); | 100 FileSystemOperation::GetMetadata(path); |
| 87 } | 101 } |
| 88 | 102 |
| 89 void SandboxedFileSystemOperation::ReadDirectory(const FilePath& path) { | 103 void SandboxedFileSystemOperation::ReadDirectory(const FilePath& path) { |
| 90 if (!VerifyFileSystemPathForRead(path)) | 104 if (!VerifyFileSystemPathForRead(path)) { |
| 105 delete this; |
| 91 return; | 106 return; |
| 107 } |
| 92 FileSystemOperation::ReadDirectory(path); | 108 FileSystemOperation::ReadDirectory(path); |
| 93 } | 109 } |
| 94 | 110 |
| 95 void SandboxedFileSystemOperation::Remove( | 111 void SandboxedFileSystemOperation::Remove( |
| 96 const FilePath& path, bool recursive) { | 112 const FilePath& path, bool recursive) { |
| 97 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) | 113 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) { |
| 114 delete this; |
| 98 return; | 115 return; |
| 116 } |
| 99 FileSystemOperation::Remove(path, recursive); | 117 FileSystemOperation::Remove(path, recursive); |
| 100 } | 118 } |
| 101 | 119 |
| 102 void SandboxedFileSystemOperation::Write( | 120 void SandboxedFileSystemOperation::Write( |
| 103 scoped_refptr<URLRequestContext> url_request_context, | 121 scoped_refptr<URLRequestContext> url_request_context, |
| 104 const FilePath& path, const GURL& blob_url, int64 offset) { | 122 const FilePath& path, const GURL& blob_url, int64 offset) { |
| 105 if (!VerifyFileSystemPathForWrite(path, true /* create */, | 123 if (!VerifyFileSystemPathForWrite(path, true /* create */, |
| 106 FileSystemQuotaManager::kUnknownSize)) | 124 FileSystemQuotaManager::kUnknownSize)) { |
| 125 delete this; |
| 107 return; | 126 return; |
| 127 } |
| 108 FileSystemOperation::Write(url_request_context, path, blob_url, offset); | 128 FileSystemOperation::Write(url_request_context, path, blob_url, offset); |
| 109 } | 129 } |
| 110 | 130 |
| 111 void SandboxedFileSystemOperation::Truncate( | 131 void SandboxedFileSystemOperation::Truncate( |
| 112 const FilePath& path, int64 length) { | 132 const FilePath& path, int64 length) { |
| 113 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) | 133 if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) { |
| 134 delete this; |
| 114 return; | 135 return; |
| 136 } |
| 115 FileSystemOperation::Truncate(path, length); | 137 FileSystemOperation::Truncate(path, length); |
| 116 } | 138 } |
| 117 | 139 |
| 118 void SandboxedFileSystemOperation::TouchFile(const FilePath& path, | 140 void SandboxedFileSystemOperation::TouchFile(const FilePath& path, |
| 119 const base::Time& last_access_time, | 141 const base::Time& last_access_time, |
| 120 const base::Time& last_modified_time) { | 142 const base::Time& last_modified_time) { |
| 121 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) | 143 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { |
| 144 delete this; |
| 122 return; | 145 return; |
| 146 } |
| 123 FileSystemOperation::TouchFile(path, last_access_time, last_modified_time); | 147 FileSystemOperation::TouchFile(path, last_access_time, last_modified_time); |
| 124 } | 148 } |
| 125 | 149 |
| 126 void SandboxedFileSystemOperation::DidGetRootPath( | 150 void SandboxedFileSystemOperation::DidGetRootPath( |
| 127 bool success, const FilePath& path, const std::string& name) { | 151 bool success, const FilePath& path, const std::string& name) { |
| 128 DCHECK(success || path.empty()); | 152 DCHECK(success || path.empty()); |
| 129 dispatcher()->DidOpenFileSystem(name, path); | 153 dispatcher()->DidOpenFileSystem(name, path); |
| 154 delete this; |
| 130 } | 155 } |
| 131 | 156 |
| 132 bool SandboxedFileSystemOperation::VerifyFileSystemPathForRead( | 157 bool SandboxedFileSystemOperation::VerifyFileSystemPathForRead( |
| 133 const FilePath& path) { | 158 const FilePath& path) { |
| 134 // We may want do more checks, but for now it just checks if the given | 159 // We may want do more checks, but for now it just checks if the given |
| 135 // |path| is under the valid FileSystem root path for this host context. | 160 // |path| is under the valid FileSystem root path for this host context. |
| 136 if (!file_system_context_->path_manager()->CrackFileSystemPath( | 161 if (!file_system_context_->path_manager()->CrackFileSystemPath( |
| 137 path, NULL, NULL, NULL)) { | 162 path, NULL, NULL, NULL)) { |
| 138 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 163 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 139 return false; | 164 return false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 const FilePath& path) { | 200 const FilePath& path) { |
| 176 if (file_system_context_->path_manager()->IsRestrictedFileName( | 201 if (file_system_context_->path_manager()->IsRestrictedFileName( |
| 177 path.BaseName())) { | 202 path.BaseName())) { |
| 178 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 203 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 179 return false; | 204 return false; |
| 180 } | 205 } |
| 181 return true; | 206 return true; |
| 182 } | 207 } |
| 183 | 208 |
| 184 } // namespace fileapi | 209 } // namespace fileapi |
| OLD | NEW |