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 Thu Feb 28 11:58:17 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/ppb_instance_api.h"
13 #include "ppapi/thunk/ppb_websocket_api.h"
14 #include "ppapi/thunk/resource_creation_api.h"
15 #include "ppapi/thunk/thunk.h"
22 PP_Resource
Create(PP_Instance instance
) {
23 VLOG(4) << "PPB_WebSocket::Create()";
24 EnterResourceCreation
enter(instance
);
27 return enter
.functions()->CreateWebSocket(instance
);
30 PP_Bool
IsWebSocket(PP_Resource resource
) {
31 VLOG(4) << "PPB_WebSocket::IsWebSocket()";
32 EnterResource
<PPB_WebSocket_API
> enter(resource
, false);
33 return PP_FromBool(enter
.succeeded());
36 int32_t Connect(PP_Resource web_socket
,
38 const struct PP_Var protocols
[],
39 uint32_t protocol_count
,
40 struct PP_CompletionCallback callback
) {
41 VLOG(4) << "PPB_WebSocket::Connect()";
42 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
44 return enter
.retval();
45 return enter
.SetResult(enter
.object()->Connect(url
,
51 int32_t Close(PP_Resource web_socket
,
54 struct PP_CompletionCallback callback
) {
55 VLOG(4) << "PPB_WebSocket::Close()";
56 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
58 return enter
.retval();
59 return enter
.SetResult(enter
.object()->Close(code
, reason
, enter
.callback()));
62 int32_t ReceiveMessage(PP_Resource web_socket
,
63 struct PP_Var
* message
,
64 struct PP_CompletionCallback callback
) {
65 VLOG(4) << "PPB_WebSocket::ReceiveMessage()";
66 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, callback
, false);
68 return enter
.retval();
69 return enter
.SetResult(enter
.object()->ReceiveMessage(message
,
73 int32_t SendMessage(PP_Resource web_socket
, struct PP_Var message
) {
74 VLOG(4) << "PPB_WebSocket::SendMessage()";
75 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
77 return enter
.retval();
78 return enter
.object()->SendMessage(message
);
81 uint64_t GetBufferedAmount(PP_Resource web_socket
) {
82 VLOG(4) << "PPB_WebSocket::GetBufferedAmount()";
83 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
86 return enter
.object()->GetBufferedAmount();
89 uint16_t GetCloseCode(PP_Resource web_socket
) {
90 VLOG(4) << "PPB_WebSocket::GetCloseCode()";
91 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
94 return enter
.object()->GetCloseCode();
97 struct PP_Var
GetCloseReason(PP_Resource web_socket
) {
98 VLOG(4) << "PPB_WebSocket::GetCloseReason()";
99 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
101 return PP_MakeUndefined();
102 return enter
.object()->GetCloseReason();
105 PP_Bool
GetCloseWasClean(PP_Resource web_socket
) {
106 VLOG(4) << "PPB_WebSocket::GetCloseWasClean()";
107 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
110 return enter
.object()->GetCloseWasClean();
113 struct PP_Var
GetExtensions(PP_Resource web_socket
) {
114 VLOG(4) << "PPB_WebSocket::GetExtensions()";
115 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
117 return PP_MakeUndefined();
118 return enter
.object()->GetExtensions();
121 struct PP_Var
GetProtocol(PP_Resource web_socket
) {
122 VLOG(4) << "PPB_WebSocket::GetProtocol()";
123 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
125 return PP_MakeUndefined();
126 return enter
.object()->GetProtocol();
129 PP_WebSocketReadyState
GetReadyState(PP_Resource web_socket
) {
130 VLOG(4) << "PPB_WebSocket::GetReadyState()";
131 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
133 return PP_WEBSOCKETREADYSTATE_INVALID
;
134 return enter
.object()->GetReadyState();
137 struct PP_Var
GetURL(PP_Resource web_socket
) {
138 VLOG(4) << "PPB_WebSocket::GetURL()";
139 EnterResource
<PPB_WebSocket_API
> enter(web_socket
, false);
141 return PP_MakeUndefined();
142 return enter
.object()->GetURL();
145 const PPB_WebSocket_1_0 g_ppb_websocket_thunk_1_0
= {
164 const PPB_WebSocket_1_0
* GetPPB_WebSocket_1_0_Thunk() {
165 return &g_ppb_websocket_thunk_1_0
;