blob: 74d0ecde128c4e7596757ec75757c4b9f68e4c55 [file] [log] [blame]
[email protected]f24448db2011-01-27 20:40:391// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]a3010332010-11-12 07:09:352// 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]f24448db2011-01-27 20:40:397#include "ppapi/c/dev/pp_cursor_type_dev.h"
[email protected]a3010332010-11-12 07:09:358#include "ppapi/c/dev/ppb_cursor_control_dev.h"
9#include "ppapi/proxy/plugin_dispatcher.h"
[email protected]f24448db2011-01-27 20:40:3910#include "ppapi/proxy/plugin_resource.h"
11#include "ppapi/proxy/plugin_resource_tracker.h"
[email protected]a3010332010-11-12 07:09:3512#include "ppapi/proxy/ppapi_messages.h"
13
14namespace pp {
15namespace proxy {
16
17namespace {
18
19PP_Bool SetCursor(PP_Instance instance_id,
[email protected]4614f192011-01-21 00:26:4320 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]f24448db2011-01-27 20:40:3927 // 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]a3010332010-11-12 07:09:3540 PP_Bool result = PP_FALSE;
41 PP_Point empty_point = { 0, 0 };
[email protected]4614f192011-01-21 00:26:4342 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_SetCursor(
[email protected]a3010332010-11-12 07:09:3543 INTERFACE_ID_PPB_CURSORCONTROL,
[email protected]f24448db2011-01-27 20:40:3944 instance_id, static_cast<int32_t>(type), cursor_image_resource,
[email protected]a3010332010-11-12 07:09:3545 hot_spot ? *hot_spot : empty_point, &result));
46 return result;
47}
48
49PP_Bool LockCursor(PP_Instance instance_id) {
[email protected]4614f192011-01-21 00:26:4350 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
51 if (!dispatcher)
52 return PP_FALSE;
53
[email protected]a3010332010-11-12 07:09:3554 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4355 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_LockCursor(
[email protected]a3010332010-11-12 07:09:3556 INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
57 return result;
58}
59
60PP_Bool UnlockCursor(PP_Instance instance_id) {
[email protected]4614f192011-01-21 00:26:4361 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
62 if (!dispatcher)
63 return PP_FALSE;
64
[email protected]a3010332010-11-12 07:09:3565 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4366 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor(
[email protected]a3010332010-11-12 07:09:3567 INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
68 return result;
69}
70
71PP_Bool HasCursorLock(PP_Instance instance_id) {
[email protected]4614f192011-01-21 00:26:4372 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
73 if (!dispatcher)
74 return PP_FALSE;
75
[email protected]a3010332010-11-12 07:09:3576 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4377 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock(
[email protected]a3010332010-11-12 07:09:3578 INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
79 return result;
80}
81
82PP_Bool CanLockCursor(PP_Instance instance_id) {
[email protected]4614f192011-01-21 00:26:4383 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
84 if (!dispatcher)
85 return PP_FALSE;
86
[email protected]a3010332010-11-12 07:09:3587 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4388 dispatcher->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor(
[email protected]a3010332010-11-12 07:09:3589 INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result));
90 return result;
91}
92
93const PPB_CursorControl_Dev cursor_control_interface = {
94 &SetCursor,
95 &LockCursor,
96 &UnlockCursor,
97 &HasCursorLock,
98 &CanLockCursor
99};
100
[email protected]465faa22011-02-08 16:31:46101InterfaceProxy* CreateCursorControlProxy(Dispatcher* dispatcher,
102 const void* target_interface) {
103 return new PPB_CursorControl_Proxy(dispatcher, target_interface);
104}
105
[email protected]a3010332010-11-12 07:09:35106} // namespace
107
108PPB_CursorControl_Proxy::PPB_CursorControl_Proxy(Dispatcher* dispatcher,
109 const void* target_interface)
110 : InterfaceProxy(dispatcher, target_interface) {
111}
112
113PPB_CursorControl_Proxy::~PPB_CursorControl_Proxy() {
114}
115
[email protected]465faa22011-02-08 16:31:46116// static
117const 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]a3010332010-11-12 07:09:35126}
127
[email protected]a95986a82010-12-24 06:19:28128bool PPB_CursorControl_Proxy::OnMessageReceived(const IPC::Message& msg) {
129 bool handled = true;
[email protected]a3010332010-11-12 07:09:35130 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]a95986a82010-12-24 06:19:28141 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]a3010332010-11-12 07:09:35142 IPC_END_MESSAGE_MAP()
143 // TODO(brettw): handle bad messages!
[email protected]a95986a82010-12-24 06:19:28144 return handled;
[email protected]a3010332010-11-12 07:09:35145}
146
147void PPB_CursorControl_Proxy::OnMsgSetCursor(PP_Instance instance,
148 int32_t type,
[email protected]f24448db2011-01-27 20:40:39149 HostResource custom_image,
[email protected]a3010332010-11-12 07:09:35150 const PP_Point& hot_spot,
151 PP_Bool* result) {
152 *result = ppb_cursor_control_target()->SetCursor(
[email protected]f24448db2011-01-27 20:40:39153 instance, static_cast<PP_CursorType_Dev>(type),
154 custom_image.host_resource(), &hot_spot);
[email protected]a3010332010-11-12 07:09:35155}
156
157void PPB_CursorControl_Proxy::OnMsgLockCursor(PP_Instance instance,
158 PP_Bool* result) {
159 *result = ppb_cursor_control_target()->LockCursor(instance);
160}
161
162void PPB_CursorControl_Proxy::OnMsgUnlockCursor(PP_Instance instance,
163 PP_Bool* result) {
164 *result = ppb_cursor_control_target()->UnlockCursor(instance);
165}
166
167void PPB_CursorControl_Proxy::OnMsgHasCursorLock(PP_Instance instance,
168 PP_Bool* result) {
169 *result = ppb_cursor_control_target()->HasCursorLock(instance);
170}
171
172void 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