• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium 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 "ppapi/proxy/ppp_input_event_proxy.h"
6 
7 #include "ppapi/c/ppp_input_event.h"
8 #include "ppapi/proxy/host_dispatcher.h"
9 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/ppb_input_event_shared.h"
12 #include "ppapi/thunk/enter.h"
13 #include "ppapi/thunk/ppb_input_event_api.h"
14 
15 using ppapi::thunk::EnterResourceNoLock;
16 using ppapi::thunk::PPB_InputEvent_API;
17 
18 namespace ppapi {
19 namespace proxy {
20 
21 namespace {
22 
23 #if !defined(OS_NACL)
HandleInputEvent(PP_Instance instance,PP_Resource input_event)24 PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource input_event) {
25   EnterResourceNoLock<PPB_InputEvent_API> enter(input_event, false);
26   if (enter.failed()) {
27     NOTREACHED();
28     return PP_FALSE;
29   }
30   const InputEventData& data = enter.object()->GetInputEventData();
31   HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
32   if (!dispatcher) {
33     NOTREACHED();
34     return PP_FALSE;
35   }
36 
37   // Need to send different messages depending on whether filtering is needed.
38   PP_Bool result = PP_FALSE;
39   if (data.is_filtered) {
40     dispatcher->Send(new PpapiMsg_PPPInputEvent_HandleFilteredInputEvent(
41         API_ID_PPP_INPUT_EVENT, instance, data, &result));
42   } else {
43     dispatcher->Send(new PpapiMsg_PPPInputEvent_HandleInputEvent(
44         API_ID_PPP_INPUT_EVENT, instance, data));
45   }
46   return result;
47 }
48 
49 static const PPP_InputEvent input_event_interface = {
50   &HandleInputEvent
51 };
52 #else
53 // The NaCl plugin doesn't need the host side interface - stub it out.
54 static const PPP_InputEvent input_event_interface = {};
55 #endif  // !defined(OS_NACL)
56 
57 }  // namespace
58 
PPP_InputEvent_Proxy(Dispatcher * dispatcher)59 PPP_InputEvent_Proxy::PPP_InputEvent_Proxy(Dispatcher* dispatcher)
60     : InterfaceProxy(dispatcher),
61       ppp_input_event_impl_(NULL) {
62   if (dispatcher->IsPlugin()) {
63     ppp_input_event_impl_ = static_cast<const PPP_InputEvent*>(
64         dispatcher->local_get_interface()(PPP_INPUT_EVENT_INTERFACE));
65   }
66 }
67 
~PPP_InputEvent_Proxy()68 PPP_InputEvent_Proxy::~PPP_InputEvent_Proxy() {
69 }
70 
71 // static
GetProxyInterface()72 const PPP_InputEvent* PPP_InputEvent_Proxy::GetProxyInterface() {
73   return &input_event_interface;
74 }
75 
OnMessageReceived(const IPC::Message & msg)76 bool PPP_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) {
77   if (!dispatcher()->IsPlugin())
78     return false;
79 
80   bool handled = true;
81   IPC_BEGIN_MESSAGE_MAP(PPP_InputEvent_Proxy, msg)
82     IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleInputEvent,
83                         OnMsgHandleInputEvent)
84     IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent,
85                         OnMsgHandleFilteredInputEvent)
86     IPC_MESSAGE_UNHANDLED(handled = false)
87   IPC_END_MESSAGE_MAP()
88   return handled;
89 }
90 
OnMsgHandleInputEvent(PP_Instance instance,const InputEventData & data)91 void PPP_InputEvent_Proxy::OnMsgHandleInputEvent(PP_Instance instance,
92                                                  const InputEventData& data) {
93   scoped_refptr<PPB_InputEvent_Shared> resource(new PPB_InputEvent_Shared(
94       OBJECT_IS_PROXY, instance, data));
95   CallWhileUnlocked(ppp_input_event_impl_->HandleInputEvent,
96                     instance,
97                     resource->pp_resource());
98 }
99 
OnMsgHandleFilteredInputEvent(PP_Instance instance,const InputEventData & data,PP_Bool * result)100 void PPP_InputEvent_Proxy::OnMsgHandleFilteredInputEvent(
101     PP_Instance instance,
102     const InputEventData& data,
103     PP_Bool* result) {
104   scoped_refptr<PPB_InputEvent_Shared> resource(new PPB_InputEvent_Shared(
105       OBJECT_IS_PROXY, instance, data));
106   *result = CallWhileUnlocked(ppp_input_event_impl_->HandleInputEvent,
107                               instance,
108                               resource->pp_resource());
109 }
110 
111 }  // namespace proxy
112 }  // namespace ppapi
113