OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/proxy/ppb_cursor_control_proxy.h" | |
6 | |
7 #include "ppapi/c/dev/pp_cursor_type_dev.h" | |
8 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | |
9 #include "ppapi/proxy/plugin_dispatcher.h" | |
10 #include "ppapi/proxy/plugin_resource_tracker.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/shared_impl/ppapi_globals.h" | |
13 #include "ppapi/thunk/enter.h" | |
14 #include "ppapi/thunk/thunk.h" | |
15 | |
16 using ppapi::thunk::EnterFunctionNoLock; | |
17 using ppapi::thunk::PPB_CursorControl_FunctionAPI; | |
18 | |
19 namespace ppapi { | |
20 namespace proxy { | |
21 | |
22 PPB_CursorControl_Proxy::PPB_CursorControl_Proxy(Dispatcher* dispatcher) | |
23 : InterfaceProxy(dispatcher) { | |
24 } | |
25 | |
26 PPB_CursorControl_Proxy::~PPB_CursorControl_Proxy() { | |
27 } | |
28 | |
29 ppapi::thunk::PPB_CursorControl_FunctionAPI* | |
30 PPB_CursorControl_Proxy::AsPPB_CursorControl_FunctionAPI() { | |
31 return this; | |
32 } | |
33 | |
34 PP_Bool PPB_CursorControl_Proxy::SetCursor(PP_Instance instance, | |
35 PP_CursorType_Dev type, | |
36 PP_Resource custom_image_id, | |
37 const PP_Point* hot_spot) { | |
38 // It's legal for the image ID to be null if the type is not custom. | |
39 HostResource cursor_image_resource; | |
40 if (type == PP_CURSORTYPE_CUSTOM) { | |
41 Resource* cursor_image = | |
42 PpapiGlobals::Get()->GetResourceTracker()->GetResource(custom_image_id); | |
43 if (!cursor_image || cursor_image->pp_instance() != instance) | |
44 return PP_FALSE; | |
45 cursor_image_resource = cursor_image->host_resource(); | |
46 } else { | |
47 if (custom_image_id) | |
48 return PP_FALSE; // Image specified for a predefined type. | |
49 } | |
50 | |
51 PP_Bool result = PP_FALSE; | |
52 PP_Point empty_point = { 0, 0 }; | |
53 dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_SetCursor( | |
54 API_ID_PPB_CURSORCONTROL, | |
55 instance, static_cast<int32_t>(type), cursor_image_resource, | |
56 hot_spot ? *hot_spot : empty_point, &result)); | |
57 return result; | |
58 } | |
59 | |
60 PP_Bool PPB_CursorControl_Proxy::LockCursor(PP_Instance instance) { | |
61 PP_Bool result = PP_FALSE; | |
62 dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_LockCursor( | |
63 API_ID_PPB_CURSORCONTROL, instance, &result)); | |
64 return result; | |
65 } | |
66 | |
67 PP_Bool PPB_CursorControl_Proxy::UnlockCursor(PP_Instance instance) { | |
68 PP_Bool result = PP_FALSE; | |
69 dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor( | |
70 API_ID_PPB_CURSORCONTROL, instance, &result)); | |
71 return result; | |
72 } | |
73 | |
74 PP_Bool PPB_CursorControl_Proxy::HasCursorLock(PP_Instance instance) { | |
75 PP_Bool result = PP_FALSE; | |
76 dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock( | |
77 API_ID_PPB_CURSORCONTROL, instance, &result)); | |
78 return result; | |
79 } | |
80 | |
81 PP_Bool PPB_CursorControl_Proxy::CanLockCursor(PP_Instance instance) { | |
82 PP_Bool result = PP_FALSE; | |
83 dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor( | |
84 API_ID_PPB_CURSORCONTROL, instance, &result)); | |
85 return result; | |
86 } | |
87 | |
88 bool PPB_CursorControl_Proxy::OnMessageReceived(const IPC::Message& msg) { | |
89 bool handled = true; | |
90 IPC_BEGIN_MESSAGE_MAP(PPB_CursorControl_Proxy, msg) | |
91 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_SetCursor, | |
92 OnMsgSetCursor) | |
93 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_LockCursor, | |
94 OnMsgLockCursor) | |
95 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_UnlockCursor, | |
96 OnMsgUnlockCursor) | |
97 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_HasCursorLock, | |
98 OnMsgHasCursorLock) | |
99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCursorControl_CanLockCursor, | |
100 OnMsgCanLockCursor) | |
101 IPC_MESSAGE_UNHANDLED(handled = false) | |
102 IPC_END_MESSAGE_MAP() | |
103 // TODO(brettw): handle bad messages! | |
104 return handled; | |
105 } | |
106 | |
107 void PPB_CursorControl_Proxy::OnMsgSetCursor(PP_Instance instance, | |
108 int32_t type, | |
109 const HostResource& custom_image, | |
110 const PP_Point& hot_spot, | |
111 PP_Bool* result) { | |
112 EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); | |
113 if (enter.succeeded()) { | |
114 *result = enter.functions()->SetCursor( | |
115 instance, static_cast<PP_CursorType_Dev>(type), | |
116 custom_image.host_resource(), &hot_spot); | |
117 } | |
118 } | |
119 | |
120 void PPB_CursorControl_Proxy::OnMsgLockCursor(PP_Instance instance, | |
121 PP_Bool* result) { | |
122 EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); | |
123 if (enter.succeeded()) | |
124 *result = enter.functions()->LockCursor(instance); | |
125 } | |
126 | |
127 void PPB_CursorControl_Proxy::OnMsgUnlockCursor(PP_Instance instance, | |
128 PP_Bool* result) { | |
129 EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); | |
130 if (enter.succeeded()) | |
131 *result = enter.functions()->UnlockCursor(instance); | |
132 } | |
133 | |
134 void PPB_CursorControl_Proxy::OnMsgHasCursorLock(PP_Instance instance, | |
135 PP_Bool* result) { | |
136 EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); | |
137 if (enter.succeeded()) | |
138 *result = enter.functions()->HasCursorLock(instance); | |
139 } | |
140 | |
141 void PPB_CursorControl_Proxy::OnMsgCanLockCursor(PP_Instance instance, | |
142 PP_Bool* result) { | |
143 EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); | |
144 if (enter.succeeded()) | |
145 *result = enter.functions()->CanLockCursor(instance); | |
146 } | |
147 | |
148 } // namespace proxy | |
149 } // namespace ppapi | |
OLD | NEW |