summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppp_text_input_proxy.cc
blob: 061b73cd4fdb56889da9afdb6320d0c1b10dbcdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2012 The Chromium 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 "ppapi/proxy/ppp_text_input_proxy.h"

#include "ppapi/c/dev/ppp_text_input_dev.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/proxy_lock.h"

namespace ppapi {
namespace proxy {

namespace {

#if !defined(OS_NACL)
void RequestSurroundingText(PP_Instance instance,
                            uint32_t desired_number_of_characters) {
  proxy::HostDispatcher* dispatcher =
      proxy::HostDispatcher::GetForInstance(instance);
  if (!dispatcher) {
    // The dispatcher should always be valid.
    NOTREACHED();
    return;
  }

  dispatcher->Send(new PpapiMsg_PPPTextInput_RequestSurroundingText(
      API_ID_PPP_TEXT_INPUT, instance, desired_number_of_characters));
}

const PPP_TextInput_Dev g_ppp_text_input_thunk = {
  &RequestSurroundingText
};
#else
// The NaCl plugin doesn't need the host side interface - stub it out.
static const PPP_TextInput_Dev g_ppp_text_input_thunk = {};
#endif  // !defined(OS_NACL)

}  // namespace

// static
const PPP_TextInput_Dev* PPP_TextInput_Proxy::GetProxyInterface() {
  return &g_ppp_text_input_thunk;
}

PPP_TextInput_Proxy::PPP_TextInput_Proxy(Dispatcher* dispatcher)
    : InterfaceProxy(dispatcher),
      ppp_text_input_impl_(NULL) {
  if (dispatcher->IsPlugin()) {
    ppp_text_input_impl_ = static_cast<const PPP_TextInput_Dev*>(
        dispatcher->local_get_interface()(PPP_TEXTINPUT_DEV_INTERFACE));
  }
}

PPP_TextInput_Proxy::~PPP_TextInput_Proxy() {
}

bool PPP_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) {
  if (!dispatcher()->IsPlugin())
    return false;

  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(PPP_TextInput_Proxy, msg)
    IPC_MESSAGE_HANDLER(PpapiMsg_PPPTextInput_RequestSurroundingText,
                        OnMsgRequestSurroundingText)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void PPP_TextInput_Proxy::OnMsgRequestSurroundingText(
    PP_Instance instance, uint32_t desired_number_of_characters) {
  if (ppp_text_input_impl_) {
    CallWhileUnlocked(ppp_text_input_impl_->RequestSurroundingText,
                      instance, desired_number_of_characters);
  }
}

}  // namespace proxy
}  // namespace ppapi