Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: src/shared/ppapi_proxy/browser_ppp_input_event.cc

Issue 7395005: Proxy PPB_Input_Event, PPP_Input_Event, and associated IFs. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Another gyp fix, windows build fix Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // The browser should not send us input events for which we have not
33 // registered.
34 DCHECK(BrowserInputEvent::InputEventTypeIsRegistered(instance,
35 data.event_type));
36 // If the input event is not being filtered, we should ignore what the NaCl
37 // returns. This is consistent with what the browser does.
38 bool ignore_return_value =
39 !(BrowserInputEvent::InputEventTypeIsFiltered(instance, data.event_type));
40
41 switch (data.event_type) {
42 // These events all use the PPB_MouseInputEvent interface.
43 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
44 case PP_INPUTEVENT_TYPE_MOUSEUP:
45 case PP_INPUTEVENT_TYPE_MOUSEENTER:
46 case PP_INPUTEVENT_TYPE_MOUSELEAVE:
47 case PP_INPUTEVENT_TYPE_MOUSEMOVE:
48 case PP_INPUTEVENT_TYPE_CONTEXTMENU:
49 data.mouse_button =
50 PPBMouseInputEventInterface()->GetMouseButton(input_event);
51 data.mouse_position =
52 PPBMouseInputEventInterface()->GetMousePosition(input_event);
53 data.mouse_click_count =
54 PPBMouseInputEventInterface()->GetMouseClickCount(input_event);
55 break;
56 // This event uses the PPB_WheelInputEvent interface.
57 case PP_INPUTEVENT_TYPE_MOUSEWHEEL:
58 data.wheel_delta =
59 PPBWheelInputEventInterface()->GetWheelDelta(input_event);
60 data.wheel_ticks =
61 PPBWheelInputEventInterface()->GetWheelTicks(input_event);
62 data.wheel_scroll_by_page =
63 PPBWheelInputEventInterface()->GetScrollByPage(input_event);
64 break;
65 // These events all use the PPB_KeyInputEvent interface.
66 case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
67 case PP_INPUTEVENT_TYPE_KEYDOWN:
68 case PP_INPUTEVENT_TYPE_KEYUP:
69 case PP_INPUTEVENT_TYPE_CHAR:
70 data.key_code =
71 PPBKeyboardInputEventInterface()->GetKeyCode(input_event);
72 character_text =
73 PPBKeyboardInputEventInterface()->GetCharacterText(input_event);
74 break;
75 case PP_INPUTEVENT_TYPE_UNDEFINED:
76 return PP_FALSE;
77 // No default case; if any new types are added we should get a compile
78 // warning.
79 }
80 // Now data and character_text have all the data we want to send to the
81 // untrusted side.
82
83 // character_text should either be undefined or a string type.
84 DCHECK((character_text.type == PP_VARTYPE_UNDEFINED) ||
85 (character_text.type == PP_VARTYPE_STRING));
86 // Serialize the character_text Var.
87 uint32_t text_size = kMaxVarSize;
88 nacl::scoped_array<char> text_bytes(Serialize(&character_text, 1,
89 &text_size));
90 int32_t handled;
91 // char* event_data = const_cast<char*>(reinterpret_cast<const char*>(data));
sehr (please use chromium) 2011/07/20 00:33:41 Why is this commented out? Remove it.
dmichael (off chromium) 2011/07/20 03:50:22 Oops, done.
92 NaClSrpcError srpc_result =
93 PppInputEventRpcClient::PPP_InputEvent_HandleInputEvent(
94 GetMainSrpcChannel(instance),
95 instance,
96 input_event,
97 sizeof(data),
98 reinterpret_cast<char*>(&data),
99 text_size,
100 text_bytes.get(),
101 &handled);
102 DebugPrintf("PPP_Instance::HandleInputEvent: %s\n",
103 NaClSrpcErrorString(srpc_result));
104 if (srpc_result != NACL_SRPC_RESULT_OK) {
105 return PP_FALSE;
106 }
107 if (ignore_return_value) {
108 return PP_FALSE;
109 }
110 PP_Bool handled_bool = static_cast<PP_Bool>(handled);
111 // The 'handled' int should only ever have a value matching one of PP_FALSE
112 // or PP_TRUE. Otherwise, there's an error in the proxy.
113 DCHECK((handled_bool == PP_FALSE) || (handled_bool == PP_TRUE));
114 return handled_bool;
115 }
116
117 } // namespace
118
119 // static
120 void BrowserInputEvent::InputEventsRequested(PP_Instance instance,
121 uint32_t event_classes,
122 bool filtering) {
123 RegisteredTypes& registered_types = instance_registered_map()[instance];
124 if (filtering) {
125 registered_types.filtering |= event_classes;
126 registered_types.nonfiltering &= ~event_classes;
127 } else {
128 // Don't allow unfiltered keyboard access.
129 uint32_t fixed_classes =
130 event_classes & ~uint32_t(PP_INPUTEVENT_CLASS_KEYBOARD);
131 registered_types.nonfiltering |= fixed_classes;
132 registered_types.filtering &= ~fixed_classes;
133 }
134 }
135
136 // static
137 void BrowserInputEvent::InputEventsCleared(PP_Instance instance,
138 uint32_t event_classes) {
139 RegisteredTypes& registered_types = instance_registered_map()[instance];
140 registered_types.filtering &= ~(event_classes);
141 registered_types.nonfiltering &= ~(event_classes);
142 }
143
144 // static
145 void BrowserInputEvent::InstanceDestroyed(PP_Instance instance) {
146 instance_registered_map().erase(instance);
147 }
148
149 // static
150 bool BrowserInputEvent::InputEventTypeIsRegistered(PP_Instance instance,
151 PP_InputEvent_Type type) {
152 InstanceRegisteredTypesMap::const_iterator iter =
153 instance_registered_map().find(instance);
154 if (iter != instance_registered_map().end()) {
155 return ((type & iter->second.filtering) ||
156 (type & iter->second.nonfiltering));
157 }
158 return false;
159 }
160
161 // static
162 bool BrowserInputEvent::InputEventTypeIsFiltered(PP_Instance instance,
163 PP_InputEvent_Type type) {
164 InstanceRegisteredTypesMap::const_iterator iter =
165 instance_registered_map().find(instance);
166 if (iter != instance_registered_map().end()) {
167 return (type & iter->second.filtering);
168 }
169 return false;
170 }
171
172 const PPP_InputEvent* BrowserInputEvent::GetInterface() {
173 static const PPP_InputEvent interface = {
174 HandleInputEvent
175 };
176 return &interface;
177 }
178
179 } // namespace ppapi_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698