blob: 061b73cd4fdb56889da9afdb6320d0c1b10dbcdc [file] [log] [blame]
[email protected]3c8c74c2012-03-15 07:34:521// 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_text_input_proxy.h"
6
7#include "ppapi/c/dev/ppp_text_input_dev.h"
8#include "ppapi/proxy/host_dispatcher.h"
9#include "ppapi/proxy/ppapi_messages.h"
10#include "ppapi/shared_impl/proxy_lock.h"
11
12namespace ppapi {
13namespace proxy {
14
15namespace {
16
[email protected]24d70dea32012-11-19 22:18:2017#if !defined(OS_NACL)
[email protected]3c8c74c2012-03-15 07:34:5218void RequestSurroundingText(PP_Instance instance,
19 uint32_t desired_number_of_characters) {
20 proxy::HostDispatcher* dispatcher =
21 proxy::HostDispatcher::GetForInstance(instance);
22 if (!dispatcher) {
23 // The dispatcher should always be valid.
24 NOTREACHED();
25 return;
26 }
27
28 dispatcher->Send(new PpapiMsg_PPPTextInput_RequestSurroundingText(
29 API_ID_PPP_TEXT_INPUT, instance, desired_number_of_characters));
30}
31
32const PPP_TextInput_Dev g_ppp_text_input_thunk = {
33 &RequestSurroundingText
34};
[email protected]24d70dea32012-11-19 22:18:2035#else
36// The NaCl plugin doesn't need the host side interface - stub it out.
37static const PPP_TextInput_Dev g_ppp_text_input_thunk = {};
38#endif // !defined(OS_NACL)
[email protected]3c8c74c2012-03-15 07:34:5239
40} // namespace
41
42// static
43const PPP_TextInput_Dev* PPP_TextInput_Proxy::GetProxyInterface() {
44 return &g_ppp_text_input_thunk;
45}
46
47PPP_TextInput_Proxy::PPP_TextInput_Proxy(Dispatcher* dispatcher)
48 : InterfaceProxy(dispatcher),
49 ppp_text_input_impl_(NULL) {
50 if (dispatcher->IsPlugin()) {
51 ppp_text_input_impl_ = static_cast<const PPP_TextInput_Dev*>(
52 dispatcher->local_get_interface()(PPP_TEXTINPUT_DEV_INTERFACE));
53 }
54}
55
56PPP_TextInput_Proxy::~PPP_TextInput_Proxy() {
57}
58
59bool PPP_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) {
[email protected]d5f5dc12013-01-22 23:05:0360 if (!dispatcher()->IsPlugin())
61 return false;
62
[email protected]3c8c74c2012-03-15 07:34:5263 bool handled = true;
64 IPC_BEGIN_MESSAGE_MAP(PPP_TextInput_Proxy, msg)
65 IPC_MESSAGE_HANDLER(PpapiMsg_PPPTextInput_RequestSurroundingText,
66 OnMsgRequestSurroundingText)
67 IPC_MESSAGE_UNHANDLED(handled = false)
68 IPC_END_MESSAGE_MAP()
69 return handled;
70}
71
72void PPP_TextInput_Proxy::OnMsgRequestSurroundingText(
73 PP_Instance instance, uint32_t desired_number_of_characters) {
74 if (ppp_text_input_impl_) {
75 CallWhileUnlocked(ppp_text_input_impl_->RequestSurroundingText,
76 instance, desired_number_of_characters);
77 }
78}
79
80} // namespace proxy
81} // namespace ppapi