diff options
Diffstat (limited to 'webkit/fileapi/media/native_media_file_util.cc')
-rw-r--r-- | webkit/fileapi/media/native_media_file_util.cc | 119 |
1 files changed, 100 insertions, 19 deletions
diff --git a/webkit/fileapi/media/native_media_file_util.cc b/webkit/fileapi/media/native_media_file_util.cc index 4ccbc34..4e99c82 100644 --- a/webkit/fileapi/media/native_media_file_util.cc +++ b/webkit/fileapi/media/native_media_file_util.cc @@ -7,6 +7,7 @@ #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/media/media_path_filter.h" #include "webkit/fileapi/media/filtering_file_enumerator.h" +#include "webkit/fileapi/native_file_util.h" using base::PlatformFile; using base::PlatformFileError; @@ -23,17 +24,18 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen( int file_flags, PlatformFile* file_handle, bool* created) { - // TODO(tzik): Apply context()->media_path_filter() here when we support write - // access. + // Only called by NaCl, which should not have access to media file systems. return base::PLATFORM_FILE_ERROR_SECURITY; } PlatformFileError NativeMediaFileUtil::EnsureFileExists( FileSystemOperationContext* context, const FileSystemURL& url, bool* created) { - // TODO(tzik): Apply context()->media_path_filter() here when we support write - // access. - return base::PLATFORM_FILE_ERROR_SECURITY; + FilePath file_path; + PlatformFileError error = GetFilteredLocalFilePath(context, url, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::EnsureFileExists(file_path, created); } scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> @@ -53,18 +55,32 @@ PlatformFileError NativeMediaFileUtil::Touch( const FileSystemURL& url, const base::Time& last_access_time, const base::Time& last_modified_time) { - // TODO(tzik): Apply context()->media_path_filter() here when we support write - // access. - return base::PLATFORM_FILE_ERROR_SECURITY; + FilePath file_path; + PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( + context, + url, + // Touch fails for non-existent paths and filtered paths. + base::PLATFORM_FILE_ERROR_FAILED, + &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::Touch(file_path, last_access_time, last_modified_time); } PlatformFileError NativeMediaFileUtil::Truncate( FileSystemOperationContext* context, const FileSystemURL& url, int64 length) { - // TODO(tzik): Apply context()->media_path_filter() here when we support write - // access. - return base::PLATFORM_FILE_ERROR_SECURITY; + FilePath file_path; + PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( + context, + url, + // Cannot truncate paths that do not exist, or are filtered. + base::PLATFORM_FILE_ERROR_NOT_FOUND, + &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::Truncate(file_path, length); } bool NativeMediaFileUtil::IsDirectoryEmpty( @@ -89,24 +105,45 @@ PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( const FileSystemURL& src_url, const FileSystemURL& dest_url, bool copy) { - // TODO(tzik): Apply context()->media_path_filter() here when we support write - // access. - return base::PLATFORM_FILE_ERROR_SECURITY; + FilePath src_file_path; + PlatformFileError error = + GetFilteredLocalFilePath(context, src_url, &src_file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + + FilePath dest_file_path; + error = GetFilteredLocalFilePath(context, dest_url, &dest_file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + + return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); } PlatformFileError NativeMediaFileUtil::CopyInForeignFile( FileSystemOperationContext* context, const FilePath& src_file_path, const FileSystemURL& dest_url) { - // TODO(tzik): Apply context()->media_path_filter() here when we support write - // access. - return base::PLATFORM_FILE_ERROR_SECURITY; + if (src_file_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + + FilePath dest_file_path; + PlatformFileError error = + GetFilteredLocalFilePath(context, dest_url, &dest_file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true); } PlatformFileError NativeMediaFileUtil::DeleteFile( FileSystemOperationContext* context, const FileSystemURL& url) { - return base::PLATFORM_FILE_ERROR_SECURITY; + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, url, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + if (!context->media_path_filter()->Match(file_path)) + return base::PLATFORM_FILE_ERROR_NOT_FOUND; + return NativeFileUtil::DeleteFile(file_path); } PlatformFileError NativeMediaFileUtil::GetFileInfo( @@ -125,9 +162,53 @@ PlatformFileError NativeMediaFileUtil::GetFileInfo( return error; if (file_info->is_directory || - context->media_path_filter()->Match(*platform_path)) + context->media_path_filter()->Match(*platform_path)) { return base::PLATFORM_FILE_OK; + } return base::PLATFORM_FILE_ERROR_NOT_FOUND; } +PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( + FileSystemOperationContext* context, + const FileSystemURL& file_system_url, + FilePath* local_file_path) { + FilePath file_path; + PlatformFileError error = + IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + if (!context->media_path_filter()->Match(file_path)) + return base::PLATFORM_FILE_ERROR_SECURITY; + + *local_file_path = file_path; + return base::PLATFORM_FILE_OK; +} + +PlatformFileError +NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( + FileSystemOperationContext* context, + const FileSystemURL& file_system_url, + PlatformFileError failure_error, + FilePath* local_file_path) { + FilePath file_path; + PlatformFileError error = + GetLocalFilePath(context, file_system_url, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + + if (!file_util::PathExists(file_path)) + return failure_error; + PlatformFileInfo file_info; + if (!file_util::GetFileInfo(file_path, &file_info)) + return base::PLATFORM_FILE_ERROR_FAILED; + + if (!file_info.is_directory && + !context->media_path_filter()->Match(file_path)) { + return failure_error; + } + + *local_file_path = file_path; + return base::PLATFORM_FILE_OK; +} + } // namespace fileapi |