Whitelist window states to persist on ASH app windows.
[chromium-blink-merge.git] / ppapi / thunk / ppb_websocket_thunk.cc
blob10406657383907878a5842c9ffcbe7b5c4796116
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"
17 namespace ppapi {
18 namespace thunk {
20 namespace {
22 PP_Resource Create(PP_Instance instance) {
23 VLOG(4) << "PPB_WebSocket::Create()";
24 EnterResourceCreation enter(instance);
25 if (enter.failed())
26 return 0;
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,
37 struct PP_Var url,
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);
43 if (enter.failed())
44 return enter.retval();
45 return enter.SetResult(enter.object()->Connect(url,
46 protocols,
47 protocol_count,
48 enter.callback()));
51 int32_t Close(PP_Resource web_socket,
52 uint16_t code,
53 struct PP_Var reason,
54 struct PP_CompletionCallback callback) {
55 VLOG(4) << "PPB_WebSocket::Close()";
56 EnterResource<PPB_WebSocket_API> enter(web_socket, callback, false);
57 if (enter.failed())
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);
67 if (enter.failed())
68 return enter.retval();
69 return enter.SetResult(enter.object()->ReceiveMessage(message,
70 enter.callback()));
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);
76 if (enter.failed())
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);
84 if (enter.failed())
85 return 0;
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);
92 if (enter.failed())
93 return 0;
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);
100 if (enter.failed())
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);
108 if (enter.failed())
109 return PP_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);
116 if (enter.failed())
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);
124 if (enter.failed())
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);
132 if (enter.failed())
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);
140 if (enter.failed())
141 return PP_MakeUndefined();
142 return enter.object()->GetURL();
145 const PPB_WebSocket_1_0 g_ppb_websocket_thunk_1_0 = {
146 &Create,
147 &IsWebSocket,
148 &Connect,
149 &Close,
150 &ReceiveMessage,
151 &SendMessage,
152 &GetBufferedAmount,
153 &GetCloseCode,
154 &GetCloseReason,
155 &GetCloseWasClean,
156 &GetExtensions,
157 &GetProtocol,
158 &GetReadyState,
159 &GetURL
162 } // namespace
164 const PPB_WebSocket_1_0* GetPPB_WebSocket_1_0_Thunk() {
165 return &g_ppb_websocket_thunk_1_0;
168 } // namespace thunk
169 } // namespace ppapi