[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | a301033 | 2010-11-12 07:09:35 | [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_cursor_control_proxy.h" |
| 6 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 7 | #include "ppapi/c/dev/pp_cursor_type_dev.h" |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 8 | #include "ppapi/c/dev/ppb_cursor_control_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] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 12 | #include "ppapi/proxy/ppapi_messages.h" |
| 13 | |
| 14 | namespace pp { |
| 15 | namespace proxy { |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | PP_Bool SetCursor(PP_Instance instance_id, |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 20 | PP_CursorType_Dev type, |
| 21 | PP_Resource custom_image_id, |
| 22 | const PP_Point* hot_spot) { |
| 23 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 24 | if (!dispatcher) |
| 25 | return PP_FALSE; |
| 26 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 27 | // It's legal for the image ID to be null if the type is not custom. |
| 28 | HostResource cursor_image_resource; |
| 29 | if (type == PP_CURSORTYPE_CUSTOM) { |
| 30 | PluginResource* cursor_image = PluginResourceTracker::GetInstance()-> |
| 31 | GetResourceObject(custom_image_id); |
| 32 | if (!cursor_image || cursor_image->instance() != instance_id) |
| 33 | return PP_FALSE; |
| 34 | cursor_image_resource = cursor_image->host_resource(); |
| 35 | } else { |
| 36 | if (custom_image_id) |
| 37 | return PP_FALSE; // Image specified for a predefined type. |
| 38 | } |
| 39 | |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 40 | PP_Bool result = PP_FALSE; |
| 41 | PP_Point empty_point = { 0, 0 }; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 42 | dispatcher->Send(new PpapiHostMsg_PPBCursorControl_SetCursor( |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 43 | INTERFACE_ID_PPB_CURSORCONTROL, |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 44 | instance_id, static_cast<int32_t>(type), cursor_image_resource, |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 45 | hot_spot ? *hot_spot : empty_point, &result)); |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | PP_Bool LockCursor(PP_Instance instance_id) { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 50 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 51 | if (!dispatcher) |
| 52 | return PP_FALSE; |
| 53 | |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 54 | PP_Bool result = PP_FALSE; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 55 | dispatcher->Send(new PpapiHostMsg_PPBCursorControl_LockCursor( |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 56 | INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); |
| 57 | return result; |
| 58 | } |
| 59 | |
| 60 | PP_Bool UnlockCursor(PP_Instance instance_id) { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 61 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 62 | if (!dispatcher) |
| 63 | return PP_FALSE; |
| 64 | |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 65 | PP_Bool result = PP_FALSE; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 66 | dispatcher->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor( |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 67 | INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); |
| 68 | return result; |
| 69 | } |
| 70 | |
| 71 | PP_Bool HasCursorLock(PP_Instance instance_id) { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 72 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 73 | if (!dispatcher) |
| 74 | return PP_FALSE; |
| 75 | |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 76 | PP_Bool result = PP_FALSE; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 77 | dispatcher->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock( |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 78 | INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | PP_Bool CanLockCursor(PP_Instance instance_id) { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 83 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 84 | if (!dispatcher) |
| 85 | return PP_FALSE; |
| 86 | |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 87 | PP_Bool result = PP_FALSE; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 88 | dispatcher->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor( |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 89 | INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); |
| 90 | return result; |
| 91 | } |
| 92 | |
| 93 | const PPB_CursorControl_Dev cursor_control_interface = { |
| 94 | &SetCursor, |
| 95 | &LockCursor, |
| 96 | &UnlockCursor, |
| 97 | &HasCursorLock, |
| 98 | &CanLockCursor |
| 99 | }; |
| 100 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 101 | InterfaceProxy* CreateCursorControlProxy(Dispatcher* dispatcher, |
| 102 | const void* target_interface) { |
| 103 | return new PPB_CursorControl_Proxy(dispatcher, target_interface); |
| 104 | } |
| 105 | |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 106 | } // namespace |
| 107 | |
| 108 | PPB_CursorControl_Proxy::PPB_CursorControl_Proxy(Dispatcher* dispatcher, |
| 109 | const void* target_interface) |
| 110 | : InterfaceProxy(dispatcher, target_interface) { |
| 111 | } |
| 112 | |
| 113 | PPB_CursorControl_Proxy::~PPB_CursorControl_Proxy() { |
| 114 | } |
| 115 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 116 | // static |
| 117 | const InterfaceProxy::Info* PPB_CursorControl_Proxy::GetInfo() { |
| 118 | static const Info info = { |
| 119 | &cursor_control_interface, |
| 120 | PPB_CURSOR_CONTROL_DEV_INTERFACE, |
| 121 | INTERFACE_ID_PPB_CURSORCONTROL, |
| 122 | false, |
| 123 | &CreateCursorControlProxy, |
| 124 | }; |
| 125 | return &info; |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 126 | } |
| 127 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 128 | bool PPB_CursorControl_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 129 | bool handled = true; |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 130 | IPC_BEGIN_MESSAGE_MAP(PPB_CursorControl_Proxy, msg) |
| 131 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_SetCursor, |
| 132 | OnMsgSetCursor) |
| 133 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_LockCursor, |
| 134 | OnMsgLockCursor) |
| 135 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_UnlockCursor, |
| 136 | OnMsgUnlockCursor) |
| 137 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_HasCursorLock, |
| 138 | OnMsgHasCursorLock) |
| 139 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_CanLockCursor, |
| 140 | OnMsgCanLockCursor) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 141 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 142 | IPC_END_MESSAGE_MAP() |
| 143 | // TODO(brettw): handle bad messages! |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 144 | return handled; |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void PPB_CursorControl_Proxy::OnMsgSetCursor(PP_Instance instance, |
| 148 | int32_t type, |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 149 | HostResource custom_image, |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 150 | const PP_Point& hot_spot, |
| 151 | PP_Bool* result) { |
| 152 | *result = ppb_cursor_control_target()->SetCursor( |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 153 | instance, static_cast<PP_CursorType_Dev>(type), |
| 154 | custom_image.host_resource(), &hot_spot); |
[email protected] | a301033 | 2010-11-12 07:09:35 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void PPB_CursorControl_Proxy::OnMsgLockCursor(PP_Instance instance, |
| 158 | PP_Bool* result) { |
| 159 | *result = ppb_cursor_control_target()->LockCursor(instance); |
| 160 | } |
| 161 | |
| 162 | void PPB_CursorControl_Proxy::OnMsgUnlockCursor(PP_Instance instance, |
| 163 | PP_Bool* result) { |
| 164 | *result = ppb_cursor_control_target()->UnlockCursor(instance); |
| 165 | } |
| 166 | |
| 167 | void PPB_CursorControl_Proxy::OnMsgHasCursorLock(PP_Instance instance, |
| 168 | PP_Bool* result) { |
| 169 | *result = ppb_cursor_control_target()->HasCursorLock(instance); |
| 170 | } |
| 171 | |
| 172 | void PPB_CursorControl_Proxy::OnMsgCanLockCursor(PP_Instance instance, |
| 173 | PP_Bool* result) { |
| 174 | *result = ppb_cursor_control_target()->CanLockCursor(instance); |
| 175 | } |
| 176 | |
| 177 | } // namespace proxy |
| 178 | } // namespace pp |