Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 // SRPC-abstraction wrappers around PPB_WebSocket functions. | |
| 6 | |
| 7 #include "native_client/src/include/nacl_scoped_ptr.h" | |
| 8 #include "native_client/src/shared/ppapi_proxy/browser_callback.h" | |
| 9 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" | |
| 10 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | |
| 11 #include "native_client/src/shared/ppapi_proxy/utility.h" | |
| 12 #include "ppapi/c/pp_completion_callback.h" | |
| 13 #include "ppapi/c/pp_errors.h" | |
| 14 #include "ppapi/c/dev/ppb_websocket_dev.h" | |
| 15 #include "srpcgen/ppb_rpc.h" | |
| 16 | |
| 17 using ppapi_proxy::DebugPrintf; | |
| 18 using ppapi_proxy::DeleteRemoteCallbackInfo; | |
| 19 using ppapi_proxy::DeserializeTo; | |
| 20 using ppapi_proxy::MakeRemoteCompletionCallback; | |
| 21 using ppapi_proxy::PPBWebSocketInterface; | |
| 22 using ppapi_proxy::SerializeTo; | |
| 23 | |
| 24 void PpbWebSocketRpcServer::PPB_WebSocket_Create( | |
| 25 NaClSrpcRpc* rpc, | |
| 26 NaClSrpcClosure* done, | |
| 27 // inputsless | |
|
dmichael (off chromium)
2012/01/17 23:32:45
inputsless -> inputs?
Takashi Toyoshima
2012/01/18 11:07:16
Done.
PPB_URLLoader_Create looks having the same n
| |
| 28 PP_Instance instance, | |
| 29 // outputs | |
| 30 PP_Resource* resource) { | |
| 31 NaClSrpcClosureRunner runner(done); | |
| 32 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 33 | |
| 34 *resource = PPBWebSocketInterface()->Create(instance); | |
| 35 DebugPrintf("PPB_WebSocket::Create: resource=%"NACL_PRIu32"\n", *resource); | |
|
dmichael (off chromium)
2012/01/17 23:32:45
Should that be NACL_PRId32?
Takashi Toyoshima
2012/01/18 11:07:16
I see. PP_Resource is defined as typedef int32_t P
dmichael (off chromium)
2012/01/18 17:04:40
Thanks!
| |
| 36 | |
| 37 rpc->result = NACL_SRPC_RESULT_OK; | |
| 38 } | |
| 39 | |
| 40 void PpbWebSocketRpcServer::PPB_WebSocket_IsWebSocket( | |
| 41 NaClSrpcRpc* rpc, | |
| 42 NaClSrpcClosure* done, | |
| 43 // inputs | |
| 44 PP_Resource resource, | |
| 45 // outputs | |
| 46 int32_t* success) { | |
| 47 NaClSrpcClosureRunner runner(done); | |
| 48 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 49 | |
| 50 PP_Bool pp_success = PPBWebSocketInterface()->IsWebSocket(resource); | |
| 51 DebugPrintf("PPB_WebSocket::IsWebSocket: pp_success=%d\n", pp_success); | |
|
dmichael (off chromium)
2012/01/17 23:32:45
nit: It's probably safest to do static_cast<int>(p
Takashi Toyoshima
2012/01/18 11:07:16
I found a good sample which use *success after PP_
| |
| 52 | |
| 53 *success = (pp_success == PP_TRUE); | |
|
dmichael (off chromium)
2012/01/17 23:32:45
We usually use PP_ToBool() and PP_FromBool for the
Takashi Toyoshima
2012/01/18 11:07:16
Oh, sorry.
I remember you taught me this before.
D
| |
| 54 rpc->result = NACL_SRPC_RESULT_OK; | |
| 55 } | |
| 56 | |
| 57 void PpbWebSocketRpcServer::PPB_WebSocket_Connect( | |
| 58 NaClSrpcRpc* rpc, | |
| 59 NaClSrpcClosure* done, | |
| 60 // inputs | |
| 61 PP_Resource ws, | |
| 62 nacl_abi_size_t url_size, | |
| 63 char* url_bytes, | |
| 64 nacl_abi_size_t protocols_size, | |
| 65 char* protocols_bytes, | |
| 66 int32_t protocol_count, | |
| 67 int32_t callback_id, | |
| 68 // outputs | |
| 69 int32_t* pp_error) { | |
| 70 NaClSrpcClosureRunner runner(done); | |
| 71 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 72 | |
| 73 PP_CompletionCallback remote_callback = | |
| 74 MakeRemoteCompletionCallback(rpc->channel, callback_id); | |
| 75 if (NULL == remote_callback.func) | |
| 76 return; | |
| 77 | |
| 78 PP_Var url; | |
| 79 if (!DeserializeTo(url_bytes, url_size, 1, &url)) | |
| 80 return; | |
| 81 | |
| 82 nacl::scoped_array<PP_Var> protocols(new PP_Var[protocol_count]); | |
| 83 if (!DeserializeTo( | |
| 84 protocols_bytes, protocols_size, protocol_count, protocols.get())) | |
| 85 return; | |
| 86 | |
| 87 *pp_error = PPBWebSocketInterface()->Connect( | |
| 88 ws, | |
| 89 url, | |
| 90 protocols.get(), | |
| 91 static_cast<uint32_t>(protocol_count), | |
| 92 remote_callback); | |
| 93 DebugPrintf("PPB_WebSocket::Connect: pp_error=%"NACL_PRId32"\n", *pp_error); | |
| 94 | |
| 95 if (*pp_error != PP_OK_COMPLETIONPENDING) | |
| 96 DeleteRemoteCallbackInfo(remote_callback); | |
| 97 rpc->result = NACL_SRPC_RESULT_OK; | |
| 98 } | |
| 99 | |
| 100 void PpbWebSocketRpcServer::PPB_WebSocket_Close( | |
| 101 NaClSrpcRpc* rpc, | |
| 102 NaClSrpcClosure* done, | |
| 103 // inputs | |
| 104 PP_Resource ws, | |
| 105 int32_t code, | |
| 106 nacl_abi_size_t reason_size, | |
| 107 char* reason_bytes, | |
| 108 int32_t callback_id, | |
| 109 // outputs | |
| 110 int32_t* pp_error) { | |
| 111 NaClSrpcClosureRunner runner(done); | |
| 112 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 113 | |
| 114 PP_CompletionCallback remote_callback = | |
| 115 MakeRemoteCompletionCallback(rpc->channel, callback_id); | |
| 116 if (NULL == remote_callback.func) | |
| 117 return; | |
| 118 | |
| 119 PP_Var reason; | |
| 120 if (!DeserializeTo(reason_bytes, reason_size, 1, &reason)) | |
| 121 return; | |
| 122 | |
| 123 *pp_error = PPBWebSocketInterface()->Close( | |
| 124 ws, code, reason, remote_callback); | |
| 125 DebugPrintf("PPB_WebSocket::Close: pp_error=%"NACL_PRId32"\n", *pp_error); | |
| 126 | |
| 127 if (*pp_error != PP_OK_COMPLETIONPENDING) | |
| 128 DeleteRemoteCallbackInfo(remote_callback); | |
| 129 rpc->result = NACL_SRPC_RESULT_OK; | |
| 130 } | |
| 131 | |
| 132 void PpbWebSocketRpcServer::PPB_WebSocket_ReceiveMessage( | |
| 133 NaClSrpcRpc* rpc, | |
| 134 NaClSrpcClosure* done, | |
| 135 // inputs | |
| 136 PP_Resource ws, | |
| 137 int32_t callback_id, | |
| 138 // outputs | |
| 139 int32_t* pp_error) { | |
| 140 NaClSrpcClosureRunner runner(done); | |
| 141 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 142 | |
| 143 PP_Var* callback_var = NULL; | |
| 144 PP_CompletionCallback remote_callback = | |
| 145 MakeRemoteCompletionCallback(rpc->channel, callback_id, &callback_var); | |
| 146 if (NULL == remote_callback.func) | |
| 147 return; | |
| 148 | |
| 149 *pp_error = PPBWebSocketInterface()->ReceiveMessage( | |
| 150 ws, callback_var, remote_callback); | |
| 151 DebugPrintf("PPB_WebSocket::ReceiveMessage: pp_error=%"NACL_PRId32"\n", | |
| 152 *pp_error); | |
| 153 | |
| 154 if (*pp_error != PP_OK_COMPLETIONPENDING) | |
| 155 DeleteRemoteCallbackInfo(remote_callback); | |
| 156 rpc->result = NACL_SRPC_RESULT_OK; | |
| 157 } | |
| 158 | |
| 159 void PpbWebSocketRpcServer::PPB_WebSocket_SendMessage( | |
| 160 NaClSrpcRpc* rpc, | |
| 161 NaClSrpcClosure* done, | |
| 162 // inputs | |
| 163 PP_Resource ws, | |
| 164 nacl_abi_size_t message_size, | |
| 165 char* message_bytes, | |
| 166 // outputs | |
| 167 int32_t* pp_error) { | |
| 168 NaClSrpcClosureRunner runner(done); | |
| 169 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 170 | |
| 171 PP_Var message; | |
| 172 if (!DeserializeTo(message_bytes, message_size, 1, &message)) | |
| 173 return; | |
| 174 | |
| 175 *pp_error = PPBWebSocketInterface()->SendMessage(ws, message); | |
| 176 DebugPrintf("PPB_WebSocket::SendMessage: pp_error=%"NACL_PRId32"\n", | |
| 177 *pp_error); | |
| 178 | |
| 179 rpc->result = NACL_SRPC_RESULT_OK; | |
| 180 } | |
| 181 | |
| 182 void PpbWebSocketRpcServer::PPB_WebSocket_GetBufferedAmount( | |
| 183 NaClSrpcRpc* rpc, | |
| 184 NaClSrpcClosure* done, | |
| 185 // inputs | |
| 186 PP_Resource ws, | |
| 187 // outputs | |
| 188 int64_t* buffered_amount) { | |
| 189 NaClSrpcClosureRunner runner(done); | |
| 190 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 191 | |
| 192 *buffered_amount = static_cast<int64_t>( | |
| 193 PPBWebSocketInterface()->GetBufferedAmount(ws)); | |
| 194 DebugPrintf("PPB_WebSocket::GetBufferedAmount: buffered_amount=%lu\n", | |
| 195 *buffered_amount); | |
| 196 | |
| 197 rpc->result = NACL_SRPC_RESULT_OK; | |
| 198 } | |
| 199 | |
| 200 void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseCode( | |
| 201 NaClSrpcRpc* rpc, | |
| 202 NaClSrpcClosure* done, | |
| 203 // inputs | |
| 204 PP_Resource ws, | |
| 205 // outputs | |
| 206 int32_t* close_code) { | |
| 207 NaClSrpcClosureRunner runner(done); | |
| 208 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 209 | |
| 210 *close_code = static_cast<int32_t>( | |
| 211 PPBWebSocketInterface()->GetCloseCode(ws)); | |
| 212 DebugPrintf("PPB_WebSocket::GetCloseCode: close_code=%d\n", *close_code); | |
| 213 | |
| 214 rpc->result = NACL_SRPC_RESULT_OK; | |
| 215 } | |
| 216 | |
| 217 void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseReason( | |
| 218 NaClSrpcRpc* rpc, | |
| 219 NaClSrpcClosure* done, | |
| 220 // inputs | |
| 221 PP_Resource ws, | |
| 222 // outputs | |
| 223 nacl_abi_size_t* reason_size, | |
| 224 char* reason_bytes) { | |
| 225 NaClSrpcClosureRunner runner(done); | |
| 226 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 227 | |
| 228 PP_Var reason = PPBWebSocketInterface()->GetCloseReason(ws); | |
| 229 DebugPrintf("PPB_WebSocket::GetCloseReason:: reason.type=%d\n", reason.type); | |
| 230 | |
| 231 if (SerializeTo(&reason, reason_bytes, reason_size)) | |
| 232 rpc->result = NACL_SRPC_RESULT_OK; | |
| 233 } | |
| 234 | |
| 235 void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseWasClean( | |
| 236 NaClSrpcRpc* rpc, | |
| 237 NaClSrpcClosure* done, | |
| 238 // inputs | |
| 239 PP_Resource ws, | |
| 240 // outputs | |
| 241 int32_t* was_clean) { | |
| 242 NaClSrpcClosureRunner runner(done); | |
| 243 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 244 | |
| 245 PP_Bool pp_was_clean = PPBWebSocketInterface()->GetCloseWasClean(ws); | |
| 246 DebugPrintf("PPB_WebSocket::GetCloseWasClean: pp_was_clean=%d\n", | |
| 247 pp_was_clean); | |
| 248 | |
| 249 *was_clean = (pp_was_clean == PP_TRUE); | |
| 250 rpc->result = NACL_SRPC_RESULT_OK; | |
| 251 } | |
| 252 | |
| 253 void PpbWebSocketRpcServer::PPB_WebSocket_GetExtensions( | |
| 254 NaClSrpcRpc* rpc, | |
| 255 NaClSrpcClosure* done, | |
| 256 // inputs | |
| 257 PP_Resource ws, | |
| 258 // outputs | |
| 259 nacl_abi_size_t* extensions_size, | |
| 260 char* extensions_bytes) { | |
| 261 NaClSrpcClosureRunner runner(done); | |
| 262 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 263 | |
| 264 PP_Var extensions = PPBWebSocketInterface()->GetExtensions(ws); | |
| 265 DebugPrintf("PPB_WebSocket::GetExtensions:: extensions.type=%d\n", | |
| 266 extensions.type); | |
| 267 | |
| 268 if (SerializeTo(&extensions, extensions_bytes, extensions_size)) | |
| 269 rpc->result = NACL_SRPC_RESULT_OK; | |
| 270 } | |
| 271 | |
| 272 void PpbWebSocketRpcServer::PPB_WebSocket_GetProtocol( | |
| 273 NaClSrpcRpc* rpc, | |
| 274 NaClSrpcClosure* done, | |
| 275 // inputs | |
| 276 PP_Resource ws, | |
| 277 // outputs | |
| 278 nacl_abi_size_t* protocol_size, | |
| 279 char* protocol_bytes) { | |
| 280 NaClSrpcClosureRunner runner(done); | |
| 281 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 282 | |
| 283 PP_Var protocol = PPBWebSocketInterface()->GetProtocol(ws); | |
| 284 DebugPrintf("PPB_WebSocket::GetProtocol:: protocol.type=%d\n", | |
| 285 protocol.type); | |
| 286 | |
| 287 if (SerializeTo(&protocol, protocol_bytes, protocol_size)) | |
| 288 rpc->result = NACL_SRPC_RESULT_OK; | |
| 289 } | |
| 290 | |
| 291 void PpbWebSocketRpcServer::PPB_WebSocket_GetReadyState( | |
| 292 NaClSrpcRpc* rpc, | |
| 293 NaClSrpcClosure* done, | |
| 294 // inputs | |
| 295 PP_Resource ws, | |
| 296 // outputs | |
| 297 int32_t* ready_state) { | |
| 298 NaClSrpcClosureRunner runner(done); | |
| 299 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 300 | |
| 301 *ready_state = static_cast<int32_t>( | |
| 302 PPBWebSocketInterface()->GetReadyState(ws)); | |
| 303 DebugPrintf("PPB_WebSocket::GetReadyState:: ready_state=%d\n", ready_state); | |
| 304 | |
| 305 rpc->result = NACL_SRPC_RESULT_OK; | |
| 306 } | |
| 307 | |
| 308 void PpbWebSocketRpcServer::PPB_WebSocket_GetURL( | |
| 309 NaClSrpcRpc* rpc, | |
| 310 NaClSrpcClosure* done, | |
| 311 // inputs | |
| 312 PP_Resource ws, | |
| 313 // outputs | |
| 314 nacl_abi_size_t* url_size, | |
| 315 char* url_bytes) { | |
| 316 NaClSrpcClosureRunner runner(done); | |
| 317 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 318 | |
| 319 PP_Var url = PPBWebSocketInterface()->GetURL(ws); | |
| 320 DebugPrintf("PPB_WebSocket::GetURL:: url.type=%d\n", url.type); | |
| 321 | |
| 322 if (SerializeTo(&url, url_bytes, url_size)) | |
| 323 rpc->result = NACL_SRPC_RESULT_OK; | |
| 324 } | |
| 325 | |
| 326 void PpbWebSocketRpcServer::PPB_WebSocket_SetBinaryType( | |
| 327 NaClSrpcRpc* rpc, | |
| 328 NaClSrpcClosure* done, | |
| 329 // inputs | |
| 330 PP_Resource ws, | |
| 331 int32_t binary_type, | |
| 332 // outputs | |
| 333 int32_t* success) { | |
| 334 NaClSrpcClosureRunner runner(done); | |
| 335 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 336 | |
| 337 PP_Bool pp_success = PPBWebSocketInterface()->SetBinaryType( | |
| 338 ws, static_cast<PP_WebSocketBinaryType_Dev>(binary_type)); | |
| 339 DebugPrintf("PPB_WebSocket::SetBinaryType:: success=%d\n", pp_success); | |
| 340 | |
| 341 *success = (pp_success == PP_TRUE); | |
| 342 rpc->result = NACL_SRPC_RESULT_OK; | |
| 343 } | |
| 344 | |
| 345 void PpbWebSocketRpcServer::PPB_WebSocket_GetBinaryType( | |
| 346 NaClSrpcRpc* rpc, | |
| 347 NaClSrpcClosure* done, | |
| 348 // inputs | |
| 349 PP_Resource ws, | |
| 350 // outputs | |
| 351 int32_t* binary_type) { | |
| 352 NaClSrpcClosureRunner runner(done); | |
| 353 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 354 | |
| 355 *binary_type = static_cast<int32_t>( | |
| 356 PPBWebSocketInterface()->GetBinaryType(ws)); | |
| 357 DebugPrintf( | |
| 358 "PPB_WebSocket::GetBinaryType:: binary_type=%d\n", *binary_type); | |
| 359 | |
| 360 rpc->result = NACL_SRPC_RESULT_OK; | |
| 361 } | |
| OLD | NEW |