Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: ppapi/c/ppb_websocket.h

Issue 9192009: WebSocket Pepper API: make the API out of dev (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove binary type handling interfaces Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /* From dev/ppb_websocket_dev.idl modified Wed Jan 18 20:17:45 2012. */ 6 /* From ppb_websocket.idl modified Thu Jan 26 14:29:58 2012. */
7 7
8 #ifndef PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ 8 #ifndef PPAPI_C_PPB_WEBSOCKET_H_
9 #define PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ 9 #define PPAPI_C_PPB_WEBSOCKET_H_
10 10
11 #include "ppapi/c/pp_bool.h" 11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h" 12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h" 13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_macros.h" 14 #include "ppapi/c/pp_macros.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_stdint.h" 16 #include "ppapi/c/pp_stdint.h"
17 #include "ppapi/c/pp_var.h" 17 #include "ppapi/c/pp_var.h"
18 18
19 #define PPB_WEBSOCKET_DEV_INTERFACE_0_1 "PPB_WebSocket(Dev);0.1" 19 #define PPB_WEBSOCKET_INTERFACE_1_0 "PPB_WebSocket;1.0"
20 #define PPB_WEBSOCKET_DEV_INTERFACE_0_9 "PPB_WebSocket(Dev);0.9" 20 #define PPB_WEBSOCKET_INTERFACE PPB_WEBSOCKET_INTERFACE_1_0
21 #define PPB_WEBSOCKET_DEV_INTERFACE PPB_WEBSOCKET_DEV_INTERFACE_0_9
22 21
23 /** 22 /**
24 * @file 23 * @file
25 * This file defines the <code>PPB_WebSocket_Dev</code> interface. 24 * This file defines the <code>PPB_WebSocket</code> interface.
26 */ 25 */
27 26
28 27
29 /** 28 /**
30 * @addtogroup Enums 29 * @addtogroup Enums
31 * @{ 30 * @{
32 */ 31 */
33 /** 32 /**
34 * This enumeration contains the types representing the WebSocket ready state 33 * This enumeration contains the types representing the WebSocket ready state
35 * and these states are based on the JavaScript WebSocket API specification. 34 * and these states are based on the JavaScript WebSocket API specification.
36 * GetReadyState() returns one of these states. 35 * GetReadyState() returns one of these states.
37 */ 36 */
38 typedef enum { 37 typedef enum {
39 /** 38 /**
40 * Ready state is queried on an invalid resource. 39 * Ready state is queried on an invalid resource.
41 */ 40 */
42 PP_WEBSOCKETREADYSTATE_INVALID_DEV = -1, 41 PP_WEBSOCKETREADYSTATE_INVALID = -1,
43 /** 42 /**
44 * Ready state that the connection has not yet been established. 43 * Ready state that the connection has not yet been established.
45 */ 44 */
46 PP_WEBSOCKETREADYSTATE_CONNECTING_DEV = 0, 45 PP_WEBSOCKETREADYSTATE_CONNECTING = 0,
47 /** 46 /**
48 * Ready state that the WebSocket connection is established and communication 47 * Ready state that the WebSocket connection is established and communication
49 * is possible. 48 * is possible.
50 */ 49 */
51 PP_WEBSOCKETREADYSTATE_OPEN_DEV = 1, 50 PP_WEBSOCKETREADYSTATE_OPEN = 1,
52 /** 51 /**
53 * Ready state that the connection is going through the closing handshake. 52 * Ready state that the connection is going through the closing handshake.
54 */ 53 */
55 PP_WEBSOCKETREADYSTATE_CLOSING_DEV = 2, 54 PP_WEBSOCKETREADYSTATE_CLOSING = 2,
56 /** 55 /**
57 * Ready state that the connection has been closed or could not be opened. 56 * Ready state that the connection has been closed or could not be opened.
58 */ 57 */
59 PP_WEBSOCKETREADYSTATE_CLOSED_DEV = 3 58 PP_WEBSOCKETREADYSTATE_CLOSED = 3
60 } PP_WebSocketReadyState_Dev; 59 } PP_WebSocketReadyState;
61 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketReadyState_Dev, 4); 60 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketReadyState, 4);
62
63 /**
64 * This enumeration contains the types representing the WebSocket binary type
65 * to receive frames. These types are based on the JavaScript WebSocket API
66 * specification.
67 */
68 typedef enum {
69 /**
70 * Binary type is queried on an invalid resource.
71 */
72 PP_WEBSOCKETBINARYTYPE_INVALID = -1,
73 /**
74 * Binary type that represents Blob objects.
75 */
76 PP_WEBSOCKETBINARYTYPE_BLOB_DEV = 0,
77 /**
78 * Binary type that represents ArrayBuffer objects.
79 */
80 PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV = 1
81 } PP_WebSocketBinaryType_Dev;
82 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketBinaryType_Dev, 4);
83 /** 61 /**
84 * @} 62 * @}
85 */ 63 */
86 64
87 /** 65 /**
88 * @addtogroup Interfaces 66 * @addtogroup Interfaces
89 * @{ 67 * @{
90 */ 68 */
91 struct PPB_WebSocket_Dev_0_9 { 69 struct PPB_WebSocket_1_0 {
92 /** 70 /**
93 * Create() creates a WebSocket instance. 71 * Create() creates a WebSocket instance.
94 * 72 *
95 * @param[in] instance A <code>PP_Instance</code> identifying the instance 73 * @param[in] instance A <code>PP_Instance</code> identifying the instance
96 * with the WebSocket. 74 * with the WebSocket.
97 * 75 *
98 * @return A <code>PP_Resource</code> corresponding to a WebSocket if 76 * @return A <code>PP_Resource</code> corresponding to a WebSocket if
99 * successful. 77 * successful.
100 */ 78 */
101 PP_Resource (*Create)(PP_Instance instance); 79 PP_Resource (*Create)(PP_Instance instance);
102 /** 80 /**
103 * IsWebSocket() determines if the provided <code>resource</code> is a 81 * IsWebSocket() determines if the provided <code>resource</code> is a
104 * WebSocket instance. 82 * WebSocket instance.
105 * 83 *
106 * @param[in] resource A <code>PP_Resource</code> corresponding to a 84 * @param[in] resource A <code>PP_Resource</code> corresponding to a
107 * WebSocket. 85 * WebSocket.
108 * 86 *
109 * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a 87 * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a
110 * <code>PPB_WebSocket_Dev</code>, <code>PP_FALSE</code> if the 88 * <code>PPB_WebSocket</code>, <code>PP_FALSE</code> if the
111 * <code>resource</code> is invalid or some type other than 89 * <code>resource</code> is invalid or some type other than
112 * <code>PPB_WebSocket_Dev</code>. 90 * <code>PPB_WebSocket</code>.
113 */ 91 */
114 PP_Bool (*IsWebSocket)(PP_Resource resource); 92 PP_Bool (*IsWebSocket)(PP_Resource resource);
115 /** 93 /**
116 * Connect() connects to the specified WebSocket server. Caller can call this 94 * Connect() connects to the specified WebSocket server. Caller can call this
117 * method at most once for a <code>web_socket</code>. 95 * method at most once for a <code>web_socket</code>.
118 * 96 *
119 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a 97 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
120 * WebSocket. 98 * WebSocket.
121 * 99 *
122 * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL. 100 * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 * ReceiveMessage() receives a message from the WebSocket server. 167 * ReceiveMessage() receives a message from the WebSocket server.
190 * This interface only returns a single message. That is, this interface must 168 * This interface only returns a single message. That is, this interface must
191 * be called at least N times to receive N messages, no matter how small each 169 * be called at least N times to receive N messages, no matter how small each
192 * message is. 170 * message is.
193 * 171 *
194 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a 172 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
195 * WebSocket. 173 * WebSocket.
196 * 174 *
197 * @param[out] message The received message is copied to provided 175 * @param[out] message The received message is copied to provided
198 * <code>message</code>. The <code>message</code> must remain valid until 176 * <code>message</code>. The <code>message</code> must remain valid until
199 * the ReceiveMessage operation completes. 177 * the ReceiveMessage operation completes. Its <code>PP_VarType</code>
178 * will be <code>PP_VARTYPE_STRING</code> or
179 * <code>PP_VARTYPE_ARRAY_BUFFER</code> on receiving.
200 * 180 *
201 * @param[in] callback A <code>PP_CompletionCallback</code> which is called 181 * @param[in] callback A <code>PP_CompletionCallback</code> which is called
202 * when the receiving message is completed. It is ignored if ReceiveMessage 182 * when the receiving message is completed. It is ignored if ReceiveMessage
203 * completes synchronously and returns <code>PP_OK</code>. 183 * completes synchronously and returns <code>PP_OK</code>.
204 * 184 *
205 * @return An int32_t containing an error code from <code>pp_errors.h</code>. 185 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
206 * If an error is detected or connection is closed, returns 186 * If an error is detected or connection is closed, returns
207 * <code>PP_ERROR_FAILED</code> after all buffered messages are received. 187 * <code>PP_ERROR_FAILED</code> after all buffered messages are received.
208 * Until buffered message become empty, continues to returns 188 * Until buffered message become empty, continues to returns
209 * <code>PP_OK</code> as if connection is still established without errors. 189 * <code>PP_OK</code> as if connection is still established without errors.
210 */ 190 */
211 int32_t (*ReceiveMessage)(PP_Resource web_socket, 191 int32_t (*ReceiveMessage)(PP_Resource web_socket,
212 struct PP_Var* message, 192 struct PP_Var* message,
213 struct PP_CompletionCallback callback); 193 struct PP_CompletionCallback callback);
214 /** 194 /**
215 * SendMessage() sends a message to the WebSocket server. 195 * SendMessage() sends a message to the WebSocket server.
216 * 196 *
217 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a 197 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
218 * WebSocket. 198 * WebSocket.
219 * 199 *
220 * @param[in] message A message to send. The message is copied to internal 200 * @param[in] message A message to send. The message is copied to internal
221 * buffer. So caller can free <code>message</code> safely after returning 201 * buffer. So caller can free <code>message</code> safely after returning
222 * from the function. 202 * from the function. Its <code>PP_VarType</code> must be
203 * <code>PP_VARTYPE_STRING</code> or <code>PP_VARTYPE_ARRAY_BUFFER</code>.
223 * 204 *
224 * @return An int32_t containing an error code from <code>pp_errors.h</code>. 205 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
225 * Returns <code>PP_ERROR_FAILED</code> if the ReadyState is 206 * Returns <code>PP_ERROR_FAILED</code> if the ReadyState is
226 * <code>PP_WEBSOCKETREADYSTATE_CONNECTING_DEV</code>. It corresponds 207 * <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code>. It corresponds JavaScript
227 * JavaScript InvalidStateError of the specification. 208 * InvalidStateError of the specification.
228 * Returns <code>PP_ERROR_BADARGUMENT</code> if provided <code>message</code> 209 * Returns <code>PP_ERROR_BADARGUMENT</code> if provided <code>message</code>
229 * of string type contains an invalid character as a UTF-8 string. It 210 * of string type contains an invalid character as a UTF-8 string. It
230 * corresponds to JavaScript SyntaxError of the specification. 211 * corresponds to JavaScript SyntaxError of the specification.
231 * Otherwise, returns <code>PP_OK</code>, but it doesn't necessarily mean 212 * Otherwise, returns <code>PP_OK</code>, but it doesn't necessarily mean
232 * that the server received the message. 213 * that the server received the message.
233 */ 214 */
234 int32_t (*SendMessage)(PP_Resource web_socket, struct PP_Var message); 215 int32_t (*SendMessage)(PP_Resource web_socket, struct PP_Var message);
235 /** 216 /**
236 * GetBufferedAmount() returns the number of bytes of text and binary 217 * GetBufferedAmount() returns the number of bytes of text and binary
237 * messages that have been queued for the WebSocket connection to send but 218 * messages that have been queued for the WebSocket connection to send but
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. 284 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource.
304 */ 285 */
305 struct PP_Var (*GetProtocol)(PP_Resource web_socket); 286 struct PP_Var (*GetProtocol)(PP_Resource web_socket);
306 /** 287 /**
307 * GetReadyState() returns the ready state of the specified WebSocket 288 * GetReadyState() returns the ready state of the specified WebSocket
308 * connection. 289 * connection.
309 * 290 *
310 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a 291 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
311 * WebSocket. 292 * WebSocket.
312 * 293 *
313 * @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID_DEV</code> if called 294 * @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID</code> if called
314 * before connect() is called, or called on an invalid resource. 295 * before connect() is called, or called on an invalid resource.
315 */ 296 */
316 PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket); 297 PP_WebSocketReadyState (*GetReadyState)(PP_Resource web_socket);
317 /** 298 /**
318 * GetURL() returns the URL associated with specified WebSocket connection. 299 * GetURL() returns the URL associated with specified WebSocket connection.
319 * 300 *
320 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a 301 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
321 * WebSocket. 302 * WebSocket.
322 * 303 *
323 * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the 304 * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the
324 * connection is established, it contains the empty string. Return a 305 * connection is established, it contains the empty string. Return a
325 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. 306 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource.
326 */ 307 */
327 struct PP_Var (*GetURL)(PP_Resource web_socket); 308 struct PP_Var (*GetURL)(PP_Resource web_socket);
328 /**
329 * SetBinaryType() specifies the binary object type for receiving binary
330 * frames representation. Receiving text frames are always mapped to
331 * <PP_VARTYPE_STRING</code> var regardless of this attribute.
332 * This function should be called before Connect() to ensure receiving all
333 * incoming binary frames as the specified binary object type.
334 * Default type is <code>PP_WEBSOCKETBINARYTYPE_BLOB_DEV</code>.
335 *
336 * Currently, Blob bindings is not supported in Pepper, so receiving binary
337 * type is always ArrayBuffer. To ensure backward compatibility, you must
338 * call this function with
339 * <code>PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV</code> to use binary frames.
340 *
341 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
342 * WebSocket.
343 *
344 * @param[in] binary_type Binary object type for receiving binary frames
345 * representation.
346 *
347 * @return Returns <code>PP_FALSE</code> if the specified type is not
348 * supported. Otherwise, returns <code>PP_TRUE</code>.
349 */
350 PP_Bool (*SetBinaryType)(PP_Resource web_socket,
351 PP_WebSocketBinaryType_Dev binary_type);
352 /**
353 * GetBinaryType() returns the currently specified binary object type for
354 * receiving binary frames.
355 *
356 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
357 * WebSocket.
358 *
359 * @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents the
360 * current binary object type.
361 */
362 PP_WebSocketBinaryType_Dev (*GetBinaryType)(PP_Resource web_socket);
363 }; 309 };
364 310
365 typedef struct PPB_WebSocket_Dev_0_9 PPB_WebSocket_Dev; 311 typedef struct PPB_WebSocket_1_0 PPB_WebSocket;
366
367 struct PPB_WebSocket_Dev_0_1 {
368 PP_Resource (*Create)(PP_Instance instance);
369 PP_Bool (*IsWebSocket)(PP_Resource resource);
370 int32_t (*Connect)(PP_Resource web_socket,
371 struct PP_Var url,
372 const struct PP_Var protocols[],
373 uint32_t protocol_count,
374 struct PP_CompletionCallback callback);
375 int32_t (*Close)(PP_Resource web_socket,
376 uint16_t code,
377 struct PP_Var reason,
378 struct PP_CompletionCallback callback);
379 int32_t (*ReceiveMessage)(PP_Resource web_socket,
380 struct PP_Var* message,
381 struct PP_CompletionCallback callback);
382 int32_t (*SendMessage)(PP_Resource web_socket, struct PP_Var message);
383 uint64_t (*GetBufferedAmount)(PP_Resource web_socket);
384 uint16_t (*GetCloseCode)(PP_Resource web_socket);
385 struct PP_Var (*GetCloseReason)(PP_Resource web_socket);
386 PP_Bool (*GetCloseWasClean)(PP_Resource web_socket);
387 struct PP_Var (*GetExtensions)(PP_Resource web_socket);
388 struct PP_Var (*GetProtocol)(PP_Resource web_socket);
389 PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket);
390 struct PP_Var (*GetURL)(PP_Resource web_socket);
391 };
392 /** 312 /**
393 * @} 313 * @}
394 */ 314 */
395 315
396 #endif /* PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ */ 316 #endif /* PPAPI_C_PPB_WEBSOCKET_H_ */
397 317
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698