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/browser/fileapi/local_file_util.h" | 5 #include "webkit/browser/fileapi/local_file_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/file_util_proxy.h" | 9 #include "base/files/file_util_proxy.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 private: | 44 private: |
45 base::FileEnumerator file_enum_; | 45 base::FileEnumerator file_enum_; |
46 base::FileEnumerator::FileInfo file_util_info_; | 46 base::FileEnumerator::FileInfo file_util_info_; |
47 base::FilePath platform_root_path_; | 47 base::FilePath platform_root_path_; |
48 base::FilePath virtual_root_path_; | 48 base::FilePath virtual_root_path_; |
49 }; | 49 }; |
50 | 50 |
51 base::FilePath LocalFileEnumerator::Next() { | 51 base::FilePath LocalFileEnumerator::Next() { |
52 base::FilePath next = file_enum_.Next(); | 52 base::FilePath next = file_enum_.Next(); |
53 // Don't return symlinks. | 53 // Don't return symlinks. |
54 while (!next.empty() && file_util::IsLink(next)) | 54 while (!next.empty() && base::IsLink(next)) |
55 next = file_enum_.Next(); | 55 next = file_enum_.Next(); |
56 if (next.empty()) | 56 if (next.empty()) |
57 return next; | 57 return next; |
58 file_util_info_ = file_enum_.GetInfo(); | 58 file_util_info_ = file_enum_.GetInfo(); |
59 | 59 |
60 base::FilePath path; | 60 base::FilePath path; |
61 platform_root_path_.AppendRelativePath(next, &path); | 61 platform_root_path_.AppendRelativePath(next, &path); |
62 return virtual_root_path_.Append(path); | 62 return virtual_root_path_.Append(path); |
63 } | 63 } |
64 | 64 |
(...skipping 16 matching lines...) Expand all Loading... |
81 PlatformFileError LocalFileUtil::CreateOrOpen( | 81 PlatformFileError LocalFileUtil::CreateOrOpen( |
82 FileSystemOperationContext* context, | 82 FileSystemOperationContext* context, |
83 const FileSystemURL& url, int file_flags, | 83 const FileSystemURL& url, int file_flags, |
84 base::PlatformFile* file_handle, bool* created) { | 84 base::PlatformFile* file_handle, bool* created) { |
85 *created = false; | 85 *created = false; |
86 base::FilePath file_path; | 86 base::FilePath file_path; |
87 PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 87 PlatformFileError error = GetLocalFilePath(context, url, &file_path); |
88 if (error != base::PLATFORM_FILE_OK) | 88 if (error != base::PLATFORM_FILE_OK) |
89 return error; | 89 return error; |
90 // Disallow opening files in symlinked paths. | 90 // Disallow opening files in symlinked paths. |
91 if (file_util::IsLink(file_path)) | 91 if (base::IsLink(file_path)) |
92 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 92 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
93 return NativeFileUtil::CreateOrOpen( | 93 return NativeFileUtil::CreateOrOpen( |
94 file_path, file_flags, file_handle, created); | 94 file_path, file_flags, file_handle, created); |
95 } | 95 } |
96 | 96 |
97 PlatformFileError LocalFileUtil::Close(FileSystemOperationContext* context, | 97 PlatformFileError LocalFileUtil::Close(FileSystemOperationContext* context, |
98 base::PlatformFile file) { | 98 base::PlatformFile file) { |
99 return NativeFileUtil::Close(file); | 99 return NativeFileUtil::Close(file); |
100 } | 100 } |
101 | 101 |
(...skipping 23 matching lines...) Expand all Loading... |
125 PlatformFileError LocalFileUtil::GetFileInfo( | 125 PlatformFileError LocalFileUtil::GetFileInfo( |
126 FileSystemOperationContext* context, | 126 FileSystemOperationContext* context, |
127 const FileSystemURL& url, | 127 const FileSystemURL& url, |
128 base::PlatformFileInfo* file_info, | 128 base::PlatformFileInfo* file_info, |
129 base::FilePath* platform_file_path) { | 129 base::FilePath* platform_file_path) { |
130 base::FilePath file_path; | 130 base::FilePath file_path; |
131 PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 131 PlatformFileError error = GetLocalFilePath(context, url, &file_path); |
132 if (error != base::PLATFORM_FILE_OK) | 132 if (error != base::PLATFORM_FILE_OK) |
133 return error; | 133 return error; |
134 // We should not follow symbolic links in sandboxed file system. | 134 // We should not follow symbolic links in sandboxed file system. |
135 if (file_util::IsLink(file_path)) | 135 if (base::IsLink(file_path)) |
136 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 136 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
137 error = NativeFileUtil::GetFileInfo(file_path, file_info); | 137 error = NativeFileUtil::GetFileInfo(file_path, file_info); |
138 if (error == base::PLATFORM_FILE_OK) | 138 if (error == base::PLATFORM_FILE_OK) |
139 *platform_file_path = file_path; | 139 *platform_file_path = file_path; |
140 return error; | 140 return error; |
141 } | 141 } |
142 | 142 |
143 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> LocalFileUtil:: | 143 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> LocalFileUtil:: |
144 CreateFileEnumerator( | 144 CreateFileEnumerator( |
145 FileSystemOperationContext* context, | 145 FileSystemOperationContext* context, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 base::FilePath* platform_path) { | 257 base::FilePath* platform_path) { |
258 DCHECK(file_info); | 258 DCHECK(file_info); |
259 // We're just returning the local file information. | 259 // We're just returning the local file information. |
260 *error = GetFileInfo(context, url, file_info, platform_path); | 260 *error = GetFileInfo(context, url, file_info, platform_path); |
261 if (*error == base::PLATFORM_FILE_OK && file_info->is_directory) | 261 if (*error == base::PLATFORM_FILE_OK && file_info->is_directory) |
262 *error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 262 *error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
263 return webkit_blob::ScopedFile(); | 263 return webkit_blob::ScopedFile(); |
264 } | 264 } |
265 | 265 |
266 } // namespace fileapi | 266 } // namespace fileapi |
OLD | NEW |