Chromium Code Reviews| 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 "ppapi/proxy/ppb_flash_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_proxy.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "ppapi/c/dev/ppb_font_dev.h" | 15 #include "ppapi/c/dev/ppb_font_dev.h" |
| 16 #include "ppapi/c/dev/ppb_var_deprecated.h" | 16 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 17 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 18 #include "ppapi/c/pp_resource.h" | 18 #include "ppapi/c/pp_resource.h" |
| 19 #include "ppapi/c/private/ppb_flash.h" | 19 #include "ppapi/c/private/ppb_flash.h" |
| 20 #include "ppapi/c/private/ppb_flash_print.h" | 20 #include "ppapi/c/private/ppb_flash_print.h" |
| 21 #include "ppapi/proxy/host_dispatcher.h" | 21 #include "ppapi/proxy/host_dispatcher.h" |
| 22 #include "ppapi/proxy/pepper_file_messages.h" | |
| 23 #include "ppapi/proxy/plugin_dispatcher.h" | 22 #include "ppapi/proxy/plugin_dispatcher.h" |
| 24 #include "ppapi/proxy/plugin_globals.h" | 23 #include "ppapi/proxy/plugin_globals.h" |
| 25 #include "ppapi/proxy/plugin_proxy_delegate.h" | 24 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 26 #include "ppapi/proxy/ppapi_messages.h" | 25 #include "ppapi/proxy/ppapi_messages.h" |
| 27 #include "ppapi/proxy/proxy_module.h" | 26 #include "ppapi/proxy/proxy_module.h" |
| 28 #include "ppapi/proxy/serialized_var.h" | 27 #include "ppapi/proxy/serialized_var.h" |
| 29 #include "ppapi/shared_impl/dir_contents.h" | 28 #include "ppapi/shared_impl/dir_contents.h" |
| 30 #include "ppapi/shared_impl/file_type_conversion.h" | 29 #include "ppapi/shared_impl/file_type_conversion.h" |
|
yzshen1
2012/11/21 00:38:59
is this needed?
raymes
2012/11/21 22:44:53
Done.
| |
| 31 #include "ppapi/shared_impl/ppapi_globals.h" | 30 #include "ppapi/shared_impl/ppapi_globals.h" |
| 32 #include "ppapi/shared_impl/proxy_lock.h" | 31 #include "ppapi/shared_impl/proxy_lock.h" |
| 33 #include "ppapi/shared_impl/resource.h" | 32 #include "ppapi/shared_impl/resource.h" |
| 34 #include "ppapi/shared_impl/resource_tracker.h" | 33 #include "ppapi/shared_impl/resource_tracker.h" |
| 35 #include "ppapi/shared_impl/scoped_pp_resource.h" | 34 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 36 #include "ppapi/shared_impl/time_conversion.h" | 35 #include "ppapi/shared_impl/time_conversion.h" |
| 37 #include "ppapi/shared_impl/var.h" | 36 #include "ppapi/shared_impl/var.h" |
| 38 #include "ppapi/shared_impl/var_tracker.h" | 37 #include "ppapi/shared_impl/var_tracker.h" |
| 39 #include "ppapi/thunk/enter.h" | 38 #include "ppapi/thunk/enter.h" |
| 40 #include "ppapi/thunk/ppb_instance_api.h" | 39 #include "ppapi/thunk/ppb_instance_api.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QuitMessageLoop, | 114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QuitMessageLoop, |
| 116 OnHostMsgQuitMessageLoop) | 115 OnHostMsgQuitMessageLoop) |
| 117 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset, | 116 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset, |
| 118 OnHostMsgGetLocalTimeZoneOffset) | 117 OnHostMsgGetLocalTimeZoneOffset) |
| 119 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsRectTopmost, | 118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsRectTopmost, |
| 120 OnHostMsgIsRectTopmost) | 119 OnHostMsgIsRectTopmost) |
| 121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashSetFullscreen, | 120 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashSetFullscreen, |
| 122 OnHostMsgFlashSetFullscreen) | 121 OnHostMsgFlashSetFullscreen) |
| 123 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashGetScreenSize, | 122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashGetScreenSize, |
| 124 OnHostMsgFlashGetScreenSize) | 123 OnHostMsgFlashGetScreenSize) |
| 125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFileRef, | |
| 126 OnHostMsgOpenFileRef) | |
| 127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFileRef, | |
| 128 OnHostMsgQueryFileRef) | |
| 129 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDeviceID, | 124 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDeviceID, |
| 130 OnHostMsgGetDeviceID) | 125 OnHostMsgGetDeviceID) |
| 131 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, | 126 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, |
| 132 OnHostMsgInvokePrinting) | 127 OnHostMsgInvokePrinting) |
| 133 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetSetting, | 128 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetSetting, |
| 134 OnHostMsgGetSetting) | 129 OnHostMsgGetSetting) |
| 135 IPC_MESSAGE_UNHANDLED(handled = false) | 130 IPC_MESSAGE_UNHANDLED(handled = false) |
| 136 IPC_END_MESSAGE_MAP() | 131 IPC_END_MESSAGE_MAP() |
| 137 // TODO(brettw) handle bad messages! | 132 // TODO(brettw) handle bad messages! |
| 138 return handled; | 133 return handled; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 StringVar *url_string_var(StringVar::FromPPVar(value)); | 345 StringVar *url_string_var(StringVar::FromPPVar(value)); |
| 351 if (!url_string_var) | 346 if (!url_string_var) |
| 352 return PP_FALSE; | 347 return PP_FALSE; |
| 353 std::string url_string(url_string_var->value()); | 348 std::string url_string(url_string_var->value()); |
| 354 PluginGlobals::Get()->plugin_proxy_delegate()->SetActiveURL(url_string); | 349 PluginGlobals::Get()->plugin_proxy_delegate()->SetActiveURL(url_string); |
| 355 return PP_TRUE; | 350 return PP_TRUE; |
| 356 } | 351 } |
| 357 return PP_FALSE; | 352 return PP_FALSE; |
| 358 } | 353 } |
| 359 | 354 |
| 360 bool PPB_Flash_Proxy::CreateThreadAdapterForInstance(PP_Instance instance) { | |
| 361 return true; | |
| 362 } | |
| 363 | |
| 364 void PPB_Flash_Proxy::ClearThreadAdapterForInstance(PP_Instance instance) { | |
| 365 } | |
| 366 | |
| 367 int32_t PPB_Flash_Proxy::OpenFile(PP_Instance, | |
| 368 const char* path, | |
| 369 int32_t mode, | |
| 370 PP_FileHandle* file) { | |
| 371 int flags = 0; | |
| 372 if (!path || | |
| 373 !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | |
| 374 !file) | |
| 375 return PP_ERROR_BADARGUMENT; | |
| 376 | |
| 377 base::PlatformFileError error; | |
| 378 IPC::PlatformFileForTransit transit_file; | |
| 379 ppapi::PepperFilePath pepper_path(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 380 FilePath::FromUTF8Unsafe(path)); | |
| 381 | |
| 382 if (PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 383 new PepperFileMsg_OpenFile(pepper_path, flags, | |
| 384 &error, &transit_file))) { | |
| 385 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file); | |
| 386 } else { | |
| 387 *file = base::kInvalidPlatformFileValue; | |
| 388 error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 389 } | |
| 390 | |
| 391 return ppapi::PlatformFileErrorToPepperError(error); | |
| 392 } | |
| 393 | |
| 394 int32_t PPB_Flash_Proxy::RenameFile(PP_Instance, | |
| 395 const char* from_path, | |
| 396 const char* to_path) { | |
| 397 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 398 ppapi::PepperFilePath pepper_from(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 399 FilePath::FromUTF8Unsafe(from_path)); | |
| 400 ppapi::PepperFilePath pepper_to(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 401 FilePath::FromUTF8Unsafe(to_path)); | |
| 402 | |
| 403 PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 404 new PepperFileMsg_RenameFile(pepper_from, pepper_to, &error)); | |
| 405 | |
| 406 return ppapi::PlatformFileErrorToPepperError(error); | |
| 407 } | |
| 408 | |
| 409 int32_t PPB_Flash_Proxy::DeleteFileOrDir(PP_Instance, | |
| 410 const char* path, | |
| 411 PP_Bool recursive) { | |
| 412 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 413 ppapi::PepperFilePath pepper_path(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 414 FilePath::FromUTF8Unsafe(path)); | |
| 415 | |
| 416 PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 417 new PepperFileMsg_DeleteFileOrDir(pepper_path, | |
| 418 PP_ToBool(recursive), | |
| 419 &error)); | |
| 420 | |
| 421 return ppapi::PlatformFileErrorToPepperError(error); | |
| 422 } | |
| 423 | |
| 424 int32_t PPB_Flash_Proxy::CreateDir(PP_Instance, const char* path) { | |
| 425 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 426 ppapi::PepperFilePath pepper_path(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 427 FilePath::FromUTF8Unsafe(path)); | |
| 428 | |
| 429 PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 430 new PepperFileMsg_CreateDir(pepper_path, &error)); | |
| 431 | |
| 432 return ppapi::PlatformFileErrorToPepperError(error); | |
| 433 } | |
| 434 | |
| 435 int32_t PPB_Flash_Proxy::QueryFile(PP_Instance, | |
| 436 const char* path, | |
| 437 PP_FileInfo* info) { | |
| 438 base::PlatformFileInfo file_info; | |
| 439 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 440 ppapi::PepperFilePath pepper_path(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 441 FilePath::FromUTF8Unsafe(path)); | |
| 442 | |
| 443 PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 444 new PepperFileMsg_QueryFile(pepper_path, &file_info, &error)); | |
| 445 | |
| 446 if (error == base::PLATFORM_FILE_OK) { | |
| 447 info->size = file_info.size; | |
| 448 info->creation_time = TimeToPPTime(file_info.creation_time); | |
| 449 info->last_access_time = TimeToPPTime(file_info.last_accessed); | |
| 450 info->last_modified_time = TimeToPPTime(file_info.last_modified); | |
| 451 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
| 452 if (file_info.is_directory) | |
| 453 info->type = PP_FILETYPE_DIRECTORY; | |
| 454 else | |
| 455 info->type = PP_FILETYPE_REGULAR; | |
| 456 } | |
| 457 | |
| 458 return ppapi::PlatformFileErrorToPepperError(error); | |
| 459 } | |
| 460 | |
| 461 int32_t PPB_Flash_Proxy::GetDirContents(PP_Instance, | |
| 462 const char* path, | |
| 463 PP_DirContents_Dev** contents) { | |
| 464 ppapi::DirContents entries; | |
| 465 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 466 ppapi::PepperFilePath pepper_path(ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 467 FilePath::FromUTF8Unsafe(path)); | |
| 468 | |
| 469 PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 470 new PepperFileMsg_GetDirContents(pepper_path, &entries, &error)); | |
| 471 | |
| 472 if (error == base::PLATFORM_FILE_OK) { | |
| 473 // Copy the serialized dir entries to the output struct. | |
| 474 *contents = new PP_DirContents_Dev; | |
| 475 (*contents)->count = static_cast<int32_t>(entries.size()); | |
| 476 (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; | |
| 477 for (size_t i = 0; i < entries.size(); i++) { | |
| 478 const ppapi::DirEntry& source = entries[i]; | |
| 479 PP_DirEntry_Dev* dest = &(*contents)->entries[i]; | |
| 480 std::string name = source.name.AsUTF8Unsafe(); | |
| 481 char* name_copy = new char[name.size() + 1]; | |
| 482 memcpy(name_copy, name.c_str(), name.size() + 1); | |
| 483 dest->name = name_copy; | |
| 484 dest->is_dir = PP_FromBool(source.is_dir); | |
| 485 } | |
| 486 } | |
| 487 | |
| 488 return ppapi::PlatformFileErrorToPepperError(error); | |
| 489 } | |
| 490 | |
| 491 int32_t PPB_Flash_Proxy::CreateTemporaryFile(PP_Instance instance, | |
| 492 PP_FileHandle* file) { | |
| 493 if (!file) | |
| 494 return PP_ERROR_BADARGUMENT; | |
| 495 | |
| 496 base::PlatformFileError error; | |
| 497 IPC::PlatformFileForTransit transit_file; | |
| 498 | |
| 499 if (PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( | |
| 500 new PepperFileMsg_CreateTemporaryFile(&error, &transit_file))) { | |
| 501 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file); | |
| 502 } else { | |
| 503 error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 504 *file = base::kInvalidPlatformFileValue; | |
| 505 } | |
| 506 | |
| 507 return ppapi::PlatformFileErrorToPepperError(error); | |
| 508 } | |
| 509 | |
| 510 int32_t PPB_Flash_Proxy::OpenFileRef(PP_Instance instance, | |
| 511 PP_Resource file_ref_id, | |
| 512 int32_t mode, | |
| 513 PP_FileHandle* file) { | |
| 514 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref_id, true); | |
| 515 if (enter.failed()) | |
| 516 return PP_ERROR_BADRESOURCE; | |
| 517 | |
| 518 int32_t result = PP_ERROR_FAILED; | |
| 519 IPC::PlatformFileForTransit transit; | |
| 520 dispatcher()->Send(new PpapiHostMsg_PPBFlash_OpenFileRef( | |
| 521 API_ID_PPB_FLASH, instance, enter.resource()->host_resource(), mode, | |
| 522 &transit, &result)); | |
| 523 *file = IPC::PlatformFileForTransitToPlatformFile(transit); | |
| 524 return result; | |
| 525 } | |
| 526 | |
| 527 int32_t PPB_Flash_Proxy::QueryFileRef(PP_Instance instance, | |
| 528 PP_Resource file_ref_id, | |
| 529 PP_FileInfo* info) { | |
| 530 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref_id, true); | |
| 531 if (enter.failed()) | |
| 532 return PP_ERROR_BADRESOURCE; | |
| 533 | |
| 534 int32_t result = PP_ERROR_FAILED; | |
| 535 dispatcher()->Send(new PpapiHostMsg_PPBFlash_QueryFileRef( | |
| 536 API_ID_PPB_FLASH, instance, enter.resource()->host_resource(), info, | |
| 537 &result)); | |
| 538 return result; | |
| 539 } | |
| 540 | |
| 541 PP_Bool PPB_Flash_Proxy::FlashIsFullscreen(PP_Instance instance) { | 355 PP_Bool PPB_Flash_Proxy::FlashIsFullscreen(PP_Instance instance) { |
| 542 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> | 356 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
| 543 GetInstanceData(instance); | 357 GetInstanceData(instance); |
| 544 if (!data) | 358 if (!data) |
| 545 return PP_FALSE; | 359 return PP_FALSE; |
| 546 return data->flash_fullscreen; | 360 return data->flash_fullscreen; |
| 547 } | 361 } |
| 548 | 362 |
| 549 PP_Bool PPB_Flash_Proxy::FlashSetFullscreen(PP_Instance instance, | 363 PP_Bool PPB_Flash_Proxy::FlashSetFullscreen(PP_Instance instance, |
| 550 PP_Bool fullscreen) { | 364 PP_Bool fullscreen) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 EnterInstanceNoLock enter(instance); | 509 EnterInstanceNoLock enter(instance); |
| 696 if (enter.succeeded()) { | 510 if (enter.succeeded()) { |
| 697 *result = enter.functions()->GetFlashAPI()->FlashGetScreenSize( | 511 *result = enter.functions()->GetFlashAPI()->FlashGetScreenSize( |
| 698 instance, size); | 512 instance, size); |
| 699 } else { | 513 } else { |
| 700 size->width = 0; | 514 size->width = 0; |
| 701 size->height = 0; | 515 size->height = 0; |
| 702 } | 516 } |
| 703 } | 517 } |
| 704 | 518 |
| 705 void PPB_Flash_Proxy::OnHostMsgOpenFileRef( | |
| 706 PP_Instance instance, | |
| 707 const HostResource& host_resource, | |
| 708 int32_t mode, | |
| 709 IPC::PlatformFileForTransit* file_handle, | |
| 710 int32_t* result) { | |
| 711 EnterInstanceNoLock enter(instance); | |
| 712 if (enter.failed()) { | |
| 713 *result = PP_ERROR_BADARGUMENT; | |
| 714 return; | |
| 715 } | |
| 716 | |
| 717 base::PlatformFile file; | |
| 718 *result = enter.functions()->GetFlashAPI()->OpenFileRef( | |
| 719 instance, host_resource.host_resource(), mode, &file); | |
| 720 *file_handle = PlatformFileToPlatformFileForTransit(dispatcher(), | |
| 721 result, file); | |
| 722 } | |
| 723 | |
| 724 void PPB_Flash_Proxy::OnHostMsgQueryFileRef( | |
| 725 PP_Instance instance, | |
| 726 const HostResource& host_resource, | |
| 727 PP_FileInfo* info, | |
| 728 int32_t* result) { | |
| 729 EnterInstanceNoLock enter(instance); | |
| 730 if (enter.failed()) { | |
| 731 *result = PP_ERROR_BADARGUMENT; | |
| 732 return; | |
| 733 } | |
| 734 *result = enter.functions()->GetFlashAPI()->QueryFileRef( | |
| 735 instance, host_resource.host_resource(), info); | |
| 736 } | |
| 737 | |
| 738 void PPB_Flash_Proxy::OnHostMsgGetSetting(PP_Instance instance, | 519 void PPB_Flash_Proxy::OnHostMsgGetSetting(PP_Instance instance, |
| 739 PP_FlashSetting setting, | 520 PP_FlashSetting setting, |
| 740 SerializedVarReturnValue id) { | 521 SerializedVarReturnValue id) { |
| 741 EnterInstanceNoLock enter(instance); | 522 EnterInstanceNoLock enter(instance); |
| 742 if (enter.succeeded()) { | 523 if (enter.succeeded()) { |
| 743 id.Return(dispatcher(), | 524 id.Return(dispatcher(), |
| 744 enter.functions()->GetFlashAPI()->GetSetting( | 525 enter.functions()->GetFlashAPI()->GetSetting( |
| 745 instance, setting)); | 526 instance, setting)); |
| 746 } else { | 527 } else { |
| 747 id.Return(dispatcher(), PP_MakeUndefined()); | 528 id.Return(dispatcher(), PP_MakeUndefined()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 765 // It's rarely used enough that we just request this interface when needed. | 546 // It's rarely used enough that we just request this interface when needed. |
| 766 const PPB_Flash_Print_1_0* print_interface = | 547 const PPB_Flash_Print_1_0* print_interface = |
| 767 static_cast<const PPB_Flash_Print_1_0*>( | 548 static_cast<const PPB_Flash_Print_1_0*>( |
| 768 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); | 549 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); |
| 769 if (print_interface) | 550 if (print_interface) |
| 770 print_interface->InvokePrinting(instance); | 551 print_interface->InvokePrinting(instance); |
| 771 } | 552 } |
| 772 | 553 |
| 773 } // namespace proxy | 554 } // namespace proxy |
| 774 } // namespace ppapi | 555 } // namespace ppapi |
| OLD | NEW |