summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppp_mouse_lock_proxy.cc
blob: 10aa47f7bd5cf273f01fde5264785d4a07f3ef04 (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
// 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_mouse_lock_proxy.h"

#include "ppapi/c/ppp_mouse_lock.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 {

void MouseLockLost(PP_Instance instance) {
  HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
  if (!dispatcher) {
    // The dispatcher should always be valid.
    NOTREACHED();
    return;
  }

  dispatcher->Send(new PpapiMsg_PPPMouseLock_MouseLockLost(
      API_ID_PPP_MOUSE_LOCK, instance));
}

static const PPP_MouseLock mouse_lock_interface = {
  &MouseLockLost
};

InterfaceProxy* CreateMouseLockProxy(Dispatcher* dispatcher) {
  return new PPP_MouseLock_Proxy(dispatcher);
}

}  // namespace

PPP_MouseLock_Proxy::PPP_MouseLock_Proxy(Dispatcher* dispatcher)
    : InterfaceProxy(dispatcher),
      ppp_mouse_lock_impl_(NULL) {
  if (dispatcher->IsPlugin()) {
    ppp_mouse_lock_impl_ = static_cast<const PPP_MouseLock*>(
        dispatcher->local_get_interface()(PPP_MOUSELOCK_INTERFACE));
  }
}

PPP_MouseLock_Proxy::~PPP_MouseLock_Proxy() {
}

// static
const InterfaceProxy::Info* PPP_MouseLock_Proxy::GetInfo() {
  static const Info info = {
    &mouse_lock_interface,
    PPP_MOUSELOCK_INTERFACE,
    API_ID_PPP_MOUSE_LOCK,
    false,
    &CreateMouseLockProxy,
  };
  return &info;
}

bool PPP_MouseLock_Proxy::OnMessageReceived(const IPC::Message& msg) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(PPP_MouseLock_Proxy, msg)
    IPC_MESSAGE_HANDLER(PpapiMsg_PPPMouseLock_MouseLockLost,
                        OnMsgMouseLockLost)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void PPP_MouseLock_Proxy::OnMsgMouseLockLost(PP_Instance instance) {
  if (ppp_mouse_lock_impl_)
    CallWhileUnlocked(ppp_mouse_lock_impl_->MouseLockLost, instance);
}

}  // namespace proxy
}  // namespace ppapi