Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ppapi / thunk / ppb_websocket_thunk.cc
bloba632305e7fad7bd4f0cc38b1516aff904284d78b
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"
15 namespace ppapi {
16 namespace thunk {
18 namespace {
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);
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,
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, protocols, protocol_count,
44 enter.callback()));
47 int32_t Close(PP_Resource web_socket,
48 uint16_t code,
49 struct PP_Var reason,
50 struct PP_CompletionCallback callback) {
51 VLOG(4) << "PPB_WebSocket::Close()";
52 EnterResource<PPB_WebSocket_API> enter(web_socket, callback, false);
53 if (enter.failed())
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);
63 if (enter.failed())
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);
72 if (enter.failed())
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);
80 if (enter.failed())
81 return 0;
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);
88 if (enter.failed())
89 return 0;
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);
96 if (enter.failed())
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);
104 if (enter.failed())
105 return PP_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);
112 if (enter.failed())
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);
120 if (enter.failed())
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);
128 if (enter.failed())
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);
136 if (enter.failed())
137 return PP_MakeUndefined();
138 return enter.object()->GetURL();
141 const PPB_WebSocket_1_0 g_ppb_websocket_thunk_1_0 = {&Create,
142 &IsWebSocket,
143 &Connect,
144 &Close,
145 &ReceiveMessage,
146 &SendMessage,
147 &GetBufferedAmount,
148 &GetCloseCode,
149 &GetCloseReason,
150 &GetCloseWasClean,
151 &GetExtensions,
152 &GetProtocol,
153 &GetReadyState,
154 &GetURL};
156 } // namespace
158 PPAPI_THUNK_EXPORT const PPB_WebSocket_1_0* GetPPB_WebSocket_1_0_Thunk() {
159 return &g_ppb_websocket_thunk_1_0;
162 } // namespace thunk
163 } // namespace ppapi