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/plugins/ppapi/ppb_flash_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 #include "ppapi/c/dev/ppb_font_dev.h" | 14 #include "ppapi/c/dev/ppb_font_dev.h" |
15 #include "ppapi/c/private/ppb_flash.h" | 15 #include "ppapi/c/private/ppb_flash.h" |
16 #include "ppapi/shared_impl/file_type_conversion.h" | |
16 #include "ppapi/shared_impl/time_conversion.h" | 17 #include "ppapi/shared_impl/time_conversion.h" |
17 #include "ppapi/shared_impl/var.h" | 18 #include "ppapi/shared_impl/var.h" |
18 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
20 #include "ppapi/thunk/ppb_file_ref_api.h" | |
19 #include "ppapi/thunk/ppb_image_data_api.h" | 21 #include "ppapi/thunk/ppb_image_data_api.h" |
20 #include "skia/ext/platform_canvas.h" | 22 #include "skia/ext/platform_canvas.h" |
21 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
22 #include "third_party/skia/include/core/SkMatrix.h" | 24 #include "third_party/skia/include/core/SkMatrix.h" |
23 #include "third_party/skia/include/core/SkPaint.h" | 25 #include "third_party/skia/include/core/SkPaint.h" |
24 #include "third_party/skia/include/core/SkPoint.h" | 26 #include "third_party/skia/include/core/SkPoint.h" |
25 #include "third_party/skia/include/core/SkTemplates.h" | 27 #include "third_party/skia/include/core/SkTemplates.h" |
26 #include "third_party/skia/include/core/SkTypeface.h" | 28 #include "third_party/skia/include/core/SkTypeface.h" |
27 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
28 #include "webkit/glue/clipboard_client.h" | 30 #include "webkit/glue/clipboard_client.h" |
29 #include "webkit/glue/scoped_clipboard_writer_glue.h" | 31 #include "webkit/glue/scoped_clipboard_writer_glue.h" |
30 #include "webkit/plugins/ppapi/common.h" | 32 #include "webkit/plugins/ppapi/common.h" |
33 #include "webkit/plugins/ppapi/file_path.h" | |
31 #include "webkit/plugins/ppapi/host_globals.h" | 34 #include "webkit/plugins/ppapi/host_globals.h" |
32 #include "webkit/plugins/ppapi/plugin_delegate.h" | 35 #include "webkit/plugins/ppapi/plugin_delegate.h" |
33 #include "webkit/plugins/ppapi/plugin_module.h" | 36 #include "webkit/plugins/ppapi/plugin_module.h" |
34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 37 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
38 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | |
35 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 39 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
36 #include "webkit/plugins/ppapi/resource_helper.h" | 40 #include "webkit/plugins/ppapi/resource_helper.h" |
37 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 41 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
38 | 42 |
39 using ppapi::PPTimeToTime; | 43 using ppapi::PPTimeToTime; |
40 using ppapi::StringVar; | 44 using ppapi::StringVar; |
45 using ppapi::TimeToPPTime; | |
46 using ppapi::thunk::EnterResource; | |
41 using ppapi::thunk::EnterResourceNoLock; | 47 using ppapi::thunk::EnterResourceNoLock; |
48 using ppapi::thunk::PPB_FileRef_API; | |
42 using ppapi::thunk::PPB_ImageData_API; | 49 using ppapi::thunk::PPB_ImageData_API; |
43 using ppapi::thunk::PPB_URLRequestInfo_API; | 50 using ppapi::thunk::PPB_URLRequestInfo_API; |
44 | 51 |
45 namespace webkit { | 52 namespace webkit { |
46 namespace ppapi { | 53 namespace ppapi { |
47 | 54 |
48 namespace { | 55 namespace { |
49 | 56 |
50 const size_t kMaxClipboardWriteSize = 1000000; | 57 const size_t kMaxClipboardWriteSize = 1000000; |
51 | 58 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 if (res != PP_OK) { | 366 if (res != PP_OK) { |
360 // Need to clear the objects so nothing is written. | 367 // Need to clear the objects so nothing is written. |
361 scw.Reset(); | 368 scw.Reset(); |
362 return res; | 369 return res; |
363 } | 370 } |
364 } | 371 } |
365 | 372 |
366 return PP_OK; | 373 return PP_OK; |
367 } | 374 } |
368 | 375 |
376 bool PPB_Flash_Impl::CreateThreadAdapterForInstance(PP_Instance instance) { | |
brettw
2012/04/24 22:48:47
This was just copied from the flash_file_impl
| |
377 return false; // No multithreaded access allowed. | |
378 } | |
379 | |
380 void PPB_Flash_Impl::ClearThreadAdapterForInstance(PP_Instance instance) { | |
381 } | |
382 | |
383 int32_t PPB_Flash_Impl::OpenFile(PP_Instance pp_instance, | |
384 const char* path, | |
385 int32_t mode, | |
386 PP_FileHandle* file) { | |
387 int flags = 0; | |
388 if (!path || | |
389 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | |
390 !file) | |
391 return PP_ERROR_BADARGUMENT; | |
392 | |
393 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
394 if (!instance) | |
395 return PP_ERROR_FAILED; | |
396 | |
397 base::PlatformFile base_file; | |
398 base::PlatformFileError result = instance->delegate()->OpenFile( | |
399 PepperFilePath::MakeModuleLocal(instance->module(), path), | |
400 flags, | |
401 &base_file); | |
402 *file = base_file; | |
403 return ::ppapi::PlatformFileErrorToPepperError(result); | |
404 } | |
405 | |
406 int32_t PPB_Flash_Impl::RenameFile(PP_Instance pp_instance, | |
407 const char* path_from, | |
408 const char* path_to) { | |
409 if (!path_from || !path_to) | |
410 return PP_ERROR_BADARGUMENT; | |
411 | |
412 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
413 if (!instance) | |
414 return PP_ERROR_FAILED; | |
415 | |
416 base::PlatformFileError result = instance->delegate()->RenameFile( | |
417 PepperFilePath::MakeModuleLocal(instance->module(), path_from), | |
418 PepperFilePath::MakeModuleLocal(instance->module(), path_to)); | |
419 return ::ppapi::PlatformFileErrorToPepperError(result); | |
420 } | |
421 | |
422 int32_t PPB_Flash_Impl::DeleteFileOrDir(PP_Instance pp_instance, | |
423 const char* path, | |
424 PP_Bool recursive) { | |
425 if (!path) | |
426 return PP_ERROR_BADARGUMENT; | |
427 | |
428 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
429 if (!instance) | |
430 return PP_ERROR_FAILED; | |
431 | |
432 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( | |
433 PepperFilePath::MakeModuleLocal(instance->module(), path), | |
434 PPBoolToBool(recursive)); | |
435 return ::ppapi::PlatformFileErrorToPepperError(result); | |
436 } | |
437 | |
438 int32_t PPB_Flash_Impl::CreateDir(PP_Instance pp_instance, const char* path) { | |
439 if (!path) | |
440 return PP_ERROR_BADARGUMENT; | |
441 | |
442 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
443 if (!instance) | |
444 return PP_ERROR_FAILED; | |
445 | |
446 base::PlatformFileError result = instance->delegate()->CreateDir( | |
447 PepperFilePath::MakeModuleLocal(instance->module(), path)); | |
448 return ::ppapi::PlatformFileErrorToPepperError(result); | |
449 } | |
450 | |
451 int32_t PPB_Flash_Impl::QueryFile(PP_Instance pp_instance, | |
452 const char* path, | |
453 PP_FileInfo* info) { | |
454 if (!path || !info) | |
455 return PP_ERROR_BADARGUMENT; | |
456 | |
457 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
458 if (!instance) | |
459 return PP_ERROR_FAILED; | |
460 | |
461 base::PlatformFileInfo file_info; | |
462 base::PlatformFileError result = instance->delegate()->QueryFile( | |
463 PepperFilePath::MakeModuleLocal(instance->module(), path), | |
464 &file_info); | |
465 if (result == base::PLATFORM_FILE_OK) { | |
466 info->size = file_info.size; | |
467 info->creation_time = TimeToPPTime(file_info.creation_time); | |
468 info->last_access_time = TimeToPPTime(file_info.last_accessed); | |
469 info->last_modified_time = TimeToPPTime(file_info.last_modified); | |
470 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
471 if (file_info.is_directory) | |
472 info->type = PP_FILETYPE_DIRECTORY; | |
473 else | |
474 info->type = PP_FILETYPE_REGULAR; | |
475 } | |
476 return ::ppapi::PlatformFileErrorToPepperError(result); | |
477 } | |
478 | |
479 int32_t PPB_Flash_Impl::GetDirContents(PP_Instance pp_instance, | |
480 const char* path, | |
481 PP_DirContents_Dev** contents) { | |
482 if (!path || !contents) | |
483 return PP_ERROR_BADARGUMENT; | |
484 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
485 if (!instance) | |
486 return PP_ERROR_FAILED; | |
487 | |
488 *contents = NULL; | |
489 DirContents pepper_contents; | |
490 base::PlatformFileError result = instance->delegate()->GetDirContents( | |
491 PepperFilePath::MakeModuleLocal(instance->module(), path), | |
492 &pepper_contents); | |
493 | |
494 if (result != base::PLATFORM_FILE_OK) | |
495 return ::ppapi::PlatformFileErrorToPepperError(result); | |
496 | |
497 *contents = new PP_DirContents_Dev; | |
498 size_t count = pepper_contents.size(); | |
499 (*contents)->count = count; | |
500 (*contents)->entries = new PP_DirEntry_Dev[count]; | |
501 for (size_t i = 0; i < count; ++i) { | |
502 PP_DirEntry_Dev& entry = (*contents)->entries[i]; | |
503 #if defined(OS_WIN) | |
504 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); | |
505 #else | |
506 const std::string& name = pepper_contents[i].name.value(); | |
507 #endif | |
508 size_t size = name.size() + 1; | |
509 char* name_copy = new char[size]; | |
510 memcpy(name_copy, name.c_str(), size); | |
511 entry.name = name_copy; | |
512 entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir); | |
513 } | |
514 return PP_OK; | |
515 } | |
516 | |
517 int32_t PPB_Flash_Impl::OpenFileRef(PP_Instance pp_instance, | |
518 PP_Resource file_ref_id, | |
519 int32_t mode, | |
520 PP_FileHandle* file) { | |
521 int flags = 0; | |
522 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) | |
523 return PP_ERROR_BADARGUMENT; | |
524 | |
525 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); | |
yzshen1
2012/04/25 20:50:47
Here and line 546: Is it EnterResourceNoLock?
| |
526 if (enter.failed()) | |
527 return PP_ERROR_BADRESOURCE; | |
528 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | |
529 | |
530 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
531 if (!instance) | |
532 return PP_ERROR_FAILED; | |
533 | |
534 base::PlatformFile base_file; | |
535 base::PlatformFileError result = instance->delegate()->OpenFile( | |
536 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
537 flags, | |
538 &base_file); | |
539 *file = base_file; | |
540 return ::ppapi::PlatformFileErrorToPepperError(result); | |
541 } | |
542 | |
543 int32_t PPB_Flash_Impl::QueryFileRef(PP_Instance pp_instance, | |
544 PP_Resource file_ref_id, | |
545 PP_FileInfo* info) { | |
546 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); | |
547 if (enter.failed()) | |
548 return PP_ERROR_BADRESOURCE; | |
549 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | |
550 | |
551 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
552 if (!instance) | |
553 return PP_ERROR_FAILED; | |
554 | |
555 base::PlatformFileInfo file_info; | |
556 base::PlatformFileError result = instance->delegate()->QueryFile( | |
557 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
558 &file_info); | |
559 if (result == base::PLATFORM_FILE_OK) { | |
560 info->size = file_info.size; | |
561 info->creation_time = TimeToPPTime(file_info.creation_time); | |
562 info->last_access_time = TimeToPPTime(file_info.last_accessed); | |
563 info->last_modified_time = TimeToPPTime(file_info.last_modified); | |
564 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
565 if (file_info.is_directory) | |
566 info->type = PP_FILETYPE_DIRECTORY; | |
567 else | |
568 info->type = PP_FILETYPE_REGULAR; | |
569 } | |
570 return ::ppapi::PlatformFileErrorToPepperError(result); | |
571 } | |
572 | |
369 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) { | 573 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) { |
370 return PP_FromBool(instance_->flash_fullscreen()); | 574 return PP_FromBool(instance_->flash_fullscreen()); |
371 } | 575 } |
372 | 576 |
373 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance, | 577 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance, |
374 PP_Bool fullscreen) { | 578 PP_Bool fullscreen) { |
375 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); | 579 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); |
376 return PP_TRUE; | 580 return PP_TRUE; |
377 } | 581 } |
378 | 582 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 } | 640 } |
437 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | 641 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: |
438 break; | 642 break; |
439 } | 643 } |
440 | 644 |
441 return PP_ERROR_BADARGUMENT; | 645 return PP_ERROR_BADARGUMENT; |
442 } | 646 } |
443 | 647 |
444 } // namespace ppapi | 648 } // namespace ppapi |
445 } // namespace webkit | 649 } // namespace webkit |
OLD | NEW |