[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/proxy/ppb_testing_proxy.h" |
| 6 | |
| 7 | #include "base/message_loop.h" |
| 8 | #include "ppapi/c/dev/ppb_testing_dev.h" |
| 9 | #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 | #include "ppapi/proxy/ppapi_messages.h" |
| 11 | |
| 12 | namespace pp { |
| 13 | namespace proxy { |
| 14 | |
| 15 | namespace { |
| 16 | |
[email protected] | 19d2b01 | 2010-11-08 16:32:18 | [diff] [blame^] | 17 | PP_Bool ReadImageData(PP_Resource device_context_2d, |
| 18 | PP_Resource image, |
| 19 | const PP_Point* top_left) { |
| 20 | PP_Bool result = PP_FALSE; |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 21 | PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_ReadImageData( |
| 22 | INTERFACE_ID_PPB_TESTING, device_context_2d, image, *top_left, &result)); |
| 23 | return result; |
| 24 | } |
| 25 | |
| 26 | void RunMessageLoop() { |
| 27 | bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 28 | MessageLoop::current()->SetNestableTasksAllowed(true); |
| 29 | MessageLoop::current()->Run(); |
| 30 | MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 31 | } |
| 32 | |
| 33 | void QuitMessageLoop() { |
| 34 | MessageLoop::current()->QuitNow(); |
| 35 | } |
| 36 | |
| 37 | uint32_t GetLiveObjectCount(PP_Module module_id) { |
| 38 | uint32_t result = 0; |
| 39 | PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectCount( |
| 40 | INTERFACE_ID_PPB_TESTING, module_id, &result)); |
| 41 | return result; |
| 42 | } |
| 43 | |
| 44 | const PPB_Testing_Dev testing_interface = { |
| 45 | &ReadImageData, |
| 46 | &RunMessageLoop, |
| 47 | &QuitMessageLoop, |
| 48 | &GetLiveObjectCount |
| 49 | }; |
| 50 | |
| 51 | } // namespace |
| 52 | |
| 53 | PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, |
| 54 | const void* target_interface) |
| 55 | : InterfaceProxy(dispatcher, target_interface) { |
| 56 | } |
| 57 | |
| 58 | PPB_Testing_Proxy::~PPB_Testing_Proxy() { |
| 59 | } |
| 60 | |
| 61 | const void* PPB_Testing_Proxy::GetSourceInterface() const { |
| 62 | return &testing_interface; |
| 63 | } |
| 64 | |
| 65 | InterfaceID PPB_Testing_Proxy::GetInterfaceId() const { |
| 66 | return INTERFACE_ID_PPB_TESTING; |
| 67 | } |
| 68 | |
| 69 | void PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 70 | IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
| 71 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
| 72 | OnMsgReadImageData) |
| 73 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, |
| 74 | OnMsgRunMessageLoop) |
| 75 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, |
| 76 | OnMsgQuitMessageLoop) |
| 77 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectCount, |
| 78 | OnMsgGetLiveObjectCount) |
| 79 | IPC_END_MESSAGE_MAP() |
| 80 | } |
| 81 | |
| 82 | void PPB_Testing_Proxy::OnMsgReadImageData(PP_Resource device_context_2d, |
| 83 | PP_Resource image, |
| 84 | const PP_Point& top_left, |
[email protected] | 19d2b01 | 2010-11-08 16:32:18 | [diff] [blame^] | 85 | PP_Bool* result) { |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 86 | *result = ppb_testing_target()->ReadImageData( |
| 87 | device_context_2d, image, &top_left); |
| 88 | } |
| 89 | |
| 90 | void PPB_Testing_Proxy::OnMsgRunMessageLoop(bool* dummy) { |
| 91 | ppb_testing_target()->RunMessageLoop(); |
| 92 | *dummy = false; |
| 93 | } |
| 94 | |
| 95 | void PPB_Testing_Proxy::OnMsgQuitMessageLoop() { |
| 96 | ppb_testing_target()->QuitMessageLoop(); |
| 97 | } |
| 98 | |
| 99 | void PPB_Testing_Proxy::OnMsgGetLiveObjectCount(PP_Module module_id, |
| 100 | uint32_t* result) { |
| 101 | *result = ppb_testing_target()->GetLiveObjectCount(module_id); |
| 102 | } |
| 103 | |
| 104 | } // namespace proxy |
| 105 | } // namespace pp |