1 // 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.
5 // From ppb_websocket.idl modified Tue Aug 20 08:13:36 2013.
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_websocket.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppapi_thunk_export.h"
13 #include "ppapi/thunk/ppb_websocket_api.h"
20 PP_Resource
Create(PP_Instance instance
) {
21 VLOG(4) << "PPB_WebSocket::Create()";
22 EnterResourceCreation
enter(instance
);
25 return enter
.functions()->CreateWebSocket(instance
);
28 PP_Bool
IsWebSocket(PP_Resource resource
) {
29 VLOG(4) << "PPB_WebSocket::IsWebSocket()";
30 EnterResource
<PPB_WebSocket_API
> enter(resource
, false);
31 return PP_FromBool(enter
.succeeded());
34 int32_t Connect(PP_Resource web_socket
,
36 const struct PP_Var protocols
[],
37 uint32_t protocol_count
,
38 struct PP_CompletionCallback callback
) {
39 VLOG(4) << "PPB_WebSocket::Connect()";
40 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
42 return enter
.retval();
43 return enter
.SetResult(enter
.object()->Connect(url
,
49 int32_t Close(PP_Resource web_socket
,
52 struct PP_CompletionCallback callback
) {
53 VLOG(4) << "PPB_WebSocket::Close()";
54 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
56 return enter
.retval();
57 return enter
.SetResult(enter
.object()->Close(code
, reason
, enter
.callback()));
60 int32_t ReceiveMessage(PP_Resource web_socket
,
61 struct PP_Var
* message
,
62 struct PP_CompletionCallback callback
) {
63 VLOG(4) << "PPB_WebSocket::ReceiveMessage()";
64 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
66 return enter
.retval();
67 return enter
.SetResult(enter
.object()->ReceiveMessage(message
,
71 int32_t SendMessage(PP_Resource web_socket
, struct PP_Var message
) {
72 VLOG(4) << "PPB_WebSocket::SendMessage()";
73 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
75 return enter
.retval();
76 return enter
.object()->SendMessage(message
);
79 uint64_t GetBufferedAmount(PP_Resource web_socket
) {
80 VLOG(4) << "PPB_WebSocket::GetBufferedAmount()";
81 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
84 return enter
.object()->GetBufferedAmount();
87 uint16_t GetCloseCode(PP_Resource web_socket
) {
88 VLOG(4) << "PPB_WebSocket::GetCloseCode()";
89 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
92 return enter
.object()->GetCloseCode();
95 struct PP_Var
GetCloseReason(PP_Resource web_socket
) {
96 VLOG(4) << "PPB_WebSocket::GetCloseReason()";
97 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
99 return PP_MakeUndefined();
100 return enter
.object()->GetCloseReason();
103 PP_Bool
GetCloseWasClean(PP_Resource web_socket
) {
104 VLOG(4) << "PPB_WebSocket::GetCloseWasClean()";
105 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
108 return enter
.object()->GetCloseWasClean();
111 struct PP_Var
GetExtensions(PP_Resource web_socket
) {
112 VLOG(4) << "PPB_WebSocket::GetExtensions()";
113 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
115 return PP_MakeUndefined();
116 return enter
.object()->GetExtensions();
119 struct PP_Var
GetProtocol(PP_Resource web_socket
) {
120 VLOG(4) << "PPB_WebSocket::GetProtocol()";
121 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
123 return PP_MakeUndefined();
124 return enter
.object()->GetProtocol();
127 PP_WebSocketReadyState
GetReadyState(PP_Resource web_socket
) {
128 VLOG(4) << "PPB_WebSocket::GetReadyState()";
129 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
131 return PP_WEBSOCKETREADYSTATE_INVALID
;
132 return enter
.object()->GetReadyState();
135 struct PP_Var
GetURL(PP_Resource web_socket
) {
136 VLOG(4) << "PPB_WebSocket::GetURL()";
137 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
139 return PP_MakeUndefined();
140 return enter
.object()->GetURL();
143 const PPB_WebSocket_1_0 g_ppb_websocket_thunk_1_0
= {
162 PPAPI_THUNK_EXPORT
const PPB_WebSocket_1_0
* GetPPB_WebSocket_1_0_Thunk() {
163 return &g_ppb_websocket_thunk_1_0
;