| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/fileapi/isolated_file_util.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "webkit/blob/shareable_file_reference.h" | |
| 11 #include "webkit/fileapi/file_system_context.h" | |
| 12 #include "webkit/fileapi/file_system_operation_context.h" | |
| 13 #include "webkit/fileapi/file_system_url.h" | |
| 14 #include "webkit/fileapi/isolated_context.h" | |
| 15 #include "webkit/fileapi/native_file_util.h" | |
| 16 | |
| 17 using base::PlatformFileError; | |
| 18 using base::PlatformFileInfo; | |
| 19 | |
| 20 namespace fileapi { | |
| 21 | |
| 22 typedef IsolatedContext::MountPointInfo FileInfo; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 // Simply enumerate each path from a given fileinfo set. | |
| 27 // Used to enumerate top-level paths of an isolated filesystem. | |
| 28 class SetFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { | |
| 29 public: | |
| 30 explicit SetFileEnumerator(const std::vector<FileInfo>& files) | |
| 31 : files_(files) { | |
| 32 file_iter_ = files_.begin(); | |
| 33 } | |
| 34 virtual ~SetFileEnumerator() {} | |
| 35 | |
| 36 // AbstractFileEnumerator overrides. | |
| 37 virtual base::FilePath Next() OVERRIDE { | |
| 38 if (file_iter_ == files_.end()) | |
| 39 return base::FilePath(); | |
| 40 base::FilePath platform_file = (file_iter_++)->path; | |
| 41 NativeFileUtil::GetFileInfo(platform_file, &file_info_); | |
| 42 return platform_file; | |
| 43 } | |
| 44 virtual int64 Size() OVERRIDE { return file_info_.size; } | |
| 45 virtual bool IsDirectory() OVERRIDE { return file_info_.is_directory; } | |
| 46 virtual base::Time LastModifiedTime() OVERRIDE { | |
| 47 return file_info_.last_modified; | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 std::vector<FileInfo> files_; | |
| 52 std::vector<FileInfo>::const_iterator file_iter_; | |
| 53 base::PlatformFileInfo file_info_; | |
| 54 }; | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 //------------------------------------------------------------------------- | |
| 59 | |
| 60 IsolatedFileUtil::IsolatedFileUtil() {} | |
| 61 | |
| 62 PlatformFileError IsolatedFileUtil::GetLocalFilePath( | |
| 63 FileSystemOperationContext* context, | |
| 64 const FileSystemURL& url, | |
| 65 base::FilePath* local_file_path) { | |
| 66 DCHECK(local_file_path); | |
| 67 DCHECK(url.is_valid()); | |
| 68 if (url.path().empty()) { | |
| 69 // Root direcory case, which should not be accessed. | |
| 70 return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | |
| 71 } | |
| 72 *local_file_path = url.path(); | |
| 73 return base::PLATFORM_FILE_OK; | |
| 74 } | |
| 75 | |
| 76 //------------------------------------------------------------------------- | |
| 77 | |
| 78 DraggedFileUtil::DraggedFileUtil() {} | |
| 79 | |
| 80 PlatformFileError DraggedFileUtil::GetFileInfo( | |
| 81 FileSystemOperationContext* context, | |
| 82 const FileSystemURL& url, | |
| 83 PlatformFileInfo* file_info, | |
| 84 base::FilePath* platform_path) { | |
| 85 DCHECK(file_info); | |
| 86 std::string filesystem_id; | |
| 87 DCHECK(url.is_valid()); | |
| 88 if (url.path().empty()) { | |
| 89 // The root directory case. | |
| 90 // For now we leave three time fields (modified/accessed/creation time) | |
| 91 // NULL as it is not really clear what to be set for this virtual directory. | |
| 92 // TODO(kinuko): Maybe we want to set the time when this filesystem is | |
| 93 // created (i.e. when the files/directories are dropped). | |
| 94 file_info->is_directory = true; | |
| 95 file_info->is_symbolic_link = false; | |
| 96 file_info->size = 0; | |
| 97 return base::PLATFORM_FILE_OK; | |
| 98 } | |
| 99 base::PlatformFileError error = | |
| 100 NativeFileUtil::GetFileInfo(url.path(), file_info); | |
| 101 if (file_util::IsLink(url.path()) && !base::FilePath().IsParent(url.path())) { | |
| 102 // Don't follow symlinks unless it's the one that are selected by the user. | |
| 103 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 104 } | |
| 105 if (error == base::PLATFORM_FILE_OK) | |
| 106 *platform_path = url.path(); | |
| 107 return error; | |
| 108 } | |
| 109 | |
| 110 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | |
| 111 DraggedFileUtil::CreateFileEnumerator( | |
| 112 FileSystemOperationContext* context, | |
| 113 const FileSystemURL& root) { | |
| 114 DCHECK(root.is_valid()); | |
| 115 if (!root.path().empty()) | |
| 116 return LocalFileUtil::CreateFileEnumerator(context, root); | |
| 117 | |
| 118 // Root path case. | |
| 119 std::vector<FileInfo> toplevels; | |
| 120 IsolatedContext::GetInstance()->GetDraggedFileInfo( | |
| 121 root.filesystem_id(), &toplevels); | |
| 122 return scoped_ptr<AbstractFileEnumerator>(new SetFileEnumerator(toplevels)); | |
| 123 } | |
| 124 | |
| 125 } // namespace fileapi | |
| OLD | NEW |