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 // SRPC-abstraction wrappers around PPB_InputEvent functions. |
| 6 |
| 7 #include <cstring> |
| 8 |
| 9 #include "native_client/src/include/portability.h" |
| 10 #include "native_client/src/include/portability_process.h" |
| 11 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 12 #include "native_client/src/shared/ppapi_proxy/input_event_data.h" |
| 13 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" |
| 14 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
| 15 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" |
| 16 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_input_event.h" |
| 17 #include "native_client/src/shared/ppapi_proxy/plugin_resource.h" |
| 18 #include "native_client/src/shared/ppapi_proxy/plugin_resource_tracker.h" |
| 19 #include "native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h" |
| 20 #include "native_client/src/shared/ppapi_proxy/utility.h" |
| 21 #include "native_client/src/third_party/ppapi/c/pp_resource.h" |
| 22 #include "native_client/src/third_party/ppapi/c/pp_var.h" |
| 23 #include "native_client/src/third_party/ppapi/c/ppp.h" |
| 24 #include "native_client/src/third_party/ppapi/c/ppp_input_event.h" |
| 25 |
| 26 using nacl::scoped_ptr; |
| 27 using ppapi_proxy::DebugPrintf; |
| 28 using ppapi_proxy::DeserializeTo; |
| 29 using ppapi_proxy::InputEventData; |
| 30 using ppapi_proxy::PPPInputEventInterface; |
| 31 using ppapi_proxy::PluginInputEvent; |
| 32 using ppapi_proxy::PluginResource; |
| 33 using ppapi_proxy::PluginResourceTracker; |
| 34 |
| 35 |
| 36 void PppInputEventRpcServer::PPP_InputEvent_HandleInputEvent( |
| 37 NaClSrpcRpc* rpc, |
| 38 NaClSrpcClosure* done, |
| 39 // inputs |
| 40 PP_Instance instance, |
| 41 PP_Resource browser_resource, |
| 42 uint32_t event_data_size, char* event_data, |
| 43 uint32_t character_text_size, char* character_text_bytes, |
| 44 // outputs |
| 45 int32_t* handled) { |
| 46 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
| 47 NaClSrpcClosureRunner runner(done); |
| 48 *handled = static_cast<int32_t>(PP_FALSE); |
| 49 |
| 50 const PPP_InputEvent* input_event_interface = PPPInputEventInterface(); |
| 51 if (!input_event_interface || !(input_event_interface->HandleInputEvent)) { |
| 52 DebugPrintf("PppInstanceRpcServer::PPP_InputEvent_HandleInputEvent: " |
| 53 "No PPP_InputEvent interface registered, or it has an invalid " |
| 54 "HandleInputEvent function.\n"); |
| 55 DCHECK(false); |
| 56 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
| 57 return; |
| 58 } |
| 59 // The browser will immediately release this resource when we return, hence |
| 60 // we use a browser count of 0. If the NaCl instance calls AddRefResource, |
| 61 // the ResourceTracker will inform the browser synchronously, so the resource |
| 62 // will be retained. |
| 63 scoped_refptr<PluginInputEvent> input_event = |
| 64 PluginResource::AdoptAsWithNoBrowserCount<PluginInputEvent>( |
| 65 browser_resource); |
| 66 // Now deserialize the input event data and initialize the local |
| 67 // InputEventData with it. Note that we don't actually use the provided |
| 68 // PP_Resource for anything; we have all the data sent to us immediately to |
| 69 // avoid too much RPC in input event handling calls. Using the browser- |
| 70 // provided resource id, however, guarantees our PP_Resource is unique (since |
| 71 // all other resource ids used in the untrusted side were also provided by |
| 72 // the browser). |
| 73 InputEventData data; |
| 74 std::memcpy(&data, event_data, event_data_size); |
| 75 PP_Var character_text_var = PP_MakeUndefined(); |
| 76 DeserializeTo(rpc->channel, character_text_bytes, character_text_size, 1, |
| 77 &character_text_var); |
| 78 input_event->Init(data, character_text_var); |
| 79 |
| 80 *handled = static_cast<int32_t>( |
| 81 input_event_interface->HandleInputEvent(instance, browser_resource)); |
| 82 DebugPrintf("PPP_InputEvent::HandleInputEvent: handled=%d\n", handled); |
| 83 // Now release the input, to match the behavior of the browser. If the NaCl |
| 84 // instance wants to retain the input event for any reason (e.g. to share it |
| 85 // to another thread), it must have called AddRefResource by now. If it has |
| 86 // not, then the input event resource will be deleted from |
| 87 // PluginResourceTracker's cache, and because the browser refcount was set to |
| 88 // 0, the resource tracker will *not* tell the browser. When we return, the |
| 89 // browser decrements its local reference count for us. |
| 90 PluginResourceTracker::Get()->UnrefResource(browser_resource); |
| 91 |
| 92 rpc->result = NACL_SRPC_RESULT_OK; |
| 93 } |
| 94 |
OLD | NEW |