summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppb_talk_private_proxy.cc
blob: 3b301f0360923cf9639c66f01a24f775d35edc14 (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
82
83
84
85
86
87
88
89
90
91
92
// 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/ppb_talk_private_proxy.h"

#include "ipc/ipc_message_macros.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/plugin_proxy_delegate.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_talk_private_api.h"

namespace ppapi {
namespace proxy {

namespace {

class Talk : public Resource, public thunk::PPB_Talk_Private_API {
 public:
  Talk(PP_Instance instance) : Resource(OBJECT_IS_PROXY, instance) {
  }

  // Resource overrides.
  thunk::PPB_Talk_Private_API* AsPPB_Talk_Private_API() { return this; }

  // PPB_Talk_API implementation.
  int32_t GetPermission(const PP_CompletionCallback& callback) {
    if (TrackedCallback::IsPending(callback_))
      return PP_ERROR_INPROGRESS;
    PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
        pp_instance());
    if (!dispatcher)
      return PP_ERROR_FAILED;

    callback_ = new TrackedCallback(this, callback);

    if (PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(
        new PpapiHostMsg_PPBTalk_GetPermission(
            API_ID_PPB_TALK,
            dispatcher->plugin_dispatcher_id(),
            pp_resource())))
      return PP_OK_COMPLETIONPENDING;
    return PP_ERROR_FAILED;
  }

  void GotCompletion(int32_t result) {
    TrackedCallback::ClearAndRun(&callback_, result);
  }

 private:
  scoped_refptr<TrackedCallback> callback_;

  DISALLOW_COPY_AND_ASSIGN(Talk);
};

}  // namespace

PPB_Talk_Private_Proxy::PPB_Talk_Private_Proxy(Dispatcher* dispatcher)
    : InterfaceProxy(dispatcher) {
}

// static
PP_Resource PPB_Talk_Private_Proxy::CreateProxyResource(PP_Instance instance) {
  return (new Talk(instance))->GetReference();
}

bool PPB_Talk_Private_Proxy::OnMessageReceived(const IPC::Message& msg) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(PPB_Talk_Private_Proxy, msg)
    IPC_MESSAGE_HANDLER(PpapiMsg_PPBTalk_GetPermissionACK,
                        OnMsgGetPermissionACK)
    IPC_MESSAGE_UNHANDLED(handled = false);
  IPC_END_MESSAGE_MAP();
  return handled;
}

void PPB_Talk_Private_Proxy::OnMsgGetPermissionACK(uint32 /* dispatcher_id */,
                                                   PP_Resource resource,
                                                   int32_t result) {
  thunk::EnterResourceNoLock<thunk::PPB_Talk_Private_API> enter(
      resource, false);
  if (enter.succeeded())
    static_cast<Talk*>(enter.object())->GotCompletion(result);
}

}  // namespace proxy
}  // namespace ppapi