[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 1 | /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
| 6 | /** |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 7 | * This file defines the <code>PPB_WebSocket</code> interface. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 8 | */ |
| 9 | label Chrome { |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 10 | M18 = 1.0 |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 11 | }; |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * This enumeration contains the types representing the WebSocket ready state |
| 16 | * and these states are based on the JavaScript WebSocket API specification. |
| 17 | * GetReadyState() returns one of these states. |
| 18 | */ |
| 19 | [assert_size(4)] |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 20 | enum PP_WebSocketReadyState { |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 21 | /** |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 22 | * Ready state is queried on an invalid resource. |
| 23 | */ |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 24 | PP_WEBSOCKETREADYSTATE_INVALID = -1, |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 25 | /** |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 26 | * Ready state that the connection has not yet been established. |
| 27 | */ |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 28 | PP_WEBSOCKETREADYSTATE_CONNECTING = 0, |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Ready state that the WebSocket connection is established and communication |
| 32 | * is possible. |
| 33 | */ |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 34 | PP_WEBSOCKETREADYSTATE_OPEN = 1, |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Ready state that the connection is going through the closing handshake. |
| 38 | */ |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 39 | PP_WEBSOCKETREADYSTATE_CLOSING = 2, |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Ready state that the connection has been closed or could not be opened. |
| 43 | */ |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 44 | PP_WEBSOCKETREADYSTATE_CLOSED = 3 |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 45 | }; |
| 46 | |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 47 | interface PPB_WebSocket { |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 48 | /** |
| 49 | * Create() creates a WebSocket instance. |
| 50 | * |
| 51 | * @param[in] instance A <code>PP_Instance</code> identifying the instance |
| 52 | * with the WebSocket. |
| 53 | * |
| 54 | * @return A <code>PP_Resource</code> corresponding to a WebSocket if |
| 55 | * successful. |
| 56 | */ |
| 57 | PP_Resource Create([in] PP_Instance instance); |
| 58 | |
| 59 | /** |
| 60 | * IsWebSocket() determines if the provided <code>resource</code> is a |
| 61 | * WebSocket instance. |
| 62 | * |
| 63 | * @param[in] resource A <code>PP_Resource</code> corresponding to a |
| 64 | * WebSocket. |
| 65 | * |
| 66 | * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 67 | * <code>PPB_WebSocket</code>, <code>PP_FALSE</code> if the |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 68 | * <code>resource</code> is invalid or some type other than |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 69 | * <code>PPB_WebSocket</code>. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 70 | */ |
| 71 | PP_Bool IsWebSocket([in] PP_Resource resource); |
| 72 | |
| 73 | /** |
| 74 | * Connect() connects to the specified WebSocket server. Caller can call this |
| 75 | * method at most once for a <code>web_socket</code>. |
| 76 | * |
| 77 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 78 | * WebSocket. |
| 79 | * |
| 80 | * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL. |
| 81 | * The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>. |
| 82 | * |
| 83 | * @param[in] protocols A pointer to an array of <code>PP_Var</code> |
| 84 | * specifying sub-protocols. Each <code>PP_Var</code> represents one |
| 85 | * sub-protocol and its <code>PP_VarType</code> must be |
| 86 | * <code>PP_VARTYPE_STRING</code>. This argument can be null only if |
| 87 | * <code>protocol_count</code> is 0. |
| 88 | * |
| 89 | * @param[in] protocol_count The number of sub-protocols in |
| 90 | * <code>protocols</code>. |
| 91 | * |
| 92 | * @param[in] callback A <code>PP_CompletionCallback</code> which is called |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 93 | * when a connection is established or an error occurs in establishing |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 94 | * connection. |
| 95 | * |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 96 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 97 | * Returns <code>PP_ERROR_BADARGUMENT</code> if specified <code>url</code>, |
| 98 | * or <code>protocols</code> contains invalid string as |
| 99 | * <code>The WebSocket API specification</code> defines. It corresponds to |
| 100 | * SyntaxError of the specification. |
| 101 | * Returns <code>PP_ERROR_NOACCESS</code> if the protocol specified in the |
| 102 | * <code>url</code> is not a secure protocol, but the origin of the caller |
| 103 | * has a secure scheme. Also returns it if the port specified in the |
| 104 | * <code>url</code> is a port to which the user agent is configured to block |
| 105 | * access because the port is a well-known port like SMTP. It corresponds to |
| 106 | * SecurityError of the specification. |
| 107 | * Returns <code>PP_ERROR_INPROGRESS</code> if the call is not the first |
| 108 | * time. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 109 | */ |
| 110 | int32_t Connect([in] PP_Resource web_socket, |
| 111 | [in] PP_Var url, |
| 112 | [in, size_as=protocol_count] PP_Var[] protocols, |
| 113 | [in] uint32_t protocol_count, |
| 114 | [in] PP_CompletionCallback callback); |
| 115 | |
| 116 | /** |
| 117 | * Close() closes the specified WebSocket connection by specifying |
| 118 | * <code>code</code> and <code>reason</code>. |
| 119 | * |
| 120 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 121 | * WebSocket. |
| 122 | * |
| 123 | * @param[in] code The WebSocket close code. Ignored if it is 0. |
| 124 | * |
| 125 | * @param[in] reason A <code>PP_Var</code> which represents the WebSocket |
| 126 | * close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>. |
| 127 | * Otherwise, its <code>PP_VarType</code> must be |
| 128 | * <code>PP_VARTYPE_STRING</code>. |
| 129 | * |
| 130 | * @param[in] callback A <code>PP_CompletionCallback</code> which is called |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 131 | * when the connection is closed or an error occurs in closing the |
| 132 | * connection. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 133 | * |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 134 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 135 | * Returns <code>PP_ERROR_BADARGUMENT</code> if <code>reason</code> contains |
| 136 | * an invalid character as a UTF-8 string, or longer than 123 bytes. It |
| 137 | * corresponds to JavaScript SyntaxError of the specification. |
| 138 | * Returns <code>PP_ERROR_NOACCESS</code> if the code is not an integer |
| 139 | * equal to 1000 or in the range 3000 to 4999. It corresponds to |
| 140 | * InvalidAccessError of the specification. Returns |
| 141 | * <code>PP_ERROR_INPROGRESS</code> if the call is not the first time. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 142 | */ |
| 143 | int32_t Close([in] PP_Resource web_socket, |
| 144 | [in] uint16_t code, |
| 145 | [in] PP_Var reason, |
| 146 | [in] PP_CompletionCallback callback); |
| 147 | |
| 148 | /** |
| 149 | * ReceiveMessage() receives a message from the WebSocket server. |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 150 | * This interface only returns a single message. That is, this interface must |
| 151 | * be called at least N times to receive N messages, no matter how small each |
| 152 | * message is. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 153 | * |
| 154 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 155 | * WebSocket. |
| 156 | * |
| 157 | * @param[out] message The received message is copied to provided |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 158 | * <code>message</code>. The <code>message</code> must remain valid until |
[email protected] | dc909a9 | 2012-01-27 06:07:25 | [diff] [blame] | 159 | * the ReceiveMessage operation completes. Its <code>PP_VarType</code> |
| 160 | * will be <code>PP_VARTYPE_STRING</code> or |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 161 | * <code>PP_VARTYPE_ARRAY_BUFFER</code> on receiving. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 162 | * |
| 163 | * @param[in] callback A <code>PP_CompletionCallback</code> which is called |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 164 | * when the receiving message is completed. It is ignored if ReceiveMessage |
| 165 | * completes synchronously and returns <code>PP_OK</code>. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 166 | * |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 167 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 168 | * If an error is detected or connection is closed, returns |
| 169 | * <code>PP_ERROR_FAILED</code> after all buffered messages are received. |
| 170 | * Until buffered message become empty, continues to returns |
| 171 | * <code>PP_OK</code> as if connection is still established without errors. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 172 | */ |
| 173 | int32_t ReceiveMessage([in] PP_Resource web_socket, |
| 174 | [out] PP_Var message, |
| 175 | [in] PP_CompletionCallback callback); |
| 176 | |
| 177 | /** |
| 178 | * SendMessage() sends a message to the WebSocket server. |
| 179 | * |
| 180 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 181 | * WebSocket. |
| 182 | * |
| 183 | * @param[in] message A message to send. The message is copied to internal |
| 184 | * buffer. So caller can free <code>message</code> safely after returning |
[email protected] | dc909a9 | 2012-01-27 06:07:25 | [diff] [blame] | 185 | * from the function. Its <code>PP_VarType</code> must be |
| 186 | * <code>PP_VARTYPE_STRING</code> or <code>PP_VARTYPE_ARRAY_BUFFER</code>. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 187 | * |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 188 | * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 189 | * Returns <code>PP_ERROR_FAILED</code> if the ReadyState is |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 190 | * <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code>. It corresponds JavaScript |
| 191 | * InvalidStateError of the specification. |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 192 | * Returns <code>PP_ERROR_BADARGUMENT</code> if provided <code>message</code> |
| 193 | * of string type contains an invalid character as a UTF-8 string. It |
| 194 | * corresponds to JavaScript SyntaxError of the specification. |
| 195 | * Otherwise, returns <code>PP_OK</code>, but it doesn't necessarily mean |
| 196 | * that the server received the message. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 197 | */ |
| 198 | int32_t SendMessage([in] PP_Resource web_socket, |
| 199 | [in] PP_Var message); |
| 200 | |
| 201 | /** |
| 202 | * GetBufferedAmount() returns the number of bytes of text and binary |
| 203 | * messages that have been queued for the WebSocket connection to send but |
| 204 | * have not been transmitted to the network yet. |
| 205 | * |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 206 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 207 | * WebSocket. |
| 208 | * |
| 209 | * @return Returns the number of bytes. |
| 210 | */ |
| 211 | uint64_t GetBufferedAmount([in] PP_Resource web_socket); |
| 212 | |
| 213 | /** |
| 214 | * GetCloseCode() returns the connection close code for the WebSocket |
| 215 | * connection. |
| 216 | * |
| 217 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 218 | * WebSocket. |
| 219 | * |
| 220 | * @return Returns 0 if called before the close code is set. |
| 221 | */ |
| 222 | uint16_t GetCloseCode([in] PP_Resource web_socket); |
| 223 | |
| 224 | /** |
| 225 | * GetCloseReason() returns the connection close reason for the WebSocket |
| 226 | * connection. |
| 227 | * |
| 228 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 229 | * WebSocket. |
| 230 | * |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 231 | * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the |
| 232 | * close reason is set, it contains an empty string. Returns a |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 233 | * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 234 | */ |
| 235 | PP_Var GetCloseReason([in] PP_Resource web_socket); |
| 236 | |
| 237 | /** |
| 238 | * GetCloseWasClean() returns if the connection was closed cleanly for the |
| 239 | * specified WebSocket connection. |
| 240 | * |
| 241 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 242 | * WebSocket. |
| 243 | * |
| 244 | * @return Returns <code>PP_FALSE</code> if called before the connection is |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 245 | * closed, or called on an invalid resource. Otherwise, returns |
| 246 | * <code>PP_TRUE</code> if the connection was closed cleanly, or returns |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 247 | * <code>PP_FALSE</code> if the connection was closed for abnormal reasons. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 248 | */ |
| 249 | PP_Bool GetCloseWasClean([in] PP_Resource web_socket); |
| 250 | |
| 251 | /** |
| 252 | * GetExtensions() returns the extensions selected by the server for the |
| 253 | * specified WebSocket connection. |
| 254 | * |
| 255 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 256 | * WebSocket. |
| 257 | * |
| 258 | * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 259 | * connection is established, its data is an empty string. Returns a |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 260 | * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 261 | * Currently its data for valid resources are always an empty string. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 262 | */ |
| 263 | PP_Var GetExtensions([in] PP_Resource web_socket); |
| 264 | |
| 265 | /** |
| 266 | * GetProtocol() returns the sub-protocol chosen by the server for the |
| 267 | * specified WebSocket connection. |
| 268 | * |
| 269 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 270 | * WebSocket. |
| 271 | * |
| 272 | * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 273 | * connection is established, it contains the empty string. Returns a |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 274 | * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 275 | */ |
| 276 | PP_Var GetProtocol([in] PP_Resource web_socket); |
| 277 | |
| 278 | /** |
| 279 | * GetReadyState() returns the ready state of the specified WebSocket |
| 280 | * connection. |
| 281 | * |
| 282 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 283 | * WebSocket. |
| 284 | * |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 285 | * @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID</code> if called |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 286 | * before connect() is called, or called on an invalid resource. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 287 | */ |
[email protected] | 5350822 | 2012-01-27 09:42:41 | [diff] [blame^] | 288 | PP_WebSocketReadyState GetReadyState([in] PP_Resource web_socket); |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 289 | |
| 290 | /** |
| 291 | * GetURL() returns the URL associated with specified WebSocket connection. |
| 292 | * |
| 293 | * @param[in] web_socket A <code>PP_Resource</code> corresponding to a |
| 294 | * WebSocket. |
| 295 | * |
| 296 | * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the |
[email protected] | 3e919cb | 2011-12-16 07:28:21 | [diff] [blame] | 297 | * connection is established, it contains the empty string. Return a |
[email protected] | 4454db0 | 2011-11-16 05:25:01 | [diff] [blame] | 298 | * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 299 | */ |
| 300 | PP_Var GetURL([in] PP_Resource web_socket); |
[email protected] | f88c2e0 | 2011-11-11 05:50:59 | [diff] [blame] | 301 | }; |