summaryrefslogtreecommitdiffstats
path: root/ppapi/api/dev/ppb_websocket_dev.idl
blob: 6dd0bd86c08de14cdefa5cdfb46252473980fdd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/* 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 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
};

/**
 * 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_STRING</code> var. if called before the
   * close reason is set, its data is empty string. Returns a
   * <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, or called on an invalid resource. Otherwise, returns
   * <code>PP_TRUE</code> if the connection was closed cleanly, or 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, its data is empty string. Returns a
   * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource.
   * Currently its data for valid resources are 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, its data is empty string. Returns a
   * <code>PP_VARTYPE_UNDEFINED</code> 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 <code>PP_Resource</code> corresponding to a
   * WebSocket.
   *
   * @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID_DEV</code> 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 <code>PP_Resource</code> corresponding to a
   * WebSocket.
   *
   * @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before the
   * connection is established, its data is empty string. Return a
   * <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource.
   */
  PP_Var GetURL([in] PP_Resource web_socket);
};