From 5350822e0ce84c1284f0631ff5f3e6cce81d9e21 Mon Sep 17 00:00:00 2001 From: "toyoshim@chromium.org" Date: Fri, 27 Jan 2012 09:42:41 +0000 Subject: WebSocket Pepper API: make the API out of dev BUG=87310 TEST=ui_test Review URL: http://codereview.chromium.org/9192009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119425 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/api/dev/ppb_websocket_dev.idl | 301 ------------------- ppapi/api/ppb_websocket.idl | 301 +++++++++++++++++++ ppapi/c/dev/ppb_websocket_dev.h | 317 --------------------- ppapi/c/ppb_websocket.h | 317 +++++++++++++++++++++ ppapi/cpp/dev/websocket_dev.h | 185 ------------ ppapi/cpp/websocket.cc | 148 ++++++++++ ppapi/cpp/websocket.h | 185 ++++++++++++ .../src/shared/ppapi_proxy/browser_globals.cc | 8 +- .../src/shared/ppapi_proxy/browser_globals.h | 4 +- .../browser_ppb_websocket_rpc_server.cc | 2 +- .../src/shared/ppapi_proxy/plugin_globals.cc | 6 +- .../src/shared/ppapi_proxy/plugin_globals.h | 4 +- .../src/shared/ppapi_proxy/plugin_ppb.cc | 2 +- .../src/shared/ppapi_proxy/plugin_ppb_websocket.cc | 12 +- .../src/shared/ppapi_proxy/plugin_ppb_websocket.h | 4 +- .../src/shared/ppapi_proxy/ppb_websocket.srpc | 4 +- ppapi/ppapi_sources.gypi | 6 +- ppapi/tests/all_c_includes.h | 2 +- ppapi/tests/all_cpp_includes.h | 2 +- ppapi/tests/test_websocket.cc | 22 +- ppapi/tests/test_websocket.h | 4 +- ppapi/thunk/interfaces_ppb_public_dev.h | 4 +- ppapi/thunk/ppb_websocket_api.h | 4 +- ppapi/thunk/ppb_websocket_thunk.cc | 10 +- ppapi/thunk/resource_creation_api.h | 2 +- 25 files changed, 1002 insertions(+), 854 deletions(-) delete mode 100644 ppapi/api/dev/ppb_websocket_dev.idl create mode 100644 ppapi/api/ppb_websocket.idl delete mode 100644 ppapi/c/dev/ppb_websocket_dev.h create mode 100644 ppapi/c/ppb_websocket.h delete mode 100644 ppapi/cpp/dev/websocket_dev.h create mode 100644 ppapi/cpp/websocket.cc create mode 100644 ppapi/cpp/websocket.h (limited to 'ppapi') diff --git a/ppapi/api/dev/ppb_websocket_dev.idl b/ppapi/api/dev/ppb_websocket_dev.idl deleted file mode 100644 index 0a68e7c..0000000 --- a/ppapi/api/dev/ppb_websocket_dev.idl +++ /dev/null @@ -1,301 +0,0 @@ -/* 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. - */ - -/** - * This file defines the PPB_WebSocket_Dev interface. - */ -label Chrome { - M17 = 0.1 -}; - - -/** - * This enumeration contains the types representing the WebSocket ready state - * and these states are based on the JavaScript WebSocket API specification. - * GetReadyState() returns one of these states. - */ -[assert_size(4)] -enum PP_WebSocketReadyState_Dev { - /** - * Ready state is queried on an invalid resource. - */ - PP_WEBSOCKETREADYSTATE_INVALID_DEV = -1, - /** - * Ready state that the connection has not yet been established. - */ - PP_WEBSOCKETREADYSTATE_CONNECTING_DEV = 0, - - /** - * Ready state that the WebSocket connection is established and communication - * is possible. - */ - PP_WEBSOCKETREADYSTATE_OPEN_DEV = 1, - - /** - * Ready state that the connection is going through the closing handshake. - */ - PP_WEBSOCKETREADYSTATE_CLOSING_DEV = 2, - - /** - * Ready state that the connection has been closed or could not be opened. - */ - PP_WEBSOCKETREADYSTATE_CLOSED_DEV = 3 -}; - -interface PPB_WebSocket_Dev { - /** - * Create() creates a WebSocket instance. - * - * @param[in] instance A PP_Instance identifying the instance - * with the WebSocket. - * - * @return A PP_Resource corresponding to a WebSocket if - * successful. - */ - PP_Resource Create([in] PP_Instance instance); - - /** - * IsWebSocket() determines if the provided resource is a - * WebSocket instance. - * - * @param[in] resource A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns PP_TRUE if resource is a - * PPB_WebSocket_Dev, PP_FALSE if the - * resource is invalid or some type other than - * PPB_WebSocket_Dev. - */ - PP_Bool IsWebSocket([in] PP_Resource resource); - - /** - * Connect() connects to the specified WebSocket server. Caller can call this - * method at most once for a web_socket. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[in] url A PP_Var representing a WebSocket server URL. - * The PP_VarType must be PP_VARTYPE_STRING. - * - * @param[in] protocols A pointer to an array of PP_Var - * specifying sub-protocols. Each PP_Var represents one - * sub-protocol and its PP_VarType must be - * PP_VARTYPE_STRING. This argument can be null only if - * protocol_count is 0. - * - * @param[in] protocol_count The number of sub-protocols in - * protocols. - * - * @param[in] callback A PP_CompletionCallback which is called - * when a connection is established or an error occurs in establishing - * connection. - * - * @return An int32_t containing an error code from pp_errors.h. - * Returns PP_ERROR_BADARGUMENT if specified url, - * or protocols contains invalid string as - * The WebSocket API specification defines. It corresponds to - * SyntaxError of the specification. - * Returns PP_ERROR_NOACCESS if the protocol specified in the - * url is not a secure protocol, but the origin of the caller - * has a secure scheme. Also returns it if the port specified in the - * url is a port to which the user agent is configured to block - * access because the port is a well-known port like SMTP. It corresponds to - * SecurityError of the specification. - * Returns PP_ERROR_INPROGRESS if the call is not the first - * time. - */ - int32_t Connect([in] PP_Resource web_socket, - [in] PP_Var url, - [in, size_as=protocol_count] PP_Var[] protocols, - [in] uint32_t protocol_count, - [in] PP_CompletionCallback callback); - - /** - * Close() closes the specified WebSocket connection by specifying - * code and reason. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[in] code The WebSocket close code. Ignored if it is 0. - * - * @param[in] reason A PP_Var which represents the WebSocket - * close reason. Ignored if it is PP_VARTYPE_UNDEFINED. - * Otherwise, its PP_VarType must be - * PP_VARTYPE_STRING. - * - * @param[in] callback A PP_CompletionCallback which is called - * when the connection is closed or an error occurs in closing the - * connection. - * - * @return An int32_t containing an error code from pp_errors.h. - * Returns PP_ERROR_BADARGUMENT if reason contains - * an invalid character as a UTF-8 string, or longer than 123 bytes. It - * corresponds to JavaScript SyntaxError of the specification. - * Returns PP_ERROR_NOACCESS if the code is not an integer - * equal to 1000 or in the range 3000 to 4999. It corresponds to - * InvalidAccessError of the specification. Returns - * PP_ERROR_INPROGRESS if the call is not the first time. - */ - int32_t Close([in] PP_Resource web_socket, - [in] uint16_t code, - [in] PP_Var reason, - [in] PP_CompletionCallback callback); - - /** - * ReceiveMessage() receives a message from the WebSocket server. - * This interface only returns a single message. That is, this interface must - * be called at least N times to receive N messages, no matter how small each - * message is. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[out] message The received message is copied to provided - * message. The message must remain valid until - * the ReceiveMessage operation completes. Its PP_VarType - * will be PP_VARTYPE_STRING or - * PP_VARTYPE_ARRAY_BYFFER on receiving. - * - * @param[in] callback A PP_CompletionCallback which is called - * when the receiving message is completed. It is ignored if ReceiveMessage - * completes synchronously and returns PP_OK. - * - * @return An int32_t containing an error code from pp_errors.h. - * If an error is detected or connection is closed, returns - * PP_ERROR_FAILED after all buffered messages are received. - * Until buffered message become empty, continues to returns - * PP_OK as if connection is still established without errors. - */ - int32_t ReceiveMessage([in] PP_Resource web_socket, - [out] PP_Var message, - [in] PP_CompletionCallback callback); - - /** - * SendMessage() sends a message to the WebSocket server. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[in] message A message to send. The message is copied to internal - * buffer. So caller can free message safely after returning - * from the function. Its PP_VarType must be - * PP_VARTYPE_STRING or PP_VARTYPE_ARRAY_BUFFER. - * - * @return An int32_t containing an error code from pp_errors.h. - * Returns PP_ERROR_FAILED if the ReadyState is - * PP_WEBSOCKETREADYSTATE_CONNECTING_DEV. It corresponds - * JavaScript InvalidStateError of the specification. - * Returns PP_ERROR_BADARGUMENT if provided message - * of string type contains an invalid character as a UTF-8 string. It - * corresponds to JavaScript SyntaxError of the specification. - * Otherwise, returns PP_OK, but it doesn't necessarily mean - * that the server received the message. - */ - int32_t SendMessage([in] PP_Resource web_socket, - [in] PP_Var message); - - /** - * GetBufferedAmount() returns the number of bytes of text and binary - * messages that have been queued for the WebSocket connection to send but - * have not been transmitted to the network yet. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns the number of bytes. - */ - uint64_t GetBufferedAmount([in] PP_Resource web_socket); - - /** - * GetCloseCode() returns the connection close code for the WebSocket - * connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns 0 if called before the close code is set. - */ - uint16_t GetCloseCode([in] PP_Resource web_socket); - - /** - * GetCloseReason() returns the connection close reason for the WebSocket - * connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * close reason is set, it contains an empty string. Returns a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - */ - PP_Var GetCloseReason([in] PP_Resource web_socket); - - /** - * GetCloseWasClean() returns if the connection was closed cleanly for the - * specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns PP_FALSE if called before the connection is - * closed, or called on an invalid resource. Otherwise, returns - * PP_TRUE if the connection was closed cleanly, or returns - * PP_FALSE if the connection was closed for abnormal reasons. - */ - PP_Bool GetCloseWasClean([in] PP_Resource web_socket); - - /** - * GetExtensions() returns the extensions selected by the server for the - * specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * connection is established, its data is an empty string. Returns a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - * Currently its data for valid resources are always an empty string. - */ - PP_Var GetExtensions([in] PP_Resource web_socket); - - /** - * GetProtocol() returns the sub-protocol chosen by the server for the - * specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * connection is established, it contains the empty string. Returns a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - */ - PP_Var GetProtocol([in] PP_Resource web_socket); - - /** - * GetReadyState() returns the ready state of the specified WebSocket - * connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns PP_WEBSOCKETREADYSTATE_INVALID_DEV if called - * before connect() is called, or called on an invalid resource. - */ - PP_WebSocketReadyState_Dev GetReadyState([in] PP_Resource web_socket); - - /** - * GetURL() returns the URL associated with specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * connection is established, it contains the empty string. Return a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - */ - PP_Var GetURL([in] PP_Resource web_socket); -}; diff --git a/ppapi/api/ppb_websocket.idl b/ppapi/api/ppb_websocket.idl new file mode 100644 index 0000000..7dd42b1 --- /dev/null +++ b/ppapi/api/ppb_websocket.idl @@ -0,0 +1,301 @@ +/* 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. + */ + +/** + * This file defines the PPB_WebSocket interface. + */ +label Chrome { + M18 = 1.0 +}; + + +/** + * This enumeration contains the types representing the WebSocket ready state + * and these states are based on the JavaScript WebSocket API specification. + * GetReadyState() returns one of these states. + */ +[assert_size(4)] +enum PP_WebSocketReadyState { + /** + * Ready state is queried on an invalid resource. + */ + PP_WEBSOCKETREADYSTATE_INVALID = -1, + /** + * Ready state that the connection has not yet been established. + */ + PP_WEBSOCKETREADYSTATE_CONNECTING = 0, + + /** + * Ready state that the WebSocket connection is established and communication + * is possible. + */ + PP_WEBSOCKETREADYSTATE_OPEN = 1, + + /** + * Ready state that the connection is going through the closing handshake. + */ + PP_WEBSOCKETREADYSTATE_CLOSING = 2, + + /** + * Ready state that the connection has been closed or could not be opened. + */ + PP_WEBSOCKETREADYSTATE_CLOSED = 3 +}; + +interface PPB_WebSocket { + /** + * Create() creates a WebSocket instance. + * + * @param[in] instance A PP_Instance identifying the instance + * with the WebSocket. + * + * @return A PP_Resource corresponding to a WebSocket if + * successful. + */ + PP_Resource Create([in] PP_Instance instance); + + /** + * IsWebSocket() determines if the provided resource is a + * WebSocket instance. + * + * @param[in] resource A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns PP_TRUE if resource is a + * PPB_WebSocket, PP_FALSE if the + * resource is invalid or some type other than + * PPB_WebSocket. + */ + PP_Bool IsWebSocket([in] PP_Resource resource); + + /** + * Connect() connects to the specified WebSocket server. Caller can call this + * method at most once for a web_socket. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[in] url A PP_Var representing a WebSocket server URL. + * The PP_VarType must be PP_VARTYPE_STRING. + * + * @param[in] protocols A pointer to an array of PP_Var + * specifying sub-protocols. Each PP_Var represents one + * sub-protocol and its PP_VarType must be + * PP_VARTYPE_STRING. This argument can be null only if + * protocol_count is 0. + * + * @param[in] protocol_count The number of sub-protocols in + * protocols. + * + * @param[in] callback A PP_CompletionCallback which is called + * when a connection is established or an error occurs in establishing + * connection. + * + * @return An int32_t containing an error code from pp_errors.h. + * Returns PP_ERROR_BADARGUMENT if specified url, + * or protocols contains invalid string as + * The WebSocket API specification defines. It corresponds to + * SyntaxError of the specification. + * Returns PP_ERROR_NOACCESS if the protocol specified in the + * url is not a secure protocol, but the origin of the caller + * has a secure scheme. Also returns it if the port specified in the + * url is a port to which the user agent is configured to block + * access because the port is a well-known port like SMTP. It corresponds to + * SecurityError of the specification. + * Returns PP_ERROR_INPROGRESS if the call is not the first + * time. + */ + int32_t Connect([in] PP_Resource web_socket, + [in] PP_Var url, + [in, size_as=protocol_count] PP_Var[] protocols, + [in] uint32_t protocol_count, + [in] PP_CompletionCallback callback); + + /** + * Close() closes the specified WebSocket connection by specifying + * code and reason. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[in] code The WebSocket close code. Ignored if it is 0. + * + * @param[in] reason A PP_Var which represents the WebSocket + * close reason. Ignored if it is PP_VARTYPE_UNDEFINED. + * Otherwise, its PP_VarType must be + * PP_VARTYPE_STRING. + * + * @param[in] callback A PP_CompletionCallback which is called + * when the connection is closed or an error occurs in closing the + * connection. + * + * @return An int32_t containing an error code from pp_errors.h. + * Returns PP_ERROR_BADARGUMENT if reason contains + * an invalid character as a UTF-8 string, or longer than 123 bytes. It + * corresponds to JavaScript SyntaxError of the specification. + * Returns PP_ERROR_NOACCESS if the code is not an integer + * equal to 1000 or in the range 3000 to 4999. It corresponds to + * InvalidAccessError of the specification. Returns + * PP_ERROR_INPROGRESS if the call is not the first time. + */ + int32_t Close([in] PP_Resource web_socket, + [in] uint16_t code, + [in] PP_Var reason, + [in] PP_CompletionCallback callback); + + /** + * ReceiveMessage() receives a message from the WebSocket server. + * This interface only returns a single message. That is, this interface must + * be called at least N times to receive N messages, no matter how small each + * message is. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[out] message The received message is copied to provided + * message. The message must remain valid until + * the ReceiveMessage operation completes. Its PP_VarType + * will be PP_VARTYPE_STRING or + * PP_VARTYPE_ARRAY_BUFFER on receiving. + * + * @param[in] callback A PP_CompletionCallback which is called + * when the receiving message is completed. It is ignored if ReceiveMessage + * completes synchronously and returns PP_OK. + * + * @return An int32_t containing an error code from pp_errors.h. + * If an error is detected or connection is closed, returns + * PP_ERROR_FAILED after all buffered messages are received. + * Until buffered message become empty, continues to returns + * PP_OK as if connection is still established without errors. + */ + int32_t ReceiveMessage([in] PP_Resource web_socket, + [out] PP_Var message, + [in] PP_CompletionCallback callback); + + /** + * SendMessage() sends a message to the WebSocket server. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[in] message A message to send. The message is copied to internal + * buffer. So caller can free message safely after returning + * from the function. Its PP_VarType must be + * PP_VARTYPE_STRING or PP_VARTYPE_ARRAY_BUFFER. + * + * @return An int32_t containing an error code from pp_errors.h. + * Returns PP_ERROR_FAILED if the ReadyState is + * PP_WEBSOCKETREADYSTATE_CONNECTING. It corresponds JavaScript + * InvalidStateError of the specification. + * Returns PP_ERROR_BADARGUMENT if provided message + * of string type contains an invalid character as a UTF-8 string. It + * corresponds to JavaScript SyntaxError of the specification. + * Otherwise, returns PP_OK, but it doesn't necessarily mean + * that the server received the message. + */ + int32_t SendMessage([in] PP_Resource web_socket, + [in] PP_Var message); + + /** + * GetBufferedAmount() returns the number of bytes of text and binary + * messages that have been queued for the WebSocket connection to send but + * have not been transmitted to the network yet. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns the number of bytes. + */ + uint64_t GetBufferedAmount([in] PP_Resource web_socket); + + /** + * GetCloseCode() returns the connection close code for the WebSocket + * connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns 0 if called before the close code is set. + */ + uint16_t GetCloseCode([in] PP_Resource web_socket); + + /** + * GetCloseReason() returns the connection close reason for the WebSocket + * connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * close reason is set, it contains an empty string. Returns a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + */ + PP_Var GetCloseReason([in] PP_Resource web_socket); + + /** + * GetCloseWasClean() returns if the connection was closed cleanly for the + * specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns PP_FALSE if called before the connection is + * closed, or called on an invalid resource. Otherwise, returns + * PP_TRUE if the connection was closed cleanly, or returns + * PP_FALSE if the connection was closed for abnormal reasons. + */ + PP_Bool GetCloseWasClean([in] PP_Resource web_socket); + + /** + * GetExtensions() returns the extensions selected by the server for the + * specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * connection is established, its data is an empty string. Returns a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + * Currently its data for valid resources are always an empty string. + */ + PP_Var GetExtensions([in] PP_Resource web_socket); + + /** + * GetProtocol() returns the sub-protocol chosen by the server for the + * specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * connection is established, it contains the empty string. Returns a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + */ + PP_Var GetProtocol([in] PP_Resource web_socket); + + /** + * GetReadyState() returns the ready state of the specified WebSocket + * connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns PP_WEBSOCKETREADYSTATE_INVALID if called + * before connect() is called, or called on an invalid resource. + */ + PP_WebSocketReadyState GetReadyState([in] PP_Resource web_socket); + + /** + * GetURL() returns the URL associated with specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * connection is established, it contains the empty string. Return a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + */ + PP_Var GetURL([in] PP_Resource web_socket); +}; diff --git a/ppapi/c/dev/ppb_websocket_dev.h b/ppapi/c/dev/ppb_websocket_dev.h deleted file mode 100644 index 2a6f78b..0000000 --- a/ppapi/c/dev/ppb_websocket_dev.h +++ /dev/null @@ -1,317 +0,0 @@ -/* 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. - */ - -/* From dev/ppb_websocket_dev.idl modified Fri Jan 27 10:09:34 2012. */ - -#ifndef PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ -#define PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ - -#include "ppapi/c/pp_bool.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_macros.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/pp_stdint.h" -#include "ppapi/c/pp_var.h" - -#define PPB_WEBSOCKET_DEV_INTERFACE_0_1 "PPB_WebSocket(Dev);0.1" -#define PPB_WEBSOCKET_DEV_INTERFACE PPB_WEBSOCKET_DEV_INTERFACE_0_1 - -/** - * @file - * This file defines the PPB_WebSocket_Dev interface. - */ - - -/** - * @addtogroup Enums - * @{ - */ -/** - * This enumeration contains the types representing the WebSocket ready state - * and these states are based on the JavaScript WebSocket API specification. - * GetReadyState() returns one of these states. - */ -typedef enum { - /** - * Ready state is queried on an invalid resource. - */ - PP_WEBSOCKETREADYSTATE_INVALID_DEV = -1, - /** - * Ready state that the connection has not yet been established. - */ - PP_WEBSOCKETREADYSTATE_CONNECTING_DEV = 0, - /** - * Ready state that the WebSocket connection is established and communication - * is possible. - */ - PP_WEBSOCKETREADYSTATE_OPEN_DEV = 1, - /** - * Ready state that the connection is going through the closing handshake. - */ - PP_WEBSOCKETREADYSTATE_CLOSING_DEV = 2, - /** - * Ready state that the connection has been closed or could not be opened. - */ - PP_WEBSOCKETREADYSTATE_CLOSED_DEV = 3 -} PP_WebSocketReadyState_Dev; -PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketReadyState_Dev, 4); -/** - * @} - */ - -/** - * @addtogroup Interfaces - * @{ - */ -struct PPB_WebSocket_Dev_0_1 { - /** - * Create() creates a WebSocket instance. - * - * @param[in] instance A PP_Instance identifying the instance - * with the WebSocket. - * - * @return A PP_Resource corresponding to a WebSocket if - * successful. - */ - PP_Resource (*Create)(PP_Instance instance); - /** - * IsWebSocket() determines if the provided resource is a - * WebSocket instance. - * - * @param[in] resource A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns PP_TRUE if resource is a - * PPB_WebSocket_Dev, PP_FALSE if the - * resource is invalid or some type other than - * PPB_WebSocket_Dev. - */ - PP_Bool (*IsWebSocket)(PP_Resource resource); - /** - * Connect() connects to the specified WebSocket server. Caller can call this - * method at most once for a web_socket. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[in] url A PP_Var representing a WebSocket server URL. - * The PP_VarType must be PP_VARTYPE_STRING. - * - * @param[in] protocols A pointer to an array of PP_Var - * specifying sub-protocols. Each PP_Var represents one - * sub-protocol and its PP_VarType must be - * PP_VARTYPE_STRING. This argument can be null only if - * protocol_count is 0. - * - * @param[in] protocol_count The number of sub-protocols in - * protocols. - * - * @param[in] callback A PP_CompletionCallback which is called - * when a connection is established or an error occurs in establishing - * connection. - * - * @return An int32_t containing an error code from pp_errors.h. - * Returns PP_ERROR_BADARGUMENT if specified url, - * or protocols contains invalid string as - * The WebSocket API specification defines. It corresponds to - * SyntaxError of the specification. - * Returns PP_ERROR_NOACCESS if the protocol specified in the - * url is not a secure protocol, but the origin of the caller - * has a secure scheme. Also returns it if the port specified in the - * url is a port to which the user agent is configured to block - * access because the port is a well-known port like SMTP. It corresponds to - * SecurityError of the specification. - * Returns PP_ERROR_INPROGRESS if the call is not the first - * time. - */ - int32_t (*Connect)(PP_Resource web_socket, - struct PP_Var url, - const struct PP_Var protocols[], - uint32_t protocol_count, - struct PP_CompletionCallback callback); - /** - * Close() closes the specified WebSocket connection by specifying - * code and reason. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[in] code The WebSocket close code. Ignored if it is 0. - * - * @param[in] reason A PP_Var which represents the WebSocket - * close reason. Ignored if it is PP_VARTYPE_UNDEFINED. - * Otherwise, its PP_VarType must be - * PP_VARTYPE_STRING. - * - * @param[in] callback A PP_CompletionCallback which is called - * when the connection is closed or an error occurs in closing the - * connection. - * - * @return An int32_t containing an error code from pp_errors.h. - * Returns PP_ERROR_BADARGUMENT if reason contains - * an invalid character as a UTF-8 string, or longer than 123 bytes. It - * corresponds to JavaScript SyntaxError of the specification. - * Returns PP_ERROR_NOACCESS if the code is not an integer - * equal to 1000 or in the range 3000 to 4999. It corresponds to - * InvalidAccessError of the specification. Returns - * PP_ERROR_INPROGRESS if the call is not the first time. - */ - int32_t (*Close)(PP_Resource web_socket, - uint16_t code, - struct PP_Var reason, - struct PP_CompletionCallback callback); - /** - * ReceiveMessage() receives a message from the WebSocket server. - * This interface only returns a single message. That is, this interface must - * be called at least N times to receive N messages, no matter how small each - * message is. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[out] message The received message is copied to provided - * message. The message must remain valid until - * the ReceiveMessage operation completes. Its PP_VarType - * will be PP_VARTYPE_STRING or - * PP_VARTYPE_ARRAY_BYFFER on receiving. - * - * @param[in] callback A PP_CompletionCallback which is called - * when the receiving message is completed. It is ignored if ReceiveMessage - * completes synchronously and returns PP_OK. - * - * @return An int32_t containing an error code from pp_errors.h. - * If an error is detected or connection is closed, returns - * PP_ERROR_FAILED after all buffered messages are received. - * Until buffered message become empty, continues to returns - * PP_OK as if connection is still established without errors. - */ - int32_t (*ReceiveMessage)(PP_Resource web_socket, - struct PP_Var* message, - struct PP_CompletionCallback callback); - /** - * SendMessage() sends a message to the WebSocket server. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @param[in] message A message to send. The message is copied to internal - * buffer. So caller can free message safely after returning - * from the function. Its PP_VarType must be - * PP_VARTYPE_STRING or PP_VARTYPE_ARRAY_BUFFER. - * - * @return An int32_t containing an error code from pp_errors.h. - * Returns PP_ERROR_FAILED if the ReadyState is - * PP_WEBSOCKETREADYSTATE_CONNECTING_DEV. It corresponds - * JavaScript InvalidStateError of the specification. - * Returns PP_ERROR_BADARGUMENT if provided message - * of string type contains an invalid character as a UTF-8 string. It - * corresponds to JavaScript SyntaxError of the specification. - * Otherwise, returns PP_OK, but it doesn't necessarily mean - * that the server received the message. - */ - int32_t (*SendMessage)(PP_Resource web_socket, struct PP_Var message); - /** - * GetBufferedAmount() returns the number of bytes of text and binary - * messages that have been queued for the WebSocket connection to send but - * have not been transmitted to the network yet. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns the number of bytes. - */ - uint64_t (*GetBufferedAmount)(PP_Resource web_socket); - /** - * GetCloseCode() returns the connection close code for the WebSocket - * connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns 0 if called before the close code is set. - */ - uint16_t (*GetCloseCode)(PP_Resource web_socket); - /** - * GetCloseReason() returns the connection close reason for the WebSocket - * connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * close reason is set, it contains an empty string. Returns a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - */ - struct PP_Var (*GetCloseReason)(PP_Resource web_socket); - /** - * GetCloseWasClean() returns if the connection was closed cleanly for the - * specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns PP_FALSE if called before the connection is - * closed, or called on an invalid resource. Otherwise, returns - * PP_TRUE if the connection was closed cleanly, or returns - * PP_FALSE if the connection was closed for abnormal reasons. - */ - PP_Bool (*GetCloseWasClean)(PP_Resource web_socket); - /** - * GetExtensions() returns the extensions selected by the server for the - * specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * connection is established, its data is an empty string. Returns a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - * Currently its data for valid resources are always an empty string. - */ - struct PP_Var (*GetExtensions)(PP_Resource web_socket); - /** - * GetProtocol() returns the sub-protocol chosen by the server for the - * specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * connection is established, it contains the empty string. Returns a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - */ - struct PP_Var (*GetProtocol)(PP_Resource web_socket); - /** - * GetReadyState() returns the ready state of the specified WebSocket - * connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns PP_WEBSOCKETREADYSTATE_INVALID_DEV if called - * before connect() is called, or called on an invalid resource. - */ - PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket); - /** - * GetURL() returns the URL associated with specified WebSocket connection. - * - * @param[in] web_socket A PP_Resource corresponding to a - * WebSocket. - * - * @return Returns a PP_VARTYPE_STRING var. If called before the - * connection is established, it contains the empty string. Return a - * PP_VARTYPE_UNDEFINED if called on an invalid resource. - */ - struct PP_Var (*GetURL)(PP_Resource web_socket); -}; - -typedef struct PPB_WebSocket_Dev_0_1 PPB_WebSocket_Dev; -/** - * @} - */ - -#endif /* PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ */ - diff --git a/ppapi/c/ppb_websocket.h b/ppapi/c/ppb_websocket.h new file mode 100644 index 0000000..9124c28 --- /dev/null +++ b/ppapi/c/ppb_websocket.h @@ -0,0 +1,317 @@ +/* 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. + */ + +/* From ppb_websocket.idl modified Fri Jan 27 15:51:19 2012. */ + +#ifndef PPAPI_C_PPB_WEBSOCKET_H_ +#define PPAPI_C_PPB_WEBSOCKET_H_ + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_var.h" + +#define PPB_WEBSOCKET_INTERFACE_1_0 "PPB_WebSocket;1.0" +#define PPB_WEBSOCKET_INTERFACE PPB_WEBSOCKET_INTERFACE_1_0 + +/** + * @file + * This file defines the PPB_WebSocket interface. + */ + + +/** + * @addtogroup Enums + * @{ + */ +/** + * This enumeration contains the types representing the WebSocket ready state + * and these states are based on the JavaScript WebSocket API specification. + * GetReadyState() returns one of these states. + */ +typedef enum { + /** + * Ready state is queried on an invalid resource. + */ + PP_WEBSOCKETREADYSTATE_INVALID = -1, + /** + * Ready state that the connection has not yet been established. + */ + PP_WEBSOCKETREADYSTATE_CONNECTING = 0, + /** + * Ready state that the WebSocket connection is established and communication + * is possible. + */ + PP_WEBSOCKETREADYSTATE_OPEN = 1, + /** + * Ready state that the connection is going through the closing handshake. + */ + PP_WEBSOCKETREADYSTATE_CLOSING = 2, + /** + * Ready state that the connection has been closed or could not be opened. + */ + PP_WEBSOCKETREADYSTATE_CLOSED = 3 +} PP_WebSocketReadyState; +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketReadyState, 4); +/** + * @} + */ + +/** + * @addtogroup Interfaces + * @{ + */ +struct PPB_WebSocket_1_0 { + /** + * Create() creates a WebSocket instance. + * + * @param[in] instance A PP_Instance identifying the instance + * with the WebSocket. + * + * @return A PP_Resource corresponding to a WebSocket if + * successful. + */ + PP_Resource (*Create)(PP_Instance instance); + /** + * IsWebSocket() determines if the provided resource is a + * WebSocket instance. + * + * @param[in] resource A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns PP_TRUE if resource is a + * PPB_WebSocket, PP_FALSE if the + * resource is invalid or some type other than + * PPB_WebSocket. + */ + PP_Bool (*IsWebSocket)(PP_Resource resource); + /** + * Connect() connects to the specified WebSocket server. Caller can call this + * method at most once for a web_socket. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[in] url A PP_Var representing a WebSocket server URL. + * The PP_VarType must be PP_VARTYPE_STRING. + * + * @param[in] protocols A pointer to an array of PP_Var + * specifying sub-protocols. Each PP_Var represents one + * sub-protocol and its PP_VarType must be + * PP_VARTYPE_STRING. This argument can be null only if + * protocol_count is 0. + * + * @param[in] protocol_count The number of sub-protocols in + * protocols. + * + * @param[in] callback A PP_CompletionCallback which is called + * when a connection is established or an error occurs in establishing + * connection. + * + * @return An int32_t containing an error code from pp_errors.h. + * Returns PP_ERROR_BADARGUMENT if specified url, + * or protocols contains invalid string as + * The WebSocket API specification defines. It corresponds to + * SyntaxError of the specification. + * Returns PP_ERROR_NOACCESS if the protocol specified in the + * url is not a secure protocol, but the origin of the caller + * has a secure scheme. Also returns it if the port specified in the + * url is a port to which the user agent is configured to block + * access because the port is a well-known port like SMTP. It corresponds to + * SecurityError of the specification. + * Returns PP_ERROR_INPROGRESS if the call is not the first + * time. + */ + int32_t (*Connect)(PP_Resource web_socket, + struct PP_Var url, + const struct PP_Var protocols[], + uint32_t protocol_count, + struct PP_CompletionCallback callback); + /** + * Close() closes the specified WebSocket connection by specifying + * code and reason. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[in] code The WebSocket close code. Ignored if it is 0. + * + * @param[in] reason A PP_Var which represents the WebSocket + * close reason. Ignored if it is PP_VARTYPE_UNDEFINED. + * Otherwise, its PP_VarType must be + * PP_VARTYPE_STRING. + * + * @param[in] callback A PP_CompletionCallback which is called + * when the connection is closed or an error occurs in closing the + * connection. + * + * @return An int32_t containing an error code from pp_errors.h. + * Returns PP_ERROR_BADARGUMENT if reason contains + * an invalid character as a UTF-8 string, or longer than 123 bytes. It + * corresponds to JavaScript SyntaxError of the specification. + * Returns PP_ERROR_NOACCESS if the code is not an integer + * equal to 1000 or in the range 3000 to 4999. It corresponds to + * InvalidAccessError of the specification. Returns + * PP_ERROR_INPROGRESS if the call is not the first time. + */ + int32_t (*Close)(PP_Resource web_socket, + uint16_t code, + struct PP_Var reason, + struct PP_CompletionCallback callback); + /** + * ReceiveMessage() receives a message from the WebSocket server. + * This interface only returns a single message. That is, this interface must + * be called at least N times to receive N messages, no matter how small each + * message is. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[out] message The received message is copied to provided + * message. The message must remain valid until + * the ReceiveMessage operation completes. Its PP_VarType + * will be PP_VARTYPE_STRING or + * PP_VARTYPE_ARRAY_BUFFER on receiving. + * + * @param[in] callback A PP_CompletionCallback which is called + * when the receiving message is completed. It is ignored if ReceiveMessage + * completes synchronously and returns PP_OK. + * + * @return An int32_t containing an error code from pp_errors.h. + * If an error is detected or connection is closed, returns + * PP_ERROR_FAILED after all buffered messages are received. + * Until buffered message become empty, continues to returns + * PP_OK as if connection is still established without errors. + */ + int32_t (*ReceiveMessage)(PP_Resource web_socket, + struct PP_Var* message, + struct PP_CompletionCallback callback); + /** + * SendMessage() sends a message to the WebSocket server. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @param[in] message A message to send. The message is copied to internal + * buffer. So caller can free message safely after returning + * from the function. Its PP_VarType must be + * PP_VARTYPE_STRING or PP_VARTYPE_ARRAY_BUFFER. + * + * @return An int32_t containing an error code from pp_errors.h. + * Returns PP_ERROR_FAILED if the ReadyState is + * PP_WEBSOCKETREADYSTATE_CONNECTING. It corresponds JavaScript + * InvalidStateError of the specification. + * Returns PP_ERROR_BADARGUMENT if provided message + * of string type contains an invalid character as a UTF-8 string. It + * corresponds to JavaScript SyntaxError of the specification. + * Otherwise, returns PP_OK, but it doesn't necessarily mean + * that the server received the message. + */ + int32_t (*SendMessage)(PP_Resource web_socket, struct PP_Var message); + /** + * GetBufferedAmount() returns the number of bytes of text and binary + * messages that have been queued for the WebSocket connection to send but + * have not been transmitted to the network yet. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns the number of bytes. + */ + uint64_t (*GetBufferedAmount)(PP_Resource web_socket); + /** + * GetCloseCode() returns the connection close code for the WebSocket + * connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns 0 if called before the close code is set. + */ + uint16_t (*GetCloseCode)(PP_Resource web_socket); + /** + * GetCloseReason() returns the connection close reason for the WebSocket + * connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * close reason is set, it contains an empty string. Returns a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + */ + struct PP_Var (*GetCloseReason)(PP_Resource web_socket); + /** + * GetCloseWasClean() returns if the connection was closed cleanly for the + * specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns PP_FALSE if called before the connection is + * closed, or called on an invalid resource. Otherwise, returns + * PP_TRUE if the connection was closed cleanly, or returns + * PP_FALSE if the connection was closed for abnormal reasons. + */ + PP_Bool (*GetCloseWasClean)(PP_Resource web_socket); + /** + * GetExtensions() returns the extensions selected by the server for the + * specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * connection is established, its data is an empty string. Returns a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + * Currently its data for valid resources are always an empty string. + */ + struct PP_Var (*GetExtensions)(PP_Resource web_socket); + /** + * GetProtocol() returns the sub-protocol chosen by the server for the + * specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * connection is established, it contains the empty string. Returns a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + */ + struct PP_Var (*GetProtocol)(PP_Resource web_socket); + /** + * GetReadyState() returns the ready state of the specified WebSocket + * connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns PP_WEBSOCKETREADYSTATE_INVALID if called + * before connect() is called, or called on an invalid resource. + */ + PP_WebSocketReadyState (*GetReadyState)(PP_Resource web_socket); + /** + * GetURL() returns the URL associated with specified WebSocket connection. + * + * @param[in] web_socket A PP_Resource corresponding to a + * WebSocket. + * + * @return Returns a PP_VARTYPE_STRING var. If called before the + * connection is established, it contains the empty string. Return a + * PP_VARTYPE_UNDEFINED if called on an invalid resource. + */ + struct PP_Var (*GetURL)(PP_Resource web_socket); +}; + +typedef struct PPB_WebSocket_1_0 PPB_WebSocket; +/** + * @} + */ + +#endif /* PPAPI_C_PPB_WEBSOCKET_H_ */ + diff --git a/ppapi/cpp/dev/websocket_dev.h b/ppapi/cpp/dev/websocket_dev.h deleted file mode 100644 index e1de536..0000000 --- a/ppapi/cpp/dev/websocket_dev.h +++ /dev/null @@ -1,185 +0,0 @@ -// 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 PPAPI_CPP_DEV_WEBSOCKET_DEV_H_ -#define PPAPI_CPP_DEV_WEBSOCKET_DEV_H_ - -#include "ppapi/c/dev/ppb_websocket_dev.h" -#include "ppapi/cpp/resource.h" - -/// @file -/// This file defines the WebSocket_Dev interface. - -namespace pp { - -class CompletionCallback; -class Instance; -class Var; - -/// The WebSocket_Dev class -class WebSocket_Dev : public Resource { - public: - /// Constructs a WebSocket_Dev object. - WebSocket_Dev(Instance* instance); - - /// Destructs a WebSocket_Dev object. - virtual ~WebSocket_Dev(); - - /// Connect() connects to the specified WebSocket server. Caller can call - /// this method at most once. - /// - /// @param[in] url A Var of string type representing a WebSocket - /// server URL. - /// @param[in] protocols A pointer to an array of string type - /// Var specifying sub-protocols. Each Var - /// represents one sub-protocol. This argument can be null only if - /// protocol_count is 0. - /// @param[in] protocol_count The number of sub-protocols in - /// protocols. - /// @param[in] callback A CompletionCallback which is called - /// when a connection is established or an error occurs in establishing - /// connection. - /// - /// @return An int32_t containing an error code from - /// pp_errors.h. - /// Returns PP_ERROR_BADARGUMENT if specified url, - /// or protocols contains invalid string as - /// The WebSocket API specification defines. It corresponds to - /// SyntaxError of the specification. - /// Returns PP_ERROR_NOACCESS if the protocol specified in the - /// url is not a secure protocol, but the origin of the caller - /// has a secure scheme. Also returns it if the port specified in the - /// url is a port to which the user agent is configured to block - /// access because the port is a well-known port like SMTP. It corresponds to - /// SecurityError of the specification. - /// Returns PP_ERROR_INPROGRESS if the call is not the first - /// time. - int32_t Connect(const Var& url, const Var protocols[], - uint32_t protocol_count, const CompletionCallback& callback); - - /// Close() closes the specified WebSocket connection by specifying - /// code and reason. - /// - /// @param[in] code The WebSocket close code. Ignored if it is 0. - /// @param[in] reason A Var of string type which represents the - /// WebSocket close reason. Ignored if it is undefined type. - /// @param[in] callback A CompletionCallback which is called - /// when the connection is closed or an error occurs in closing the - /// connection. - /// - /// @return An int32_t containing an error code from - /// pp_errors.h. - /// Returns PP_ERROR_BADARGUMENT if reason contains - /// an invalid character as a UTF-8 string, or longer than 123 bytes. It - /// corresponds to JavaScript SyntaxError of the specification. - /// Returns PP_ERROR_NOACCESS if the code is not an integer - /// equal to 1000 or in the range 3000 to 4999. It corresponds to - /// InvalidAccessError of the specification. Returns - /// PP_ERROR_INPROGRESS if the call is not the first time. - int32_t Close(uint16_t code, const Var& reason, - const CompletionCallback& callback); - - /// ReceiveMessage() receives a message from the WebSocket server. - /// This interface only returns a single message. That is, this interface - /// must be called at least N times to receive N messages, no matter how - /// small each message is. - /// - /// @param[out] message The received message is copied to provided - /// message. The message must remain valid until - /// the ReceiveMessage operation completes. It will be a Var of - /// string or ArrayBuffer types on receiving. - /// @param[in] callback A CompletionCallback which is called - /// when the receiving message is completed. It is ignored if ReceiveMessage - /// completes synchronously and returns PP_OK. - /// - /// @return An int32_t containing an error code from - /// pp_errors.h. - /// If an error is detected or connection is closed, returns - /// PP_ERROR_FAILED after all buffered messages are received. - /// Until buffered message become empty, continues to returns - /// PP_OK as if connection is still established without errors. - int32_t ReceiveMessage(Var* message, - const CompletionCallback& callback); - - /// Send() sends a message to the WebSocket server. - /// - /// @param[in] data A message to send. The message is copied to internal - /// buffer. So caller can free data safely after returning - /// from the function. It must be a Var of string or ArrayBuffer - /// types. - /// - /// @return An int32_t containing an error code from - /// pp_errors.h. - /// Returns PP_ERROR_FAILED if the ReadyState is - /// PP_WEBSOCKETREADYSTATE_CONNECTING_DEV. It corresponds - /// JavaScript InvalidStateError of the specification. - /// Returns PP_ERROR_BADARGUMENT if provided - /// message of string type contains an invalid character as a - /// UTF-8 string. It corresponds to JavaScript SyntaxError of the - /// specification. - /// Otherwise, returns PP_OK, but it doesn't necessarily mean - /// that the server received the message. - int32_t SendMessage(const Var& message); - - /// GetBufferedAmount() returns the number of bytes of text and binary - /// messages that have been queued for the WebSocket connection to send but - /// have not been transmitted to the network yet. - /// - /// @return Returns the number of bytes. - uint64_t GetBufferedAmount(); - - /// GetCloseCode() returns the connection close code for the WebSocket - /// connection. - /// - /// @return Returns 0 if called before the close code is set. - uint16_t GetCloseCode(); - - /// GetCloseReason() returns the connection close reason for the WebSocket - /// connection. - /// - /// @return Returns a Var of string type. If called before the - /// close reason is set, it contains an empty string. - Var GetCloseReason(); - - /// GetCloseWasClean() returns if the connection was closed cleanly for the - /// specified WebSocket connection. - /// - /// @return Returns false if called before the connection is - /// closed, or called on an invalid resource. Otherwise, returns - /// true if the connection was closed cleanly, or returns - /// false if the connection was closed for abnormal reasons. - bool GetCloseWasClean(); - - /// GetExtensions() returns the extensions selected by the server for the - /// specified WebSocket connection. - /// - /// @return Returns a Var of string type. If called before the - /// connection is established, its data is an empty string. - /// Currently its data is always an empty string. - Var GetExtensions(); - - /// GetProtocol() returns the sub-protocol chosen by the server for the - /// specified WebSocket connection. - /// - /// @return Returns a Var of string type. If called before the - /// connection is established, it contains the empty string. - Var GetProtocol(); - - /// GetReadyState() returns the ready state of the specified WebSocket - /// connection. - /// - /// @return Returns PP_WEBSOCKETREADYSTATE_INVALID_DEV if called - /// before connect() is called. - PP_WebSocketReadyState_Dev GetReadyState(); - - /// GetURL() returns the URL associated with specified WebSocket connection. - /// - /// @return Returns a Var of string type. If called before the - /// connection is established, it contains the empty string. - Var GetURL(); -}; - -} // namespace pp - -#endif // PPAPI_CPP_DEV_WEBSOCKET_DEV_H_ diff --git a/ppapi/cpp/websocket.cc b/ppapi/cpp/websocket.cc new file mode 100644 index 0000000..2a65370 --- /dev/null +++ b/ppapi/cpp/websocket.cc @@ -0,0 +1,148 @@ +// 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 "ppapi/cpp/websocket.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name() { + return PPB_WEBSOCKET_INTERFACE; +} + +} // namespace + +WebSocket::WebSocket(Instance* instance) { + if (!has_interface()) + return; + PassRefFromConstructor(get_interface()->Create( + instance->pp_instance())); +} + +WebSocket::~WebSocket() { +} + +int32_t WebSocket::Connect(const Var& url, const Var protocols[], + uint32_t protocol_count, const CompletionCallback& callback) { + if (!has_interface()) + return PP_ERROR_BADRESOURCE; + + // Convert protocols to C interface. + PP_Var *c_protocols = NULL; + if (protocol_count) { + c_protocols = new PP_Var[protocol_count]; + if (!c_protocols) + return PP_ERROR_NOMEMORY; + } + for (uint32_t i = 0; i < protocol_count; ++i) + c_protocols[i] = protocols[i].pp_var(); + + int32_t result = get_interface()->Connect( + pp_resource(), url.pp_var(), c_protocols, protocol_count, + callback.pp_completion_callback()); + if (c_protocols) + delete[] c_protocols; + return result; +} + +int32_t WebSocket::Close(uint16_t code, const Var& reason, + const CompletionCallback& callback) { + if (!has_interface()) + return PP_ERROR_BADRESOURCE; + + return get_interface()->Close( + pp_resource(), code, reason.pp_var(), + callback.pp_completion_callback()); +} + +int32_t WebSocket::ReceiveMessage(Var* message, + const CompletionCallback& callback) { + if (!has_interface()) + return PP_ERROR_BADRESOURCE; + + return get_interface()->ReceiveMessage( + pp_resource(), const_cast(&message->pp_var()), + callback.pp_completion_callback()); +} + +int32_t WebSocket::SendMessage(const Var& message) { + if (!has_interface()) + return PP_ERROR_BADRESOURCE; + + return get_interface()->SendMessage( + pp_resource(), message.pp_var()); +} + +uint64_t WebSocket::GetBufferedAmount() { + if (!has_interface()) + return 0; + + return get_interface()->GetBufferedAmount(pp_resource()); +} + +uint16_t WebSocket::GetCloseCode() { + if (!has_interface()) + return 0; + + return get_interface()->GetCloseCode(pp_resource()); +} + +Var WebSocket::GetCloseReason() { + if (!has_interface()) + return 0; + + return Var(Var::PassRef(), + get_interface()->GetCloseReason(pp_resource())); +} + +bool WebSocket::GetCloseWasClean() { + if (!has_interface()) + return false; + + PP_Bool result = + get_interface()->GetCloseWasClean(pp_resource()); + return PP_ToBool(result); +} + +Var WebSocket::GetExtensions() { + if (!has_interface()) + return Var(); + + return Var(Var::PassRef(), + get_interface()->GetExtensions(pp_resource())); +} + +Var WebSocket::GetProtocol() { + if (!has_interface()) + return Var(); + + return Var(Var::PassRef(), + get_interface()->GetProtocol(pp_resource())); +} + +PP_WebSocketReadyState WebSocket::GetReadyState() { + if (!has_interface()) + return PP_WEBSOCKETREADYSTATE_INVALID; + + return get_interface()->GetReadyState(pp_resource()); +} + +Var WebSocket::GetURL() { + if (!has_interface()) + return Var(); + + return Var(Var::PassRef(), + get_interface()->GetURL(pp_resource())); +} + +} // namespace pp diff --git a/ppapi/cpp/websocket.h b/ppapi/cpp/websocket.h new file mode 100644 index 0000000..61e61df --- /dev/null +++ b/ppapi/cpp/websocket.h @@ -0,0 +1,185 @@ +// 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 PPAPI_CPP_WEBSOCKET_H_ +#define PPAPI_CPP_WEBSOCKET_H_ + +#include "ppapi/c/ppb_websocket.h" +#include "ppapi/cpp/resource.h" + +/// @file +/// This file defines the WebSocket interface. + +namespace pp { + +class CompletionCallback; +class Instance; +class Var; + +/// The WebSocket class +class WebSocket : public Resource { + public: + /// Constructs a WebSocket object. + WebSocket(Instance* instance); + + /// Destructs a WebSocket object. + virtual ~WebSocket(); + + /// Connect() connects to the specified WebSocket server. Caller can call + /// this method at most once. + /// + /// @param[in] url A Var of string type representing a WebSocket + /// server URL. + /// @param[in] protocols A pointer to an array of string type + /// Var specifying sub-protocols. Each Var + /// represents one sub-protocol. This argument can be null only if + /// protocol_count is 0. + /// @param[in] protocol_count The number of sub-protocols in + /// protocols. + /// @param[in] callback A CompletionCallback which is called + /// when a connection is established or an error occurs in establishing + /// connection. + /// + /// @return An int32_t containing an error code from + /// pp_errors.h. + /// Returns PP_ERROR_BADARGUMENT if specified url, + /// or protocols contains invalid string as + /// The WebSocket API specification defines. It corresponds to + /// SyntaxError of the specification. + /// Returns PP_ERROR_NOACCESS if the protocol specified in the + /// url is not a secure protocol, but the origin of the caller + /// has a secure scheme. Also returns it if the port specified in the + /// url is a port to which the user agent is configured to block + /// access because the port is a well-known port like SMTP. It corresponds to + /// SecurityError of the specification. + /// Returns PP_ERROR_INPROGRESS if the call is not the first + /// time. + int32_t Connect(const Var& url, const Var protocols[], + uint32_t protocol_count, const CompletionCallback& callback); + + /// Close() closes the specified WebSocket connection by specifying + /// code and reason. + /// + /// @param[in] code The WebSocket close code. Ignored if it is 0. + /// @param[in] reason A Var of string type which represents the + /// WebSocket close reason. Ignored if it is undefined type. + /// @param[in] callback A CompletionCallback which is called + /// when the connection is closed or an error occurs in closing the + /// connection. + /// + /// @return An int32_t containing an error code from + /// pp_errors.h. + /// Returns PP_ERROR_BADARGUMENT if reason contains + /// an invalid character as a UTF-8 string, or longer than 123 bytes. It + /// corresponds to JavaScript SyntaxError of the specification. + /// Returns PP_ERROR_NOACCESS if the code is not an integer + /// equal to 1000 or in the range 3000 to 4999. It corresponds to + /// InvalidAccessError of the specification. Returns + /// PP_ERROR_INPROGRESS if the call is not the first time. + int32_t Close(uint16_t code, const Var& reason, + const CompletionCallback& callback); + + /// ReceiveMessage() receives a message from the WebSocket server. + /// This interface only returns a single message. That is, this interface + /// must be called at least N times to receive N messages, no matter how + /// small each message is. + /// + /// @param[out] message The received message is copied to provided + /// message. The message must remain valid until + /// the ReceiveMessage operation completes. It will be a Var of + /// string or ArrayBuffer types on receiving. + /// @param[in] callback A CompletionCallback which is called + /// when the receiving message is completed. It is ignored if ReceiveMessage + /// completes synchronously and returns PP_OK. + /// + /// @return An int32_t containing an error code from + /// pp_errors.h. + /// If an error is detected or connection is closed, returns + /// PP_ERROR_FAILED after all buffered messages are received. + /// Until buffered message become empty, continues to returns + /// PP_OK as if connection is still established without errors. + int32_t ReceiveMessage(Var* message, + const CompletionCallback& callback); + + /// Send() sends a message to the WebSocket server. + /// + /// @param[in] data A message to send. The message is copied to internal + /// buffer. So caller can free data safely after returning + /// from the function. It must be a Var of string or ArrayBuffer + /// types. + /// + /// @return An int32_t containing an error code from + /// pp_errors.h. + /// Returns PP_ERROR_FAILED if the ReadyState is + /// PP_WEBSOCKETREADYSTATE_CONNECTING. It corresponds JavaScript + /// InvalidStateError of the specification. + /// Returns PP_ERROR_BADARGUMENT if provided + /// message of string type contains an invalid character as a + /// UTF-8 string. It corresponds to JavaScript SyntaxError of the + /// specification. + /// Otherwise, returns PP_OK, but it doesn't necessarily mean + /// that the server received the message. + int32_t SendMessage(const Var& message); + + /// GetBufferedAmount() returns the number of bytes of text and binary + /// messages that have been queued for the WebSocket connection to send but + /// have not been transmitted to the network yet. + /// + /// @return Returns the number of bytes. + uint64_t GetBufferedAmount(); + + /// GetCloseCode() returns the connection close code for the WebSocket + /// connection. + /// + /// @return Returns 0 if called before the close code is set. + uint16_t GetCloseCode(); + + /// GetCloseReason() returns the connection close reason for the WebSocket + /// connection. + /// + /// @return Returns a Var of string type. If called before the + /// close reason is set, it contains an empty string. + Var GetCloseReason(); + + /// GetCloseWasClean() returns if the connection was closed cleanly for the + /// specified WebSocket connection. + /// + /// @return Returns false if called before the connection is + /// closed, or called on an invalid resource. Otherwise, returns + /// true if the connection was closed cleanly, or returns + /// false if the connection was closed for abnormal reasons. + bool GetCloseWasClean(); + + /// GetExtensions() returns the extensions selected by the server for the + /// specified WebSocket connection. + /// + /// @return Returns a Var of string type. If called before the + /// connection is established, its data is an empty string. + /// Currently its data is always an empty string. + Var GetExtensions(); + + /// GetProtocol() returns the sub-protocol chosen by the server for the + /// specified WebSocket connection. + /// + /// @return Returns a Var of string type. If called before the + /// connection is established, it contains the empty string. + Var GetProtocol(); + + /// GetReadyState() returns the ready state of the specified WebSocket + /// connection. + /// + /// @return Returns PP_WEBSOCKETREADYSTATE_INVALID if called + /// before connect() is called. + PP_WebSocketReadyState GetReadyState(); + + /// GetURL() returns the URL associated with specified WebSocket connection. + /// + /// @return Returns a Var of string type. If called before the + /// connection is established, it contains the empty string. + Var GetURL(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_WEBSOCKET_H_ 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 284e56d..9eb4215bd 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc @@ -416,10 +416,10 @@ const PPB_View* PPBViewInterface() { return ppb; } -const PPB_WebSocket_Dev* PPBWebSocketInterface() { - static const PPB_WebSocket_Dev* ppb = - static_cast( - GetBrowserInterfaceSafe(PPB_WEBSOCKET_DEV_INTERFACE)); +const PPB_WebSocket* PPBWebSocketInterface() { + static const PPB_WebSocket* ppb = + static_cast( + GetBrowserInterfaceSafe(PPB_WEBSOCKET_INTERFACE)); return ppb; } 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 913cf10..19ffd4f 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h @@ -12,7 +12,6 @@ #include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_testing_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" @@ -36,6 +35,7 @@ #include "ppapi/c/ppb_var.h" #include "ppapi/c/ppb_var_array_buffer.h" #include "ppapi/c/ppb_view.h" +#include "ppapi/c/ppb_websocket.h" #include "ppapi/c/private/ppb_net_address_private.h" #include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_tcp_socket_private.h" @@ -133,7 +133,7 @@ const PPB_Var* PPBVarInterface(); // shared const PPB_VarArrayBuffer* PPBVarArrayBufferInterface(); // shared const PPB_View* PPBViewInterface(); const PPB_WheelInputEvent* PPBWheelInputEventInterface(); -const PPB_WebSocket_Dev* PPBWebSocketInterface(); +const PPB_WebSocket* 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 index d59997b..65c0877 100644 --- 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 @@ -11,8 +11,8 @@ #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" +#include "ppapi/c/ppb_websocket.h" using ppapi_proxy::DebugPrintf; using ppapi_proxy::DeleteRemoteCallbackInfo; 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 493cacb..b8ef392 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc @@ -90,9 +90,9 @@ const PPB_VarArrayBuffer* PPBVarArrayBufferInterface() { GetBrowserInterfaceSafe(PPB_VAR_ARRAY_BUFFER_INTERFACE)); } -const PPB_WebSocket_Dev* PPBWebSocketInterface() { - return static_cast( - GetBrowserInterfaceSafe(PPB_WEBSOCKET_DEV_INTERFACE)); +const PPB_WebSocket* PPBWebSocketInterface() { + return static_cast( + GetBrowserInterfaceSafe(PPB_WEBSOCKET_INTERFACE)); } // Plugin interface helpers 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 fbcba2d..600f098 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h @@ -6,7 +6,6 @@ #define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_GLOBALS_H_ #include "ppapi/c/dev/ppb_memory_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" @@ -18,6 +17,7 @@ #include "ppapi/c/ppb_core.h" #include "ppapi/c/ppb_var.h" #include "ppapi/c/ppb_var_array_buffer.h" +#include "ppapi/c/ppb_websocket.h" #include "ppapi/c/ppp_input_event.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/c/ppp_messaging.h" @@ -56,7 +56,7 @@ const PPB_Core* PPBCoreInterface(); // shared const PPB_Memory_Dev* PPBMemoryInterface(); // shared const PPB_Var* PPBVarInterface(); // shared const PPB_VarArrayBuffer* PPBVarArrayBufferInterface(); // shared -const PPB_WebSocket_Dev* PPBWebSocketInterface(); +const PPB_WebSocket* 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 1efbab9..8d1734d 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc @@ -103,7 +103,7 @@ 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(), + { PPB_WEBSOCKET_INTERFACE, PluginWebSocket::GetInterface(), true }, { PPB_WHEEL_INPUT_EVENT_INTERFACE, PluginInputEvent::GetWheelInterface(), 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 index 56b4de2..1fdbf2c 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc @@ -13,7 +13,7 @@ #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 "ppapi/c/ppb_websocket.h" #include "srpcgen/ppb_rpc.h" namespace ppapi_proxy { @@ -267,7 +267,7 @@ PP_Var GetProtocol(PP_Resource ws) { return PP_MakeUndefined(); } -PP_WebSocketReadyState_Dev GetReadyState(PP_Resource ws) { +PP_WebSocketReadyState GetReadyState(PP_Resource ws) { DebugPrintf( "PPB_WebSocket::GetReadyState: ws=%"NACL_PRId32"\n", ws); @@ -279,8 +279,8 @@ PP_WebSocketReadyState_Dev GetReadyState(PP_Resource ws) { NaClSrpcErrorString(srpc_result)); if (srpc_result != NACL_SRPC_RESULT_OK) - return PP_WEBSOCKETREADYSTATE_INVALID_DEV; - return static_cast(ready_state); + return PP_WEBSOCKETREADYSTATE_INVALID; + return static_cast(ready_state); } PP_Var GetURL(PP_Resource ws) { @@ -305,8 +305,8 @@ PP_Var GetURL(PP_Resource ws) { } // namespace -const PPB_WebSocket_Dev* PluginWebSocket::GetInterface() { - static const PPB_WebSocket_Dev websocket_interface = { +const PPB_WebSocket* PluginWebSocket::GetInterface() { + static const PPB_WebSocket websocket_interface = { &Create, &IsWebSocket, &Connect, 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 index fb209ac..285ec36 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h @@ -6,14 +6,14 @@ #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" +#include "ppapi/c/ppb_websocket.h" namespace ppapi_proxy { // Implements the untrusted side of the PPB_WebSocket interface. class PluginWebSocket { public: - static const PPB_WebSocket_Dev* GetInterface(); + static const PPB_WebSocket* GetInterface(); private: NACL_DISALLOW_COPY_AND_ASSIGN(PluginWebSocket); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc index 6c6fe49..9b9c665 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_websocket.srpc @@ -2,8 +2,8 @@ # 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. +# RPC methods used to implement PPB_WebSocket calls from the plugin. +# See ppapi/c/ppb_websocket.h for interface details. { 'name': 'PpbWebSocketRpc', diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index 3f69a6c..7c9e664 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -43,6 +43,7 @@ 'c/ppb_var.h', 'c/ppb_var_array_buffer.h', 'c/ppb_view.h', + 'c/ppb_websocket.h', 'c/ppp.h', 'c/ppp_graphics_3d.h', 'c/ppp_input_event.h', @@ -72,7 +73,6 @@ 'c/dev/ppb_testing_dev.h', 'c/dev/ppb_url_util_dev.h', 'c/dev/ppb_video_decoder_dev.h', - 'c/dev/ppb_websocket_dev.h', 'c/dev/ppb_widget_dev.h', 'c/dev/ppb_zoom_dev.h', 'c/dev/ppp_cursor_control_dev.h', @@ -173,6 +173,8 @@ 'cpp/var_array_buffer.h', 'cpp/view.cc', 'cpp/view.h', + 'cpp/websocket.cc', + 'cpp/websocket.h', # Dev interfaces. 'cpp/dev/audio_input_dev.cc', @@ -219,8 +221,6 @@ 'cpp/dev/video_decoder_client_dev.h', 'cpp/dev/video_decoder_dev.cc', 'cpp/dev/video_decoder_dev.h', - 'cpp/dev/websocket_dev.cc', - 'cpp/dev/websocket_dev.h', 'cpp/dev/widget_client_dev.cc', 'cpp/dev/widget_client_dev.h', 'cpp/dev/widget_dev.cc', diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index 46f2fcf..b3d96f0 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -35,7 +35,6 @@ #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/dev/ppb_video_decoder_dev.h" #include "ppapi/c/dev/ppb_video_layer_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/dev/ppp_class_deprecated.h" @@ -84,6 +83,7 @@ #include "ppapi/c/ppb_url_request_info.h" #include "ppapi/c/ppb_url_response_info.h" #include "ppapi/c/ppb_var_array_buffer.h" +#include "ppapi/c/ppb_websocket.h" #include "ppapi/c/ppp.h" #include "ppapi/c/ppp_graphics_3d.h" #include "ppapi/c/ppp_input_event.h" diff --git a/ppapi/tests/all_cpp_includes.h b/ppapi/tests/all_cpp_includes.h index 481d627..5416a36 100644 --- a/ppapi/tests/all_cpp_includes.h +++ b/ppapi/tests/all_cpp_includes.h @@ -31,7 +31,6 @@ #include "ppapi/cpp/dev/transport_dev.h" #include "ppapi/cpp/dev/url_util_dev.h" #include "ppapi/cpp/dev/video_decoder_dev.h" -#include "ppapi/cpp/dev/websocket_dev.h" #include "ppapi/cpp/dev/widget_client_dev.h" #include "ppapi/cpp/dev/widget_dev.h" #include "ppapi/cpp/dev/zoom_dev.h" @@ -59,6 +58,7 @@ #include "ppapi/cpp/url_response_info.h" #include "ppapi/cpp/var.h" #include "ppapi/cpp/var_array_buffer.h" +#include "ppapi/cpp/websocket.h" #include "ppapi/utility/graphics/paint_aggregator.h" #include "ppapi/utility/graphics/paint_manager.h" #include "ppapi/utility/non_thread_safe_ref_count.h" diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc index 91f6379..8eeeac2 100644 --- a/ppapi/tests/test_websocket.cc +++ b/ppapi/tests/test_websocket.cc @@ -8,16 +8,16 @@ #include #include "ppapi/c/dev/ppb_testing_dev.h" -#include "ppapi/c/dev/ppb_websocket_dev.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_var.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/ppb_core.h" #include "ppapi/c/ppb_var.h" #include "ppapi/c/ppb_var_array_buffer.h" -#include "ppapi/cpp/dev/websocket_dev.h" +#include "ppapi/c/ppb_websocket.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" +#include "ppapi/cpp/websocket.h" #include "ppapi/tests/test_utils.h" #include "ppapi/tests/testing_instance.h" @@ -49,8 +49,8 @@ const uint64_t kMessageFrameOverhead = 6; REGISTER_TEST_CASE(WebSocket); bool TestWebSocket::Init() { - websocket_interface_ = static_cast( - pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_DEV_INTERFACE)); + websocket_interface_ = static_cast( + pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_INTERFACE)); var_interface_ = static_cast( pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); arraybuffer_interface_ = static_cast( @@ -189,9 +189,9 @@ std::string TestWebSocket::TestUninitializedPropertiesAccess() { ASSERT_TRUE(AreEqualWithString(protocol, "")); ReleaseVar(protocol); - PP_WebSocketReadyState_Dev ready_state = + PP_WebSocketReadyState ready_state = websocket_interface_->GetReadyState(ws); - ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ready_state); PP_Var url = websocket_interface_->GetURL(ws); ASSERT_TRUE(AreEqualWithString(url, "")); @@ -519,12 +519,12 @@ std::string TestWebSocket::TestBufferedAmount() { result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, static_cast(callback).pp_completion_callback()); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); - ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING_DEV, + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, websocket_interface_->GetReadyState(ws)); result = callback.WaitForResult(); ASSERT_EQ(PP_OK, result); - ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, websocket_interface_->GetReadyState(ws)); uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws); @@ -555,7 +555,7 @@ std::string TestWebSocket::TestBufferedAmount() { std::string TestWebSocket::TestCcInterfaces() { // C++ bindings is simple straightforward, then just verifies interfaces work // as a interface bridge fine. - pp::WebSocket_Dev ws(instance_); + pp::WebSocket ws(instance_); // Check uninitialized properties access. ASSERT_EQ(0, ws.GetBufferedAmount()); @@ -564,7 +564,7 @@ std::string TestWebSocket::TestCcInterfaces() { ASSERT_EQ(false, ws.GetCloseWasClean()); ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); - ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState()); + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ws.GetReadyState()); ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); // Check communication interfaces (connect, send, receive, and close). @@ -619,7 +619,7 @@ std::string TestWebSocket::TestCcInterfaces() { ASSERT_EQ(true, ws.GetCloseWasClean()); ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); - ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState()); + ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); PASS(); diff --git a/ppapi/tests/test_websocket.h b/ppapi/tests/test_websocket.h index 43c56cb..f63d717 100644 --- a/ppapi/tests/test_websocket.h +++ b/ppapi/tests/test_websocket.h @@ -7,10 +7,10 @@ #include -#include "ppapi/c/dev/ppb_websocket_dev.h" #include "ppapi/c/ppb_core.h" #include "ppapi/c/ppb_var.h" #include "ppapi/c/ppb_var_array_buffer.h" +#include "ppapi/c/ppb_websocket.h" #include "ppapi/tests/test_case.h" class TestWebSocket : public TestCase { @@ -48,7 +48,7 @@ class TestWebSocket : public TestCase { std::string TestCcInterfaces(); // Used by the tests that access the C API directly. - const PPB_WebSocket_Dev* websocket_interface_; + const PPB_WebSocket* websocket_interface_; const PPB_Var* var_interface_; const PPB_VarArrayBuffer* arraybuffer_interface_; const PPB_Core* core_interface_; diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index bfc828e..9a2ad23 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -64,8 +64,8 @@ PROXIED_IFACE(PPB_VideoDecoder, PPB_VIDEODECODER_DEV_INTERFACE_0_16, PPB_VideoDecoder_Dev_0_16) UNPROXIED_IFACE(PPB_VideoLayer, PPB_VIDEOLAYER_DEV_INTERFACE_0_1, PPB_VideoLayer_Dev_0_1) -UNPROXIED_IFACE(PPB_WebSocket, PPB_WEBSOCKET_DEV_INTERFACE_0_1, - PPB_WebSocket_Dev_0_1) +UNPROXIED_IFACE(PPB_WebSocket, PPB_WEBSOCKET_INTERFACE_1_0, + PPB_WebSocket_1_0) UNPROXIED_IFACE(PPB_Widget, PPB_WIDGET_DEV_INTERFACE_0_3, PPB_Widget_Dev_0_3) #include "ppapi/thunk/interfaces_postamble.h" diff --git a/ppapi/thunk/ppb_websocket_api.h b/ppapi/thunk/ppb_websocket_api.h index 867550d..c769cec 100644 --- a/ppapi/thunk/ppb_websocket_api.h +++ b/ppapi/thunk/ppb_websocket_api.h @@ -6,7 +6,7 @@ #define PPAPI_THUNK_WEBSOCKET_API_H_ #include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/dev/ppb_websocket_dev.h" +#include "ppapi/c/ppb_websocket.h" namespace ppapi { namespace thunk { @@ -31,7 +31,7 @@ class PPB_WebSocket_API { virtual PP_Bool GetCloseWasClean() = 0; virtual PP_Var GetExtensions() = 0; virtual PP_Var GetProtocol() = 0; - virtual PP_WebSocketReadyState_Dev GetReadyState() = 0; + virtual PP_WebSocketReadyState GetReadyState() = 0; virtual PP_Var GetURL() = 0; }; diff --git a/ppapi/thunk/ppb_websocket_thunk.cc b/ppapi/thunk/ppb_websocket_thunk.cc index ea67f84..1fcae10 100644 --- a/ppapi/thunk/ppb_websocket_thunk.cc +++ b/ppapi/thunk/ppb_websocket_thunk.cc @@ -110,10 +110,10 @@ PP_Var GetProtocol(PP_Resource resource) { return enter.object()->GetProtocol(); } -PP_WebSocketReadyState_Dev GetReadyState(PP_Resource resource) { +PP_WebSocketReadyState GetReadyState(PP_Resource resource) { EnterResource enter(resource, false); if (enter.failed()) - return PP_WEBSOCKETREADYSTATE_INVALID_DEV; + return PP_WEBSOCKETREADYSTATE_INVALID; return enter.object()->GetReadyState(); } @@ -124,7 +124,7 @@ PP_Var GetURL(PP_Resource resource) { return enter.object()->GetURL(); } -const PPB_WebSocket_Dev_0_1 g_ppb_websocket_0_1_thunk = { +const PPB_WebSocket_1_0 g_ppb_websocket_1_0_thunk = { &Create, &IsWebSocket, &Connect, @@ -143,8 +143,8 @@ const PPB_WebSocket_Dev_0_1 g_ppb_websocket_0_1_thunk = { } // namespace -const PPB_WebSocket_Dev_0_1* GetPPB_WebSocket_Dev_0_1_Thunk() { - return &g_ppb_websocket_0_1_thunk; +const PPB_WebSocket_1_0* GetPPB_WebSocket_1_0_Thunk() { + return &g_ppb_websocket_1_0_thunk; } } // namespace thunk diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 90442ed..7d895d8 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -17,9 +17,9 @@ #include "ppapi/c/ppb_graphics_3d.h" #include "ppapi/c/ppb_image_data.h" #include "ppapi/c/ppb_input_event.h" +#include "ppapi/c/ppb_websocket.h" #include "ppapi/c/dev/pp_video_dev.h" #include "ppapi/c/dev/ppb_transport_dev.h" -#include "ppapi/c/dev/ppb_websocket_dev.h" #include "ppapi/shared_impl/api_id.h" struct PP_Flash_Menu; -- cgit v1.1