| 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashSetFullscreen, | 419 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashSetFullscreen, |
| 420 OnHostMsgFlashSetFullscreen) | 420 OnHostMsgFlashSetFullscreen) |
| 421 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashGetScreenSize, | 421 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashGetScreenSize, |
| 422 OnHostMsgFlashGetScreenSize) | 422 OnHostMsgFlashGetScreenSize) |
| 423 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsClipboardFormatAvailable, | 423 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsClipboardFormatAvailable, |
| 424 OnHostMsgIsClipboardFormatAvailable) | 424 OnHostMsgIsClipboardFormatAvailable) |
| 425 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_ReadClipboardData, | 425 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_ReadClipboardData, |
| 426 OnHostMsgReadClipboardData) | 426 OnHostMsgReadClipboardData) |
| 427 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_WriteClipboardData, | 427 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_WriteClipboardData, |
| 428 OnHostMsgWriteClipboardData) | 428 OnHostMsgWriteClipboardData) |
| 429 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFile, | |
| 430 OnHostMsgOpenFile) | |
| 431 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RenameFile, | |
| 432 OnHostMsgRenameFile) | |
| 433 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DeleteFileOrDir, | |
| 434 OnHostMsgDeleteFileOrDir) | |
| 435 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_CreateDir, | |
| 436 OnHostMsgCreateDir) | |
| 437 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFile, | |
| 438 OnHostMsgQueryFile) | |
| 439 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDirContents, | |
| 440 OnHostMsgGetDirContents) | |
| 441 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFileRef, | 429 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFileRef, |
| 442 OnHostMsgOpenFileRef) | 430 OnHostMsgOpenFileRef) |
| 443 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFileRef, | 431 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFileRef, |
| 444 OnHostMsgQueryFileRef) | 432 OnHostMsgQueryFileRef) |
| 445 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDeviceID, | 433 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDeviceID, |
| 446 OnHostMsgGetDeviceID) | 434 OnHostMsgGetDeviceID) |
| 447 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, | 435 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, |
| 448 OnHostMsgInvokePrinting) | 436 OnHostMsgInvokePrinting) |
| 449 IPC_MESSAGE_UNHANDLED(handled = false) | 437 IPC_MESSAGE_UNHANDLED(handled = false) |
| 450 IPC_END_MESSAGE_MAP() | 438 IPC_END_MESSAGE_MAP() |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 } | 649 } |
| 662 g_module_local_thread_adapter->AddInstanceRouting(instance, dispatcher); | 650 g_module_local_thread_adapter->AddInstanceRouting(instance, dispatcher); |
| 663 return true; | 651 return true; |
| 664 } | 652 } |
| 665 | 653 |
| 666 void PPB_Flash_Proxy::ClearThreadAdapterForInstance(PP_Instance instance) { | 654 void PPB_Flash_Proxy::ClearThreadAdapterForInstance(PP_Instance instance) { |
| 667 if (g_module_local_thread_adapter) | 655 if (g_module_local_thread_adapter) |
| 668 g_module_local_thread_adapter->ClearInstanceRouting(instance); | 656 g_module_local_thread_adapter->ClearInstanceRouting(instance); |
| 669 } | 657 } |
| 670 | 658 |
| 671 int32_t PPB_Flash_Proxy::OpenFile(PP_Instance instance, | 659 int32_t PPB_Flash_Proxy::OpenFile(PP_Instance, |
| 672 const char* path, | 660 const char* path, |
| 673 int32_t mode, | 661 int32_t mode, |
| 674 PP_FileHandle* file) { | 662 PP_FileHandle* file) { |
| 675 if (!g_module_local_thread_adapter) | 663 return PluginGlobals::Get()->plugin_proxy_delegate()-> |
| 676 return PP_ERROR_FAILED; | 664 SendOpenFileRequestToBrowser(path, mode, file); |
| 677 | |
| 678 int32_t result = PP_ERROR_FAILED; | |
| 679 IPC::PlatformFileForTransit transit; | |
| 680 g_module_local_thread_adapter->Send(instance, | |
| 681 new PpapiHostMsg_PPBFlash_OpenFile( | |
| 682 API_ID_PPB_FLASH, instance, path, mode, &transit, &result)); | |
| 683 *file = IPC::PlatformFileForTransitToPlatformFile(transit); | |
| 684 return result; | |
| 685 } | 665 } |
| 686 | 666 |
| 687 int32_t PPB_Flash_Proxy::RenameFile(PP_Instance instance, | 667 int32_t PPB_Flash_Proxy::RenameFile(PP_Instance, |
| 688 const char* path_from, | 668 const char* from_path, |
| 689 const char* path_to) { | 669 const char* to_path) { |
| 690 if (!g_module_local_thread_adapter) | 670 return PluginGlobals::Get()->plugin_proxy_delegate()-> |
| 691 return PP_ERROR_FAILED; | 671 SendRenameFileRequestToBrowser(from_path, to_path); |
| 692 | |
| 693 int32_t result = PP_ERROR_FAILED; | |
| 694 g_module_local_thread_adapter->Send(instance, | |
| 695 new PpapiHostMsg_PPBFlash_RenameFile( | |
| 696 API_ID_PPB_FLASH, instance, path_from, path_to, &result)); | |
| 697 return result; | |
| 698 } | 672 } |
| 699 | 673 |
| 700 int32_t PPB_Flash_Proxy::DeleteFileOrDir(PP_Instance instance, | 674 int32_t PPB_Flash_Proxy::DeleteFileOrDir(PP_Instance, |
| 701 const char* path, | 675 const char* path, |
| 702 PP_Bool recursive) { | 676 PP_Bool recursive) { |
| 703 if (!g_module_local_thread_adapter) | 677 return PluginGlobals::Get()->plugin_proxy_delegate()-> |
| 704 return PP_ERROR_FAILED; | 678 SendDeleteFileOrDirRequestToBrowser(path, recursive); |
| 705 | |
| 706 int32_t result = PP_ERROR_FAILED; | |
| 707 g_module_local_thread_adapter->Send(instance, | |
| 708 new PpapiHostMsg_PPBFlash_DeleteFileOrDir( | |
| 709 API_ID_PPB_FLASH, instance, path, recursive, &result)); | |
| 710 return result; | |
| 711 } | 679 } |
| 712 | 680 |
| 713 int32_t PPB_Flash_Proxy::CreateDir(PP_Instance instance, const char* path) { | 681 int32_t PPB_Flash_Proxy::CreateDir(PP_Instance, const char* path) { |
| 714 if (!g_module_local_thread_adapter) | 682 return PluginGlobals::Get()->plugin_proxy_delegate()-> |
| 715 return PP_ERROR_FAILED; | 683 SendCreateDirRequestToBrowser(path); |
| 716 | |
| 717 int32_t result = PP_ERROR_FAILED; | |
| 718 g_module_local_thread_adapter->Send(instance, | |
| 719 new PpapiHostMsg_PPBFlash_CreateDir( | |
| 720 API_ID_PPB_FLASH, instance, path, &result)); | |
| 721 return result; | |
| 722 } | 684 } |
| 723 | 685 |
| 724 int32_t PPB_Flash_Proxy::QueryFile(PP_Instance instance, | 686 int32_t PPB_Flash_Proxy::QueryFile(PP_Instance, |
| 725 const char* path, | 687 const char* path, |
| 726 PP_FileInfo* info) { | 688 PP_FileInfo* info) { |
| 727 if (!g_module_local_thread_adapter) | 689 return PluginGlobals::Get()->plugin_proxy_delegate()-> |
| 728 return PP_ERROR_FAILED; | 690 SendQueryFileRequestToBrowser(path, info); |
| 729 | |
| 730 int32_t result = PP_ERROR_FAILED; | |
| 731 g_module_local_thread_adapter->Send(instance, | |
| 732 new PpapiHostMsg_PPBFlash_QueryFile( | |
| 733 API_ID_PPB_FLASH, instance, path, info, &result)); | |
| 734 return result; | |
| 735 } | 691 } |
| 736 | 692 |
| 737 int32_t PPB_Flash_Proxy::GetDirContents(PP_Instance instance, | 693 int32_t PPB_Flash_Proxy::GetDirContents(PP_Instance, |
| 738 const char* path, | 694 const char* path, |
| 739 PP_DirContents_Dev** contents) { | 695 PP_DirContents_Dev** contents) { |
| 740 if (!g_module_local_thread_adapter) | 696 return PluginGlobals::Get()->plugin_proxy_delegate()-> |
| 741 return PP_ERROR_FAILED; | 697 SendGetDirContentsRequestToBrowser(path, contents); |
| 742 | |
| 743 int32_t result = PP_ERROR_FAILED; | |
| 744 std::vector<SerializedDirEntry> entries; | |
| 745 g_module_local_thread_adapter->Send(instance, | |
| 746 new PpapiHostMsg_PPBFlash_GetDirContents( | |
| 747 API_ID_PPB_FLASH, instance, path, &entries, &result)); | |
| 748 | |
| 749 if (result != PP_OK) | |
| 750 return result; | |
| 751 | |
| 752 // Copy the serialized dir entries to the output struct. | |
| 753 *contents = new PP_DirContents_Dev; | |
| 754 (*contents)->count = static_cast<int32_t>(entries.size()); | |
| 755 (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; | |
| 756 for (size_t i = 0; i < entries.size(); i++) { | |
| 757 const SerializedDirEntry& source = entries[i]; | |
| 758 PP_DirEntry_Dev* dest = &(*contents)->entries[i]; | |
| 759 | |
| 760 char* name_copy = new char[source.name.size() + 1]; | |
| 761 memcpy(name_copy, source.name.c_str(), source.name.size() + 1); | |
| 762 dest->name = name_copy; | |
| 763 dest->is_dir = PP_FromBool(source.is_dir); | |
| 764 } | |
| 765 | |
| 766 return result; | |
| 767 } | 698 } |
| 768 | 699 |
| 769 int32_t PPB_Flash_Proxy::OpenFileRef(PP_Instance instance, | 700 int32_t PPB_Flash_Proxy::OpenFileRef(PP_Instance instance, |
| 770 PP_Resource file_ref_id, | 701 PP_Resource file_ref_id, |
| 771 int32_t mode, | 702 int32_t mode, |
| 772 PP_FileHandle* file) { | 703 PP_FileHandle* file) { |
| 773 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref_id, true); | 704 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref_id, true); |
| 774 if (enter.failed()) | 705 if (enter.failed()) |
| 775 return PP_ERROR_BADRESOURCE; | 706 return PP_ERROR_BADRESOURCE; |
| 776 | 707 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 953 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 1023 data_item_count, | 954 data_item_count, |
| 1024 formats_array.get(), | 955 formats_array.get(), |
| 1025 data_items_array); | 956 data_items_array); |
| 1026 DLOG_IF(WARNING, result != PP_OK) | 957 DLOG_IF(WARNING, result != PP_OK) |
| 1027 << "Write to clipboard failed unexpectedly."; | 958 << "Write to clipboard failed unexpectedly."; |
| 1028 (void)result; // Prevent warning in release mode. | 959 (void)result; // Prevent warning in release mode. |
| 1029 } | 960 } |
| 1030 } | 961 } |
| 1031 | 962 |
| 1032 void PPB_Flash_Proxy::OnHostMsgOpenFile( | |
| 1033 PP_Instance instance, | |
| 1034 const std::string& path, | |
| 1035 int32_t mode, | |
| 1036 IPC::PlatformFileForTransit* file_handle, | |
| 1037 int32_t* result) { | |
| 1038 EnterInstanceNoLock enter(instance); | |
| 1039 if (enter.succeeded()) { | |
| 1040 base::PlatformFile file; | |
| 1041 *result = enter.functions()->GetFlashAPI()->OpenFile( | |
| 1042 instance, path.c_str(), mode, &file); | |
| 1043 *file_handle = PlatformFileToPlatformFileForTransit( | |
| 1044 dispatcher(), result, file); | |
| 1045 } else { | |
| 1046 *result = PP_ERROR_BADARGUMENT; | |
| 1047 } | |
| 1048 } | |
| 1049 | |
| 1050 void PPB_Flash_Proxy::OnHostMsgRenameFile(PP_Instance instance, | |
| 1051 const std::string& from_path, | |
| 1052 const std::string& to_path, | |
| 1053 int32_t* result) { | |
| 1054 EnterInstanceNoLock enter(instance); | |
| 1055 if (enter.succeeded()) { | |
| 1056 *result = enter.functions()->GetFlashAPI()->RenameFile( | |
| 1057 instance, from_path.c_str(), to_path.c_str()); | |
| 1058 } else { | |
| 1059 *result = PP_ERROR_BADARGUMENT; | |
| 1060 } | |
| 1061 } | |
| 1062 | |
| 1063 void PPB_Flash_Proxy::OnHostMsgDeleteFileOrDir(PP_Instance instance, | |
| 1064 const std::string& path, | |
| 1065 PP_Bool recursive, | |
| 1066 int32_t* result) { | |
| 1067 EnterInstanceNoLock enter(instance); | |
| 1068 if (enter.succeeded()) { | |
| 1069 *result = enter.functions()->GetFlashAPI()->DeleteFileOrDir( | |
| 1070 instance, path.c_str(), recursive); | |
| 1071 } else { | |
| 1072 *result = PP_ERROR_BADARGUMENT; | |
| 1073 } | |
| 1074 } | |
| 1075 | |
| 1076 void PPB_Flash_Proxy::OnHostMsgCreateDir(PP_Instance instance, | |
| 1077 const std::string& path, | |
| 1078 int32_t* result) { | |
| 1079 EnterInstanceNoLock enter(instance); | |
| 1080 if (enter.succeeded()) { | |
| 1081 *result = enter.functions()->GetFlashAPI()->CreateDir( | |
| 1082 instance, path.c_str()); | |
| 1083 } else { | |
| 1084 *result = PP_ERROR_BADARGUMENT; | |
| 1085 } | |
| 1086 } | |
| 1087 | |
| 1088 void PPB_Flash_Proxy::OnHostMsgQueryFile(PP_Instance instance, | |
| 1089 const std::string& path, | |
| 1090 PP_FileInfo* info, | |
| 1091 int32_t* result) { | |
| 1092 EnterInstanceNoLock enter(instance); | |
| 1093 if (enter.succeeded()) { | |
| 1094 *result = enter.functions()->GetFlashAPI()->QueryFile( | |
| 1095 instance, path.c_str(), info); | |
| 1096 } else { | |
| 1097 *result = PP_ERROR_BADARGUMENT; | |
| 1098 } | |
| 1099 } | |
| 1100 | |
| 1101 void PPB_Flash_Proxy::OnHostMsgGetDirContents( | |
| 1102 PP_Instance instance, | |
| 1103 const std::string& path, | |
| 1104 std::vector<SerializedDirEntry>* entries, | |
| 1105 int32_t* result) { | |
| 1106 EnterInstanceNoLock enter(instance); | |
| 1107 if (enter.failed()) { | |
| 1108 *result = PP_ERROR_BADARGUMENT; | |
| 1109 return; | |
| 1110 } | |
| 1111 | |
| 1112 PP_DirContents_Dev* contents = NULL; | |
| 1113 *result = enter.functions()->GetFlashAPI()->GetDirContents( | |
| 1114 instance, path.c_str(), &contents); | |
| 1115 if (*result != PP_OK) | |
| 1116 return; | |
| 1117 | |
| 1118 // Convert the list of entries to the serialized version. | |
| 1119 entries->resize(contents->count); | |
| 1120 for (int32_t i = 0; i < contents->count; i++) { | |
| 1121 (*entries)[i].name.assign(contents->entries[i].name); | |
| 1122 (*entries)[i].is_dir = PP_ToBool(contents->entries[i].is_dir); | |
| 1123 } | |
| 1124 enter.functions()->GetFlashAPI()->FreeDirContents(instance, contents); | |
| 1125 } | |
| 1126 | |
| 1127 void PPB_Flash_Proxy::OnHostMsgOpenFileRef( | 963 void PPB_Flash_Proxy::OnHostMsgOpenFileRef( |
| 1128 PP_Instance instance, | 964 PP_Instance instance, |
| 1129 const HostResource& host_resource, | 965 const HostResource& host_resource, |
| 1130 int32_t mode, | 966 int32_t mode, |
| 1131 IPC::PlatformFileForTransit* file_handle, | 967 IPC::PlatformFileForTransit* file_handle, |
| 1132 int32_t* result) { | 968 int32_t* result) { |
| 1133 EnterInstanceNoLock enter(instance); | 969 EnterInstanceNoLock enter(instance); |
| 1134 if (enter.failed()) { | 970 if (enter.failed()) { |
| 1135 *result = PP_ERROR_BADARGUMENT; | 971 *result = PP_ERROR_BADARGUMENT; |
| 1136 return; | 972 return; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 // It's rarely used enough that we just request this interface when needed. | 1010 // It's rarely used enough that we just request this interface when needed. |
| 1175 const PPB_Flash_Print_1_0* print_interface = | 1011 const PPB_Flash_Print_1_0* print_interface = |
| 1176 static_cast<const PPB_Flash_Print_1_0*>( | 1012 static_cast<const PPB_Flash_Print_1_0*>( |
| 1177 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); | 1013 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); |
| 1178 if (print_interface) | 1014 if (print_interface) |
| 1179 print_interface->InvokePrinting(instance); | 1015 print_interface->InvokePrinting(instance); |
| 1180 } | 1016 } |
| 1181 | 1017 |
| 1182 } // namespace proxy | 1018 } // namespace proxy |
| 1183 } // namespace ppapi | 1019 } // namespace ppapi |
| OLD | NEW |