OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Native Client 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 "native_client/src/shared/ppapi_proxy/browser_ppp_input_event.h" |
| 6 |
| 7 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 8 #include "native_client/src/include/portability.h" |
| 9 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" |
| 10 #include "native_client/src/shared/ppapi_proxy/input_event_data.h" |
| 11 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" |
| 12 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h" |
| 13 #include "native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h" |
| 14 #include "native_client/src/shared/ppapi_proxy/utility.h" |
| 15 #include "native_client/src/third_party/ppapi/c/pp_resource.h" |
| 16 #include "native_client/src/third_party/ppapi/c/ppp_input_event.h" |
| 17 |
| 18 namespace ppapi_proxy { |
| 19 |
| 20 namespace { |
| 21 |
| 22 PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource input_event) { |
| 23 DebugPrintf("PPP_InputEvent::HandleInputEvent: instance=%"NACL_PRIu32", " |
| 24 "input_event = %"NACL_PRIu32"\n", |
| 25 instance, input_event); |
| 26 |
| 27 PP_Var character_text = PP_MakeUndefined(); |
| 28 InputEventData data; |
| 29 data.event_type = PPBInputEventInterface()->GetType(input_event); |
| 30 data.event_time_stamp = PPBInputEventInterface()->GetTimeStamp(input_event); |
| 31 data.event_modifiers = PPBInputEventInterface()->GetModifiers(input_event); |
| 32 |
| 33 switch (data.event_type) { |
| 34 // These events all use the PPB_MouseInputEvent interface. |
| 35 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| 36 case PP_INPUTEVENT_TYPE_MOUSEUP: |
| 37 case PP_INPUTEVENT_TYPE_MOUSEENTER: |
| 38 case PP_INPUTEVENT_TYPE_MOUSELEAVE: |
| 39 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
| 40 case PP_INPUTEVENT_TYPE_CONTEXTMENU: |
| 41 data.mouse_button = |
| 42 PPBMouseInputEventInterface()->GetMouseButton(input_event); |
| 43 data.mouse_position = |
| 44 PPBMouseInputEventInterface()->GetMousePosition(input_event); |
| 45 data.mouse_click_count = |
| 46 PPBMouseInputEventInterface()->GetMouseClickCount(input_event); |
| 47 break; |
| 48 // This event uses the PPB_WheelInputEvent interface. |
| 49 case PP_INPUTEVENT_TYPE_MOUSEWHEEL: |
| 50 data.wheel_delta = |
| 51 PPBWheelInputEventInterface()->GetWheelDelta(input_event); |
| 52 data.wheel_ticks = |
| 53 PPBWheelInputEventInterface()->GetWheelTicks(input_event); |
| 54 data.wheel_scroll_by_page = |
| 55 PPBWheelInputEventInterface()->GetScrollByPage(input_event); |
| 56 break; |
| 57 // These events all use the PPB_KeyInputEvent interface. |
| 58 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: |
| 59 case PP_INPUTEVENT_TYPE_KEYDOWN: |
| 60 case PP_INPUTEVENT_TYPE_KEYUP: |
| 61 case PP_INPUTEVENT_TYPE_CHAR: |
| 62 data.key_code = |
| 63 PPBKeyboardInputEventInterface()->GetKeyCode(input_event); |
| 64 character_text = |
| 65 PPBKeyboardInputEventInterface()->GetCharacterText(input_event); |
| 66 break; |
| 67 case PP_INPUTEVENT_TYPE_UNDEFINED: |
| 68 return PP_FALSE; |
| 69 // No default case; if any new types are added we should get a compile |
| 70 // warning. |
| 71 } |
| 72 // Now data and character_text have all the data we want to send to the |
| 73 // untrusted side. |
| 74 |
| 75 // character_text should either be undefined or a string type. |
| 76 DCHECK((character_text.type == PP_VARTYPE_UNDEFINED) || |
| 77 (character_text.type == PP_VARTYPE_STRING)); |
| 78 // Serialize the character_text Var. |
| 79 uint32_t text_size = kMaxVarSize; |
| 80 nacl::scoped_array<char> text_bytes(Serialize(&character_text, 1, |
| 81 &text_size)); |
| 82 int32_t handled; |
| 83 NaClSrpcError srpc_result = |
| 84 PppInputEventRpcClient::PPP_InputEvent_HandleInputEvent( |
| 85 GetMainSrpcChannel(instance), |
| 86 instance, |
| 87 input_event, |
| 88 sizeof(data), |
| 89 reinterpret_cast<char*>(&data), |
| 90 text_size, |
| 91 text_bytes.get(), |
| 92 &handled); |
| 93 DebugPrintf("PPP_Instance::HandleInputEvent: %s\n", |
| 94 NaClSrpcErrorString(srpc_result)); |
| 95 if (srpc_result != NACL_SRPC_RESULT_OK) { |
| 96 return PP_FALSE; |
| 97 } |
| 98 PP_Bool handled_bool = static_cast<PP_Bool>(handled); |
| 99 // The 'handled' int should only ever have a value matching one of PP_FALSE |
| 100 // or PP_TRUE. Otherwise, there's an error in the proxy. |
| 101 DCHECK((handled_bool == PP_FALSE) || (handled_bool == PP_TRUE)); |
| 102 return handled_bool; |
| 103 } |
| 104 |
| 105 } // namespace |
| 106 |
| 107 const PPP_InputEvent* BrowserInputEvent::GetInterface() { |
| 108 static const PPP_InputEvent input_event_interface = { |
| 109 HandleInputEvent |
| 110 }; |
| 111 return &input_event_interface; |
| 112 } |
| 113 |
| 114 } // namespace ppapi_proxy |
OLD | NEW |