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

Unified 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: copyright headers 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/shared/ppapi_proxy/browser_ppp_input_event.h ('k') | src/shared/ppapi_proxy/browser_ppp_instance.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/shared/ppapi_proxy/browser_ppp_input_event.cc
diff --git a/src/shared/ppapi_proxy/browser_ppp_input_event.cc b/src/shared/ppapi_proxy/browser_ppp_input_event.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3e8ee5b3747f35bf85d3df7672c2dcd26cef7bbc
--- /dev/null
+++ b/src/shared/ppapi_proxy/browser_ppp_input_event.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2011 The Native Client Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "native_client/src/shared/ppapi_proxy/browser_ppp_input_event.h"
+
+#include "native_client/src/include/nacl_scoped_ptr.h"
+#include "native_client/src/include/portability.h"
+#include "native_client/src/shared/ppapi_proxy/browser_globals.h"
+#include "native_client/src/shared/ppapi_proxy/input_event_data.h"
+#include "native_client/src/shared/ppapi_proxy/object_serialize.h"
+#include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
+#include "native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h"
+#include "native_client/src/shared/ppapi_proxy/utility.h"
+#include "native_client/src/third_party/ppapi/c/pp_resource.h"
+#include "native_client/src/third_party/ppapi/c/ppp_input_event.h"
+
+namespace ppapi_proxy {
+
+namespace {
+
+PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource input_event) {
+ DebugPrintf("PPP_InputEvent::HandleInputEvent: instance=%"NACL_PRIu32", "
+ "input_event = %"NACL_PRIu32"\n",
+ instance, input_event);
+
+ PP_Var character_text = PP_MakeUndefined();
+ InputEventData data;
+ data.event_type = PPBInputEventInterface()->GetType(input_event);
+ data.event_time_stamp = PPBInputEventInterface()->GetTimeStamp(input_event);
+ data.event_modifiers = PPBInputEventInterface()->GetModifiers(input_event);
+
+ switch (data.event_type) {
+ // These events all use the PPB_MouseInputEvent interface.
+ case PP_INPUTEVENT_TYPE_MOUSEDOWN:
+ case PP_INPUTEVENT_TYPE_MOUSEUP:
+ case PP_INPUTEVENT_TYPE_MOUSEENTER:
+ case PP_INPUTEVENT_TYPE_MOUSELEAVE:
+ case PP_INPUTEVENT_TYPE_MOUSEMOVE:
+ case PP_INPUTEVENT_TYPE_CONTEXTMENU:
+ data.mouse_button =
+ PPBMouseInputEventInterface()->GetMouseButton(input_event);
+ data.mouse_position =
+ PPBMouseInputEventInterface()->GetMousePosition(input_event);
+ data.mouse_click_count =
+ PPBMouseInputEventInterface()->GetMouseClickCount(input_event);
+ break;
+ // This event uses the PPB_WheelInputEvent interface.
+ case PP_INPUTEVENT_TYPE_MOUSEWHEEL:
+ data.wheel_delta =
+ PPBWheelInputEventInterface()->GetWheelDelta(input_event);
+ data.wheel_ticks =
+ PPBWheelInputEventInterface()->GetWheelTicks(input_event);
+ data.wheel_scroll_by_page =
+ PPBWheelInputEventInterface()->GetScrollByPage(input_event);
+ break;
+ // These events all use the PPB_KeyInputEvent interface.
+ case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
+ case PP_INPUTEVENT_TYPE_KEYDOWN:
+ case PP_INPUTEVENT_TYPE_KEYUP:
+ case PP_INPUTEVENT_TYPE_CHAR:
+ data.key_code =
+ PPBKeyboardInputEventInterface()->GetKeyCode(input_event);
+ character_text =
+ PPBKeyboardInputEventInterface()->GetCharacterText(input_event);
+ break;
+ case PP_INPUTEVENT_TYPE_UNDEFINED:
+ return PP_FALSE;
+ // No default case; if any new types are added we should get a compile
+ // warning.
+ }
+ // Now data and character_text have all the data we want to send to the
+ // untrusted side.
+
+ // character_text should either be undefined or a string type.
+ DCHECK((character_text.type == PP_VARTYPE_UNDEFINED) ||
+ (character_text.type == PP_VARTYPE_STRING));
+ // Serialize the character_text Var.
+ uint32_t text_size = kMaxVarSize;
+ nacl::scoped_array<char> text_bytes(Serialize(&character_text, 1,
+ &text_size));
+ int32_t handled;
+ NaClSrpcError srpc_result =
+ PppInputEventRpcClient::PPP_InputEvent_HandleInputEvent(
+ GetMainSrpcChannel(instance),
+ instance,
+ input_event,
+ sizeof(data),
+ reinterpret_cast<char*>(&data),
+ text_size,
+ text_bytes.get(),
+ &handled);
+ DebugPrintf("PPP_Instance::HandleInputEvent: %s\n",
+ NaClSrpcErrorString(srpc_result));
+ if (srpc_result != NACL_SRPC_RESULT_OK) {
+ return PP_FALSE;
+ }
+ PP_Bool handled_bool = static_cast<PP_Bool>(handled);
+ // The 'handled' int should only ever have a value matching one of PP_FALSE
+ // or PP_TRUE. Otherwise, there's an error in the proxy.
+ DCHECK((handled_bool == PP_FALSE) || (handled_bool == PP_TRUE));
+ return handled_bool;
+}
+
+} // namespace
+
+const PPP_InputEvent* BrowserInputEvent::GetInterface() {
+ static const PPP_InputEvent input_event_interface = {
+ HandleInputEvent
+ };
+ return &input_event_interface;
+}
+
+} // namespace ppapi_proxy
« no previous file with comments | « src/shared/ppapi_proxy/browser_ppp_input_event.h ('k') | src/shared/ppapi_proxy/browser_ppp_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698