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 Mon May 6 10:11:29 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
, protocols
, protocol_count
,
47 int32_t Close(PP_Resource web_socket
,
50 struct PP_CompletionCallback callback
) {
51 VLOG(4) << "PPB_WebSocket::Close()";
52 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
54 return enter
.retval();
55 return enter
.SetResult(enter
.object()->Close(code
, reason
, enter
.callback()));
58 int32_t ReceiveMessage(PP_Resource web_socket
,
59 struct PP_Var
* message
,
60 struct PP_CompletionCallback callback
) {
61 VLOG(4) << "PPB_WebSocket::ReceiveMessage()";
62 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
64 return enter
.retval();
65 return enter
.SetResult(
66 enter
.object()->ReceiveMessage(message
, enter
.callback()));
69 int32_t SendMessage(PP_Resource web_socket
, struct PP_Var message
) {
70 VLOG(4) << "PPB_WebSocket::SendMessage()";
71 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
73 return enter
.retval();
74 return enter
.object()->SendMessage(message
);
77 uint64_t GetBufferedAmount(PP_Resource web_socket
) {
78 VLOG(4) << "PPB_WebSocket::GetBufferedAmount()";
79 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
82 return enter
.object()->GetBufferedAmount();
85 uint16_t GetCloseCode(PP_Resource web_socket
) {
86 VLOG(4) << "PPB_WebSocket::GetCloseCode()";
87 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
90 return enter
.object()->GetCloseCode();
93 struct PP_Var
GetCloseReason(PP_Resource web_socket
) {
94 VLOG(4) << "PPB_WebSocket::GetCloseReason()";
95 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
97 return PP_MakeUndefined();
98 return enter
.object()->GetCloseReason();
101 PP_Bool
GetCloseWasClean(PP_Resource web_socket
) {
102 VLOG(4) << "PPB_WebSocket::GetCloseWasClean()";
103 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
106 return enter
.object()->GetCloseWasClean();
109 struct PP_Var
GetExtensions(PP_Resource web_socket
) {
110 VLOG(4) << "PPB_WebSocket::GetExtensions()";
111 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
113 return PP_MakeUndefined();
114 return enter
.object()->GetExtensions();
117 struct PP_Var
GetProtocol(PP_Resource web_socket
) {
118 VLOG(4) << "PPB_WebSocket::GetProtocol()";
119 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
121 return PP_MakeUndefined();
122 return enter
.object()->GetProtocol();
125 PP_WebSocketReadyState
GetReadyState(PP_Resource web_socket
) {
126 VLOG(4) << "PPB_WebSocket::GetReadyState()";
127 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
129 return PP_WEBSOCKETREADYSTATE_INVALID
;
130 return enter
.object()->GetReadyState();
133 struct PP_Var
GetURL(PP_Resource web_socket
) {
134 VLOG(4) << "PPB_WebSocket::GetURL()";
135 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
137 return PP_MakeUndefined();
138 return enter
.object()->GetURL();
141 const PPB_WebSocket_1_0 g_ppb_websocket_thunk_1_0
= {&Create
,
158 PPAPI_THUNK_EXPORT
const PPB_WebSocket_1_0
* GetPPB_WebSocket_1_0_Thunk() {
159 return &g_ppb_websocket_thunk_1_0
;