diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 08:44:47 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 08:44:47 +0000 |
commit | 9082aa5b3ae45dfc11394f2b23eb2f6f4b47c38c (patch) | |
tree | 265caf45929489312afc3d266065a3d24222afb8 /ppapi | |
parent | b3796c85f72d673203f203d655341876bf079948 (diff) | |
download | chromium_src-9082aa5b3ae45dfc11394f2b23eb2f6f4b47c38c.zip chromium_src-9082aa5b3ae45dfc11394f2b23eb2f6f4b47c38c.tar.gz chromium_src-9082aa5b3ae45dfc11394f2b23eb2f6f4b47c38c.tar.bz2 |
WebSocket Pepper API: SRPC proxy implementation
Implement PPB_WebSocket _Dev SRPC proxy
- support PP_Var write back in plugin/browser callback bridge
- resource leak fix in browser_callback
Enable all WebSocket related ppapi tests in NaCl
- support TEST_PPAPI_NACL_VIA_HTTP_WITH_WS macro in ppapi_uitest
- fix a test which expects synchronous completion
BUG=87310
TEST=ui_tests --gtest_filter='PPAPINaClTest.WebSocket_*'
Review URL: https://chromiumcodereview.appspot.com/9227008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
24 files changed, 1711 insertions, 14 deletions
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.cc index 234a93c..5f5e7c3 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "native_client/src/shared/platform/nacl_check.h" #include "native_client/src/shared/ppapi_proxy/browser_globals.h" #include "native_client/src/shared/ppapi_proxy/browser_ppp.h" +#include "native_client/src/shared/ppapi_proxy/object_serialize.h" #include "native_client/src/shared/ppapi_proxy/utility.h" #include "native_client/src/shared/srpc/nacl_srpc.h" #include "ppapi/c/pp_completion_callback.h" @@ -49,6 +50,7 @@ struct RemoteCallbackInfo { NaClSrpcChannel* srpc_channel; int32_t callback_id; char* read_buffer; + PP_Var read_var; CheckResultFunc check_result_func; GetReadSizeFunc get_size_read_func; }; @@ -83,6 +85,11 @@ void RunRemoteCallback(void* user_data, int32_t result) { GetReadSizeFunc get_size_read_func = remote_callback->get_size_read_func; if ((*check_result_func)(result) && remote_callback->read_buffer != NULL) read_buffer_size = (*get_size_read_func)(result); + if (remote_callback->read_var.type != PP_VARTYPE_NULL) { + read_buffer_size = kMaxReturnVarSize; + read_buffer.reset( + Serialize(&remote_callback->read_var, 1, &read_buffer_size)); + } NaClSrpcError srpc_result = CompletionCallbackRpcClient::RunCompletionCallback( @@ -106,14 +113,17 @@ struct PP_CompletionCallback MakeRemoteCompletionCallback( int32_t callback_id, int32_t bytes_to_read, char** buffer, + PP_Var** var, CheckResultFunc check_result_func, GetReadSizeFunc get_size_read_func) { - RemoteCallbackInfo* remote_callback = new(std::nothrow) RemoteCallbackInfo; - if (remote_callback == NULL) // new failed. + nacl::scoped_ptr<RemoteCallbackInfo> remote_callback( + new(std::nothrow) RemoteCallbackInfo); + if (remote_callback.get() == NULL) // new failed. return PP_BlockUntilComplete(); remote_callback->srpc_channel = srpc_channel; remote_callback->callback_id = callback_id; remote_callback->read_buffer = NULL; + remote_callback->read_var = PP_MakeNull(); remote_callback->check_result_func = check_result_func; remote_callback->get_size_read_func = get_size_read_func; @@ -123,9 +133,23 @@ struct PP_CompletionCallback MakeRemoteCompletionCallback( return PP_BlockUntilComplete(); remote_callback->read_buffer = *buffer; } + if (var) + *var = &remote_callback->read_var; return PP_MakeOptionalCompletionCallback( - RunRemoteCallback, remote_callback); + RunRemoteCallback, remote_callback.release()); +} + +struct PP_CompletionCallback MakeRemoteCompletionCallback( + NaClSrpcChannel* srpc_channel, + int32_t callback_id, + int32_t bytes_to_read, + char** buffer, + CheckResultFunc check_result_func, + GetReadSizeFunc get_size_read_func) { + return MakeRemoteCompletionCallback(srpc_channel, callback_id, bytes_to_read, + buffer, NULL, check_result_func, + get_size_read_func); } struct PP_CompletionCallback MakeRemoteCompletionCallback( @@ -139,6 +163,14 @@ struct PP_CompletionCallback MakeRemoteCompletionCallback( struct PP_CompletionCallback MakeRemoteCompletionCallback( NaClSrpcChannel* srpc_channel, + int32_t callback_id, + PP_Var** var) { + return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL, var, + BytesWereRead, CastToNaClAbiSize); +} + +struct PP_CompletionCallback MakeRemoteCompletionCallback( + NaClSrpcChannel* srpc_channel, int32_t callback_id) { return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL); } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.h b/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.h index 456b765..e4a133b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_callback.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ struct NaClSrpcChannel; struct PP_CompletionCallback; +struct PP_Var; namespace ppapi_proxy { @@ -40,6 +41,20 @@ struct PP_CompletionCallback MakeRemoteCompletionCallback( char** buffer, CheckResultFunc check_result, GetReadSizeFunc get_size_read_func); +struct PP_CompletionCallback MakeRemoteCompletionCallback( + NaClSrpcChannel* srpc_channel, + int32_t callback_id, + // For callbacks invoked on PP_Var read. + PP_Var** var); +struct PP_CompletionCallback MakeRemoteCompletionCallback( + NaClSrpcChannel* srpc_channel, + int32_t callback_id, + // For callbacks invoked on a byte read. + int32_t bytes_to_read, + char** buffer, + PP_Var** var, + CheckResultFunc check_result, + GetReadSizeFunc get_size_read_func); // If the callback won't be called, use this to clean up the data from // the function above. diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc index b8548da..001158e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc @@ -416,6 +416,13 @@ const PPB_View* PPBViewInterface() { return ppb; } +const PPB_WebSocket_Dev* PPBWebSocketInterface() { + static const PPB_WebSocket_Dev* ppb = + static_cast<const PPB_WebSocket_Dev*>( + GetBrowserInterfaceSafe(PPB_WEBSOCKET_DEV_INTERFACE)); + return ppb; +} + const PPB_Widget_Dev* PPBWidgetInterface() { static const PPB_Widget_Dev* ppb = static_cast<const PPB_Widget_Dev*>( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h index aa44ac4..8d63f38 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h @@ -13,6 +13,7 @@ #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_var_array_buffer_dev.h" +#include "ppapi/c/dev/ppb_websocket_dev.h" #include "ppapi/c/dev/ppb_widget_dev.h" #include "ppapi/c/dev/ppb_zoom_dev.h" #include "ppapi/c/pp_instance.h" @@ -132,6 +133,7 @@ const PPB_Var* PPBVarInterface(); // shared const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface(); // shared const PPB_View* PPBViewInterface(); const PPB_WheelInputEvent* PPBWheelInputEventInterface(); +const PPB_WebSocket_Dev* PPBWebSocketInterface(); const PPB_Widget_Dev* PPBWidgetInterface(); const PPB_Zoom_Dev* PPBZoomInterface(); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_websocket_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_websocket_rpc_server.cc new file mode 100644 index 0000000..01749fc --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_websocket_rpc_server.cc @@ -0,0 +1,360 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// SRPC-abstraction wrappers around PPB_WebSocket functions. + +#include "native_client/src/include/nacl_scoped_ptr.h" +#include "native_client/src/shared/ppapi_proxy/browser_callback.h" +#include "native_client/src/shared/ppapi_proxy/browser_globals.h" +#include "native_client/src/shared/ppapi_proxy/object_serialize.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/dev/ppb_websocket_dev.h" +#include "srpcgen/ppb_rpc.h" + +using ppapi_proxy::DebugPrintf; +using ppapi_proxy::DeleteRemoteCallbackInfo; +using ppapi_proxy::DeserializeTo; +using ppapi_proxy::MakeRemoteCompletionCallback; +using ppapi_proxy::PPBWebSocketInterface; +using ppapi_proxy::SerializeTo; + +void PpbWebSocketRpcServer::PPB_WebSocket_Create( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Instance instance, + // outputs + PP_Resource* resource) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + *resource = PPBWebSocketInterface()->Create(instance); + DebugPrintf("PPB_WebSocket::Create: resource=%"NACL_PRId32"\n", *resource); + + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_IsWebSocket( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource resource, + // outputs + int32_t* success) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Bool pp_success = PPBWebSocketInterface()->IsWebSocket(resource); + *success = PP_ToBool(pp_success); + DebugPrintf("PPB_WebSocket::IsWebSocket: success=%d\n", *success); + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_Connect( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + nacl_abi_size_t url_size, + char* url_bytes, + nacl_abi_size_t protocols_size, + char* protocols_bytes, + int32_t protocol_count, + int32_t callback_id, + // outputs + int32_t* pp_error) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_CompletionCallback remote_callback = + MakeRemoteCompletionCallback(rpc->channel, callback_id); + if (NULL == remote_callback.func) + return; + + PP_Var url; + if (!DeserializeTo(url_bytes, url_size, 1, &url)) + return; + + nacl::scoped_array<PP_Var> protocols(new PP_Var[protocol_count]); + if (!DeserializeTo( + protocols_bytes, protocols_size, protocol_count, protocols.get())) + return; + + *pp_error = PPBWebSocketInterface()->Connect( + ws, + url, + protocols.get(), + static_cast<uint32_t>(protocol_count), + remote_callback); + DebugPrintf("PPB_WebSocket::Connect: pp_error=%"NACL_PRId32"\n", *pp_error); + + if (*pp_error != PP_OK_COMPLETIONPENDING) + DeleteRemoteCallbackInfo(remote_callback); + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_Close( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + int32_t code, + nacl_abi_size_t reason_size, + char* reason_bytes, + int32_t callback_id, + // outputs + int32_t* pp_error) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_CompletionCallback remote_callback = + MakeRemoteCompletionCallback(rpc->channel, callback_id); + if (NULL == remote_callback.func) + return; + + PP_Var reason; + if (!DeserializeTo(reason_bytes, reason_size, 1, &reason)) + return; + + *pp_error = PPBWebSocketInterface()->Close( + ws, code, reason, remote_callback); + DebugPrintf("PPB_WebSocket::Close: pp_error=%"NACL_PRId32"\n", *pp_error); + + if (*pp_error != PP_OK_COMPLETIONPENDING) + DeleteRemoteCallbackInfo(remote_callback); + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_ReceiveMessage( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + int32_t callback_id, + // outputs + int32_t* pp_error) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Var* callback_var = NULL; + PP_CompletionCallback remote_callback = + MakeRemoteCompletionCallback(rpc->channel, callback_id, &callback_var); + if (NULL == remote_callback.func) + return; + + // The callback is always invoked asynchronously for now, so it doesn't care + // about re-entrancy. + *pp_error = PPBWebSocketInterface()->ReceiveMessage( + ws, callback_var, remote_callback); + DebugPrintf("PPB_WebSocket::ReceiveMessage: pp_error=%"NACL_PRId32"\n", + *pp_error); + + if (*pp_error != PP_OK_COMPLETIONPENDING) + DeleteRemoteCallbackInfo(remote_callback); + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_SendMessage( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + nacl_abi_size_t message_size, + char* message_bytes, + // outputs + int32_t* pp_error) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Var message; + if (!DeserializeTo(message_bytes, message_size, 1, &message)) + return; + + *pp_error = PPBWebSocketInterface()->SendMessage(ws, message); + DebugPrintf("PPB_WebSocket::SendMessage: pp_error=%"NACL_PRId32"\n", + *pp_error); + + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetBufferedAmount( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + int64_t* buffered_amount) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + *buffered_amount = static_cast<int64_t>( + PPBWebSocketInterface()->GetBufferedAmount(ws)); + DebugPrintf("PPB_WebSocket::GetBufferedAmount: buffered_amount=%lu\n", + *buffered_amount); + + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseCode( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + int32_t* close_code) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + *close_code = static_cast<int32_t>( + PPBWebSocketInterface()->GetCloseCode(ws)); + DebugPrintf("PPB_WebSocket::GetCloseCode: close_code=%d\n", *close_code); + + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseReason( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + nacl_abi_size_t* reason_size, + char* reason_bytes) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Var reason = PPBWebSocketInterface()->GetCloseReason(ws); + DebugPrintf("PPB_WebSocket::GetCloseReason:: reason.type=%d\n", reason.type); + + if (SerializeTo(&reason, reason_bytes, reason_size)) + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseWasClean( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + int32_t* was_clean) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Bool pp_was_clean = PPBWebSocketInterface()->GetCloseWasClean(ws); + *was_clean = PP_ToBool(pp_was_clean); + DebugPrintf("PPB_WebSocket::GetCloseWasClean: was_clean=%d\n", *was_clean); + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetExtensions( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + nacl_abi_size_t* extensions_size, + char* extensions_bytes) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Var extensions = PPBWebSocketInterface()->GetExtensions(ws); + DebugPrintf("PPB_WebSocket::GetExtensions:: extensions.type=%d\n", + extensions.type); + + if (SerializeTo(&extensions, extensions_bytes, extensions_size)) + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetProtocol( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + nacl_abi_size_t* protocol_size, + char* protocol_bytes) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Var protocol = PPBWebSocketInterface()->GetProtocol(ws); + DebugPrintf("PPB_WebSocket::GetProtocol:: protocol.type=%d\n", + protocol.type); + + if (SerializeTo(&protocol, protocol_bytes, protocol_size)) + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetReadyState( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + int32_t* ready_state) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + *ready_state = static_cast<int32_t>( + PPBWebSocketInterface()->GetReadyState(ws)); + DebugPrintf("PPB_WebSocket::GetReadyState:: ready_state=%d\n", ready_state); + + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetURL( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + nacl_abi_size_t* url_size, + char* url_bytes) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Var url = PPBWebSocketInterface()->GetURL(ws); + DebugPrintf("PPB_WebSocket::GetURL:: url.type=%d\n", url.type); + + if (SerializeTo(&url, url_bytes, url_size)) + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_SetBinaryType( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + int32_t binary_type, + // outputs + int32_t* success) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_Bool pp_success = PPBWebSocketInterface()->SetBinaryType( + ws, static_cast<PP_WebSocketBinaryType_Dev>(binary_type)); + *success = PP_ToBool(pp_success); + DebugPrintf("PPB_WebSocket::SetBinaryType:: success=%d\n", *success); + + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbWebSocketRpcServer::PPB_WebSocket_GetBinaryType( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Resource ws, + // outputs + int32_t* binary_type) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + *binary_type = static_cast<int32_t>( + PPBWebSocketInterface()->GetBinaryType(ws)); + DebugPrintf( + "PPB_WebSocket::GetBinaryType:: binary_type=%d\n", *binary_type); + + rpc->result = NACL_SRPC_RESULT_OK; +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/build.scons b/ppapi/native_client/src/shared/ppapi_proxy/build.scons index 9ccf14e..b1f803e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/build.scons +++ b/ppapi/native_client/src/shared/ppapi_proxy/build.scons @@ -64,6 +64,7 @@ env.DualLibrary('ppapi_browser', 'browser_ppb_url_loader_rpc_server.cc', 'browser_ppb_url_request_info_rpc_server.cc', 'browser_ppb_url_response_info_rpc_server.cc', + 'browser_ppb_websocket_rpc_server.cc', 'browser_ppb_widget_rpc_server.cc', 'browser_ppb_zoom_rpc_server.cc', 'browser_ppp_find.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons b/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons index aab055a..2bfed5d 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons +++ b/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons @@ -83,6 +83,7 @@ libppruntime = env.NaClSdkLibrary( 'plugin_ppb_url_response_info.cc', 'plugin_ppb_var.cc', 'plugin_ppb_view.cc', + 'plugin_ppb_websocket.cc', 'plugin_ppb_widget.cc', 'plugin_ppb_zoom.cc', 'plugin_ppp_find_rpc_server.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.cc index 7fac85a..54e8dd3 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" #include <string.h> +#include "native_client/src/shared/ppapi_proxy/object_serialize.h" #include "native_client/src/shared/ppapi_proxy/utility.h" #include "ppapi/c/pp_errors.h" #include "srpcgen/ppp_rpc.h" @@ -27,26 +28,41 @@ pthread_mutex_t CompletionCallbackTable::mutex_ = PTHREAD_MUTEX_INITIALIZER; int32_t CompletionCallbackTable::AddCallback( const PP_CompletionCallback& callback, - void* read_buffer) { + void* read_buffer, + PP_Var* read_var) { CallbackTableCriticalSection guard; + DCHECK (!read_buffer || !read_var); if (callback.func == NULL) { DebugPrintf("CompletionCallbackTable attempted to add NULL func!!\n"); return 0; } int32_t callback_id = next_id_; ++next_id_; - CallbackInfo info = { callback, read_buffer }; + CallbackInfo info = { callback, read_buffer, read_var }; table_.insert(std::pair<int32_t, CallbackInfo>(callback_id, info)); return callback_id; } int32_t CompletionCallbackTable::AddCallback( const PP_CompletionCallback& callback) { - return AddCallback(callback, NULL); + return AddCallback(callback, NULL, NULL); +} + +int32_t CompletionCallbackTable::AddCallback( + const PP_CompletionCallback& callback, + void* read_buffer) { + return AddCallback(callback, read_buffer, NULL); } +int32_t CompletionCallbackTable::AddCallback( + const PP_CompletionCallback& callback, + PP_Var* read_var) { + return AddCallback(callback, NULL, read_var); +} + + PP_CompletionCallback CompletionCallbackTable::RemoveCallback( - int32_t callback_id, void** read_buffer) { + int32_t callback_id, void** read_buffer, PP_Var** read_var) { CallbackTableCriticalSection guard; CallbackTable::iterator it = table_.find(callback_id); DebugPrintf("CompletionCallbackTable::RemoveCallback id: %"NACL_PRId32"\n", @@ -56,6 +72,8 @@ PP_CompletionCallback CompletionCallbackTable::RemoveCallback( table_.erase(it); if (read_buffer != NULL) *read_buffer = info.read_buffer; + if (read_var != NULL) + *read_var = info.read_var; return info.callback; } *read_buffer = NULL; @@ -77,9 +95,10 @@ void CompletionCallbackRpcServer::RunCompletionCallback( rpc->result = NACL_SRPC_RESULT_APP_ERROR; void* user_buffer; + PP_Var* user_var; PP_CompletionCallback callback = ppapi_proxy::CompletionCallbackTable::Get()->RemoveCallback( - callback_id, &user_buffer); + callback_id, &user_buffer, &user_var); if (callback.func == NULL) { ppapi_proxy::DebugPrintf( "CompletionCallbackRpcServer: id of %"NACL_PRId32" is NULL callback!\n", @@ -89,6 +108,8 @@ void CompletionCallbackRpcServer::RunCompletionCallback( if (user_buffer != NULL && read_buffer_size > 0) memcpy(user_buffer, read_buffer, read_buffer_size); + else if (user_var != NULL && read_buffer_size > 0) + ppapi_proxy::DeserializeTo(read_buffer, read_buffer_size, 1, user_var); PP_RunCompletionCallback(&callback, result); rpc->result = NACL_SRPC_RESULT_OK; diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.h index 658df75..72ba082 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_callback.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ #include <map> #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" #include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_var.h" namespace ppapi_proxy { @@ -32,19 +33,26 @@ class CompletionCallbackTable { // If |callback| is NULL, then returns 0. int32_t AddCallback(const PP_CompletionCallback& callback); int32_t AddCallback(const PP_CompletionCallback& callback, void* read_buffer); + int32_t AddCallback(const PP_CompletionCallback& callback, PP_Var* read_var); // Removes and returns the callback and optionally the associated // |read_buffer| corresponding to the given |callback_id|. // If no callback is found, returns a NULL callback. - PP_CompletionCallback RemoveCallback(int32_t callback_id, void** read_buffer); + PP_CompletionCallback RemoveCallback( + int32_t callback_id, void** read_buffer, PP_Var** read_var); private: // Currently implemented as singleton, so use a private constructor. CompletionCallbackTable() : next_id_(1) { } ~CompletionCallbackTable() { } + int32_t AddCallback(const PP_CompletionCallback& callback, + void* read_buffer, + PP_Var* read_var); + struct CallbackInfo { PP_CompletionCallback callback; void* read_buffer; // To be used with callbacks invoked on byte reads. + PP_Var* read_var; // To be used with callbacks invoked on PP_Var reads. }; typedef std::map<int32_t, CallbackInfo> CallbackTable; diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc index 5416468..1aef642 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc @@ -90,6 +90,11 @@ const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface() { GetBrowserInterfaceSafe(PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE)); } +const PPB_WebSocket_Dev* PPBWebSocketInterface() { + return static_cast<const PPB_WebSocket_Dev*>( + GetBrowserInterfaceSafe(PPB_WEBSOCKET_DEV_INTERFACE)); +} + // Plugin interface helpers const void* GetPluginInterface(const char* interface_name) { diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h index bfec43c..18ea331 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h @@ -7,6 +7,7 @@ #include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppb_var_array_buffer_dev.h" +#include "ppapi/c/dev/ppb_websocket_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_scrollbar_dev.h" @@ -55,6 +56,7 @@ const PPB_Core* PPBCoreInterface(); // shared const PPB_Memory_Dev* PPBMemoryInterface(); // shared const PPB_Var* PPBVarInterface(); // shared const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface(); // shared +const PPB_WebSocket_Dev* PPBWebSocketInterface(); // Support for getting PPP_ plugin interfaces. // Safe version CHECK's for NULL. diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc index ec8aefc..b57a8d4 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc @@ -38,6 +38,7 @@ #include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_response_info.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_view.h" +#include "native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_widget.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_zoom.h" #include "native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h" @@ -102,6 +103,8 @@ InterfaceMapElement interface_map[] = { { PPB_VAR_INTERFACE, PluginVar::GetInterface(), true }, { PPB_VAR_INTERFACE_1_0, PluginVar::GetInterface1_0(), true }, { PPB_VIEW_INTERFACE, PluginView::GetInterface(), true }, + { PPB_WEBSOCKET_DEV_INTERFACE, PluginWebSocket::GetInterface(), + true }, { PPB_WHEEL_INPUT_EVENT_INTERFACE, PluginInputEvent::GetWheelInterface(), true }, { PPB_WIDGET_DEV_INTERFACE, PluginWidget::GetInterface(), true }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc new file mode 100644 index 0000000..a24c654 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc @@ -0,0 +1,366 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h" + +#include "native_client/src/include/nacl_scoped_ptr.h" +#include "native_client/src/shared/ppapi_proxy/object_serialize.h" +#include "native_client/src/shared/ppapi_proxy/plugin_callback.h" +#include "native_client/src/shared/ppapi_proxy/plugin_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "native_client/src/shared/srpc/nacl_srpc.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/c/dev/ppb_websocket_dev.h" +#include "srpcgen/ppb_rpc.h" + +namespace ppapi_proxy { + +namespace { + +PP_Resource Create(PP_Instance instance) { + DebugPrintf("PPB_WebSocket::Create: instance=%"NACL_PRId32"\n", instance); + + PP_Resource resource; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_Create( + GetMainSrpcChannel(), instance, &resource); + DebugPrintf("PPB_WebSocket::Create: %s\n", NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK) + return resource; + return kInvalidResourceId; +} + +PP_Bool IsWebSocket(PP_Resource resource) { + DebugPrintf( + "PPB_WebSocket::IsWebSocket: resource=%"NACL_PRId32"\n", resource); + + int32_t is_websocket; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_IsWebSocket( + GetMainSrpcChannel(), resource, &is_websocket); + DebugPrintf("PPB_WebSocket::IsWebSocket: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK && is_websocket) + return PP_TRUE; + return PP_FALSE; +} + +int32_t Connect(PP_Resource ws, + PP_Var url, + const PP_Var protocols[], + uint32_t protocol_count, + PP_CompletionCallback callback) { + DebugPrintf("PPB_WebSocket::Connect: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t url_size = 0; + nacl::scoped_array<char> url_bytes(Serialize(&url, 1, &url_size)); + + nacl_abi_size_t protocols_size = 0; + nacl::scoped_array<char> protocols_bytes( + Serialize(protocols, protocol_count, &protocols_size)); + + int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); + if (callback_id == 0) + return PP_ERROR_BLOCKS_MAIN_THREAD; + + int32_t pp_error; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_Connect( + GetMainSrpcChannel(), + ws, + url_size, url_bytes.get(), + protocols_size, protocols_bytes.get(), + static_cast<int32_t>(protocol_count), + callback_id, + &pp_error); + DebugPrintf("PPB_WebSocket::Connect: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + pp_error = PP_ERROR_FAILED; + return MayForceCallback(callback, pp_error); +} + +int32_t Close(PP_Resource ws, + uint16_t code, + PP_Var reason, + PP_CompletionCallback callback) { + DebugPrintf("PPB_WebSocket::Close: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t reason_size = 0; + nacl::scoped_array<char> reason_bytes(Serialize(&reason, 1, &reason_size)); + + int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); + if (callback_id == 0) + return PP_ERROR_BLOCKS_MAIN_THREAD; + + int32_t pp_error; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_Close( + GetMainSrpcChannel(), + ws, + code, + reason_size, reason_bytes.get(), + callback_id, + &pp_error); + DebugPrintf("PPB_WebSocket::Close: %s\n", NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + pp_error = PP_ERROR_FAILED; + return MayForceCallback(callback, pp_error); +} + +int32_t ReceiveMessage(PP_Resource ws, + PP_Var* message, + PP_CompletionCallback callback) { + DebugPrintf("PPB_WebSocket::ReceiveMessage: ws=%"NACL_PRId32"\n", ws); + + int32_t callback_id = + CompletionCallbackTable::Get()->AddCallback(callback, message); + if (callback_id == 0) + return PP_ERROR_BLOCKS_MAIN_THREAD; + + // TODO(toyoshim): ReceiveMessage needs performance optimization to reduce + // chances to call RPC. + int32_t pp_error; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage( + GetMainSrpcChannel(), + ws, + callback_id, + &pp_error); + DebugPrintf("PPB_WebSocket::ReceiveMessage: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + pp_error = PP_ERROR_FAILED; + return MayForceCallback(callback, pp_error); +} + +int32_t SendMessage(PP_Resource ws, + PP_Var message) { + DebugPrintf("PPB_WebSocket::SendMessage: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t message_size = 0; + nacl::scoped_array<char> message_bytes( + Serialize(&message, 1, &message_size)); + + int32_t pp_error; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_SendMessage( + GetMainSrpcChannel(), + ws, + message_size, message_bytes.get(), + &pp_error); + DebugPrintf("PPB_WebSocket::SendMessage: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + return PP_ERROR_FAILED; + return pp_error; +} + +uint64_t GetBufferedAmount(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetBufferedAmount: ws=%"NACL_PRId32"\n", ws); + + int64_t buffered_amount = 0; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetBufferedAmount( + GetMainSrpcChannel(), ws, &buffered_amount); + DebugPrintf("PPB_WebSocket::GetBufferedAmount: %s\n", + NaClSrpcErrorString(srpc_result)); + + return static_cast<uint64_t>(buffered_amount); +} + +uint16_t GetCloseCode(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetCloseCode: ws=%"NACL_PRId32"\n", ws); + + int32_t close_code = 0; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetCloseCode( + GetMainSrpcChannel(), ws, &close_code); + DebugPrintf("PPB_WebSocket::GetCloseCode: %s\n", + NaClSrpcErrorString(srpc_result)); + + return static_cast<uint16_t>(close_code); +} + +PP_Var GetCloseReason(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetCloseReason: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t reason_size = kMaxReturnVarSize; + nacl::scoped_array<char> reason_bytes(new char[reason_size]); + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetCloseReason( + GetMainSrpcChannel(), ws, &reason_size, reason_bytes.get()); + DebugPrintf("PPB_WebSocket::GetCloseReason: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK) { + PP_Var reason = PP_MakeUndefined(); + if (DeserializeTo(reason_bytes.get(), reason_size, 1, &reason)) + return reason; + } + + return PP_MakeUndefined(); +} + +PP_Bool GetCloseWasClean(PP_Resource ws) { + DebugPrintf( + "PPB_WebSocket::GetCloseWasClean: ws=%"NACL_PRId32"\n", ws); + + int32_t was_clean; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetCloseWasClean( + GetMainSrpcChannel(), ws, &was_clean); + DebugPrintf("PPB_WebSocket::GetCloseWasClean: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK && was_clean) + return PP_TRUE; + return PP_FALSE; +} + +PP_Var GetExtensions(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetExtensions: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t extensions_size = kMaxReturnVarSize; + nacl::scoped_array<char> extensions_bytes(new char[extensions_size]); + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetExtensions( + GetMainSrpcChannel(), ws, &extensions_size, extensions_bytes.get()); + DebugPrintf("PPB_WebSocket::GetExtensions: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK) { + PP_Var extensions = PP_MakeUndefined(); + if (DeserializeTo(extensions_bytes.get(), extensions_size, 1, &extensions)) + return extensions; + } + + return PP_MakeUndefined(); +} + +PP_Var GetProtocol(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetProtocol: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t protocol_size = kMaxReturnVarSize; + nacl::scoped_array<char> protocol_bytes(new char[protocol_size]); + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetProtocol( + GetMainSrpcChannel(), ws, &protocol_size, protocol_bytes.get()); + DebugPrintf("PPB_WebSocket::GetProtocol: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK) { + PP_Var protocol = PP_MakeUndefined(); + if (DeserializeTo(protocol_bytes.get(), protocol_size, 1, &protocol)) + return protocol; + } + + return PP_MakeUndefined(); +} + +PP_WebSocketReadyState_Dev GetReadyState(PP_Resource ws) { + DebugPrintf( + "PPB_WebSocket::GetReadyState: ws=%"NACL_PRId32"\n", ws); + + int32_t ready_state; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetReadyState( + GetMainSrpcChannel(), ws, &ready_state); + DebugPrintf("PPB_WebSocket::GetReadyState: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + return PP_WEBSOCKETREADYSTATE_INVALID_DEV; + return static_cast<PP_WebSocketReadyState_Dev>(ready_state); +} + +PP_Var GetURL(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetURL: ws=%"NACL_PRId32"\n", ws); + + nacl_abi_size_t url_size = kMaxReturnVarSize; + nacl::scoped_array<char> url_bytes(new char[url_size]); + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetURL( + GetMainSrpcChannel(), ws, &url_size, url_bytes.get()); + DebugPrintf("PPB_WebSocket::GetURL: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK) { + PP_Var url = PP_MakeUndefined(); + if (DeserializeTo(url_bytes.get(), url_size, 1, &url)) + return url; + } + + return PP_MakeUndefined(); +} + +PP_Bool SetBinaryType(PP_Resource ws, + PP_WebSocketBinaryType_Dev binary_type) { + DebugPrintf("PPB_WebSocket::SetBinaryType: ws=%"NACL_PRId32"\n", ws); + + int32_t success; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_SetBinaryType( + GetMainSrpcChannel(), + ws, + static_cast<int32_t>(binary_type), + &success); + DebugPrintf("PPB_WebSocket::SetBinaryType: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK && success) + return PP_TRUE; + return PP_FALSE; +} + +PP_WebSocketBinaryType_Dev GetBinaryType(PP_Resource ws) { + DebugPrintf("PPB_WebSocket::GetBinaryType: ws=%"NACL_PRId32"\n", ws); + + int32_t binary_type; + NaClSrpcError srpc_result = + PpbWebSocketRpcClient::PPB_WebSocket_GetBinaryType( + GetMainSrpcChannel(), + ws, + &binary_type); + DebugPrintf("PPB_WebSocket::GetBinaryType: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + return PP_WEBSOCKETBINARYTYPE_INVALID; + return static_cast<PP_WebSocketBinaryType_Dev>(binary_type); +} + +} // namespace + +const PPB_WebSocket_Dev* PluginWebSocket::GetInterface() { + static const PPB_WebSocket_Dev websocket_interface = { + &Create, + &IsWebSocket, + &Connect, + &Close, + &ReceiveMessage, + &SendMessage, + &GetBufferedAmount, + &GetCloseCode, + &GetCloseReason, + &GetCloseWasClean, + &GetExtensions, + &GetProtocol, + &GetReadyState, + &GetURL, + &SetBinaryType, + &GetBinaryType + }; + return &websocket_interface; +} + +} // namespace ppapi_proxy diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h new file mode 100644 index 0000000..fb209ac --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h @@ -0,0 +1,24 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_WEBSOCKET_H_ +#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_WEBSOCKET_H_ + +#include "native_client/src/include/nacl_macros.h" +#include "ppapi/c/dev/ppb_websocket_dev.h" + +namespace ppapi_proxy { + +// Implements the untrusted side of the PPB_WebSocket interface. +class PluginWebSocket { + public: + static const PPB_WebSocket_Dev* GetInterface(); + + private: + NACL_DISALLOW_COPY_AND_ASSIGN(PluginWebSocket); +}; + +} // namespace ppapi_proxy + +#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_WEBSOCKET_H_ diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp index 5956b32..354683d 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp @@ -42,6 +42,7 @@ 'browser_ppb_url_loader_rpc_server.cc', 'browser_ppb_url_request_info_rpc_server.cc', 'browser_ppb_url_response_info_rpc_server.cc', + 'browser_ppb_websocket_rpc_server.cc', 'browser_ppb_widget_rpc_server.cc', 'browser_ppb_zoom_rpc_server.cc', 'browser_ppp_find.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp index 8f1a457..58dad08 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp @@ -80,6 +80,7 @@ 'plugin_ppb_url_response_info.cc', 'plugin_ppb_var.cc', 'plugin_ppb_view.cc', + 'plugin_ppb_websocket.cc', 'plugin_ppb_widget.cc', 'plugin_ppb_zoom.cc', 'plugin_ppp_find_rpc_server.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index 8e52b59..1f51f54 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -3182,6 +3182,298 @@ NaClSrpcError PpbURLResponseInfoRpcClient::PPB_URLResponseInfo_GetBodyAsFileRef( return retval; } +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_Create( + NaClSrpcChannel* channel, + PP_Instance instance, + PP_Resource* resource) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_Create:i:i", + instance, + resource + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_IsWebSocket( + NaClSrpcChannel* channel, + PP_Resource instance, + int32_t* is_websocket) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_IsWebSocket:i:i", + instance, + is_websocket + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_Connect( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t url_bytes, char* url, + nacl_abi_size_t protocols_bytes, char* protocols, + int32_t protocol_count, + int32_t callback_id, + int32_t* pp_error) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_Connect:iCCii:i", + ws, + url_bytes, url, + protocols_bytes, protocols, + protocol_count, + callback_id, + pp_error + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_Close( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t code, + nacl_abi_size_t reason_bytes, char* reason, + int32_t callback_id, + int32_t* pp_error) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_Close:iiCi:i", + ws, + code, + reason_bytes, reason, + callback_id, + pp_error + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t callback_id, + int32_t* pp_error) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_ReceiveMessage:ii:i", + ws, + callback_id, + pp_error + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_SendMessage( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t message_bytes, char* message, + int32_t* pp_error) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_SendMessage:iC:i", + ws, + message_bytes, message, + pp_error + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetBufferedAmount( + NaClSrpcChannel* channel, + PP_Resource ws, + int64_t* buffered_amount) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetBufferedAmount:i:l", + ws, + buffered_amount + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetCloseCode( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* close_code) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetCloseCode:i:i", + ws, + close_code + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetCloseReason( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* reason_bytes, char* reason) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetCloseReason:i:C", + ws, + reason_bytes, reason + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetCloseWasClean( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* was_clean) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetCloseWasClean:i:i", + ws, + was_clean + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetExtensions( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* extensions_bytes, char* extensions) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetExtensions:i:C", + ws, + extensions_bytes, extensions + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetProtocol( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* protocol_bytes, char* protocol) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetProtocol:i:C", + ws, + protocol_bytes, protocol + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetReadyState( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* ready_state) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetReadyState:i:i", + ws, + ready_state + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetURL( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* url_bytes, char* url) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetURL:i:C", + ws, + url_bytes, url + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_SetBinaryType( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t binary_type, + int32_t* success) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_SetBinaryType:ii:i", + ws, + binary_type, + success + ); + return retval; +} + +NaClSrpcError PpbWebSocketRpcClient::PPB_WebSocket_GetBinaryType( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* binary_type) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_WebSocket_GetBinaryType:i:i", + ws, + binary_type + ); + return retval; +} + NaClSrpcError PpbWidgetRpcClient::PPB_Widget_IsWidget( NaClSrpcChannel* channel, PP_Resource resource, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index f5b63a8..31a0a6f 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -2555,6 +2555,240 @@ static void PPB_URLResponseInfo_GetBodyAsFileRefDispatcher( ); } +static void PPB_WebSocket_CreateDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_Create( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_IsWebSocketDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_IsWebSocket( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_ConnectDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_Connect( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.count, inputs[1]->arrays.carr, + inputs[2]->u.count, inputs[2]->arrays.carr, + inputs[3]->u.ival, + inputs[4]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_CloseDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_Close( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.ival, + inputs[2]->u.count, inputs[2]->arrays.carr, + inputs[3]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_ReceiveMessageDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_ReceiveMessage( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_SendMessageDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_SendMessage( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.count, inputs[1]->arrays.carr, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_GetBufferedAmountDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetBufferedAmount( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.lval) + ); +} + +static void PPB_WebSocket_GetCloseCodeDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetCloseCode( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_GetCloseReasonDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetCloseReason( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr + ); +} + +static void PPB_WebSocket_GetCloseWasCleanDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetCloseWasClean( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_GetExtensionsDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetExtensions( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr + ); +} + +static void PPB_WebSocket_GetProtocolDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetProtocol( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr + ); +} + +static void PPB_WebSocket_GetReadyStateDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetReadyState( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_GetURLDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetURL( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr + ); +} + +static void PPB_WebSocket_SetBinaryTypeDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_SetBinaryType( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_WebSocket_GetBinaryTypeDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbWebSocketRpcServer::PPB_WebSocket_GetBinaryType( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.ival) + ); +} + static void PPB_Widget_IsWidgetDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -2830,6 +3064,22 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_URLResponseInfo_IsURLResponseInfo:i:i", PPB_URLResponseInfo_IsURLResponseInfoDispatcher }, { "PPB_URLResponseInfo_GetProperty:ii:C", PPB_URLResponseInfo_GetPropertyDispatcher }, { "PPB_URLResponseInfo_GetBodyAsFileRef:i:i", PPB_URLResponseInfo_GetBodyAsFileRefDispatcher }, + { "PPB_WebSocket_Create:i:i", PPB_WebSocket_CreateDispatcher }, + { "PPB_WebSocket_IsWebSocket:i:i", PPB_WebSocket_IsWebSocketDispatcher }, + { "PPB_WebSocket_Connect:iCCii:i", PPB_WebSocket_ConnectDispatcher }, + { "PPB_WebSocket_Close:iiCi:i", PPB_WebSocket_CloseDispatcher }, + { "PPB_WebSocket_ReceiveMessage:ii:i", PPB_WebSocket_ReceiveMessageDispatcher }, + { "PPB_WebSocket_SendMessage:iC:i", PPB_WebSocket_SendMessageDispatcher }, + { "PPB_WebSocket_GetBufferedAmount:i:l", PPB_WebSocket_GetBufferedAmountDispatcher }, + { "PPB_WebSocket_GetCloseCode:i:i", PPB_WebSocket_GetCloseCodeDispatcher }, + { "PPB_WebSocket_GetCloseReason:i:C", PPB_WebSocket_GetCloseReasonDispatcher }, + { "PPB_WebSocket_GetCloseWasClean:i:i", PPB_WebSocket_GetCloseWasCleanDispatcher }, + { "PPB_WebSocket_GetExtensions:i:C", PPB_WebSocket_GetExtensionsDispatcher }, + { "PPB_WebSocket_GetProtocol:i:C", PPB_WebSocket_GetProtocolDispatcher }, + { "PPB_WebSocket_GetReadyState:i:i", PPB_WebSocket_GetReadyStateDispatcher }, + { "PPB_WebSocket_GetURL:i:C", PPB_WebSocket_GetURLDispatcher }, + { "PPB_WebSocket_SetBinaryType:ii:i", PPB_WebSocket_SetBinaryTypeDispatcher }, + { "PPB_WebSocket_GetBinaryType:i:i", PPB_WebSocket_GetBinaryTypeDispatcher }, { "PPB_Widget_IsWidget:i:i", PPB_Widget_IsWidgetDispatcher }, { "PPB_Widget_Paint:iCi:i", PPB_Widget_PaintDispatcher }, { "PPB_Widget_HandleEvent:ii:i", PPB_Widget_HandleEventDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc new file mode 100644 index 0000000..9f6a8c0 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc @@ -0,0 +1,118 @@ +# Copyright (c) 2012 The Native Client Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# RPC methods used to implement PPB_WebSocket_Dev calls from the plugin. +# See ppapi/c/dev/ppb_websocket_dev.h for interface details. + +{ + 'name': 'PpbWebSocketRpc', + 'rpcs': [ + {'name': 'PPB_WebSocket_Create', + 'inputs': [['instance', 'PP_Instance'], # PP_Instance + ], + 'outputs': [['resource', 'PP_Resource'], # PP_Resource + ] + }, + {'name': 'PPB_WebSocket_IsWebSocket', + 'inputs': [['instance', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['is_websocket', 'int32_t'], # PP_Bool + ] + }, + {'name': 'PPB_WebSocket_Connect', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ['url', 'char[]'], # PP_Var + ['protocols', 'char[]'], # PP_Var[] + ['protocol_count', 'int32_t'], # uint32_t + ['callback_id', 'int32_t'], # PP_CompletionCallback + ], + 'outputs': [['pp_error', 'int32_t'], # int32_t + ] + }, + {'name': 'PPB_WebSocket_Close', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ['code', 'int32_t'], # uint16_t + ['reason', 'char[]'], # PP_Var + ['callback_id', 'int32_t'], # PP_CompletionCallback + ], + 'outputs': [['pp_error', 'int32_t'], # int32_t + ] + }, + {'name': 'PPB_WebSocket_ReceiveMessage', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ['callback_id', 'int32_t'], # PP_CompletionCallback + ], + 'outputs': [['pp_error', 'int32_t'], # int32_t + ] + }, + {'name': 'PPB_WebSocket_SendMessage', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ['message', 'char[]'], # PP_Var + ], + 'outputs': [['pp_error', 'int32_t'], # int32_t + ] + }, + {'name': 'PPB_WebSocket_GetBufferedAmount', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['buffered_amount', 'int64_t'], # uint64_t + ] + }, + {'name': 'PPB_WebSocket_GetCloseCode', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['close_code', 'int32_t'], # uint16_t + ] + }, + {'name': 'PPB_WebSocket_GetCloseReason', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['reason', 'char[]'], # PP_Var + ] + }, + {'name': 'PPB_WebSocket_GetCloseWasClean', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['was_clean', 'int32_t'], # PP_Bool + ] + }, + {'name': 'PPB_WebSocket_GetExtensions', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['extensions', 'char[]'], # PP_Var + ] + }, + {'name': 'PPB_WebSocket_GetProtocol', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['protocol', 'char[]'], # PP_Var + ] + }, + {'name': 'PPB_WebSocket_GetReadyState', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['ready_state', 'int32_t'], # PP_WebSocketReadyState + ] + }, + {'name': 'PPB_WebSocket_GetURL', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['url', 'char[]'], # PP_Var + ] + }, + {'name': 'PPB_WebSocket_SetBinaryType', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ['binary_type', 'int32_t'], # PP_WebSocketBinaryType + ], + 'outputs': [['success', 'int32_t'], # PP_Bool + ] + }, + {'name': 'PPB_WebSocket_GetBinaryType', + 'inputs': [['ws', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['binary_type', 'int32_t'], # PP_WebSocketBinaryType + ] + } + ] +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py b/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py index 508dcdd..2323430 100755 --- a/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py +++ b/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py @@ -85,6 +85,7 @@ all_units = [ 'ppb_url_loader.srpc', 'ppb_url_request_info.srpc', 'ppb_url_response_info.srpc', + 'ppb_websocket.srpc', 'ppb_widget.srpc', 'ppb_zoom.srpc', ]}, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index 36e65e0..d6fa45e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -1281,6 +1281,105 @@ class PpbURLResponseInfoRpcServer { void operator=(const PpbURLResponseInfoRpcServer); }; // class PpbURLResponseInfoRpcServer +class PpbWebSocketRpcServer { + public: + static void PPB_WebSocket_Create( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + PP_Resource* resource); + static void PPB_WebSocket_IsWebSocket( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource instance, + int32_t* is_websocket); + static void PPB_WebSocket_Connect( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + nacl_abi_size_t url_bytes, char* url, + nacl_abi_size_t protocols_bytes, char* protocols, + int32_t protocol_count, + int32_t callback_id, + int32_t* pp_error); + static void PPB_WebSocket_Close( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t code, + nacl_abi_size_t reason_bytes, char* reason, + int32_t callback_id, + int32_t* pp_error); + static void PPB_WebSocket_ReceiveMessage( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t callback_id, + int32_t* pp_error); + static void PPB_WebSocket_SendMessage( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + nacl_abi_size_t message_bytes, char* message, + int32_t* pp_error); + static void PPB_WebSocket_GetBufferedAmount( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int64_t* buffered_amount); + static void PPB_WebSocket_GetCloseCode( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t* close_code); + static void PPB_WebSocket_GetCloseReason( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + nacl_abi_size_t* reason_bytes, char* reason); + static void PPB_WebSocket_GetCloseWasClean( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t* was_clean); + static void PPB_WebSocket_GetExtensions( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + nacl_abi_size_t* extensions_bytes, char* extensions); + static void PPB_WebSocket_GetProtocol( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + nacl_abi_size_t* protocol_bytes, char* protocol); + static void PPB_WebSocket_GetReadyState( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t* ready_state); + static void PPB_WebSocket_GetURL( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + nacl_abi_size_t* url_bytes, char* url); + static void PPB_WebSocket_SetBinaryType( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t binary_type, + int32_t* success); + static void PPB_WebSocket_GetBinaryType( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource ws, + int32_t* binary_type); + + private: + PpbWebSocketRpcServer(); + PpbWebSocketRpcServer(const PpbWebSocketRpcServer&); + void operator=(const PpbWebSocketRpcServer); +}; // class PpbWebSocketRpcServer + class PpbWidgetRpcServer { public: static void PPB_Widget_IsWidget( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index 1ed396b..c76832c 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -1115,6 +1115,89 @@ class PpbURLResponseInfoRpcClient { void operator=(const PpbURLResponseInfoRpcClient); }; // class PpbURLResponseInfoRpcClient +class PpbWebSocketRpcClient { + public: + static NaClSrpcError PPB_WebSocket_Create( + NaClSrpcChannel* channel, + PP_Instance instance, + PP_Resource* resource); + static NaClSrpcError PPB_WebSocket_IsWebSocket( + NaClSrpcChannel* channel, + PP_Resource instance, + int32_t* is_websocket); + static NaClSrpcError PPB_WebSocket_Connect( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t url_bytes, char* url, + nacl_abi_size_t protocols_bytes, char* protocols, + int32_t protocol_count, + int32_t callback_id, + int32_t* pp_error); + static NaClSrpcError PPB_WebSocket_Close( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t code, + nacl_abi_size_t reason_bytes, char* reason, + int32_t callback_id, + int32_t* pp_error); + static NaClSrpcError PPB_WebSocket_ReceiveMessage( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t callback_id, + int32_t* pp_error); + static NaClSrpcError PPB_WebSocket_SendMessage( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t message_bytes, char* message, + int32_t* pp_error); + static NaClSrpcError PPB_WebSocket_GetBufferedAmount( + NaClSrpcChannel* channel, + PP_Resource ws, + int64_t* buffered_amount); + static NaClSrpcError PPB_WebSocket_GetCloseCode( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* close_code); + static NaClSrpcError PPB_WebSocket_GetCloseReason( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* reason_bytes, char* reason); + static NaClSrpcError PPB_WebSocket_GetCloseWasClean( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* was_clean); + static NaClSrpcError PPB_WebSocket_GetExtensions( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* extensions_bytes, char* extensions); + static NaClSrpcError PPB_WebSocket_GetProtocol( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* protocol_bytes, char* protocol); + static NaClSrpcError PPB_WebSocket_GetReadyState( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* ready_state); + static NaClSrpcError PPB_WebSocket_GetURL( + NaClSrpcChannel* channel, + PP_Resource ws, + nacl_abi_size_t* url_bytes, char* url); + static NaClSrpcError PPB_WebSocket_SetBinaryType( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t binary_type, + int32_t* success); + static NaClSrpcError PPB_WebSocket_GetBinaryType( + NaClSrpcChannel* channel, + PP_Resource ws, + int32_t* binary_type); + + private: + PpbWebSocketRpcClient(); + PpbWebSocketRpcClient(const PpbWebSocketRpcClient&); + void operator=(const PpbWebSocketRpcClient); +}; // class PpbWebSocketRpcClient + class PpbWidgetRpcClient { public: static NaClSrpcError PPB_Widget_IsWidget( diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index 2c82412..9f094d2 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -313,6 +313,7 @@ 'tests/test_url_loader.cc', 'tests/test_var.cc', 'tests/test_view.cc', + 'tests/test_websocket.cc', ], # # Sources used in trusted tests. diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc index 34b56b0..f129420 100644 --- a/ppapi/tests/test_websocket.cc +++ b/ppapi/tests/test_websocket.cc @@ -249,8 +249,12 @@ std::string TestWebSocket::TestProtocols() { PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); ASSERT_TRUE(ws); + TestCompletionCallback callback(instance_->pp_instance(), force_async_); int32_t result = websocket_interface_->Connect( - ws, url, bad_protocols, 2U, PP_BlockUntilComplete()); + ws, url, bad_protocols, 2U, + static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); + if (result == PP_OK_COMPLETIONPENDING) + result = callback.WaitForResult(); ASSERT_EQ(PP_ERROR_BADARGUMENT, result); core_interface_->ReleaseResource(ws); |