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