[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 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" |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 10 | #include "ppapi/proxy/plugin_resource.h" |
| 11 | #include "ppapi/proxy/plugin_resource_tracker.h" |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 12 | #include "ppapi/proxy/ppapi_messages.h" |
| 13 | |
| 14 | namespace pp { |
| 15 | namespace proxy { |
| 16 | |
| 17 | namespace { |
| 18 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 19 | PP_Bool ReadImageData(PP_Resource graphics_2d, |
[email protected] | 19d2b01 | 2010-11-08 16:32:18 | [diff] [blame] | 20 | PP_Resource image, |
| 21 | const PP_Point* top_left) { |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 22 | PluginResource* image_object = PluginResourceTracker::GetInstance()-> |
| 23 | GetResourceObject(image); |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 24 | if (!image_object) |
| 25 | return PP_FALSE; |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 26 | PluginResource* graphics_2d_object = |
| 27 | PluginResourceTracker::GetInstance()->GetResourceObject(graphics_2d); |
| 28 | if (!graphics_2d_object || |
| 29 | image_object->instance() != graphics_2d_object->instance()) |
| 30 | return PP_FALSE; |
| 31 | |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 32 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 33 | image_object->instance()); |
| 34 | if (!dispatcher) |
| 35 | return PP_FALSE; |
| 36 | |
[email protected] | 19d2b01 | 2010-11-08 16:32:18 | [diff] [blame] | 37 | PP_Bool result = PP_FALSE; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 38 | dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData( |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 39 | INTERFACE_ID_PPB_TESTING, graphics_2d_object->host_resource(), |
| 40 | image_object->host_resource(), *top_left, &result)); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 41 | return result; |
| 42 | } |
| 43 | |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame^] | 44 | void RunMessageLoop(PP_Instance instance) { |
| 45 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 46 | if (!dispatcher) |
| 47 | return; |
| 48 | IPC::SyncMessage* msg = new PpapiHostMsg_PPBTesting_RunMessageLoop( |
| 49 | INTERFACE_ID_PPB_TESTING, instance); |
| 50 | msg->EnableMessagePumping(); |
| 51 | dispatcher->Send(msg); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 52 | } |
| 53 | |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame^] | 54 | void QuitMessageLoop(PP_Instance instance) { |
| 55 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 56 | if (!dispatcher) |
| 57 | return; |
| 58 | dispatcher->Send(new PpapiHostMsg_PPBTesting_QuitMessageLoop( |
| 59 | INTERFACE_ID_PPB_TESTING, instance)); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 62 | uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { |
| 63 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 64 | if (!dispatcher) |
| 65 | return static_cast<uint32_t>(-1); |
| 66 | |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 67 | uint32_t result = 0; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 68 | dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( |
| 69 | INTERFACE_ID_PPB_TESTING, instance_id, &result)); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 70 | return result; |
| 71 | } |
| 72 | |
| 73 | const PPB_Testing_Dev testing_interface = { |
| 74 | &ReadImageData, |
| 75 | &RunMessageLoop, |
| 76 | &QuitMessageLoop, |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 77 | &GetLiveObjectsForInstance |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 78 | }; |
| 79 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 80 | InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher, |
| 81 | const void* target_interface) { |
| 82 | return new PPB_Testing_Proxy(dispatcher, target_interface); |
| 83 | } |
| 84 | |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 85 | } // namespace |
| 86 | |
| 87 | PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, |
| 88 | const void* target_interface) |
| 89 | : InterfaceProxy(dispatcher, target_interface) { |
| 90 | } |
| 91 | |
| 92 | PPB_Testing_Proxy::~PPB_Testing_Proxy() { |
| 93 | } |
| 94 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 95 | // static |
| 96 | const InterfaceProxy::Info* PPB_Testing_Proxy::GetInfo() { |
| 97 | static const Info info = { |
| 98 | &testing_interface, |
| 99 | PPB_TESTING_DEV_INTERFACE, |
| 100 | INTERFACE_ID_PPB_TESTING, |
| 101 | false, |
| 102 | &CreateTestingProxy, |
| 103 | }; |
| 104 | return &info; |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 107 | bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 108 | bool handled = true; |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 109 | IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
| 110 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
| 111 | OnMsgReadImageData) |
| 112 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, |
| 113 | OnMsgRunMessageLoop) |
| 114 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, |
| 115 | OnMsgQuitMessageLoop) |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 116 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, |
| 117 | OnMsgGetLiveObjectsForInstance) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 118 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 119 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 120 | return handled; |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 123 | void PPB_Testing_Proxy::OnMsgReadImageData( |
| 124 | const HostResource& device_context_2d, |
| 125 | const HostResource& image, |
| 126 | const PP_Point& top_left, |
| 127 | PP_Bool* result) { |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 128 | *result = ppb_testing_target()->ReadImageData( |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 129 | device_context_2d.host_resource(), image.host_resource(), &top_left); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame^] | 132 | void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { |
| 133 | ppb_testing_target()->RunMessageLoop(instance); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 134 | } |
| 135 | |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame^] | 136 | void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { |
| 137 | ppb_testing_target()->QuitMessageLoop(instance); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 140 | void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 141 | uint32_t* result) { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 142 | *result = ppb_testing_target()->GetLiveObjectsForInstance(instance); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | } // namespace proxy |
| 146 | } // namespace pp |