| 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/media/native_media_file_util.h" | 5 #include "webkit/fileapi/media/native_media_file_util.h" |
| 6 | 6 |
| 7 #include "webkit/fileapi/file_system_operation_context.h" | 7 #include "webkit/fileapi/file_system_operation_context.h" |
| 8 #include "webkit/fileapi/media/media_path_filter.h" | 8 #include "webkit/fileapi/media/media_path_filter.h" |
| 9 #include "webkit/fileapi/media/filtering_file_enumerator.h" | 9 #include "webkit/fileapi/media/filtering_file_enumerator.h" |
| 10 #include "webkit/fileapi/native_file_util.h" | 10 #include "webkit/fileapi/native_file_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 context, | 76 context, |
| 77 url, | 77 url, |
| 78 // Cannot truncate paths that do not exist, or are filtered. | 78 // Cannot truncate paths that do not exist, or are filtered. |
| 79 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 79 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 80 &file_path); | 80 &file_path); |
| 81 if (error != base::PLATFORM_FILE_OK) | 81 if (error != base::PLATFORM_FILE_OK) |
| 82 return error; | 82 return error; |
| 83 return NativeFileUtil::Truncate(file_path, length); | 83 return NativeFileUtil::Truncate(file_path, length); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool NativeMediaFileUtil::IsDirectoryEmpty( | |
| 87 FileSystemOperationContext* context, | |
| 88 const FileSystemURL& url) { | |
| 89 DCHECK(context); | |
| 90 DCHECK(context->media_path_filter()); | |
| 91 | |
| 92 scoped_ptr<AbstractFileEnumerator> enumerator( | |
| 93 CreateFileEnumerator(context, url, false)); | |
| 94 FilePath path; | |
| 95 while (!(path = enumerator->Next()).empty()) { | |
| 96 if (enumerator->IsDirectory() || | |
| 97 context->media_path_filter()->Match(path)) | |
| 98 return false; | |
| 99 } | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( | 86 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( |
| 104 FileSystemOperationContext* context, | 87 FileSystemOperationContext* context, |
| 105 const FileSystemURL& src_url, | 88 const FileSystemURL& src_url, |
| 106 const FileSystemURL& dest_url, | 89 const FileSystemURL& dest_url, |
| 107 bool copy) { | 90 bool copy) { |
| 108 FilePath src_file_path; | 91 FilePath src_file_path; |
| 109 PlatformFileError error = | 92 PlatformFileError error = |
| 110 GetFilteredLocalFilePath(context, src_url, &src_file_path); | 93 GetFilteredLocalFilePathForExistingFileOrDirectory( |
| 94 context, src_url, |
| 95 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 96 &src_file_path); |
| 111 if (error != base::PLATFORM_FILE_OK) | 97 if (error != base::PLATFORM_FILE_OK) |
| 112 return error; | 98 return error; |
| 99 if (NativeFileUtil::DirectoryExists(src_file_path)) |
| 100 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 113 | 101 |
| 114 FilePath dest_file_path; | 102 FilePath dest_file_path; |
| 115 error = GetFilteredLocalFilePath(context, dest_url, &dest_file_path); | 103 error = GetLocalFilePath(context, dest_url, &dest_file_path); |
| 116 if (error != base::PLATFORM_FILE_OK) | 104 if (error != base::PLATFORM_FILE_OK) |
| 117 return error; | 105 return error; |
| 106 PlatformFileInfo file_info; |
| 107 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info); |
| 108 if (error != base::PLATFORM_FILE_OK && |
| 109 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) |
| 110 return error; |
| 111 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) |
| 112 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 113 if (!context->media_path_filter()->Match(dest_file_path)) |
| 114 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 118 | 115 |
| 119 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); | 116 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); |
| 120 } | 117 } |
| 121 | 118 |
| 122 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( | 119 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( |
| 123 FileSystemOperationContext* context, | 120 FileSystemOperationContext* context, |
| 124 const FilePath& src_file_path, | 121 const FilePath& src_file_path, |
| 125 const FileSystemURL& dest_url) { | 122 const FileSystemURL& dest_url) { |
| 126 if (src_file_path.empty()) | 123 if (src_file_path.empty()) |
| 127 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 124 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 128 | 125 |
| 129 FilePath dest_file_path; | 126 FilePath dest_file_path; |
| 130 PlatformFileError error = | 127 PlatformFileError error = |
| 131 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); | 128 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); |
| 132 if (error != base::PLATFORM_FILE_OK) | 129 if (error != base::PLATFORM_FILE_OK) |
| 133 return error; | 130 return error; |
| 134 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true); | 131 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true); |
| 135 } | 132 } |
| 136 | 133 |
| 137 PlatformFileError NativeMediaFileUtil::DeleteFile( | 134 PlatformFileError NativeMediaFileUtil::DeleteFile( |
| 138 FileSystemOperationContext* context, | 135 FileSystemOperationContext* context, |
| 139 const FileSystemURL& url) { | 136 const FileSystemURL& url) { |
| 140 FilePath file_path; | 137 FilePath file_path; |
| 141 PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 138 PlatformFileError error = GetLocalFilePath(context, url, &file_path); |
| 142 if (error != base::PLATFORM_FILE_OK) | 139 if (error != base::PLATFORM_FILE_OK) |
| 143 return error; | 140 return error; |
| 141 PlatformFileInfo file_info; |
| 142 error = NativeFileUtil::GetFileInfo(file_path, &file_info); |
| 143 if (error != base::PLATFORM_FILE_OK) |
| 144 return error; |
| 145 if (file_info.is_directory) |
| 146 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 144 if (!context->media_path_filter()->Match(file_path)) | 147 if (!context->media_path_filter()->Match(file_path)) |
| 145 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 148 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 146 return NativeFileUtil::DeleteFile(file_path); | 149 return NativeFileUtil::DeleteFile(file_path); |
| 147 } | 150 } |
| 148 | 151 |
| 149 PlatformFileError NativeMediaFileUtil::GetFileInfo( | 152 PlatformFileError NativeMediaFileUtil::GetFileInfo( |
| 150 FileSystemOperationContext* context, | 153 FileSystemOperationContext* context, |
| 151 const FileSystemURL& url, | 154 const FileSystemURL& url, |
| 152 PlatformFileInfo* file_info, | 155 PlatformFileInfo* file_info, |
| 153 FilePath* platform_path) { | 156 FilePath* platform_path) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (!file_info.is_directory && | 208 if (!file_info.is_directory && |
| 206 !context->media_path_filter()->Match(file_path)) { | 209 !context->media_path_filter()->Match(file_path)) { |
| 207 return failure_error; | 210 return failure_error; |
| 208 } | 211 } |
| 209 | 212 |
| 210 *local_file_path = file_path; | 213 *local_file_path = file_path; |
| 211 return base::PLATFORM_FILE_OK; | 214 return base::PLATFORM_FILE_OK; |
| 212 } | 215 } |
| 213 | 216 |
| 214 } // namespace fileapi | 217 } // namespace fileapi |
| OLD | NEW |