| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugins/ppapi/ppb_flash_file_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_file_impl.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "ppapi/c/pp_file_info.h" | 11 #include "ppapi/c/pp_file_info.h" |
| 12 #include "ppapi/c/ppb_file_io.h" | 12 #include "ppapi/c/ppb_file_io.h" |
| 13 #include "ppapi/c/private/ppb_flash_file.h" | 13 #include "ppapi/c/private/ppb_flash_file.h" |
| 14 #include "ppapi/shared_impl/file_type_conversion.h" | |
| 15 #include "ppapi/shared_impl/time_conversion.h" | 14 #include "ppapi/shared_impl/time_conversion.h" |
| 16 #include "ppapi/thunk/enter.h" | 15 #include "ppapi/thunk/enter.h" |
| 17 #include "webkit/plugins/ppapi/common.h" | 16 #include "webkit/plugins/ppapi/common.h" |
| 18 #include "webkit/plugins/ppapi/file_path.h" | 17 #include "webkit/plugins/ppapi/file_path.h" |
| 18 #include "webkit/plugins/ppapi/file_type_conversions.h" |
| 19 #include "webkit/plugins/ppapi/host_globals.h" | 19 #include "webkit/plugins/ppapi/host_globals.h" |
| 20 #include "webkit/plugins/ppapi/plugin_delegate.h" | 20 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 21 #include "webkit/plugins/ppapi/plugin_module.h" | 21 #include "webkit/plugins/ppapi/plugin_module.h" |
| 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 23 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 23 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 24 #include "webkit/plugins/ppapi/resource_helper.h" | 24 #include "webkit/plugins/ppapi/resource_helper.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 27 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
| 28 #endif | 28 #endif |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ClearThreadAdapterForInstance(PP_Instance instance) { | 58 void ClearThreadAdapterForInstance(PP_Instance instance) { |
| 59 } | 59 } |
| 60 | 60 |
| 61 int32_t OpenModuleLocalFile(PP_Instance pp_instance, | 61 int32_t OpenModuleLocalFile(PP_Instance pp_instance, |
| 62 const char* path, | 62 const char* path, |
| 63 int32_t mode, | 63 int32_t mode, |
| 64 PP_FileHandle* file) { | 64 PP_FileHandle* file) { |
| 65 int flags = 0; | 65 int flags = 0; |
| 66 if (!path || | 66 if (!path || !PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) |
| 67 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | |
| 68 !file) | |
| 69 return PP_ERROR_BADARGUMENT; | 67 return PP_ERROR_BADARGUMENT; |
| 70 | 68 |
| 71 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 69 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 72 if (!instance) | 70 if (!instance) |
| 73 return PP_ERROR_FAILED; | 71 return PP_ERROR_FAILED; |
| 74 | 72 |
| 75 base::PlatformFile base_file; | 73 base::PlatformFile base_file; |
| 76 base::PlatformFileError result = instance->delegate()->OpenFile( | 74 base::PlatformFileError result = instance->delegate()->OpenFile( |
| 77 PepperFilePath::MakeModuleLocal(instance->module(), path), | 75 PepperFilePath::MakeModuleLocal(instance->module(), path), |
| 78 flags, | 76 flags, |
| 79 &base_file); | 77 &base_file); |
| 80 *file = base_file; | 78 *file = base_file; |
| 81 return ::ppapi::PlatformFileErrorToPepperError(result); | 79 return PlatformFileErrorToPepperError(result); |
| 82 } | 80 } |
| 83 | 81 |
| 84 int32_t RenameModuleLocalFile(PP_Instance pp_instance, | 82 int32_t RenameModuleLocalFile(PP_Instance pp_instance, |
| 85 const char* from_path, | 83 const char* from_path, |
| 86 const char* to_path) { | 84 const char* to_path) { |
| 87 if (!from_path || !to_path) | 85 if (!from_path || !to_path) |
| 88 return PP_ERROR_BADARGUMENT; | 86 return PP_ERROR_BADARGUMENT; |
| 89 | 87 |
| 90 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 88 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 91 if (!instance) | 89 if (!instance) |
| 92 return PP_ERROR_FAILED; | 90 return PP_ERROR_FAILED; |
| 93 | 91 |
| 94 base::PlatformFileError result = instance->delegate()->RenameFile( | 92 base::PlatformFileError result = instance->delegate()->RenameFile( |
| 95 PepperFilePath::MakeModuleLocal(instance->module(), from_path), | 93 PepperFilePath::MakeModuleLocal(instance->module(), from_path), |
| 96 PepperFilePath::MakeModuleLocal(instance->module(), to_path)); | 94 PepperFilePath::MakeModuleLocal(instance->module(), to_path)); |
| 97 return ::ppapi::PlatformFileErrorToPepperError(result); | 95 return PlatformFileErrorToPepperError(result); |
| 98 } | 96 } |
| 99 | 97 |
| 100 int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, | 98 int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, |
| 101 const char* path, | 99 const char* path, |
| 102 PP_Bool recursive) { | 100 PP_Bool recursive) { |
| 103 if (!path) | 101 if (!path) |
| 104 return PP_ERROR_BADARGUMENT; | 102 return PP_ERROR_BADARGUMENT; |
| 105 | 103 |
| 106 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 104 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 107 if (!instance) | 105 if (!instance) |
| 108 return PP_ERROR_FAILED; | 106 return PP_ERROR_FAILED; |
| 109 | 107 |
| 110 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( | 108 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( |
| 111 PepperFilePath::MakeModuleLocal(instance->module(), path), | 109 PepperFilePath::MakeModuleLocal(instance->module(), path), |
| 112 PPBoolToBool(recursive)); | 110 PPBoolToBool(recursive)); |
| 113 return ::ppapi::PlatformFileErrorToPepperError(result); | 111 return PlatformFileErrorToPepperError(result); |
| 114 } | 112 } |
| 115 | 113 |
| 116 int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) { | 114 int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) { |
| 117 if (!path) | 115 if (!path) |
| 118 return PP_ERROR_BADARGUMENT; | 116 return PP_ERROR_BADARGUMENT; |
| 119 | 117 |
| 120 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 118 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 121 if (!instance) | 119 if (!instance) |
| 122 return PP_ERROR_FAILED; | 120 return PP_ERROR_FAILED; |
| 123 | 121 |
| 124 base::PlatformFileError result = instance->delegate()->CreateDir( | 122 base::PlatformFileError result = instance->delegate()->CreateDir( |
| 125 PepperFilePath::MakeModuleLocal(instance->module(), path)); | 123 PepperFilePath::MakeModuleLocal(instance->module(), path)); |
| 126 return ::ppapi::PlatformFileErrorToPepperError(result); | 124 return PlatformFileErrorToPepperError(result); |
| 127 } | 125 } |
| 128 | 126 |
| 129 int32_t QueryModuleLocalFile(PP_Instance pp_instance, | 127 int32_t QueryModuleLocalFile(PP_Instance pp_instance, |
| 130 const char* path, | 128 const char* path, |
| 131 PP_FileInfo* info) { | 129 PP_FileInfo* info) { |
| 132 if (!path || !info) | 130 if (!path || !info) |
| 133 return PP_ERROR_BADARGUMENT; | 131 return PP_ERROR_BADARGUMENT; |
| 134 | 132 |
| 135 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 133 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 136 if (!instance) | 134 if (!instance) |
| 137 return PP_ERROR_FAILED; | 135 return PP_ERROR_FAILED; |
| 138 | 136 |
| 139 base::PlatformFileInfo file_info; | 137 base::PlatformFileInfo file_info; |
| 140 base::PlatformFileError result = instance->delegate()->QueryFile( | 138 base::PlatformFileError result = instance->delegate()->QueryFile( |
| 141 PepperFilePath::MakeModuleLocal(instance->module(), path), | 139 PepperFilePath::MakeModuleLocal(instance->module(), path), |
| 142 &file_info); | 140 &file_info); |
| 143 if (result == base::PLATFORM_FILE_OK) { | 141 if (result == base::PLATFORM_FILE_OK) { |
| 144 info->size = file_info.size; | 142 info->size = file_info.size; |
| 145 info->creation_time = TimeToPPTime(file_info.creation_time); | 143 info->creation_time = TimeToPPTime(file_info.creation_time); |
| 146 info->last_access_time = TimeToPPTime(file_info.last_accessed); | 144 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 147 info->last_modified_time = TimeToPPTime(file_info.last_modified); | 145 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 148 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | 146 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 149 if (file_info.is_directory) | 147 if (file_info.is_directory) |
| 150 info->type = PP_FILETYPE_DIRECTORY; | 148 info->type = PP_FILETYPE_DIRECTORY; |
| 151 else | 149 else |
| 152 info->type = PP_FILETYPE_REGULAR; | 150 info->type = PP_FILETYPE_REGULAR; |
| 153 } | 151 } |
| 154 return ::ppapi::PlatformFileErrorToPepperError(result); | 152 return PlatformFileErrorToPepperError(result); |
| 155 } | 153 } |
| 156 | 154 |
| 157 int32_t GetModuleLocalDirContents(PP_Instance pp_instance, | 155 int32_t GetModuleLocalDirContents(PP_Instance pp_instance, |
| 158 const char* path, | 156 const char* path, |
| 159 PP_DirContents_Dev** contents) { | 157 PP_DirContents_Dev** contents) { |
| 160 if (!path || !contents) | 158 if (!path || !contents) |
| 161 return PP_ERROR_BADARGUMENT; | 159 return PP_ERROR_BADARGUMENT; |
| 162 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 160 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 163 if (!instance) | 161 if (!instance) |
| 164 return PP_ERROR_FAILED; | 162 return PP_ERROR_FAILED; |
| 165 | 163 |
| 166 *contents = NULL; | 164 *contents = NULL; |
| 167 DirContents pepper_contents; | 165 DirContents pepper_contents; |
| 168 base::PlatformFileError result = instance->delegate()->GetDirContents( | 166 base::PlatformFileError result = instance->delegate()->GetDirContents( |
| 169 PepperFilePath::MakeModuleLocal(instance->module(), path), | 167 PepperFilePath::MakeModuleLocal(instance->module(), path), |
| 170 &pepper_contents); | 168 &pepper_contents); |
| 171 | 169 |
| 172 if (result != base::PLATFORM_FILE_OK) | 170 if (result != base::PLATFORM_FILE_OK) |
| 173 return ::ppapi::PlatformFileErrorToPepperError(result); | 171 return PlatformFileErrorToPepperError(result); |
| 174 | 172 |
| 175 *contents = new PP_DirContents_Dev; | 173 *contents = new PP_DirContents_Dev; |
| 176 size_t count = pepper_contents.size(); | 174 size_t count = pepper_contents.size(); |
| 177 (*contents)->count = count; | 175 (*contents)->count = count; |
| 178 (*contents)->entries = new PP_DirEntry_Dev[count]; | 176 (*contents)->entries = new PP_DirEntry_Dev[count]; |
| 179 for (size_t i = 0; i < count; ++i) { | 177 for (size_t i = 0; i < count; ++i) { |
| 180 PP_DirEntry_Dev& entry = (*contents)->entries[i]; | 178 PP_DirEntry_Dev& entry = (*contents)->entries[i]; |
| 181 #if defined(OS_WIN) | 179 #if defined(OS_WIN) |
| 182 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); | 180 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); |
| 183 #else | 181 #else |
| (...skipping 29 matching lines...) Expand all Loading... |
| 213 } | 211 } |
| 214 | 212 |
| 215 // PPB_Flash_File_FileRef_Impl ------------------------------------------------- | 213 // PPB_Flash_File_FileRef_Impl ------------------------------------------------- |
| 216 | 214 |
| 217 namespace { | 215 namespace { |
| 218 | 216 |
| 219 int32_t OpenFileRefFile(PP_Resource file_ref_id, | 217 int32_t OpenFileRefFile(PP_Resource file_ref_id, |
| 220 int32_t mode, | 218 int32_t mode, |
| 221 PP_FileHandle* file) { | 219 PP_FileHandle* file) { |
| 222 int flags = 0; | 220 int flags = 0; |
| 223 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) | 221 if (!PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) |
| 224 return PP_ERROR_BADARGUMENT; | 222 return PP_ERROR_BADARGUMENT; |
| 225 | 223 |
| 226 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); | 224 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); |
| 227 if (enter.failed()) | 225 if (enter.failed()) |
| 228 return PP_ERROR_BADRESOURCE; | 226 return PP_ERROR_BADRESOURCE; |
| 229 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | 227 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 230 | 228 |
| 231 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); | 229 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); |
| 232 if (!instance) | 230 if (!instance) |
| 233 return PP_ERROR_FAILED; | 231 return PP_ERROR_FAILED; |
| 234 | 232 |
| 235 base::PlatformFile base_file; | 233 base::PlatformFile base_file; |
| 236 base::PlatformFileError result = instance->delegate()->OpenFile( | 234 base::PlatformFileError result = instance->delegate()->OpenFile( |
| 237 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | 235 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| 238 flags, | 236 flags, |
| 239 &base_file); | 237 &base_file); |
| 240 *file = base_file; | 238 *file = base_file; |
| 241 return ::ppapi::PlatformFileErrorToPepperError(result); | 239 return PlatformFileErrorToPepperError(result); |
| 242 } | 240 } |
| 243 | 241 |
| 244 int32_t QueryFileRefFile(PP_Resource file_ref_id, | 242 int32_t QueryFileRefFile(PP_Resource file_ref_id, |
| 245 PP_FileInfo* info) { | 243 PP_FileInfo* info) { |
| 246 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); | 244 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); |
| 247 if (enter.failed()) | 245 if (enter.failed()) |
| 248 return PP_ERROR_BADRESOURCE; | 246 return PP_ERROR_BADRESOURCE; |
| 249 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | 247 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 250 | 248 |
| 251 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); | 249 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); |
| 252 if (!instance) | 250 if (!instance) |
| 253 return PP_ERROR_FAILED; | 251 return PP_ERROR_FAILED; |
| 254 | 252 |
| 255 base::PlatformFileInfo file_info; | 253 base::PlatformFileInfo file_info; |
| 256 base::PlatformFileError result = instance->delegate()->QueryFile( | 254 base::PlatformFileError result = instance->delegate()->QueryFile( |
| 257 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | 255 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| 258 &file_info); | 256 &file_info); |
| 259 if (result == base::PLATFORM_FILE_OK) { | 257 if (result == base::PLATFORM_FILE_OK) { |
| 260 info->size = file_info.size; | 258 info->size = file_info.size; |
| 261 info->creation_time = TimeToPPTime(file_info.creation_time); | 259 info->creation_time = TimeToPPTime(file_info.creation_time); |
| 262 info->last_access_time = TimeToPPTime(file_info.last_accessed); | 260 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 263 info->last_modified_time = TimeToPPTime(file_info.last_modified); | 261 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 264 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | 262 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 265 if (file_info.is_directory) | 263 if (file_info.is_directory) |
| 266 info->type = PP_FILETYPE_DIRECTORY; | 264 info->type = PP_FILETYPE_DIRECTORY; |
| 267 else | 265 else |
| 268 info->type = PP_FILETYPE_REGULAR; | 266 info->type = PP_FILETYPE_REGULAR; |
| 269 } | 267 } |
| 270 return ::ppapi::PlatformFileErrorToPepperError(result); | 268 return PlatformFileErrorToPepperError(result); |
| 271 } | 269 } |
| 272 | 270 |
| 273 const PPB_Flash_File_FileRef ppb_flash_file_fileref = { | 271 const PPB_Flash_File_FileRef ppb_flash_file_fileref = { |
| 274 &OpenFileRefFile, | 272 &OpenFileRefFile, |
| 275 &QueryFileRefFile, | 273 &QueryFileRefFile, |
| 276 }; | 274 }; |
| 277 | 275 |
| 278 } // namespace | 276 } // namespace |
| 279 | 277 |
| 280 // static | 278 // static |
| 281 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() { | 279 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() { |
| 282 return &ppb_flash_file_fileref; | 280 return &ppb_flash_file_fileref; |
| 283 } | 281 } |
| 284 | 282 |
| 285 } // namespace ppapi | 283 } // namespace ppapi |
| 286 } // namespace webkit | 284 } // namespace webkit |
| OLD | NEW |