OLD | NEW |
1 // Copyright (c) 2010 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_cursor_control_proxy.h" | 5 #include "ppapi/proxy/ppb_cursor_control_proxy.h" |
6 | 6 |
| 7 #include "ppapi/c/dev/pp_cursor_type_dev.h" |
7 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 8 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
| 9 #include "ppapi/proxy/image_data.h" |
8 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
9 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
10 | 12 |
11 namespace pp { | 13 namespace pp { |
12 namespace proxy { | 14 namespace proxy { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 PP_Bool SetCursor(PP_Instance instance_id, | 18 PP_Bool SetCursor(PP_Instance instance_id, |
17 PP_CursorType_Dev type, | 19 PP_CursorType_Dev type, |
18 PP_Resource custom_image_id, | 20 PP_Resource custom_image_id, |
19 const PP_Point* hot_spot) { | 21 const PP_Point* hot_spot) { |
20 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | 22 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
21 if (!dispatcher) | 23 if (!dispatcher) |
22 return PP_FALSE; | 24 return PP_FALSE; |
23 | 25 |
| 26 // It's legal for the image ID to be null if the type is not custom. |
| 27 SerializedResource cursor_image_resource; |
| 28 if (type == PP_CURSORTYPE_CUSTOM) { |
| 29 ImageData* cursor_image = PluginResource::GetAs<ImageData>(custom_image_id); |
| 30 if (!cursor_image || cursor_image->instance() != instance_id) |
| 31 return PP_FALSE; |
| 32 cursor_image_resource = cursor_image->host_resource(); |
| 33 } else { |
| 34 if (custom_image_id) |
| 35 return PP_FALSE; // Image specified for a predefined type. |
| 36 } |
| 37 |
24 PP_Bool result = PP_FALSE; | 38 PP_Bool result = PP_FALSE; |
25 PP_Point empty_point = { 0, 0 }; | 39 PP_Point empty_point = { 0, 0 }; |
26 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_SetCursor( | 40 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_SetCursor( |
27 INTERFACE_ID_PPB_CURSORCONTROL, | 41 INTERFACE_ID_PPB_CURSORCONTROL, |
28 instance_id, static_cast<int32_t>(type), custom_image_id, | 42 instance_id, static_cast<int32_t>(type), cursor_image_resource, |
29 hot_spot ? *hot_spot : empty_point, &result)); | 43 hot_spot ? *hot_spot : empty_point, &result)); |
30 return result; | 44 return result; |
31 } | 45 } |
32 | 46 |
33 PP_Bool LockCursor(PP_Instance instance_id) { | 47 PP_Bool LockCursor(PP_Instance instance_id) { |
34 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | 48 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
35 if (!dispatcher) | 49 if (!dispatcher) |
36 return PP_FALSE; | 50 return PP_FALSE; |
37 | 51 |
38 PP_Bool result = PP_FALSE; | 52 PP_Bool result = PP_FALSE; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_CanLockCursor, | 128 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_CanLockCursor, |
115 OnMsgCanLockCursor) | 129 OnMsgCanLockCursor) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 130 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 131 IPC_END_MESSAGE_MAP() |
118 // TODO(brettw): handle bad messages! | 132 // TODO(brettw): handle bad messages! |
119 return handled; | 133 return handled; |
120 } | 134 } |
121 | 135 |
122 void PPB_CursorControl_Proxy::OnMsgSetCursor(PP_Instance instance, | 136 void PPB_CursorControl_Proxy::OnMsgSetCursor(PP_Instance instance, |
123 int32_t type, | 137 int32_t type, |
124 PP_Resource custom_image, | 138 SerializedResource custom_image, |
125 const PP_Point& hot_spot, | 139 const PP_Point& hot_spot, |
126 PP_Bool* result) { | 140 PP_Bool* result) { |
127 *result = ppb_cursor_control_target()->SetCursor( | 141 *result = ppb_cursor_control_target()->SetCursor( |
128 instance, static_cast<PP_CursorType_Dev>(type), custom_image, &hot_spot); | 142 instance, static_cast<PP_CursorType_Dev>(type), |
| 143 custom_image.host_resource(), &hot_spot); |
129 } | 144 } |
130 | 145 |
131 void PPB_CursorControl_Proxy::OnMsgLockCursor(PP_Instance instance, | 146 void PPB_CursorControl_Proxy::OnMsgLockCursor(PP_Instance instance, |
132 PP_Bool* result) { | 147 PP_Bool* result) { |
133 *result = ppb_cursor_control_target()->LockCursor(instance); | 148 *result = ppb_cursor_control_target()->LockCursor(instance); |
134 } | 149 } |
135 | 150 |
136 void PPB_CursorControl_Proxy::OnMsgUnlockCursor(PP_Instance instance, | 151 void PPB_CursorControl_Proxy::OnMsgUnlockCursor(PP_Instance instance, |
137 PP_Bool* result) { | 152 PP_Bool* result) { |
138 *result = ppb_cursor_control_target()->UnlockCursor(instance); | 153 *result = ppb_cursor_control_target()->UnlockCursor(instance); |
139 } | 154 } |
140 | 155 |
141 void PPB_CursorControl_Proxy::OnMsgHasCursorLock(PP_Instance instance, | 156 void PPB_CursorControl_Proxy::OnMsgHasCursorLock(PP_Instance instance, |
142 PP_Bool* result) { | 157 PP_Bool* result) { |
143 *result = ppb_cursor_control_target()->HasCursorLock(instance); | 158 *result = ppb_cursor_control_target()->HasCursorLock(instance); |
144 } | 159 } |
145 | 160 |
146 void PPB_CursorControl_Proxy::OnMsgCanLockCursor(PP_Instance instance, | 161 void PPB_CursorControl_Proxy::OnMsgCanLockCursor(PP_Instance instance, |
147 PP_Bool* result) { | 162 PP_Bool* result) { |
148 *result = ppb_cursor_control_target()->CanLockCursor(instance); | 163 *result = ppb_cursor_control_target()->CanLockCursor(instance); |
149 } | 164 } |
150 | 165 |
151 } // namespace proxy | 166 } // namespace proxy |
152 } // namespace pp | 167 } // namespace pp |
OLD | NEW |