Chromium Code Reviews| Index: webkit/plugins/ppapi/ppb_flash_file_impl.cc |
| diff --git a/webkit/plugins/ppapi/ppb_flash_file_impl.cc b/webkit/plugins/ppapi/ppb_flash_file_impl.cc |
| index bbd7f97176329df13758ccde1dc5f38f9eaf2ec4..4df193c13d1e18cde41218774e23d97d5ebb7e6f 100644 |
| --- a/webkit/plugins/ppapi/ppb_flash_file_impl.cc |
| +++ b/webkit/plugins/ppapi/ppb_flash_file_impl.cc |
| @@ -222,5 +222,175 @@ const PPB_Flash_File_ModuleLocal* |
| return &ppb_flash_file_modulelocal; |
| } |
| +// PPB_Flash_File_FileRef_Impl ------------------------------------------------- |
| + |
| +namespace { |
| + |
| +int32_t OpenFileRefFile(PP_Resource file_ref_id, |
| + int32_t mode, |
| + PP_FileHandle* file) { |
| + int flags = 0; |
| + if (!ConvertFromPPFileOpenFlags(mode, &flags) || !file) |
| + return PP_ERROR_BADARGUMENT; |
| + |
| + scoped_refptr<PPB_FileRef_Impl> file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| + if (!file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PluginInstance* instance = file_ref->instance(); |
| + if (!instance) |
| + return PP_ERROR_FAILED; |
| + |
| + base::PlatformFile base_file; |
| + base::PlatformFileError result = instance->delegate()->OpenFile( |
| + PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| + flags, |
| + &base_file); |
| + *file = base_file; |
| + return PlatformFileErrorToPepperError(result); |
| +} |
| + |
| +int32_t RenameFileRefFile(PP_Resource from_file_ref_id, |
| + PP_Resource to_file_ref_id) { |
|
piman
2011/03/01 21:54:29
I'm not sure we actually need Rename/Delete/Create
|
| + scoped_refptr<PPB_FileRef_Impl> from_file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(from_file_ref_id)); |
| + if (!from_file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + scoped_refptr<PPB_FileRef_Impl> to_file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(to_file_ref_id)); |
| + if (!to_file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PluginInstance* instance = from_file_ref->instance(); |
| + if (!instance) |
| + return PP_ERROR_FAILED; |
| + DCHECK(to_file_ref->instance() == instance); |
| + |
| + base::PlatformFileError result = instance->delegate()->RenameFile( |
| + PepperFilePath::MakeAbsolute(from_file_ref->GetSystemPath()), |
| + PepperFilePath::MakeAbsolute(to_file_ref->GetSystemPath())); |
| + return PlatformFileErrorToPepperError(result); |
| +} |
| + |
| +int32_t DeleteFileRefFileOrDir(PP_Resource file_ref_id, |
| + PP_Bool recursive) { |
| + scoped_refptr<PPB_FileRef_Impl> file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| + if (!file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PluginInstance* instance = file_ref->instance(); |
| + if (!instance) |
| + return PP_ERROR_FAILED; |
| + |
| + base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( |
| + PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| + PPBoolToBool(recursive)); |
| + return PlatformFileErrorToPepperError(result); |
| +} |
| + |
| +int32_t CreateFileRefDir(PP_Resource file_ref_id) { |
| + scoped_refptr<PPB_FileRef_Impl> file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| + if (!file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PluginInstance* instance = file_ref->instance(); |
| + if (!instance) |
| + return PP_ERROR_FAILED; |
| + |
| + base::PlatformFileError result = instance->delegate()->CreateDir( |
| + PepperFilePath::MakeAbsolute(file_ref->GetSystemPath())); |
| + return PlatformFileErrorToPepperError(result); |
| +} |
| + |
| +int32_t QueryFileRefFile(PP_Resource file_ref_id, |
| + PP_FileInfo_Dev* info) { |
| + scoped_refptr<PPB_FileRef_Impl> file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| + if (!file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PluginInstance* instance = file_ref->instance(); |
| + if (!instance) |
| + return PP_ERROR_FAILED; |
| + |
| + base::PlatformFileInfo file_info; |
| + base::PlatformFileError result = instance->delegate()->QueryFile( |
| + PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| + &file_info); |
| + if (result == base::PLATFORM_FILE_OK) { |
| + info->size = file_info.size; |
| + info->creation_time = file_info.creation_time.ToDoubleT(); |
| + info->last_access_time = file_info.last_accessed.ToDoubleT(); |
| + info->last_modified_time = file_info.last_modified.ToDoubleT(); |
| + info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| + if (file_info.is_directory) |
| + info->type = PP_FILETYPE_DIRECTORY; |
| + else |
| + info->type = PP_FILETYPE_REGULAR; |
| + } |
| + return PlatformFileErrorToPepperError(result); |
| +} |
| + |
| +int32_t GetFileRefDirContents(PP_Resource file_ref_id, |
| + PP_DirContents_Dev** contents) { |
| + scoped_refptr<PPB_FileRef_Impl> file_ref( |
| + Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| + if (!file_ref) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PluginInstance* instance = file_ref->instance(); |
| + if (!instance) |
| + return PP_ERROR_FAILED; |
| + |
| + *contents = NULL; |
| + DirContents pepper_contents; |
| + base::PlatformFileError result = instance->delegate()->GetDirContents( |
| + PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| + &pepper_contents); |
| + |
| + if (result != base::PLATFORM_FILE_OK) |
| + return PlatformFileErrorToPepperError(result); |
| + |
| + *contents = new PP_DirContents_Dev; |
| + size_t count = pepper_contents.size(); |
| + (*contents)->count = count; |
| + (*contents)->entries = new PP_DirEntry_Dev[count]; |
| + for (size_t i = 0; i < count; ++i) { |
| + PP_DirEntry_Dev& entry = (*contents)->entries[i]; |
| +#if defined(OS_WIN) |
| + const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); |
| +#else |
| + const std::string& name = pepper_contents[i].name.value(); |
| +#endif |
| + size_t size = name.size() + 1; |
| + char* name_copy = new char[size]; |
| + memcpy(name_copy, name.c_str(), size); |
| + entry.name = name_copy; |
| + entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir); |
| + } |
| + return PP_OK; |
| +} |
| + |
| +const PPB_Flash_File_FileRef ppb_flash_file_fileref = { |
| + &OpenFileRefFile, |
| + &RenameFileRefFile, |
| + &DeleteFileRefFileOrDir, |
| + &CreateFileRefDir, |
| + &QueryFileRefFile, |
| + &GetFileRefDirContents, |
| + &FreeDirContents, |
| +}; |
| + |
| +} // namespace |
| + |
| +// static |
| +const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() { |
| + return &ppb_flash_file_fileref; |
| +} |
| + |
| } // namespace ppapi |
| } // namespace webkit |