| 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/time.h" | 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
| 10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 DCHECK(file_system_context()); | 54 DCHECK(file_system_context()); |
| 55 file_system_operation_context_.set_src_origin_url(origin_url); | 55 file_system_operation_context_.set_src_origin_url(origin_url); |
| 56 file_system_operation_context_.set_src_type(type); | 56 file_system_operation_context_.set_src_type(type); |
| 57 // TODO(ericu): We don't really need to make this call if !create. | 57 // TODO(ericu): We don't really need to make this call if !create. |
| 58 // Also, in the future we won't need it either way, as long as we do all | 58 // Also, in the future we won't need it either way, as long as we do all |
| 59 // permission+quota checks beforehand. We only need it now because we have to | 59 // permission+quota checks beforehand. We only need it now because we have to |
| 60 // create an unpredictable directory name. Without that, we could lazily | 60 // create an unpredictable directory name. Without that, we could lazily |
| 61 // create the root later on the first filesystem write operation, and just | 61 // create the root later on the first filesystem write operation, and just |
| 62 // return GetFileSystemRootURI() here. | 62 // return GetFileSystemRootURI() here. |
| 63 file_system_context()->path_manager()->GetFileSystemRootPath( | 63 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( |
| 64 origin_url, type, create, | 64 origin_url, type, create, |
| 65 callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath)); | 65 callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void FileSystemOperation::CreateFile(const GURL& path, | 68 void FileSystemOperation::CreateFile(const GURL& path, |
| 69 bool exclusive) { | 69 bool exclusive) { |
| 70 #ifndef NDEBUG | 70 #ifndef NDEBUG |
| 71 DCHECK(kOperationNone == pending_operation_); | 71 DCHECK(kOperationNone == pending_operation_); |
| 72 pending_operation_ = kOperationCreateFile; | 72 pending_operation_ = kOperationCreateFile; |
| 73 #endif | 73 #endif |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 file_system_operation_context_.set_src_origin_url(origin_url); | 227 file_system_operation_context_.set_src_origin_url(origin_url); |
| 228 file_system_operation_context_.set_src_type(type); | 228 file_system_operation_context_.set_src_type(type); |
| 229 FileSystemFileUtilProxy::GetFileInfo( | 229 FileSystemFileUtilProxy::GetFileInfo( |
| 230 file_system_operation_context_, | 230 file_system_operation_context_, |
| 231 proxy_, virtual_path, callback_factory_.NewCallback( | 231 proxy_, virtual_path, callback_factory_.NewCallback( |
| 232 &FileSystemOperation::DidFileExists)); | 232 &FileSystemOperation::DidFileExists)); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void FileSystemOperation::GetLocalPath(const GURL& path) { |
| 236 #ifndef NDEBUG |
| 237 DCHECK(kOperationNone == pending_operation_); |
| 238 pending_operation_ = kOperationGetLocalPath; |
| 239 #endif |
| 240 |
| 241 FilePath virtual_path; |
| 242 GURL origin_url; |
| 243 FileSystemType type; |
| 244 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { |
| 245 delete this; |
| 246 return; |
| 247 } |
| 248 file_system_operation_context_.set_src_origin_url(origin_url); |
| 249 file_system_operation_context_.set_src_type(type); |
| 250 FileSystemFileUtilProxy::GetLocalPath( |
| 251 file_system_operation_context_, |
| 252 proxy_, virtual_path, callback_factory_.NewCallback( |
| 253 &FileSystemOperation::DidGetLocalPath)); |
| 254 } |
| 255 |
| 235 void FileSystemOperation::GetMetadata(const GURL& path) { | 256 void FileSystemOperation::GetMetadata(const GURL& path) { |
| 236 #ifndef NDEBUG | 257 #ifndef NDEBUG |
| 237 DCHECK(kOperationNone == pending_operation_); | 258 DCHECK(kOperationNone == pending_operation_); |
| 238 pending_operation_ = kOperationGetMetadata; | 259 pending_operation_ = kOperationGetMetadata; |
| 239 #endif | 260 #endif |
| 240 | 261 |
| 241 FilePath virtual_path; | 262 FilePath virtual_path; |
| 242 GURL origin_url; | 263 GURL origin_url; |
| 243 FileSystemType type; | 264 FileSystemType type; |
| 244 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { | 265 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (file_info.is_directory) | 545 if (file_info.is_directory) |
| 525 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); | 546 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); |
| 526 else | 547 else |
| 527 dispatcher_->DidSucceed(); | 548 dispatcher_->DidSucceed(); |
| 528 } else { | 549 } else { |
| 529 dispatcher_->DidFail(rv); | 550 dispatcher_->DidFail(rv); |
| 530 } | 551 } |
| 531 delete this; | 552 delete this; |
| 532 } | 553 } |
| 533 | 554 |
| 555 void FileSystemOperation::DidGetLocalPath( |
| 556 base::PlatformFileError rv, |
| 557 const FilePath& local_path) { |
| 558 if (rv == base::PLATFORM_FILE_OK) |
| 559 dispatcher_->DidGetLocalPath(local_path); |
| 560 else |
| 561 dispatcher_->DidFail(rv); |
| 562 delete this; |
| 563 } |
| 564 |
| 534 void FileSystemOperation::DidGetMetadata( | 565 void FileSystemOperation::DidGetMetadata( |
| 535 base::PlatformFileError rv, | 566 base::PlatformFileError rv, |
| 536 const base::PlatformFileInfo& file_info, | 567 const base::PlatformFileInfo& file_info, |
| 537 const FilePath& platform_path) { | 568 const FilePath& platform_path) { |
| 538 if (rv == base::PLATFORM_FILE_OK) | 569 if (rv == base::PLATFORM_FILE_OK) |
| 539 dispatcher_->DidReadMetadata(file_info, platform_path); | 570 dispatcher_->DidReadMetadata(file_info, platform_path); |
| 540 else | 571 else |
| 541 dispatcher_->DidFail(rv); | 572 dispatcher_->DidFail(rv); |
| 542 delete this; | 573 delete this; |
| 543 } | 574 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 *virtual_path = FilePath(path.path()); | 647 *virtual_path = FilePath(path.path()); |
| 617 #endif | 648 #endif |
| 618 *type = file_system_operation_context_.src_type(); | 649 *type = file_system_operation_context_.src_type(); |
| 619 *origin_url = file_system_operation_context_.src_origin_url(); | 650 *origin_url = file_system_operation_context_.src_origin_url(); |
| 620 return true; | 651 return true; |
| 621 } | 652 } |
| 622 | 653 |
| 623 // We may want do more checks, but for now it just checks if the given | 654 // We may want do more checks, but for now it just checks if the given |
| 624 // URL is valid. | 655 // URL is valid. |
| 625 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 656 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 626 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 657 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 627 return false; | 658 return false; |
| 628 } | 659 } |
| 629 if (!file_system_context()->path_manager()->IsAccessAllowed( | 660 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 630 *origin_url, *type, *virtual_path)) { | 661 *origin_url, *type, *virtual_path)) { |
| 631 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 662 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 632 return false; | 663 return false; |
| 633 } | 664 } |
| 634 | 665 |
| 635 return true; | 666 return true; |
| 636 } | 667 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 653 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); | 684 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 654 #else | 685 #else |
| 655 *virtual_path = FilePath(path.path()); | 686 *virtual_path = FilePath(path.path()); |
| 656 #endif | 687 #endif |
| 657 *type = file_system_operation_context_.dest_type(); | 688 *type = file_system_operation_context_.dest_type(); |
| 658 *origin_url = file_system_operation_context_.dest_origin_url(); | 689 *origin_url = file_system_operation_context_.dest_origin_url(); |
| 659 return true; | 690 return true; |
| 660 } | 691 } |
| 661 | 692 |
| 662 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 693 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 663 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 694 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 664 return false; | 695 return false; |
| 665 } | 696 } |
| 666 if (!file_system_context()->path_manager()->IsAccessAllowed( | 697 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 667 *origin_url, *type, *virtual_path)) { | 698 *origin_url, *type, *virtual_path)) { |
| 668 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 699 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 669 return false; | 700 return false; |
| 670 } | 701 } |
| 671 // Any write access is disallowed on the root path. | 702 // Any write access is disallowed on the root path. |
| 672 if (virtual_path->value().length() == 0 || | 703 if (virtual_path->value().length() == 0 || |
| 673 virtual_path->DirName().value() == virtual_path->value()) { | 704 virtual_path->DirName().value() == virtual_path->value()) { |
| 674 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 705 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 675 return false; | 706 return false; |
| 676 } | 707 } |
| 677 if (create && file_system_context()->path_manager()->IsRestrictedFileName( | 708 if (create && file_system_context()->path_manager()->IsRestrictedFileName( |
| 678 *type, virtual_path->BaseName())) { | 709 *type, virtual_path->BaseName())) { |
| 679 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 710 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 680 return false; | 711 return false; |
| 681 } | 712 } |
| 682 // TODO(kinuko): the check must be moved to QuotaFileSystemFileUtil. | 713 // TODO(kinuko): the check must be moved to QuotaFileSystemFileUtil. |
| 683 if (!file_system_context()->IsStorageUnlimited(*origin_url)) { | 714 if (!file_system_context()->IsStorageUnlimited(*origin_url)) { |
| 684 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); | 715 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); |
| 685 return false; | 716 return false; |
| 686 } | 717 } |
| 687 return true; | 718 return true; |
| 688 } | 719 } |
| 689 | 720 |
| 690 } // namespace fileapi | 721 } // namespace fileapi |
| OLD | NEW |