• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 // From ppb_websocket.idl modified Tue Aug 20 08:13:36 2013.
6 
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"
14 
15 namespace ppapi {
16 namespace thunk {
17 
18 namespace {
19 
Create(PP_Instance instance)20 PP_Resource Create(PP_Instance instance) {
21   VLOG(4) << "PPB_WebSocket::Create()";
22   EnterResourceCreation enter(instance);
23   if (enter.failed())
24     return 0;
25   return enter.functions()->CreateWebSocket(instance);
26 }
27 
IsWebSocket(PP_Resource resource)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());
32 }
33 
Connect(PP_Resource web_socket,struct PP_Var url,const struct PP_Var protocols[],uint32_t protocol_count,struct PP_CompletionCallback callback)34 int32_t Connect(PP_Resource web_socket,
35                 struct PP_Var url,
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);
41   if (enter.failed())
42     return enter.retval();
43   return enter.SetResult(enter.object()->Connect(url,
44                                                  protocols,
45                                                  protocol_count,
46                                                  enter.callback()));
47 }
48 
Close(PP_Resource web_socket,uint16_t code,struct PP_Var reason,struct PP_CompletionCallback callback)49 int32_t Close(PP_Resource web_socket,
50               uint16_t code,
51               struct PP_Var reason,
52               struct PP_CompletionCallback callback) {
53   VLOG(4) << "PPB_WebSocket::Close()";
54   EnterResource<PPB_WebSocket_API> enter(web_socket, callback, false);
55   if (enter.failed())
56     return enter.retval();
57   return enter.SetResult(enter.object()->Close(code, reason, enter.callback()));
58 }
59 
ReceiveMessage(PP_Resource web_socket,struct PP_Var * message,struct PP_CompletionCallback 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);
65   if (enter.failed())
66     return enter.retval();
67   return enter.SetResult(enter.object()->ReceiveMessage(message,
68                                                         enter.callback()));
69 }
70 
SendMessage(PP_Resource web_socket,struct PP_Var 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);
74   if (enter.failed())
75     return enter.retval();
76   return enter.object()->SendMessage(message);
77 }
78 
GetBufferedAmount(PP_Resource web_socket)79 uint64_t GetBufferedAmount(PP_Resource web_socket) {
80   VLOG(4) << "PPB_WebSocket::GetBufferedAmount()";
81   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
82   if (enter.failed())
83     return 0;
84   return enter.object()->GetBufferedAmount();
85 }
86 
GetCloseCode(PP_Resource web_socket)87 uint16_t GetCloseCode(PP_Resource web_socket) {
88   VLOG(4) << "PPB_WebSocket::GetCloseCode()";
89   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
90   if (enter.failed())
91     return 0;
92   return enter.object()->GetCloseCode();
93 }
94 
GetCloseReason(PP_Resource web_socket)95 struct PP_Var GetCloseReason(PP_Resource web_socket) {
96   VLOG(4) << "PPB_WebSocket::GetCloseReason()";
97   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
98   if (enter.failed())
99     return PP_MakeUndefined();
100   return enter.object()->GetCloseReason();
101 }
102 
GetCloseWasClean(PP_Resource web_socket)103 PP_Bool GetCloseWasClean(PP_Resource web_socket) {
104   VLOG(4) << "PPB_WebSocket::GetCloseWasClean()";
105   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
106   if (enter.failed())
107     return PP_FALSE;
108   return enter.object()->GetCloseWasClean();
109 }
110 
GetExtensions(PP_Resource web_socket)111 struct PP_Var GetExtensions(PP_Resource web_socket) {
112   VLOG(4) << "PPB_WebSocket::GetExtensions()";
113   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
114   if (enter.failed())
115     return PP_MakeUndefined();
116   return enter.object()->GetExtensions();
117 }
118 
GetProtocol(PP_Resource web_socket)119 struct PP_Var GetProtocol(PP_Resource web_socket) {
120   VLOG(4) << "PPB_WebSocket::GetProtocol()";
121   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
122   if (enter.failed())
123     return PP_MakeUndefined();
124   return enter.object()->GetProtocol();
125 }
126 
GetReadyState(PP_Resource web_socket)127 PP_WebSocketReadyState GetReadyState(PP_Resource web_socket) {
128   VLOG(4) << "PPB_WebSocket::GetReadyState()";
129   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
130   if (enter.failed())
131     return PP_WEBSOCKETREADYSTATE_INVALID;
132   return enter.object()->GetReadyState();
133 }
134 
GetURL(PP_Resource web_socket)135 struct PP_Var GetURL(PP_Resource web_socket) {
136   VLOG(4) << "PPB_WebSocket::GetURL()";
137   EnterResource<PPB_WebSocket_API> enter(web_socket, false);
138   if (enter.failed())
139     return PP_MakeUndefined();
140   return enter.object()->GetURL();
141 }
142 
143 const PPB_WebSocket_1_0 g_ppb_websocket_thunk_1_0 = {
144   &Create,
145   &IsWebSocket,
146   &Connect,
147   &Close,
148   &ReceiveMessage,
149   &SendMessage,
150   &GetBufferedAmount,
151   &GetCloseCode,
152   &GetCloseReason,
153   &GetCloseWasClean,
154   &GetExtensions,
155   &GetProtocol,
156   &GetReadyState,
157   &GetURL
158 };
159 
160 }  // namespace
161 
GetPPB_WebSocket_1_0_Thunk()162 PPAPI_THUNK_EXPORT const PPB_WebSocket_1_0* GetPPB_WebSocket_1_0_Thunk() {
163   return &g_ppb_websocket_thunk_1_0;
164 }
165 
166 }  // namespace thunk
167 }  // namespace ppapi
168