| 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 "webkit/fileapi/isolated_file_util.h" | 5 #include "webkit/fileapi/isolated_file_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 new PathConverterEnumerator( | 165 new PathConverterEnumerator( |
| 166 NativeFileUtil::CreateFileEnumerator( | 166 NativeFileUtil::CreateFileEnumerator( |
| 167 next_file.path, true /* recursive */), | 167 next_file.path, true /* recursive */), |
| 168 virtual_base_path_.AppendASCII(next_file.name), next_file.path)); | 168 virtual_base_path_.AppendASCII(next_file.name), next_file.path)); |
| 169 DCHECK(current_enumerator_.get()); | 169 DCHECK(current_enumerator_.get()); |
| 170 return current_enumerator_->Next(); | 170 return current_enumerator_->Next(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace | 173 } // namespace |
| 174 | 174 |
| 175 IsolatedFileUtil::IsolatedFileUtil() { | 175 //------------------------------------------------------------------------- |
| 176 |
| 177 IsolatedFileUtil::IsolatedFileUtil() {} |
| 178 |
| 179 PlatformFileError IsolatedFileUtil::GetLocalFilePath( |
| 180 FileSystemOperationContext* context, |
| 181 const FileSystemURL& url, |
| 182 FilePath* local_file_path) { |
| 183 DCHECK(local_file_path); |
| 184 std::string filesystem_id; |
| 185 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( |
| 186 url.path(), &filesystem_id, NULL, local_file_path)) |
| 187 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 188 if (local_file_path->empty()) { |
| 189 // Root direcory case, which should not be accessed. |
| 190 return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
| 191 } |
| 192 return base::PLATFORM_FILE_OK; |
| 176 } | 193 } |
| 177 | 194 |
| 178 PlatformFileError IsolatedFileUtil::CreateOrOpen( | 195 //------------------------------------------------------------------------- |
| 179 FileSystemOperationContext* context, | |
| 180 const FileSystemURL& url, int file_flags, | |
| 181 PlatformFile* file_handle, bool* created) { | |
| 182 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 183 } | |
| 184 | 196 |
| 185 PlatformFileError IsolatedFileUtil::Close( | 197 DraggedFileUtil::DraggedFileUtil() {} |
| 186 FileSystemOperationContext* context, | |
| 187 PlatformFile file_handle) { | |
| 188 // We don't allow open thus Close won't be called. | |
| 189 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 190 } | |
| 191 | 198 |
| 192 PlatformFileError IsolatedFileUtil::EnsureFileExists( | 199 PlatformFileError DraggedFileUtil::GetFileInfo( |
| 193 FileSystemOperationContext* context, | |
| 194 const FileSystemURL& url, | |
| 195 bool* created) { | |
| 196 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 197 } | |
| 198 | |
| 199 PlatformFileError IsolatedFileUtil::CreateDirectory( | |
| 200 FileSystemOperationContext* context, | |
| 201 const FileSystemURL& url, | |
| 202 bool exclusive, | |
| 203 bool recursive) { | |
| 204 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 205 } | |
| 206 | |
| 207 PlatformFileError IsolatedFileUtil::GetFileInfo( | |
| 208 FileSystemOperationContext* context, | 200 FileSystemOperationContext* context, |
| 209 const FileSystemURL& url, | 201 const FileSystemURL& url, |
| 210 PlatformFileInfo* file_info, | 202 PlatformFileInfo* file_info, |
| 211 FilePath* platform_path) { | 203 FilePath* platform_path) { |
| 212 DCHECK(file_info); | 204 DCHECK(file_info); |
| 213 std::string filesystem_id; | 205 std::string filesystem_id; |
| 214 FilePath cracked_path; | 206 FilePath cracked_path; |
| 215 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( | 207 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( |
| 216 url.path(), &filesystem_id, NULL, &cracked_path)) | 208 url.path(), &filesystem_id, NULL, &cracked_path)) |
| 217 return base::PLATFORM_FILE_ERROR_SECURITY; | 209 return base::PLATFORM_FILE_ERROR_SECURITY; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 231 if (file_util::IsLink(cracked_path) && !FilePath().IsParent(cracked_path)) { | 223 if (file_util::IsLink(cracked_path) && !FilePath().IsParent(cracked_path)) { |
| 232 // Don't follow symlinks unless it's the one that are selected by the user. | 224 // Don't follow symlinks unless it's the one that are selected by the user. |
| 233 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 225 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 234 } | 226 } |
| 235 if (error == base::PLATFORM_FILE_OK) | 227 if (error == base::PLATFORM_FILE_OK) |
| 236 *platform_path = cracked_path; | 228 *platform_path = cracked_path; |
| 237 return error; | 229 return error; |
| 238 } | 230 } |
| 239 | 231 |
| 240 FileSystemFileUtil::AbstractFileEnumerator* | 232 FileSystemFileUtil::AbstractFileEnumerator* |
| 241 IsolatedFileUtil::CreateFileEnumerator( | 233 DraggedFileUtil::CreateFileEnumerator( |
| 242 FileSystemOperationContext* context, | 234 FileSystemOperationContext* context, |
| 243 const FileSystemURL& root, | 235 const FileSystemURL& root, |
| 244 bool recursive) { | 236 bool recursive) { |
| 245 std::string filesystem_id; | 237 std::string filesystem_id; |
| 246 FileInfo root_info; | 238 FileInfo root_info; |
| 247 FilePath cracked_path; | 239 FilePath cracked_path; |
| 248 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( | 240 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( |
| 249 root.path(), &filesystem_id, &root_info, &cracked_path)) | 241 root.path(), &filesystem_id, &root_info, &cracked_path)) |
| 250 return NULL; | 242 return NULL; |
| 251 | 243 |
| 252 FilePath virtual_base_path = | 244 FilePath virtual_base_path = |
| 253 IsolatedContext::GetInstance()->CreateVirtualRootPath(filesystem_id); | 245 IsolatedContext::GetInstance()->CreateVirtualRootPath(filesystem_id); |
| 254 | 246 |
| 255 if (!cracked_path.empty()) { | 247 if (!cracked_path.empty()) { |
| 256 return new PathConverterEnumerator( | 248 return new PathConverterEnumerator( |
| 257 NativeFileUtil::CreateFileEnumerator(cracked_path, recursive), | 249 NativeFileUtil::CreateFileEnumerator(cracked_path, recursive), |
| 258 virtual_base_path.AppendASCII(root_info.name), root_info.path); | 250 virtual_base_path.AppendASCII(root_info.name), root_info.path); |
| 259 } | 251 } |
| 260 | 252 |
| 261 // Root path case. | 253 // Root path case. |
| 262 std::vector<FileInfo> toplevels; | 254 std::vector<FileInfo> toplevels; |
| 263 IsolatedContext::GetInstance()->GetRegisteredFileInfo( | 255 IsolatedContext::GetInstance()->GetDraggedFileInfo( |
| 264 filesystem_id, &toplevels); | 256 filesystem_id, &toplevels); |
| 265 if (!recursive) | 257 if (!recursive) |
| 266 return new SetFileEnumerator(toplevels, root.path()); | 258 return new SetFileEnumerator(toplevels, root.path()); |
| 267 return new RecursiveSetFileEnumerator( | 259 return new RecursiveSetFileEnumerator( |
| 268 virtual_base_path, toplevels, root.path()); | 260 virtual_base_path, toplevels, root.path()); |
| 269 } | 261 } |
| 270 | 262 |
| 271 PlatformFileError IsolatedFileUtil::GetLocalFilePath( | 263 bool DraggedFileUtil::PathExists( |
| 272 FileSystemOperationContext* context, | |
| 273 const FileSystemURL& file_system_url, | |
| 274 FilePath* local_file_path) { | |
| 275 if (GetPlatformPath(file_system_url, local_file_path)) | |
| 276 return base::PLATFORM_FILE_OK; | |
| 277 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 278 } | |
| 279 | |
| 280 PlatformFileError IsolatedFileUtil::Touch( | |
| 281 FileSystemOperationContext* context, | |
| 282 const FileSystemURL& url, | |
| 283 const base::Time& last_access_time, | |
| 284 const base::Time& last_modified_time) { | |
| 285 FilePath platform_path; | |
| 286 if (!GetPlatformPath(url, &platform_path) || platform_path.empty()) | |
| 287 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 288 return NativeFileUtil::Touch( | |
| 289 platform_path, last_access_time, last_modified_time); | |
| 290 } | |
| 291 | |
| 292 PlatformFileError IsolatedFileUtil::Truncate( | |
| 293 FileSystemOperationContext* context, | |
| 294 const FileSystemURL& url, | |
| 295 int64 length) { | |
| 296 FilePath platform_path; | |
| 297 if (!GetPlatformPath(url, &platform_path) || platform_path.empty()) | |
| 298 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 299 return NativeFileUtil::Truncate(platform_path, length); | |
| 300 } | |
| 301 | |
| 302 bool IsolatedFileUtil::PathExists( | |
| 303 FileSystemOperationContext* context, | 264 FileSystemOperationContext* context, |
| 304 const FileSystemURL& url) { | 265 const FileSystemURL& url) { |
| 305 FilePath platform_path; | 266 FilePath platform_path; |
| 306 if (!GetPlatformPath(url, &platform_path)) | 267 if (!GetPlatformPath(url, &platform_path)) |
| 307 return false; | 268 return false; |
| 308 if (platform_path.empty()) { | 269 if (platform_path.empty()) { |
| 309 // The root directory case. | 270 // The root directory case. |
| 310 return true; | 271 return true; |
| 311 } | 272 } |
| 312 return NativeFileUtil::PathExists(platform_path); | 273 return NativeFileUtil::PathExists(platform_path); |
| 313 } | 274 } |
| 314 | 275 |
| 315 bool IsolatedFileUtil::DirectoryExists( | 276 bool DraggedFileUtil::DirectoryExists( |
| 316 FileSystemOperationContext* context, | 277 FileSystemOperationContext* context, |
| 317 const FileSystemURL& url) { | 278 const FileSystemURL& url) { |
| 318 FilePath platform_path; | 279 FilePath platform_path; |
| 319 if (!GetPlatformPath(url, &platform_path)) | 280 if (!GetPlatformPath(url, &platform_path)) |
| 320 return false; | 281 return false; |
| 321 if (platform_path.empty()) { | 282 if (platform_path.empty()) { |
| 322 // The root directory case. | 283 // The root directory case. |
| 323 return true; | 284 return true; |
| 324 } | 285 } |
| 325 return NativeFileUtil::DirectoryExists(platform_path); | 286 return NativeFileUtil::DirectoryExists(platform_path); |
| 326 } | 287 } |
| 327 | 288 |
| 328 bool IsolatedFileUtil::IsDirectoryEmpty( | 289 bool DraggedFileUtil::IsDirectoryEmpty( |
| 329 FileSystemOperationContext* context, | 290 FileSystemOperationContext* context, |
| 330 const FileSystemURL& url) { | 291 const FileSystemURL& url) { |
| 331 std::string filesystem_id; | 292 std::string filesystem_id; |
| 332 FilePath platform_path; | 293 FilePath platform_path; |
| 333 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( | 294 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( |
| 334 url.path(), &filesystem_id, | 295 url.path(), &filesystem_id, |
| 335 NULL, &platform_path)) | 296 NULL, &platform_path)) |
| 336 return false; | 297 return false; |
| 337 if (platform_path.empty()) { | 298 if (platform_path.empty()) { |
| 338 // The root directory case. | 299 // The root directory case. |
| 339 std::vector<FileInfo> toplevels; | 300 std::vector<FileInfo> toplevels; |
| 340 bool success = IsolatedContext::GetInstance()->GetRegisteredFileInfo( | 301 bool success = IsolatedContext::GetInstance()->GetDraggedFileInfo( |
| 341 filesystem_id, &toplevels); | 302 filesystem_id, &toplevels); |
| 342 DCHECK(success); | 303 DCHECK(success); |
| 343 return toplevels.empty(); | 304 return toplevels.empty(); |
| 344 } | 305 } |
| 345 return NativeFileUtil::IsDirectoryEmpty(platform_path); | 306 return NativeFileUtil::IsDirectoryEmpty(platform_path); |
| 346 } | 307 } |
| 347 | 308 |
| 348 PlatformFileError IsolatedFileUtil::CopyOrMoveFile( | 309 bool DraggedFileUtil::GetPlatformPath(const FileSystemURL& url, |
| 349 FileSystemOperationContext* context, | |
| 350 const FileSystemURL& src_url, | |
| 351 const FileSystemURL& dest_url, | |
| 352 bool copy) { | |
| 353 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 354 } | |
| 355 | |
| 356 PlatformFileError IsolatedFileUtil::CopyInForeignFile( | |
| 357 FileSystemOperationContext* context, | |
| 358 const FilePath& src_file_path, | |
| 359 const FileSystemURL& dest_url) { | |
| 360 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 361 } | |
| 362 | |
| 363 PlatformFileError IsolatedFileUtil::DeleteFile( | |
| 364 FileSystemOperationContext* context, | |
| 365 const FileSystemURL& url) { | |
| 366 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 367 } | |
| 368 | |
| 369 PlatformFileError IsolatedFileUtil::DeleteSingleDirectory( | |
| 370 FileSystemOperationContext* context, | |
| 371 const FileSystemURL& url) { | |
| 372 return base::PLATFORM_FILE_ERROR_SECURITY; | |
| 373 } | |
| 374 | |
| 375 scoped_refptr<webkit_blob::ShareableFileReference> | |
| 376 IsolatedFileUtil::CreateSnapshotFile( | |
| 377 FileSystemOperationContext* context, | |
| 378 const FileSystemURL& url, | |
| 379 base::PlatformFileError* result, | |
| 380 base::PlatformFileInfo* file_info, | |
| 381 FilePath* platform_path) { | |
| 382 DCHECK(result); | |
| 383 *result = GetFileInfo(context, url, file_info, platform_path); | |
| 384 return NULL; | |
| 385 } | |
| 386 | |
| 387 bool IsolatedFileUtil::GetPlatformPath(const FileSystemURL& url, | |
| 388 FilePath* platform_path) const { | 310 FilePath* platform_path) const { |
| 389 DCHECK(platform_path); | 311 DCHECK(platform_path); |
| 390 std::string filesystem_id; | 312 std::string filesystem_id; |
| 391 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( | 313 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( |
| 392 url.path(), &filesystem_id, NULL, platform_path)) | 314 url.path(), &filesystem_id, NULL, platform_path)) |
| 393 return false; | 315 return false; |
| 394 return true; | 316 return true; |
| 395 } | 317 } |
| 396 | 318 |
| 397 } // namespace | 319 } // namespace |
| OLD | NEW |