| 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 "ppapi/proxy/ppb_flash_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "build/build_config.h" | |
| 10 #include "ppapi/c/dev/pp_file_info_dev.h" | |
| 11 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 12 #include "ppapi/c/pp_completion_callback.h" | |
| 13 #include "ppapi/c/pp_errors.h" | |
| 14 #include "ppapi/c/pp_resource.h" | 10 #include "ppapi/c/pp_resource.h" |
| 15 #include "ppapi/c/private/ppb_flash.h" | 11 #include "ppapi/c/private/ppb_flash.h" |
| 16 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
| 17 #include "ppapi/proxy/plugin_resource.h" | 13 #include "ppapi/proxy/plugin_resource.h" |
| 18 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 19 #include "ppapi/proxy/serialized_var.h" | 15 #include "ppapi/proxy/serialized_var.h" |
| 20 | 16 |
| 21 namespace pp { | 17 namespace pp { |
| 22 namespace proxy { | 18 namespace proxy { |
| 23 | 19 |
| 24 namespace { | 20 namespace { |
| 25 | 21 |
| 26 // Given an error code and a handle result from a Pepper API call, converts | |
| 27 // to a PlatformFileForTransit, possibly also updating the error value if | |
| 28 // an error occurred. | |
| 29 IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit( | |
| 30 int32_t* error, | |
| 31 base::PlatformFile file) { | |
| 32 if (*error != PP_OK) | |
| 33 return IPC::InvalidPlatformFileForTransit(); | |
| 34 #if defined(OS_WIN) | |
| 35 /* TODO(brettw): figure out how to get the target process handle. | |
| 36 HANDLE result; | |
| 37 if (!::DuplicateHandle(::GetCurrentProcess(), file, | |
| 38 target_process, &result, 0, false, | |
| 39 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | |
| 40 *error = PP_ERROR_NOACCESS; | |
| 41 return INVALID_HANDLE_VALUE; | |
| 42 } | |
| 43 return result; | |
| 44 */ | |
| 45 NOTIMPLEMENTED(); | |
| 46 *error = PP_ERROR_NOACCESS; | |
| 47 return INVALID_HANDLE_VALUE; | |
| 48 #elif defined(OS_POSIX) | |
| 49 return base::FileDescriptor(file, true); | |
| 50 #endif | |
| 51 } | |
| 52 | |
| 53 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { | 22 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { |
| 54 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); | 23 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); |
| 55 if (dispatcher) { | 24 if (dispatcher) { |
| 56 dispatcher->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop( | 25 dispatcher->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop( |
| 57 INTERFACE_ID_PPB_FLASH, pp_instance, on_top)); | 26 INTERFACE_ID_PPB_FLASH, pp_instance, on_top)); |
| 58 } | 27 } |
| 59 } | 28 } |
| 60 | 29 |
| 61 PP_Bool DrawGlyphs(PP_Instance instance, | 30 PP_Bool DrawGlyphs(PP_Instance instance, |
| 62 PP_Resource pp_image_data, | 31 PP_Resource pp_image_data, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 79 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 111 if (!dispatcher) | 80 if (!dispatcher) |
| 112 return PP_MakeUndefined(); | 81 return PP_MakeUndefined(); |
| 113 | 82 |
| 114 ReceiveSerializedVarReturnValue result; | 83 ReceiveSerializedVarReturnValue result; |
| 115 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL( | 84 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL( |
| 116 INTERFACE_ID_PPB_FLASH, instance, url, &result)); | 85 INTERFACE_ID_PPB_FLASH, instance, url, &result)); |
| 117 return result.Return(dispatcher); | 86 return result.Return(dispatcher); |
| 118 } | 87 } |
| 119 | 88 |
| 120 int32_t OpenModuleLocalFile(PP_Instance instance, | |
| 121 const char* path, | |
| 122 int32_t mode, | |
| 123 PP_FileHandle* file) { | |
| 124 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 125 if (!dispatcher) | |
| 126 return PP_ERROR_BADARGUMENT; | |
| 127 | |
| 128 int32_t result = PP_ERROR_FAILED; | |
| 129 IPC::PlatformFileForTransit transit; | |
| 130 dispatcher->Send(new PpapiHostMsg_PPBFlash_OpenModuleLocalFile( | |
| 131 INTERFACE_ID_PPB_FLASH, instance, path, mode, &transit, &result)); | |
| 132 *file = IPC::PlatformFileForTransitToPlatformFile(transit); | |
| 133 return result; | |
| 134 } | |
| 135 | |
| 136 int32_t RenameModuleLocalFile(PP_Instance instance, | |
| 137 const char* path_from, | |
| 138 const char* path_to) { | |
| 139 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 140 if (!dispatcher) | |
| 141 return PP_ERROR_BADARGUMENT; | |
| 142 | |
| 143 int32_t result = PP_ERROR_FAILED; | |
| 144 dispatcher->Send(new PpapiHostMsg_PPBFlash_RenameModuleLocalFile( | |
| 145 INTERFACE_ID_PPB_FLASH, instance, path_from, path_to, &result)); | |
| 146 return result; | |
| 147 } | |
| 148 | |
| 149 int32_t DeleteModuleLocalFileOrDir(PP_Instance instance, | |
| 150 const char* path, | |
| 151 PP_Bool recursive) { | |
| 152 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 153 if (!dispatcher) | |
| 154 return PP_ERROR_BADARGUMENT; | |
| 155 | |
| 156 int32_t result = PP_ERROR_FAILED; | |
| 157 dispatcher->Send(new PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir( | |
| 158 INTERFACE_ID_PPB_FLASH, instance, path, recursive, &result)); | |
| 159 return result; | |
| 160 } | |
| 161 | |
| 162 int32_t CreateModuleLocalDir(PP_Instance instance, const char* path) { | |
| 163 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 164 if (!dispatcher) | |
| 165 return PP_ERROR_BADARGUMENT; | |
| 166 | |
| 167 int32_t result = PP_ERROR_FAILED; | |
| 168 dispatcher->Send(new PpapiHostMsg_PPBFlash_CreateModuleLocalDir( | |
| 169 INTERFACE_ID_PPB_FLASH, instance, path, &result)); | |
| 170 return result; | |
| 171 } | |
| 172 | |
| 173 int32_t QueryModuleLocalFile(PP_Instance instance, | |
| 174 const char* path, | |
| 175 PP_FileInfo_Dev* info) { | |
| 176 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 177 if (!dispatcher) | |
| 178 return PP_ERROR_BADARGUMENT; | |
| 179 | |
| 180 int32_t result = PP_ERROR_FAILED; | |
| 181 dispatcher->Send(new PpapiHostMsg_PPBFlash_QueryModuleLocalFile( | |
| 182 INTERFACE_ID_PPB_FLASH, instance, path, info, &result)); | |
| 183 return result; | |
| 184 } | |
| 185 | |
| 186 int32_t GetModuleLocalDirContents(PP_Instance instance, | |
| 187 const char* path, | |
| 188 PP_DirContents_Dev** contents) { | |
| 189 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 190 if (!dispatcher) | |
| 191 return PP_ERROR_BADARGUMENT; | |
| 192 | |
| 193 int32_t result = PP_ERROR_FAILED; | |
| 194 std::vector<SerializedDirEntry> entries; | |
| 195 dispatcher->Send(new PpapiHostMsg_PPBFlash_GetModuleLocalDirContents( | |
| 196 INTERFACE_ID_PPB_FLASH, instance, path, &entries, &result)); | |
| 197 | |
| 198 if (result != PP_OK) | |
| 199 return result; | |
| 200 | |
| 201 // Copy the serialized dir entries to the output struct. | |
| 202 *contents = new PP_DirContents_Dev; | |
| 203 (*contents)->count = static_cast<int32_t>(entries.size()); | |
| 204 (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; | |
| 205 for (size_t i = 0; i < entries.size(); i++) { | |
| 206 const SerializedDirEntry& source = entries[i]; | |
| 207 PP_DirEntry_Dev* dest = &(*contents)->entries[i]; | |
| 208 | |
| 209 char* name_copy = new char[source.name.size() + 1]; | |
| 210 memcpy(name_copy, source.name.c_str(), source.name.size() + 1); | |
| 211 dest->name = name_copy; | |
| 212 dest->is_dir = BoolToPPBool(source.is_dir); | |
| 213 } | |
| 214 | |
| 215 return result; | |
| 216 } | |
| 217 | |
| 218 void FreeModuleLocalDirContents(PP_Instance /* instance */, | |
| 219 PP_DirContents_Dev* contents) { | |
| 220 for (int32_t i = 0; i < contents->count; ++i) | |
| 221 delete[] contents->entries[i].name; | |
| 222 delete[] contents->entries; | |
| 223 delete contents; | |
| 224 } | |
| 225 | |
| 226 PP_Bool NavigateToURL(PP_Instance instance, | 89 PP_Bool NavigateToURL(PP_Instance instance, |
| 227 const char* url, | 90 const char* url, |
| 228 const char* target) { | 91 const char* target) { |
| 229 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 92 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 230 if (!dispatcher) | 93 if (!dispatcher) |
| 231 return PP_FALSE; | 94 return PP_FALSE; |
| 232 | 95 |
| 233 PP_Bool result = PP_FALSE; | 96 PP_Bool result = PP_FALSE; |
| 234 dispatcher->Send(new PpapiHostMsg_PPBFlash_NavigateToURL( | 97 dispatcher->Send(new PpapiHostMsg_PPBFlash_NavigateToURL( |
| 235 INTERFACE_ID_PPB_FLASH, instance, url, target, &result)); | 98 INTERFACE_ID_PPB_FLASH, instance, url, target, &result)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 251 if (!dispatcher) | 114 if (!dispatcher) |
| 252 return; | 115 return; |
| 253 dispatcher->Send(new PpapiHostMsg_PPBFlash_QuitMessageLoop( | 116 dispatcher->Send(new PpapiHostMsg_PPBFlash_QuitMessageLoop( |
| 254 INTERFACE_ID_PPB_FLASH, instance)); | 117 INTERFACE_ID_PPB_FLASH, instance)); |
| 255 } | 118 } |
| 256 | 119 |
| 257 const PPB_Flash flash_interface = { | 120 const PPB_Flash flash_interface = { |
| 258 &SetInstanceAlwaysOnTop, | 121 &SetInstanceAlwaysOnTop, |
| 259 &DrawGlyphs, | 122 &DrawGlyphs, |
| 260 &GetProxyForURL, | 123 &GetProxyForURL, |
| 261 &OpenModuleLocalFile, | |
| 262 &RenameModuleLocalFile, | |
| 263 &DeleteModuleLocalFileOrDir, | |
| 264 &CreateModuleLocalDir, | |
| 265 &QueryModuleLocalFile, | |
| 266 &GetModuleLocalDirContents, | |
| 267 &FreeModuleLocalDirContents, | |
| 268 &NavigateToURL, | 124 &NavigateToURL, |
| 269 &RunMessageLoop, | 125 &RunMessageLoop, |
| 270 &QuitMessageLoop, | 126 &QuitMessageLoop, |
| 271 }; | 127 }; |
| 272 | 128 |
| 273 InterfaceProxy* CreateFlashProxy(Dispatcher* dispatcher, | 129 InterfaceProxy* CreateFlashProxy(Dispatcher* dispatcher, |
| 274 const void* target_interface) { | 130 const void* target_interface) { |
| 275 return new PPB_Flash_Proxy(dispatcher, target_interface); | 131 return new PPB_Flash_Proxy(dispatcher, target_interface); |
| 276 } | 132 } |
| 277 | 133 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 299 | 155 |
| 300 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { | 156 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 301 bool handled = true; | 157 bool handled = true; |
| 302 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg) | 158 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg) |
| 303 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop, | 159 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop, |
| 304 OnMsgSetInstanceAlwaysOnTop) | 160 OnMsgSetInstanceAlwaysOnTop) |
| 305 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DrawGlyphs, | 161 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DrawGlyphs, |
| 306 OnMsgDrawGlyphs) | 162 OnMsgDrawGlyphs) |
| 307 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetProxyForURL, | 163 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetProxyForURL, |
| 308 OnMsgGetProxyForURL) | 164 OnMsgGetProxyForURL) |
| 309 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenModuleLocalFile, | |
| 310 OnMsgOpenModuleLocalFile) | |
| 311 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RenameModuleLocalFile, | |
| 312 OnMsgRenameModuleLocalFile) | |
| 313 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir, | |
| 314 OnMsgDeleteModuleLocalFileOrDir) | |
| 315 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_CreateModuleLocalDir, | |
| 316 OnMsgCreateModuleLocalDir) | |
| 317 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryModuleLocalFile, | |
| 318 OnMsgQueryModuleLocalFile) | |
| 319 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetModuleLocalDirContents, | |
| 320 OnMsgGetModuleLocalDirContents) | |
| 321 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_NavigateToURL, OnMsgNavigateToURL) | 165 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_NavigateToURL, OnMsgNavigateToURL) |
| 322 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RunMessageLoop, | 166 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RunMessageLoop, |
| 323 OnMsgRunMessageLoop) | 167 OnMsgRunMessageLoop) |
| 324 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QuitMessageLoop, | 168 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QuitMessageLoop, |
| 325 OnMsgQuitMessageLoop) | 169 OnMsgQuitMessageLoop) |
| 326 IPC_MESSAGE_UNHANDLED(handled = false) | 170 IPC_MESSAGE_UNHANDLED(handled = false) |
| 327 IPC_END_MESSAGE_MAP() | 171 IPC_END_MESSAGE_MAP() |
| 328 // TODO(brettw) handle bad messages! | 172 // TODO(brettw) handle bad messages! |
| 329 return handled; | 173 return handled; |
| 330 } | 174 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 357 const_cast<PP_Point*>(¶ms.glyph_advances[0])); | 201 const_cast<PP_Point*>(¶ms.glyph_advances[0])); |
| 358 } | 202 } |
| 359 | 203 |
| 360 void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance, | 204 void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance, |
| 361 const std::string& url, | 205 const std::string& url, |
| 362 SerializedVarReturnValue result) { | 206 SerializedVarReturnValue result) { |
| 363 result.Return(dispatcher(), ppb_flash_target()->GetProxyForURL( | 207 result.Return(dispatcher(), ppb_flash_target()->GetProxyForURL( |
| 364 instance, url.c_str())); | 208 instance, url.c_str())); |
| 365 } | 209 } |
| 366 | 210 |
| 367 void PPB_Flash_Proxy::OnMsgOpenModuleLocalFile( | |
| 368 PP_Instance instance, | |
| 369 const std::string& path, | |
| 370 int32_t mode, | |
| 371 IPC::PlatformFileForTransit* file_handle, | |
| 372 int32_t* result) { | |
| 373 base::PlatformFile file; | |
| 374 *result = ppb_flash_target()->OpenModuleLocalFile(instance, path.c_str(), | |
| 375 mode, &file); | |
| 376 *file_handle = PlatformFileToPlatformFileForTransit(result, file); | |
| 377 } | |
| 378 | |
| 379 void PPB_Flash_Proxy::OnMsgRenameModuleLocalFile( | |
| 380 PP_Instance instance, | |
| 381 const std::string& path_from, | |
| 382 const std::string& path_to, | |
| 383 int32_t* result) { | |
| 384 *result = ppb_flash_target()->RenameModuleLocalFile(instance, | |
| 385 path_from.c_str(), | |
| 386 path_to.c_str()); | |
| 387 } | |
| 388 | |
| 389 void PPB_Flash_Proxy::OnMsgDeleteModuleLocalFileOrDir( | |
| 390 PP_Instance instance, | |
| 391 const std::string& path, | |
| 392 PP_Bool recursive, | |
| 393 int32_t* result) { | |
| 394 *result = ppb_flash_target()->DeleteModuleLocalFileOrDir(instance, | |
| 395 path.c_str(), | |
| 396 recursive); | |
| 397 } | |
| 398 | |
| 399 void PPB_Flash_Proxy::OnMsgCreateModuleLocalDir(PP_Instance instance, | |
| 400 const std::string& path, | |
| 401 int32_t* result) { | |
| 402 *result = ppb_flash_target()->CreateModuleLocalDir(instance, path.c_str()); | |
| 403 } | |
| 404 | |
| 405 void PPB_Flash_Proxy::OnMsgQueryModuleLocalFile(PP_Instance instance, | |
| 406 const std::string& path, | |
| 407 PP_FileInfo_Dev* info, | |
| 408 int32_t* result) { | |
| 409 *result = ppb_flash_target()->QueryModuleLocalFile(instance, path.c_str(), | |
| 410 info); | |
| 411 } | |
| 412 | |
| 413 void PPB_Flash_Proxy::OnMsgGetModuleLocalDirContents( | |
| 414 PP_Instance instance, | |
| 415 const std::string& path, | |
| 416 std::vector<pp::proxy::SerializedDirEntry>* entries, | |
| 417 int32_t* result) { | |
| 418 PP_DirContents_Dev* contents = NULL; | |
| 419 *result = ppb_flash_target()->GetModuleLocalDirContents(instance, | |
| 420 path.c_str(), | |
| 421 &contents); | |
| 422 if (*result != PP_OK) | |
| 423 return; | |
| 424 | |
| 425 // Convert the list of entries to the serialized version. | |
| 426 entries->resize(contents->count); | |
| 427 for (int32_t i = 0; i < contents->count; i++) { | |
| 428 (*entries)[i].name.assign(contents->entries[i].name); | |
| 429 (*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir); | |
| 430 } | |
| 431 ppb_flash_target()->FreeModuleLocalDirContents(instance, contents); | |
| 432 } | |
| 433 | |
| 434 void PPB_Flash_Proxy::OnMsgNavigateToURL(PP_Instance instance, | 211 void PPB_Flash_Proxy::OnMsgNavigateToURL(PP_Instance instance, |
| 435 const std::string& url, | 212 const std::string& url, |
| 436 const std::string& target, | 213 const std::string& target, |
| 437 PP_Bool* result) { | 214 PP_Bool* result) { |
| 438 *result = ppb_flash_target()->NavigateToURL(instance, url.c_str(), | 215 *result = ppb_flash_target()->NavigateToURL(instance, url.c_str(), |
| 439 target.c_str()); | 216 target.c_str()); |
| 440 } | 217 } |
| 441 | 218 |
| 442 void PPB_Flash_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { | 219 void PPB_Flash_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { |
| 443 ppb_flash_target()->RunMessageLoop(instance); | 220 ppb_flash_target()->RunMessageLoop(instance); |
| 444 } | 221 } |
| 445 | 222 |
| 446 void PPB_Flash_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { | 223 void PPB_Flash_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { |
| 447 ppb_flash_target()->QuitMessageLoop(instance); | 224 ppb_flash_target()->QuitMessageLoop(instance); |
| 448 } | 225 } |
| 449 | 226 |
| 450 } // namespace proxy | 227 } // namespace proxy |
| 451 } // namespace pp | 228 } // namespace pp |
| OLD | NEW |