diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-11 05:50:59 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-11 05:50:59 +0000 |
commit | f88c2e097ceb2857cd36babc608ba9845ef0eab8 (patch) | |
tree | 03c6eaee9fef72680d0e46bd9bd4759020c28628 /ppapi | |
parent | b85fed7694f0bd4bbe445003e9ed4b19d24e5b29 (diff) | |
download | chromium_src-f88c2e097ceb2857cd36babc608ba9845ef0eab8.zip chromium_src-f88c2e097ceb2857cd36babc608ba9845ef0eab8.tar.gz chromium_src-f88c2e097ceb2857cd36babc608ba9845ef0eab8.tar.bz2 |
IDL for WebSocket Pepper API.
Define WebSocket Pepper API as IDL and generate the C interface from it.
This IDL takes over from http://codereview.chromium.org/7837022/
BUG=87310
TEST=n/a because only the interface is defined in this change.
Review URL: http://codereview.chromium.org/8395037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109592 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/dev/ppb_websocket_dev.idl | 305 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_websocket_dev.h | 317 | ||||
-rw-r--r-- | ppapi/cpp/dev/websocket_dev.h | 135 | ||||
-rw-r--r-- | ppapi/ppapi_cpp.gypi | 1 | ||||
-rw-r--r-- | ppapi/tests/all_c_includes.h | 1 | ||||
-rw-r--r-- | ppapi/tests/all_cpp_includes.h | 1 |
6 files changed, 760 insertions, 0 deletions
diff --git a/ppapi/api/dev/ppb_websocket_dev.idl b/ppapi/api/dev/ppb_websocket_dev.idl new file mode 100644 index 0000000..c481910 --- /dev/null +++ b/ppapi/api/dev/ppb_websocket_dev.idl @@ -0,0 +1,305 @@ +/* Copyright (c) 2011 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 <code>PPB_WebSocket_Dev</code> 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 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 +}; + +/** + * This enumeration contains the types representing the WebSocket message type + * and these types are based on the JavaScript WebSocket API specification. + * ReceiveMessage() and SendMessage() use them as a parameter to represent + * handling message types. + */ +[assert_size(4)] +enum PP_WebSocketMessageType_Dev { + /** + * Message type that represents a text message type. + */ + PP_WEBSOCKET_MESSAGE_TYPE_TEXT_DEV = 0, + + /** + * Message type that represents a binary message type. + */ + PP_WEBSOCKET_MESSAGE_TYPE_BINARY_DEV = 1 +}; + +[version=0.1, macro="PPB_WEBSOCKET_DEV_INTERFACE"] +interface PPB_WebSocket_Dev { + /** + * Create() creates a WebSocket instance. + * + * @param[in] instance A <code>PP_Instance</code> identifying the instance + * with the WebSocket. + * + * @return A <code>PP_Resource</code> corresponding to a WebSocket if + * successful. + */ + PP_Resource Create([in] PP_Instance instance); + + /** + * IsWebSocket() determines if the provided <code>resource</code> is a + * WebSocket instance. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a + * <code>PPB_WebSocket_Dev</code>, <code>PP_FALSE</code> if the + * <code>resource</code> is invalid or some type other than + * <code>PPB_WebSocket_Dev</code>. + */ + PP_Bool IsWebSocket([in] PP_Resource resource); + + /** + * Connect() connects to the specified WebSocket server. Caller can call this + * method at most once for a <code>web_socket</code>. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL. + * The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>. + * + * @param[in] protocols A pointer to an array of <code>PP_Var</code> + * specifying sub-protocols. Each <code>PP_Var</code> represents one + * sub-protocol and its <code>PP_VarType</code> must be + * <code>PP_VARTYPE_STRING</code>. This argument can be null only if + * <code>protocol_count</code> is 0. + * + * @param[in] protocol_count The number of sub-protocols in + * <code>protocols</code>. + * + * @param[in] callback A <code>PP_CompletionCallback</code> which is called + * when the connection is established or an error occurs in establishing + * connection. + * + * @return In case of immediate failure, returns an error code as follows. + * Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript + * SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to JavaScript + * SecurityError. Otherwise, returns <code>PP_OK_COMPLETIONPENDING</code> + * and invokes <code>callback</code> later. + */ + 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>code</code> and <code>reason</code>. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[in] code The WebSocket close code. Ignored if it is 0. + * + * @param[in] reason A <code>PP_Var</code> which represents the WebSocket + * close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>. + * Otherwise, its <code>PP_VarType</code> must be + * <code>PP_VARTYPE_STRING</code>. + * + * @param[in] callback A <code>PP_CompletionCallback</code> which is called + * when the connection is closed or an error occurs in closing connection. + * + * @return In case of immediate failure, returns an error code as follows. + * Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript + * SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to JavaScript + * InvalidAccessError. Otherwise, returns + * <code>PP_OK_COMPLETIONPENDING</code> and invokes <code>callback</code> + * later. + */ + 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 bytes of 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[out] message The received message is copied to provided + * <code>message</code>. + * + * @param[in] callback A <code>PP_CompletionCallback</code> which is called + * when the receiving message is completed. It is ignored when the function + * return <code>PP_OK</code>. + * + * @return In case of immediate failure, returns + * <code>PP_ERROR_FAILED</code>. If a message is currently available, returns + * <code>PP_OK</code>. Otherwise, returns <PP_OK_COMPLETIONPENDING</code> + * and invokes <code>callback</code> later. At that case, if GetReadyState() + * returns <code>PP_WEBSOCKETREADYSTATE_OPEN</code>, the received + * message is also copied to procided <code>message</code>. Otherwise, + * the connection is closed and ReceiveMessage() failed to receive a message. + */ + 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[in] message A message to send. The message is copied to internal + * buffer. So caller can free <code>message</code> safely after returning + * from the function. + * + * @return In case of immediate failure, returns an error code as follows. + * Returns <code>PP_ERROR_FAILED</code> corresponding to JavaScript + * InvalidStateError and <code>PP_ERROR_BADARGUMENT</code> corresponding to + * JavaScript SyntaxError. Otherwise, return <code>PP_OK</code>. + * <code>PP_OK</code> 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. + * + * Note: This interface might not be able to return exact bytes in the first + * release. Current WebSocket implementation can not estimate exact protocol + * frame overheads. + * + * @param[in] web_socket A <code>PP_Resource</code> 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 <code>PP_Resource</code> 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_NULL</code> var if called before the + * close reason is set, or <code>PP_VARTYPE_UNDEFINED</code> 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns <code>PP_FALSE</code> if called before the connection is + * closed. Otherwise, returns <code>PP_TRUE</code> if the connection was + * closed cleanly and returns <code>PP_FALSE</code> if the connection was + * closed by 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the + * connection is established or called on an invalid resource, its data is + * empty string. + * Currently its data is always 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the + * connection is established, or called on an invalid resource, its data is + * empty string. + */ + PP_Var GetProtocol([in] PP_Resource web_socket); + + /** + * GetReadyState() returns the ready state of the specified WebSocket + * connection. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code> if called + * before the connection is established. + */ + PP_WebSocketReadyState_Dev GetReadyState([in] PP_Resource web_socket); + + /** + * GetURL() returns the URL associated with specified WebSocket connection. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the + * connection is established, or called on an invalid resource, its data is + * empty string. + */ + 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 new file mode 100644 index 0000000..2be0c76 --- /dev/null +++ b/ppapi/c/dev/ppb_websocket_dev.h @@ -0,0 +1,317 @@ +/* Copyright (c) 2011 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 Mon Nov 7 15:21:42 2011. */ + +#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 <code>PPB_WebSocket_Dev</code> 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 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); + +/** + * This enumeration contains the types representing the WebSocket message type + * and these types are based on the JavaScript WebSocket API specification. + * ReceiveMessage() and SendMessage() use them as a parameter to represent + * handling message types. + */ +typedef enum { + /** + * Message type that represents a text message type. + */ + PP_WEBSOCKET_MESSAGE_TYPE_TEXT_DEV = 0, + /** + * Message type that represents a binary message type. + */ + PP_WEBSOCKET_MESSAGE_TYPE_BINARY_DEV = 1 +} PP_WebSocketMessageType_Dev; +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketMessageType_Dev, 4); +/** + * @} + */ + +/** + * @addtogroup Interfaces + * @{ + */ +struct PPB_WebSocket_Dev { + /** + * Create() creates a WebSocket instance. + * + * @param[in] instance A <code>PP_Instance</code> identifying the instance + * with the WebSocket. + * + * @return A <code>PP_Resource</code> corresponding to a WebSocket if + * successful. + */ + PP_Resource (*Create)(PP_Instance instance); + /** + * IsWebSocket() determines if the provided <code>resource</code> is a + * WebSocket instance. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a + * <code>PPB_WebSocket_Dev</code>, <code>PP_FALSE</code> if the + * <code>resource</code> is invalid or some type other than + * <code>PPB_WebSocket_Dev</code>. + */ + PP_Bool (*IsWebSocket)(PP_Resource resource); + /** + * Connect() connects to the specified WebSocket server. Caller can call this + * method at most once for a <code>web_socket</code>. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL. + * The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>. + * + * @param[in] protocols A pointer to an array of <code>PP_Var</code> + * specifying sub-protocols. Each <code>PP_Var</code> represents one + * sub-protocol and its <code>PP_VarType</code> must be + * <code>PP_VARTYPE_STRING</code>. This argument can be null only if + * <code>protocol_count</code> is 0. + * + * @param[in] protocol_count The number of sub-protocols in + * <code>protocols</code>. + * + * @param[in] callback A <code>PP_CompletionCallback</code> which is called + * when the connection is established or an error occurs in establishing + * connection. + * + * @return In case of immediate failure, returns an error code as follows. + * Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript + * SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to JavaScript + * SecurityError. Otherwise, returns <code>PP_OK_COMPLETIONPENDING</code> + * and invokes <code>callback</code> later. + */ + 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>code</code> and <code>reason</code>. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[in] code The WebSocket close code. Ignored if it is 0. + * + * @param[in] reason A <code>PP_Var</code> which represents the WebSocket + * close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>. + * Otherwise, its <code>PP_VarType</code> must be + * <code>PP_VARTYPE_STRING</code>. + * + * @param[in] callback A <code>PP_CompletionCallback</code> which is called + * when the connection is closed or an error occurs in closing connection. + * + * @return In case of immediate failure, returns an error code as follows. + * Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript + * SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to JavaScript + * InvalidAccessError. Otherwise, returns + * <code>PP_OK_COMPLETIONPENDING</code> and invokes <code>callback</code> + * later. + */ + 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 bytes of 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[out] message The received message is copied to provided + * <code>message</code>. + * + * @param[in] callback A <code>PP_CompletionCallback</code> which is called + * when the receiving message is completed. It is ignored when the function + * return <code>PP_OK</code>. + * + * @return In case of immediate failure, returns + * <code>PP_ERROR_FAILED</code>. If a message is currently available, returns + * <code>PP_OK</code>. Otherwise, returns <PP_OK_COMPLETIONPENDING</code> + * and invokes <code>callback</code> later. At that case, if GetReadyState() + * returns <code>PP_WEBSOCKETREADYSTATE_OPEN</code>, the received + * message is also copied to procided <code>message</code>. Otherwise, + * the connection is closed and ReceiveMessage() failed to receive a message. + */ + 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @param[in] message A message to send. The message is copied to internal + * buffer. So caller can free <code>message</code> safely after returning + * from the function. + * + * @return In case of immediate failure, returns an error code as follows. + * Returns <code>PP_ERROR_FAILED</code> corresponding to JavaScript + * InvalidStateError and <code>PP_ERROR_BADARGUMENT</code> corresponding to + * JavaScript SyntaxError. Otherwise, return <code>PP_OK</code>. + * <code>PP_OK</code> 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. + * + * Note: This interface might not be able to return exact bytes in the first + * release. Current WebSocket implementation can not estimate exact protocol + * frame overheads. + * + * @param[in] web_socket A <code>PP_Resource</code> 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 <code>PP_Resource</code> 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_NULL</code> var if called before the + * close reason is set, or <code>PP_VARTYPE_UNDEFINED</code> 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns <code>PP_FALSE</code> if called before the connection is + * closed. Otherwise, returns <code>PP_TRUE</code> if the connection was + * closed cleanly and returns <code>PP_FALSE</code> if the connection was + * closed by 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the + * connection is established or called on an invalid resource, its data is + * empty string. + * Currently its data is always 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 <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the + * connection is established, or called on an invalid resource, its data is + * empty string. + */ + struct PP_Var (*GetProtocol)(PP_Resource web_socket); + /** + * GetReadyState() returns the ready state of the specified WebSocket + * connection. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code> if called + * before the connection is established. + */ + PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket); + /** + * GetURL() returns the URL associated with specified WebSocket connection. + * + * @param[in] web_socket A <code>PP_Resource</code> corresponding to a + * WebSocket. + * + * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the + * connection is established, or called on an invalid resource, its data is + * empty string. + */ + struct PP_Var (*GetURL)(PP_Resource web_socket); +}; +/** + * @} + */ + +#endif /* PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ */ + diff --git a/ppapi/cpp/dev/websocket_dev.h b/ppapi/cpp/dev/websocket_dev.h new file mode 100644 index 0000000..f7bca16 --- /dev/null +++ b/ppapi/cpp/dev/websocket_dev.h @@ -0,0 +1,135 @@ +// Copyright (c) 2011 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" + +/// @file +/// This file defines the WebSocket_Dev interface. + +namespace pp { + +class Var; + +/// The <code>WebSocket_Dev</code> class +/// A version that use virtual functions +class WebSocket_Dev : public Resource { + public: + /// Constructs a WebSocket_Dev object. + WebSocket_Dev(); + + /// 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 <code>PP_Var</code> representing a WebSocket server URL. + /// The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>. + /// @param[in] protocols A pointer to an array of <code>PP_Var</code> + /// specifying sub-protocols. Each <code>PP_Var</code> represents one + /// sub-protocol and its <code>PP_VarType</code> must be + /// <code>PP_VARTYPE_STRING</code>. This argument can be null only if + /// <code>protocol_count</code> is 0. + /// @param[in] protocol_count The number of sub-protocols in + /// <code>protocols</code>. + /// + /// @return In case of immediate failure, returns an error code as follows. + /// Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript + /// SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to + /// JavaScript SecurityError. Otherwise, returns + /// <code>PP_OK_COMPLETIONPENDING</code> and later invokes + /// <code>OnOpen()</code> on success or <code>OnClose()</code> on failure. + int32_t Connect(const Var& url, const Var protocols[], + uint32_t protocol_count); + + /// Close() closes the specified WebSocket connection by specifying + /// <code>code</code> and <code>reason</code>. + /// + /// @param[in] code The WebSocket close code. Ignored if it is 0. + /// @param[in] reason A <code>PP_Var</code> which represents the WebSocket + /// close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>. + /// Otherwise, its <code>PP_VarType</code> must be + /// <code>PP_VARTYPE_STRING</code>. + /// + /// @return In case of immediate failure, returns an error code as follows. + /// Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript + /// SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to + /// JavaScript InvalidAccessError. Otherwise, returns + /// <code>PP_OK_COMPLETIONPENDING</code> and invokes <code>OnClose</code>. + int32_t Close(uint16_t code, const Var& reason); + + /// 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 <code>data</code> safely after returning + /// from the function. + /// + /// @return In case of immediate failure, returns an error code as follows. + /// Returns <code>PP_ERROR_FAILED</code> corresponding to JavaScript + /// InvalidStateError and <code>PP_ERROR_BADARGUMENT</code> corresponding to + /// JavaScript SyntaxError. Otherwise, return <code>PP_OK</code>. + /// <code>PP_OK</code> doesn't necessarily mean that the server received the + /// message. + int32_t Send(const Var& data); + + /// 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. + /// + /// Note: This interface might not be able to return exact bytes in the first + /// release. Current WebSocket implementation can not estimate exact protocol + /// frame overheads. + /// + /// @return Returns the number of bytes. + uint64_t GetBufferedAmount(); + + /// GetExtensions() returns the extensions selected by the server for the + /// specified WebSocket connection. + /// + /// @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before + /// the connection is established, its data is empty string. + /// Currently its data is always empty string. + Var GetExtensions(); + + /// GetProtocol() returns the sub-protocol chosen by the server for the + /// specified WebSocket connection. + /// + /// @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before + /// the connection is established, its data is empty string. + Var GetProtocol(); + + /// GetReadyState() returns the ready state of the specified WebSocket + /// connection. + /// + /// @return Returns <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code> if called + /// before the connection is established. + PP_WebSocketReadyState_Dev GetReadyState(); + + /// GetURL() returns the URL associated with specified WebSocket connection. + /// + /// @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before + /// the connection is established, its data is empty string. + Var GetURL(); + + /// OnOpen() is invoked when the connection is established by Connect(). + virtual void OnOpen() = 0; + + /// OnMessage() is invoked when a message is received. + virtual void OnMessage(Var message) = 0; + + /// OnError() is invoked if the user agent was required to fail the WebSocket + /// connection or the WebSocket connection is closed with prejudice. + /// OnClose() always follows OnError(). + virtual void OnError() = 0; + + /// OnClose() is invoked when the connection is closed by errors or Close(). + virtual void OnClose(bool wasClean, uint16_t code, const Var& reason) = 0; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_WEBSOCKET_DEV_H_ diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi index 7d18b3d..9771de3 100644 --- a/ppapi/ppapi_cpp.gypi +++ b/ppapi/ppapi_cpp.gypi @@ -77,6 +77,7 @@ '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', diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index 776d87a..3c41d7d 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -35,6 +35,7 @@ #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" diff --git a/ppapi/tests/all_cpp_includes.h b/ppapi/tests/all_cpp_includes.h index 50df529..4ea5e0a 100644 --- a/ppapi/tests/all_cpp_includes.h +++ b/ppapi/tests/all_cpp_includes.h @@ -31,6 +31,7 @@ #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" |