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 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 }; | 215 }; |
216 | 216 |
217 } // namespace | 217 } // namespace |
218 | 218 |
219 // static | 219 // static |
220 const PPB_Flash_File_ModuleLocal* | 220 const PPB_Flash_File_ModuleLocal* |
221 PPB_Flash_File_ModuleLocal_Impl::GetInterface() { | 221 PPB_Flash_File_ModuleLocal_Impl::GetInterface() { |
222 return &ppb_flash_file_modulelocal; | 222 return &ppb_flash_file_modulelocal; |
223 } | 223 } |
224 | 224 |
225 // PPB_Flash_File_FileRef_Impl ------------------------------------------------- | |
226 | |
227 namespace { | |
228 | |
229 int32_t OpenFileRefFile(PP_Resource file_ref_id, | |
230 int32_t mode, | |
231 PP_FileHandle* file) { | |
232 int flags = 0; | |
233 if (!ConvertFromPPFileOpenFlags(mode, &flags) || !file) | |
234 return PP_ERROR_BADARGUMENT; | |
235 | |
236 scoped_refptr<PPB_FileRef_Impl> file_ref( | |
237 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | |
238 if (!file_ref) | |
239 return PP_ERROR_BADRESOURCE; | |
240 | |
241 PluginInstance* instance = file_ref->instance(); | |
242 if (!instance) | |
243 return PP_ERROR_FAILED; | |
244 | |
245 base::PlatformFile base_file; | |
246 base::PlatformFileError result = instance->delegate()->OpenFile( | |
247 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
248 flags, | |
249 &base_file); | |
250 *file = base_file; | |
251 return PlatformFileErrorToPepperError(result); | |
252 } | |
253 | |
254 int32_t RenameFileRefFile(PP_Resource from_file_ref_id, | |
255 PP_Resource to_file_ref_id) { | |
piman
2011/03/01 21:54:29
I'm not sure we actually need Rename/Delete/Create
| |
256 scoped_refptr<PPB_FileRef_Impl> from_file_ref( | |
257 Resource::GetAs<PPB_FileRef_Impl>(from_file_ref_id)); | |
258 if (!from_file_ref) | |
259 return PP_ERROR_BADRESOURCE; | |
260 | |
261 scoped_refptr<PPB_FileRef_Impl> to_file_ref( | |
262 Resource::GetAs<PPB_FileRef_Impl>(to_file_ref_id)); | |
263 if (!to_file_ref) | |
264 return PP_ERROR_BADRESOURCE; | |
265 | |
266 PluginInstance* instance = from_file_ref->instance(); | |
267 if (!instance) | |
268 return PP_ERROR_FAILED; | |
269 DCHECK(to_file_ref->instance() == instance); | |
270 | |
271 base::PlatformFileError result = instance->delegate()->RenameFile( | |
272 PepperFilePath::MakeAbsolute(from_file_ref->GetSystemPath()), | |
273 PepperFilePath::MakeAbsolute(to_file_ref->GetSystemPath())); | |
274 return PlatformFileErrorToPepperError(result); | |
275 } | |
276 | |
277 int32_t DeleteFileRefFileOrDir(PP_Resource file_ref_id, | |
278 PP_Bool recursive) { | |
279 scoped_refptr<PPB_FileRef_Impl> file_ref( | |
280 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | |
281 if (!file_ref) | |
282 return PP_ERROR_BADRESOURCE; | |
283 | |
284 PluginInstance* instance = file_ref->instance(); | |
285 if (!instance) | |
286 return PP_ERROR_FAILED; | |
287 | |
288 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( | |
289 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
290 PPBoolToBool(recursive)); | |
291 return PlatformFileErrorToPepperError(result); | |
292 } | |
293 | |
294 int32_t CreateFileRefDir(PP_Resource file_ref_id) { | |
295 scoped_refptr<PPB_FileRef_Impl> file_ref( | |
296 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | |
297 if (!file_ref) | |
298 return PP_ERROR_BADRESOURCE; | |
299 | |
300 PluginInstance* instance = file_ref->instance(); | |
301 if (!instance) | |
302 return PP_ERROR_FAILED; | |
303 | |
304 base::PlatformFileError result = instance->delegate()->CreateDir( | |
305 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath())); | |
306 return PlatformFileErrorToPepperError(result); | |
307 } | |
308 | |
309 int32_t QueryFileRefFile(PP_Resource file_ref_id, | |
310 PP_FileInfo_Dev* info) { | |
311 scoped_refptr<PPB_FileRef_Impl> file_ref( | |
312 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | |
313 if (!file_ref) | |
314 return PP_ERROR_BADRESOURCE; | |
315 | |
316 PluginInstance* instance = file_ref->instance(); | |
317 if (!instance) | |
318 return PP_ERROR_FAILED; | |
319 | |
320 base::PlatformFileInfo file_info; | |
321 base::PlatformFileError result = instance->delegate()->QueryFile( | |
322 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
323 &file_info); | |
324 if (result == base::PLATFORM_FILE_OK) { | |
325 info->size = file_info.size; | |
326 info->creation_time = file_info.creation_time.ToDoubleT(); | |
327 info->last_access_time = file_info.last_accessed.ToDoubleT(); | |
328 info->last_modified_time = file_info.last_modified.ToDoubleT(); | |
329 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
330 if (file_info.is_directory) | |
331 info->type = PP_FILETYPE_DIRECTORY; | |
332 else | |
333 info->type = PP_FILETYPE_REGULAR; | |
334 } | |
335 return PlatformFileErrorToPepperError(result); | |
336 } | |
337 | |
338 int32_t GetFileRefDirContents(PP_Resource file_ref_id, | |
339 PP_DirContents_Dev** contents) { | |
340 scoped_refptr<PPB_FileRef_Impl> file_ref( | |
341 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | |
342 if (!file_ref) | |
343 return PP_ERROR_BADRESOURCE; | |
344 | |
345 PluginInstance* instance = file_ref->instance(); | |
346 if (!instance) | |
347 return PP_ERROR_FAILED; | |
348 | |
349 *contents = NULL; | |
350 DirContents pepper_contents; | |
351 base::PlatformFileError result = instance->delegate()->GetDirContents( | |
352 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
353 &pepper_contents); | |
354 | |
355 if (result != base::PLATFORM_FILE_OK) | |
356 return PlatformFileErrorToPepperError(result); | |
357 | |
358 *contents = new PP_DirContents_Dev; | |
359 size_t count = pepper_contents.size(); | |
360 (*contents)->count = count; | |
361 (*contents)->entries = new PP_DirEntry_Dev[count]; | |
362 for (size_t i = 0; i < count; ++i) { | |
363 PP_DirEntry_Dev& entry = (*contents)->entries[i]; | |
364 #if defined(OS_WIN) | |
365 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); | |
366 #else | |
367 const std::string& name = pepper_contents[i].name.value(); | |
368 #endif | |
369 size_t size = name.size() + 1; | |
370 char* name_copy = new char[size]; | |
371 memcpy(name_copy, name.c_str(), size); | |
372 entry.name = name_copy; | |
373 entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir); | |
374 } | |
375 return PP_OK; | |
376 } | |
377 | |
378 const PPB_Flash_File_FileRef ppb_flash_file_fileref = { | |
379 &OpenFileRefFile, | |
380 &RenameFileRefFile, | |
381 &DeleteFileRefFileOrDir, | |
382 &CreateFileRefDir, | |
383 &QueryFileRefFile, | |
384 &GetFileRefDirContents, | |
385 &FreeDirContents, | |
386 }; | |
387 | |
388 } // namespace | |
389 | |
390 // static | |
391 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() { | |
392 return &ppb_flash_file_fileref; | |
393 } | |
394 | |
225 } // namespace ppapi | 395 } // namespace ppapi |
226 } // namespace webkit | 396 } // namespace webkit |
OLD | NEW |