blob: 01ee0ac3300d1016a8406f3dd8dee23748ef1df9 [file] [log] [blame]
[email protected]f20cc692012-11-28 19:21:201// 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/talk_resource.h"
6
7#include "ppapi/proxy/ppapi_messages.h"
8
9namespace ppapi {
10namespace proxy {
11
12TalkResource::TalkResource(Connection connection, PP_Instance instance)
[email protected]ce97d7452013-06-07 19:02:0913 : PluginResource(connection, instance),
14 event_callback_(NULL),
15 event_callback_user_data_(NULL) {
16 SendCreate(BROWSER, PpapiHostMsg_Talk_Create());
[email protected]f20cc692012-11-28 19:21:2017}
18
19TalkResource::~TalkResource() {
20}
21
22thunk::PPB_Talk_Private_API* TalkResource::AsPPB_Talk_Private_API() {
23 return this;
24}
25
[email protected]ce97d7452013-06-07 19:02:0926int32_t TalkResource::RequestPermission(
27 PP_TalkPermission permission,
28 scoped_refptr<TrackedCallback> callback) {
29 if (TrackedCallback::IsPending(permission_callback_))
[email protected]f20cc692012-11-28 19:21:2030 return PP_ERROR_INPROGRESS;
[email protected]f20cc692012-11-28 19:21:2031
[email protected]ce97d7452013-06-07 19:02:0932 permission_callback_ = callback;
[email protected]f20cc692012-11-28 19:21:2033
[email protected]ce97d7452013-06-07 19:02:0934 Call<PpapiPluginMsg_Talk_RequestPermissionReply>(
[email protected]f20cc692012-11-28 19:21:2035 BROWSER,
[email protected]ce97d7452013-06-07 19:02:0936 PpapiHostMsg_Talk_RequestPermission(permission),
37 base::Bind(&TalkResource::OnRequestPermissionReply,
38 base::Unretained(this)));
[email protected]f20cc692012-11-28 19:21:2039 return PP_OK_COMPLETIONPENDING;
40}
41
[email protected]ce97d7452013-06-07 19:02:0942int32_t TalkResource::StartRemoting(PP_TalkEventCallback event_callback,
43 void* user_data,
44 scoped_refptr<TrackedCallback> callback) {
45 if (TrackedCallback::IsPending(start_callback_) ||
46 event_callback_ != NULL)
47 return PP_ERROR_INPROGRESS;
48
49 start_callback_ = callback;
50 event_callback_ = event_callback;
51 event_callback_user_data_ = user_data;
52
53 Call<PpapiPluginMsg_Talk_StartRemotingReply>(
54 BROWSER,
55 PpapiHostMsg_Talk_StartRemoting(),
56 base::Bind(&TalkResource::OnStartRemotingReply,
57 base::Unretained(this)));
58 return PP_OK_COMPLETIONPENDING;
59}
60
61int32_t TalkResource::StopRemoting(scoped_refptr<TrackedCallback> callback) {
62 if (TrackedCallback::IsPending(stop_callback_))
63 return PP_ERROR_INPROGRESS;
64
65 if (event_callback_ == NULL)
66 return PP_ERROR_FAILED;
67
68 stop_callback_ = callback;
69
70 Call<PpapiPluginMsg_Talk_StopRemotingReply>(
71 BROWSER,
72 PpapiHostMsg_Talk_StopRemoting(),
73 base::Bind(&TalkResource::OnStopRemotingReply,
74 base::Unretained(this)));
75 return PP_OK_COMPLETIONPENDING;
76}
77
78void TalkResource::OnReplyReceived(const ResourceMessageReplyParams& params,
79 const IPC::Message& msg) {
80 IPC_BEGIN_MESSAGE_MAP(TalkResource, msg)
81 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
82 PpapiPluginMsg_Talk_NotifyEvent,
83 OnNotifyEvent)
84 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
85 PluginResource::OnReplyReceived(params, msg))
86 IPC_END_MESSAGE_MAP()
87}
88
89void TalkResource::OnNotifyEvent(const ResourceMessageReplyParams& params,
90 PP_TalkEvent event) {
91 if (event_callback_ != NULL)
92 event_callback_(event_callback_user_data_, event);
93}
94
95void TalkResource::OnRequestPermissionReply(
[email protected]f20cc692012-11-28 19:21:2096 const ResourceMessageReplyParams& params) {
[email protected]ce97d7452013-06-07 19:02:0997 permission_callback_->Run(params.result());
98}
99
100void TalkResource::OnStartRemotingReply(
101 const ResourceMessageReplyParams& params) {
102 start_callback_->Run(params.result());
103}
104
105void TalkResource::OnStopRemotingReply(
106 const ResourceMessageReplyParams& params) {
107 event_callback_ = NULL;
108 event_callback_user_data_ = NULL;
109 stop_callback_->Run(params.result());
[email protected]f20cc692012-11-28 19:21:20110}
111
112} // namespace proxy
113} // namespace ppapi