| 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_path.h" |
| 16 #include "ppapi/shared_impl/file_type_conversion.h" | 17 #include "ppapi/shared_impl/file_type_conversion.h" |
| 17 #include "ppapi/shared_impl/time_conversion.h" | 18 #include "ppapi/shared_impl/time_conversion.h" |
| 18 #include "ppapi/shared_impl/var.h" | 19 #include "ppapi/shared_impl/var.h" |
| 19 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
| 20 #include "ppapi/thunk/ppb_file_ref_api.h" | 21 #include "ppapi/thunk/ppb_file_ref_api.h" |
| 21 #include "ppapi/thunk/ppb_image_data_api.h" | 22 #include "ppapi/thunk/ppb_image_data_api.h" |
| 22 #include "skia/ext/platform_canvas.h" | 23 #include "skia/ext/platform_canvas.h" |
| 23 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
| 24 #include "third_party/skia/include/core/SkMatrix.h" | 25 #include "third_party/skia/include/core/SkMatrix.h" |
| 25 #include "third_party/skia/include/core/SkPaint.h" | 26 #include "third_party/skia/include/core/SkPaint.h" |
| 26 #include "third_party/skia/include/core/SkPoint.h" | 27 #include "third_party/skia/include/core/SkPoint.h" |
| 27 #include "third_party/skia/include/core/SkTemplates.h" | 28 #include "third_party/skia/include/core/SkTemplates.h" |
| 28 #include "third_party/skia/include/core/SkTypeface.h" | 29 #include "third_party/skia/include/core/SkTypeface.h" |
| 29 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
| 30 #include "webkit/glue/clipboard_client.h" | 31 #include "webkit/glue/clipboard_client.h" |
| 31 #include "webkit/glue/scoped_clipboard_writer_glue.h" | 32 #include "webkit/glue/scoped_clipboard_writer_glue.h" |
| 32 #include "webkit/plugins/ppapi/common.h" | 33 #include "webkit/plugins/ppapi/common.h" |
| 33 #include "webkit/plugins/ppapi/file_path.h" | |
| 34 #include "webkit/plugins/ppapi/host_globals.h" | 34 #include "webkit/plugins/ppapi/host_globals.h" |
| 35 #include "webkit/plugins/ppapi/plugin_delegate.h" | 35 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 36 #include "webkit/plugins/ppapi/plugin_module.h" | 36 #include "webkit/plugins/ppapi/plugin_module.h" |
| 37 #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" | 38 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 39 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 39 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
| 40 #include "webkit/plugins/ppapi/resource_helper.h" | 40 #include "webkit/plugins/ppapi/resource_helper.h" |
| 41 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 41 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 42 | 42 |
| 43 using ppapi::PPTimeToTime; | 43 using ppapi::PPTimeToTime; |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | 391 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || |
| 392 !file) | 392 !file) |
| 393 return PP_ERROR_BADARGUMENT; | 393 return PP_ERROR_BADARGUMENT; |
| 394 | 394 |
| 395 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 395 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 396 if (!instance) | 396 if (!instance) |
| 397 return PP_ERROR_FAILED; | 397 return PP_ERROR_FAILED; |
| 398 | 398 |
| 399 base::PlatformFile base_file; | 399 base::PlatformFile base_file; |
| 400 base::PlatformFileError result = instance->delegate()->OpenFile( | 400 base::PlatformFileError result = instance->delegate()->OpenFile( |
| 401 PepperFilePath::MakeModuleLocal(instance->module(), path), | 401 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 402 instance->module()->name(), path), |
| 402 flags, | 403 flags, |
| 403 &base_file); | 404 &base_file); |
| 404 *file = base_file; | 405 *file = base_file; |
| 405 return ::ppapi::PlatformFileErrorToPepperError(result); | 406 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 406 } | 407 } |
| 407 | 408 |
| 408 int32_t PPB_Flash_Impl::RenameFile(PP_Instance pp_instance, | 409 int32_t PPB_Flash_Impl::RenameFile(PP_Instance pp_instance, |
| 409 const char* path_from, | 410 const char* path_from, |
| 410 const char* path_to) { | 411 const char* path_to) { |
| 411 if (!path_from || !path_to) | 412 if (!path_from || !path_to) |
| 412 return PP_ERROR_BADARGUMENT; | 413 return PP_ERROR_BADARGUMENT; |
| 413 | 414 |
| 414 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 415 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 415 if (!instance) | 416 if (!instance) |
| 416 return PP_ERROR_FAILED; | 417 return PP_ERROR_FAILED; |
| 417 | 418 |
| 418 base::PlatformFileError result = instance->delegate()->RenameFile( | 419 base::PlatformFileError result = instance->delegate()->RenameFile( |
| 419 PepperFilePath::MakeModuleLocal(instance->module(), path_from), | 420 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 420 PepperFilePath::MakeModuleLocal(instance->module(), path_to)); | 421 instance->module()->name(), path_from), |
| 422 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 423 instance->module()->name(), path_to)); |
| 421 return ::ppapi::PlatformFileErrorToPepperError(result); | 424 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 422 } | 425 } |
| 423 | 426 |
| 424 int32_t PPB_Flash_Impl::DeleteFileOrDir(PP_Instance pp_instance, | 427 int32_t PPB_Flash_Impl::DeleteFileOrDir(PP_Instance pp_instance, |
| 425 const char* path, | 428 const char* path, |
| 426 PP_Bool recursive) { | 429 PP_Bool recursive) { |
| 427 if (!path) | 430 if (!path) |
| 428 return PP_ERROR_BADARGUMENT; | 431 return PP_ERROR_BADARGUMENT; |
| 429 | 432 |
| 430 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 433 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 431 if (!instance) | 434 if (!instance) |
| 432 return PP_ERROR_FAILED; | 435 return PP_ERROR_FAILED; |
| 433 | 436 |
| 434 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( | 437 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( |
| 435 PepperFilePath::MakeModuleLocal(instance->module(), path), | 438 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 439 instance->module()->name(), path), |
| 436 PPBoolToBool(recursive)); | 440 PPBoolToBool(recursive)); |
| 437 return ::ppapi::PlatformFileErrorToPepperError(result); | 441 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 438 } | 442 } |
| 439 | 443 |
| 440 int32_t PPB_Flash_Impl::CreateDir(PP_Instance pp_instance, const char* path) { | 444 int32_t PPB_Flash_Impl::CreateDir(PP_Instance pp_instance, const char* path) { |
| 441 if (!path) | 445 if (!path) |
| 442 return PP_ERROR_BADARGUMENT; | 446 return PP_ERROR_BADARGUMENT; |
| 443 | 447 |
| 444 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 448 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 445 if (!instance) | 449 if (!instance) |
| 446 return PP_ERROR_FAILED; | 450 return PP_ERROR_FAILED; |
| 447 | 451 |
| 448 base::PlatformFileError result = instance->delegate()->CreateDir( | 452 base::PlatformFileError result = instance->delegate()->CreateDir( |
| 449 PepperFilePath::MakeModuleLocal(instance->module(), path)); | 453 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 454 instance->module()->name(), path)); |
| 450 return ::ppapi::PlatformFileErrorToPepperError(result); | 455 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 451 } | 456 } |
| 452 | 457 |
| 453 int32_t PPB_Flash_Impl::QueryFile(PP_Instance pp_instance, | 458 int32_t PPB_Flash_Impl::QueryFile(PP_Instance pp_instance, |
| 454 const char* path, | 459 const char* path, |
| 455 PP_FileInfo* info) { | 460 PP_FileInfo* info) { |
| 456 if (!path || !info) | 461 if (!path || !info) |
| 457 return PP_ERROR_BADARGUMENT; | 462 return PP_ERROR_BADARGUMENT; |
| 458 | 463 |
| 459 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 464 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 460 if (!instance) | 465 if (!instance) |
| 461 return PP_ERROR_FAILED; | 466 return PP_ERROR_FAILED; |
| 462 | 467 |
| 463 base::PlatformFileInfo file_info; | 468 base::PlatformFileInfo file_info; |
| 464 base::PlatformFileError result = instance->delegate()->QueryFile( | 469 base::PlatformFileError result = instance->delegate()->QueryFile( |
| 465 PepperFilePath::MakeModuleLocal(instance->module(), path), | 470 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 471 instance->module()->name(), path), |
| 466 &file_info); | 472 &file_info); |
| 467 if (result == base::PLATFORM_FILE_OK) { | 473 if (result == base::PLATFORM_FILE_OK) { |
| 468 info->size = file_info.size; | 474 info->size = file_info.size; |
| 469 info->creation_time = TimeToPPTime(file_info.creation_time); | 475 info->creation_time = TimeToPPTime(file_info.creation_time); |
| 470 info->last_access_time = TimeToPPTime(file_info.last_accessed); | 476 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 471 info->last_modified_time = TimeToPPTime(file_info.last_modified); | 477 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 472 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | 478 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 473 if (file_info.is_directory) | 479 if (file_info.is_directory) |
| 474 info->type = PP_FILETYPE_DIRECTORY; | 480 info->type = PP_FILETYPE_DIRECTORY; |
| 475 else | 481 else |
| 476 info->type = PP_FILETYPE_REGULAR; | 482 info->type = PP_FILETYPE_REGULAR; |
| 477 } | 483 } |
| 478 return ::ppapi::PlatformFileErrorToPepperError(result); | 484 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 479 } | 485 } |
| 480 | 486 |
| 481 int32_t PPB_Flash_Impl::GetDirContents(PP_Instance pp_instance, | 487 int32_t PPB_Flash_Impl::GetDirContents(PP_Instance pp_instance, |
| 482 const char* path, | 488 const char* path, |
| 483 PP_DirContents_Dev** contents) { | 489 PP_DirContents_Dev** contents) { |
| 484 if (!path || !contents) | 490 if (!path || !contents) |
| 485 return PP_ERROR_BADARGUMENT; | 491 return PP_ERROR_BADARGUMENT; |
| 486 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 492 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 487 if (!instance) | 493 if (!instance) |
| 488 return PP_ERROR_FAILED; | 494 return PP_ERROR_FAILED; |
| 489 | 495 |
| 490 *contents = NULL; | 496 *contents = NULL; |
| 491 DirContents pepper_contents; | 497 ::ppapi::DirContents pepper_contents; |
| 492 base::PlatformFileError result = instance->delegate()->GetDirContents( | 498 base::PlatformFileError result = instance->delegate()->GetDirContents( |
| 493 PepperFilePath::MakeModuleLocal(instance->module(), path), | 499 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 500 instance->module()->name(), path), |
| 494 &pepper_contents); | 501 &pepper_contents); |
| 495 | 502 |
| 496 if (result != base::PLATFORM_FILE_OK) | 503 if (result != base::PLATFORM_FILE_OK) |
| 497 return ::ppapi::PlatformFileErrorToPepperError(result); | 504 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 498 | 505 |
| 499 *contents = new PP_DirContents_Dev; | 506 *contents = new PP_DirContents_Dev; |
| 500 size_t count = pepper_contents.size(); | 507 size_t count = pepper_contents.size(); |
| 501 (*contents)->count = count; | 508 (*contents)->count = count; |
| 502 (*contents)->entries = new PP_DirEntry_Dev[count]; | 509 (*contents)->entries = new PP_DirEntry_Dev[count]; |
| 503 for (size_t i = 0; i < count; ++i) { | 510 for (size_t i = 0; i < count; ++i) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 528 if (enter.failed()) | 535 if (enter.failed()) |
| 529 return PP_ERROR_BADRESOURCE; | 536 return PP_ERROR_BADRESOURCE; |
| 530 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | 537 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 531 | 538 |
| 532 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 539 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 533 if (!instance) | 540 if (!instance) |
| 534 return PP_ERROR_FAILED; | 541 return PP_ERROR_FAILED; |
| 535 | 542 |
| 536 base::PlatformFile base_file; | 543 base::PlatformFile base_file; |
| 537 base::PlatformFileError result = instance->delegate()->OpenFile( | 544 base::PlatformFileError result = instance->delegate()->OpenFile( |
| 538 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | 545 ::ppapi::PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| 539 flags, | 546 flags, |
| 540 &base_file); | 547 &base_file); |
| 541 *file = base_file; | 548 *file = base_file; |
| 542 return ::ppapi::PlatformFileErrorToPepperError(result); | 549 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 543 } | 550 } |
| 544 | 551 |
| 545 int32_t PPB_Flash_Impl::QueryFileRef(PP_Instance pp_instance, | 552 int32_t PPB_Flash_Impl::QueryFileRef(PP_Instance pp_instance, |
| 546 PP_Resource file_ref_id, | 553 PP_Resource file_ref_id, |
| 547 PP_FileInfo* info) { | 554 PP_FileInfo* info) { |
| 548 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); | 555 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); |
| 549 if (enter.failed()) | 556 if (enter.failed()) |
| 550 return PP_ERROR_BADRESOURCE; | 557 return PP_ERROR_BADRESOURCE; |
| 551 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | 558 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 552 | 559 |
| 553 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 560 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 554 if (!instance) | 561 if (!instance) |
| 555 return PP_ERROR_FAILED; | 562 return PP_ERROR_FAILED; |
| 556 | 563 |
| 557 base::PlatformFileInfo file_info; | 564 base::PlatformFileInfo file_info; |
| 558 base::PlatformFileError result = instance->delegate()->QueryFile( | 565 base::PlatformFileError result = instance->delegate()->QueryFile( |
| 559 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | 566 ::ppapi::PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| 560 &file_info); | 567 &file_info); |
| 561 if (result == base::PLATFORM_FILE_OK) { | 568 if (result == base::PLATFORM_FILE_OK) { |
| 562 info->size = file_info.size; | 569 info->size = file_info.size; |
| 563 info->creation_time = TimeToPPTime(file_info.creation_time); | 570 info->creation_time = TimeToPPTime(file_info.creation_time); |
| 564 info->last_access_time = TimeToPPTime(file_info.last_accessed); | 571 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 565 info->last_modified_time = TimeToPPTime(file_info.last_modified); | 572 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 566 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | 573 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 567 if (file_info.is_directory) | 574 if (file_info.is_directory) |
| 568 info->type = PP_FILETYPE_DIRECTORY; | 575 info->type = PP_FILETYPE_DIRECTORY; |
| 569 else | 576 else |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 } | 649 } |
| 643 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | 650 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: |
| 644 break; | 651 break; |
| 645 } | 652 } |
| 646 | 653 |
| 647 return PP_ERROR_BADARGUMENT; | 654 return PP_ERROR_BADARGUMENT; |
| 648 } | 655 } |
| 649 | 656 |
| 650 } // namespace ppapi | 657 } // namespace ppapi |
| 651 } // namespace webkit | 658 } // namespace webkit |
| OLD | NEW |