OLD | NEW |
| (Empty) |
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 | |
3 * found in the LICENSE file. | |
4 */ | |
5 | |
6 /* From dev/ppb_websocket_dev.idl modified Wed Jan 18 20:17:45 2012. */ | |
7 | |
8 #ifndef PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ | |
9 #define PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ | |
10 | |
11 #include "ppapi/c/pp_bool.h" | |
12 #include "ppapi/c/pp_completion_callback.h" | |
13 #include "ppapi/c/pp_instance.h" | |
14 #include "ppapi/c/pp_macros.h" | |
15 #include "ppapi/c/pp_resource.h" | |
16 #include "ppapi/c/pp_stdint.h" | |
17 #include "ppapi/c/pp_var.h" | |
18 | |
19 #define PPB_WEBSOCKET_DEV_INTERFACE_0_1 "PPB_WebSocket(Dev);0.1" | |
20 #define PPB_WEBSOCKET_DEV_INTERFACE_0_9 "PPB_WebSocket(Dev);0.9" | |
21 #define PPB_WEBSOCKET_DEV_INTERFACE PPB_WEBSOCKET_DEV_INTERFACE_0_9 | |
22 | |
23 /** | |
24 * @file | |
25 * This file defines the <code>PPB_WebSocket_Dev</code> interface. | |
26 */ | |
27 | |
28 | |
29 /** | |
30 * @addtogroup Enums | |
31 * @{ | |
32 */ | |
33 /** | |
34 * This enumeration contains the types representing the WebSocket ready state | |
35 * and these states are based on the JavaScript WebSocket API specification. | |
36 * GetReadyState() returns one of these states. | |
37 */ | |
38 typedef enum { | |
39 /** | |
40 * Ready state is queried on an invalid resource. | |
41 */ | |
42 PP_WEBSOCKETREADYSTATE_INVALID_DEV = -1, | |
43 /** | |
44 * Ready state that the connection has not yet been established. | |
45 */ | |
46 PP_WEBSOCKETREADYSTATE_CONNECTING_DEV = 0, | |
47 /** | |
48 * Ready state that the WebSocket connection is established and communication | |
49 * is possible. | |
50 */ | |
51 PP_WEBSOCKETREADYSTATE_OPEN_DEV = 1, | |
52 /** | |
53 * Ready state that the connection is going through the closing handshake. | |
54 */ | |
55 PP_WEBSOCKETREADYSTATE_CLOSING_DEV = 2, | |
56 /** | |
57 * Ready state that the connection has been closed or could not be opened. | |
58 */ | |
59 PP_WEBSOCKETREADYSTATE_CLOSED_DEV = 3 | |
60 } PP_WebSocketReadyState_Dev; | |
61 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketReadyState_Dev, 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 /** | |
84 * @} | |
85 */ | |
86 | |
87 /** | |
88 * @addtogroup Interfaces | |
89 * @{ | |
90 */ | |
91 struct PPB_WebSocket_Dev_0_9 { | |
92 /** | |
93 * Create() creates a WebSocket instance. | |
94 * | |
95 * @param[in] instance A <code>PP_Instance</code> identifying the instance | |
96 * with the WebSocket. | |
97 * | |
98 * @return A <code>PP_Resource</code> corresponding to a WebSocket if | |
99 * successful. | |
100 */ | |
101 PP_Resource (*Create)(PP_Instance instance); | |
102 /** | |
103 * IsWebSocket() determines if the provided <code>resource</code> is a | |
104 * WebSocket instance. | |
105 * | |
106 * @param[in] resource A <code>PP_Resource</code> corresponding to a | |
107 * WebSocket. | |
108 * | |
109 * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a | |
110 * <code>PPB_WebSocket_Dev</code>, <code>PP_FALSE</code> if the | |
111 * <code>resource</code> is invalid or some type other than | |
112 * <code>PPB_WebSocket_Dev</code>. | |
113 */ | |
114 PP_Bool (*IsWebSocket)(PP_Resource resource); | |
115 /** | |
116 * Connect() connects to the specified WebSocket server. Caller can call this | |
117 * method at most once for a <code>web_socket</code>. | |
118 * | |
119 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
120 * WebSocket. | |
121 * | |
122 * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL. | |
123 * The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>. | |
124 * | |
125 * @param[in] protocols A pointer to an array of <code>PP_Var</code> | |
126 * specifying sub-protocols. Each <code>PP_Var</code> represents one | |
127 * sub-protocol and its <code>PP_VarType</code> must be | |
128 * <code>PP_VARTYPE_STRING</code>. This argument can be null only if | |
129 * <code>protocol_count</code> is 0. | |
130 * | |
131 * @param[in] protocol_count The number of sub-protocols in | |
132 * <code>protocols</code>. | |
133 * | |
134 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
135 * when a connection is established or an error occurs in establishing | |
136 * connection. | |
137 * | |
138 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
139 * Returns <code>PP_ERROR_BADARGUMENT</code> if specified <code>url</code>, | |
140 * or <code>protocols</code> contains invalid string as | |
141 * <code>The WebSocket API specification</code> defines. It corresponds to | |
142 * SyntaxError of the specification. | |
143 * Returns <code>PP_ERROR_NOACCESS</code> if the protocol specified in the | |
144 * <code>url</code> is not a secure protocol, but the origin of the caller | |
145 * has a secure scheme. Also returns it if the port specified in the | |
146 * <code>url</code> is a port to which the user agent is configured to block | |
147 * access because the port is a well-known port like SMTP. It corresponds to | |
148 * SecurityError of the specification. | |
149 * Returns <code>PP_ERROR_INPROGRESS</code> if the call is not the first | |
150 * time. | |
151 */ | |
152 int32_t (*Connect)(PP_Resource web_socket, | |
153 struct PP_Var url, | |
154 const struct PP_Var protocols[], | |
155 uint32_t protocol_count, | |
156 struct PP_CompletionCallback callback); | |
157 /** | |
158 * Close() closes the specified WebSocket connection by specifying | |
159 * <code>code</code> and <code>reason</code>. | |
160 * | |
161 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
162 * WebSocket. | |
163 * | |
164 * @param[in] code The WebSocket close code. Ignored if it is 0. | |
165 * | |
166 * @param[in] reason A <code>PP_Var</code> which represents the WebSocket | |
167 * close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>. | |
168 * Otherwise, its <code>PP_VarType</code> must be | |
169 * <code>PP_VARTYPE_STRING</code>. | |
170 * | |
171 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
172 * when the connection is closed or an error occurs in closing the | |
173 * connection. | |
174 * | |
175 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
176 * Returns <code>PP_ERROR_BADARGUMENT</code> if <code>reason</code> contains | |
177 * an invalid character as a UTF-8 string, or longer than 123 bytes. It | |
178 * corresponds to JavaScript SyntaxError of the specification. | |
179 * Returns <code>PP_ERROR_NOACCESS</code> if the code is not an integer | |
180 * equal to 1000 or in the range 3000 to 4999. It corresponds to | |
181 * InvalidAccessError of the specification. Returns | |
182 * <code>PP_ERROR_INPROGRESS</code> if the call is not the first time. | |
183 */ | |
184 int32_t (*Close)(PP_Resource web_socket, | |
185 uint16_t code, | |
186 struct PP_Var reason, | |
187 struct PP_CompletionCallback callback); | |
188 /** | |
189 * ReceiveMessage() receives a message from the WebSocket server. | |
190 * 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 | |
192 * message is. | |
193 * | |
194 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
195 * WebSocket. | |
196 * | |
197 * @param[out] message The received message is copied to provided | |
198 * <code>message</code>. The <code>message</code> must remain valid until | |
199 * the ReceiveMessage operation completes. | |
200 * | |
201 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
202 * when the receiving message is completed. It is ignored if ReceiveMessage | |
203 * completes synchronously and returns <code>PP_OK</code>. | |
204 * | |
205 * @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 | |
207 * <code>PP_ERROR_FAILED</code> after all buffered messages are received. | |
208 * Until buffered message become empty, continues to returns | |
209 * <code>PP_OK</code> as if connection is still established without errors. | |
210 */ | |
211 int32_t (*ReceiveMessage)(PP_Resource web_socket, | |
212 struct PP_Var* message, | |
213 struct PP_CompletionCallback callback); | |
214 /** | |
215 * SendMessage() sends a message to the WebSocket server. | |
216 * | |
217 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
218 * WebSocket. | |
219 * | |
220 * @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 | |
222 * from the function. | |
223 * | |
224 * @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 | |
226 * <code>PP_WEBSOCKETREADYSTATE_CONNECTING_DEV</code>. It corresponds | |
227 * JavaScript InvalidStateError of the specification. | |
228 * 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 | |
230 * corresponds to JavaScript SyntaxError of the specification. | |
231 * Otherwise, returns <code>PP_OK</code>, but it doesn't necessarily mean | |
232 * that the server received the message. | |
233 */ | |
234 int32_t (*SendMessage)(PP_Resource web_socket, struct PP_Var message); | |
235 /** | |
236 * GetBufferedAmount() returns the number of bytes of text and binary | |
237 * messages that have been queued for the WebSocket connection to send but | |
238 * have not been transmitted to the network yet. | |
239 * | |
240 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
241 * WebSocket. | |
242 * | |
243 * @return Returns the number of bytes. | |
244 */ | |
245 uint64_t (*GetBufferedAmount)(PP_Resource web_socket); | |
246 /** | |
247 * GetCloseCode() returns the connection close code for the WebSocket | |
248 * connection. | |
249 * | |
250 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
251 * WebSocket. | |
252 * | |
253 * @return Returns 0 if called before the close code is set. | |
254 */ | |
255 uint16_t (*GetCloseCode)(PP_Resource web_socket); | |
256 /** | |
257 * GetCloseReason() returns the connection close reason for the WebSocket | |
258 * connection. | |
259 * | |
260 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
261 * WebSocket. | |
262 * | |
263 * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the | |
264 * close reason is set, it contains an empty string. Returns a | |
265 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. | |
266 */ | |
267 struct PP_Var (*GetCloseReason)(PP_Resource web_socket); | |
268 /** | |
269 * GetCloseWasClean() returns if the connection was closed cleanly for the | |
270 * specified WebSocket connection. | |
271 * | |
272 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
273 * WebSocket. | |
274 * | |
275 * @return Returns <code>PP_FALSE</code> if called before the connection is | |
276 * closed, or called on an invalid resource. Otherwise, returns | |
277 * <code>PP_TRUE</code> if the connection was closed cleanly, or returns | |
278 * <code>PP_FALSE</code> if the connection was closed for abnormal reasons. | |
279 */ | |
280 PP_Bool (*GetCloseWasClean)(PP_Resource web_socket); | |
281 /** | |
282 * GetExtensions() returns the extensions selected by the server for the | |
283 * specified WebSocket connection. | |
284 * | |
285 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
286 * WebSocket. | |
287 * | |
288 * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the | |
289 * connection is established, its data is an empty string. Returns a | |
290 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. | |
291 * Currently its data for valid resources are always an empty string. | |
292 */ | |
293 struct PP_Var (*GetExtensions)(PP_Resource web_socket); | |
294 /** | |
295 * GetProtocol() returns the sub-protocol chosen by the server for the | |
296 * specified WebSocket connection. | |
297 * | |
298 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
299 * WebSocket. | |
300 * | |
301 * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the | |
302 * connection is established, it contains the empty string. Returns a | |
303 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. | |
304 */ | |
305 struct PP_Var (*GetProtocol)(PP_Resource web_socket); | |
306 /** | |
307 * GetReadyState() returns the ready state of the specified WebSocket | |
308 * connection. | |
309 * | |
310 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
311 * WebSocket. | |
312 * | |
313 * @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID_DEV</code> if called | |
314 * before connect() is called, or called on an invalid resource. | |
315 */ | |
316 PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket); | |
317 /** | |
318 * GetURL() returns the URL associated with specified WebSocket connection. | |
319 * | |
320 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
321 * WebSocket. | |
322 * | |
323 * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the | |
324 * connection is established, it contains the empty string. Return a | |
325 * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. | |
326 */ | |
327 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 }; | |
364 | |
365 typedef struct PPB_WebSocket_Dev_0_9 PPB_WebSocket_Dev; | |
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 /** | |
393 * @} | |
394 */ | |
395 | |
396 #endif /* PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ */ | |
397 | |
OLD | NEW |