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

Side by Side Diff: ppapi/c/dev/ppb_websocket_dev.h

Issue 7837022: WebSocket Pepper C API. In this change, only the C interface is defined and no (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed tyoshino's comments Created 9 years, 3 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
« no previous file with comments | « no previous file | ppapi/ppapi_cpp.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* Copyright (c) 2011 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 #ifndef PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_
6 #define PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_
7
8 #include "ppapi/c/pp_instance.h"
9 #include "ppapi/c/pp_macros.h"
10 #include "ppapi/c/pp_var.h"
11
12 #define PPB_WEBSOCKET_DEV_INTERFACE_0_1 "PPB_WebSocket(Dev);0.1"
13 #define PPB_WEBSOCKET_DEV_INTERFACE PPB_WEBSOCKET_DEV_INTERFACE_0_1
14
15 typedef enum {
16 PP_WEBSOCKETREADYSTATE_CONNECTING = 0,
17 PP_WEBSOCKETREADYSTATE_OPEN = 1,
18 PP_WEBSOCKETREADYSTATE_CLOSING = 2,
19 PP_WEBSOCKETREADYSTATE_CLOSED = 3
20 } PP_WebSocketReadyState_Dev;
21 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(PP_WebSocketReadyState_Dev, 4);
22
23 typedef enum {
24 PP_WEBSOCKET_MESSAGE_TYPE_TEXT = 0,
25 PP_WEBSOCKET_MESSAGE_TYPE_BINARY = 1
26 } PP_WebSocketMessageType_Dev;
27 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(PP_WebSocketMessageType_Dev, 4);
28
29 struct PPB_WebSocket_Dev {
30 // Note on the differences from JavaScript WebSocket API
brettw 2011/09/08 16:39:36 This is a nice comment.
Yuzo 2011/09/29 06:20:31 Thank you!
31 // http://dev.w3.org/html5/websockets/
32 //
33 // This interface has some differences from its JavaScript counterpart mainly
34 // to make best use of PP_CompletionCallback and be consistent with other
35 // interfaces such as PPB_Transport_Dev.
36 //
37 // - Constructor doesn't take URL or protocols and there is a method to
38 // establish connection.
39 //
40 // - Error handlers or close handlers cannot be registered. (A callback can be
41 // specified on explicitly closing a connection.) To detect an error or
42 // connection closure, ready state, closure cleanness, closure code, and
43 // closure reason should be queried instead.
44 //
45 // - Message size is represented as int32_t rather than uint64_t.
46 // PP_CompletionCallback handles int32_t better. Messages out of that range
47 // are too large to handle efficiently anyway.
48
49 // Note on error codes.
50 //
51 // Methods that take PP_CompletionCallback can return error codes. They
52 // correspond to JavaScript exceptions as follows:
53 //
54 // PP_ERROR_BADARGUMENT: SYNTAX_ERR
55 // PP_ERROR_NOACCESS: SECURITY_ERR, INVALID_ACCESS_ERR
56 // PP_ERROR_FAILED: INVALID_STATE_ERR
57 //
58 // Other error codes such as PP_ERROR_ABORTED and PP_ERROR_BADRESOURCE can
59 // also be returned.
60
61 // Creates a WebSocket instance for plugin module |instance|.
62 PP_Resource (*Create)(PP_Instance instance);
63
64 // Returns PP_TRUE if |resource| is a WebSocket instance, PP_FALSE otherwise.
65 PP_Bool (*IsWebSocket)(PP_Resource resource);
66
67 // Connects |web_socket| to null-terminated |url| specifying |protocols|.
68 // |protocols| points to an array of null-terminated sub-protocols. In case of
69 // immediate failure, returns an error code as specified above. Returns
70 // PP_OK_COMPLETIONPENDING otherwise. Calls |callback| when the connection is
71 // established or an error occurs.
72 //
73 // Caller's responsibilities:
74 // - Caller can call this method at most once for a |web_socket|.
75 // - |protocols| can be null only if |protocol_count| is 0.
76 int32_t (*Connect)(PP_Resource web_socket,
77 const char* url,
78 const char* const* protocols,
brettw 2011/09/08 16:39:36 I don't want to hold up this patch, but probably t
Yuzo 2011/09/29 06:20:31 Sure, I'll write the IDL later.
79 int32_t protocol_count,
brettw 2011/09/08 16:39:36 Can you use uint32_t here? We're using unsigned ty
Yuzo 2011/09/29 06:20:31 Done.
80 PP_CompletionCallback callback);
81
82 // Closes |web_socket| specifying |code| and null-terminated |reason|. |code|
83 // is ignored if it is 0. |reason| is ignored if it is null. In case of
84 // immediate failure, returns an error code as specified above. Returns
85 // PP_OK_COMPLETIONPENDING otherwise. Calls |callback| when the connection is
86 // closed or an error occurs.
87 int32_t (*Close)(PP_Resource web_socket,
88 uint16_t code,
89 const char* reason,
90 PP_CompletionCallback callback);
91
92 // Receives a message from |web_socket|. In case of immediate failure, returns
93 // an error code as specified above. If a message is currently available,
94 // returns the number of bytes copied to |message_bytes| (see below).
95 // Otherwise, returns PP_OK_COMPLETIONPENDING and calls |callback| when the
96 // message is available.
97 //
98 // Messages are queued internally. Hence this method can be called either
99 // before or after a message is received by the browser. If the queue grows
100 // beyond the browser-dependent limit, |web_socket| is closed and messages are
101 // discarded.
102 //
103 // The message is copied to |message_bytes| up to |message_byte_count| bytes.
104 // |message_bytes| can be null only if |message_byte_count| is 0. The number
105 // of bytes copied is passed to the |callback| as its second argument in case
106 // PP_OK_COMPLETIONPENDING has been returned. The number of remaining bytes,
107 // if any, or 0, if not, is set to |*remaining_message_byte_count| if
brettw 2011/09/08 16:39:36 I think you can remove "or 0, if not," since I thi
Yuzo 2011/09/29 06:20:31 Done.
108 // |remaining_message_byte_count| is not null. The remaining bytes of the
109 // message are returned for subsequent call(s) to this method. Bytes of a
brettw 2011/09/08 16:39:36 I'd rephrase your "Bytes of a message..." sentence
Yuzo 2011/09/29 06:20:31 Done.
110 // message are never returned together with those of other messages. That is,
111 // this method must be called at least N times to receive N messages, no
112 // matter how small each message is. The message type is set to
brettw 2011/09/08 16:39:36 Can you insert a blank line before "The message ty
Yuzo 2011/09/29 06:20:31 Done.
113 // |*message_type| if |message_type| is not null. If the message is text, it
114 // is encoded in UTF-8. In copying message to |message_bytes|, UTF-8 byte
brettw 2011/09/08 16:39:36 I'd also add a blank line before "In copying..." s
Yuzo 2011/09/29 06:20:31 Done.
115 // sequence boundaries are not considered. Hence if the message is larger than
116 // |message_bytes|, the last byte sequence may end prematurely. Likewise, the
117 // first sequence of the bytes returned for the subsequent call may start in
118 // the middle.
119 //
120 // Caller's responsibilities:
121 // - Caller must keep |message_bytes|, |remaining_message_byte_count|, and
122 // |message_type| valid until |callback| is called.
brettw 2011/09/08 16:39:36 Can you say "...until |callback| is issued or Clos
Yuzo 2011/09/29 06:20:31 Done.
123 // - |message_bytes| can be null only if |message_byte_count| is 0.
124 int32_t (*ReceiveMessage)(PP_Resource web_socket,
brettw 2011/09/08 16:39:36 This function is kind of complicated to call. I do
Yuzo 2011/09/29 06:20:31 I agree that this method should be simplified if p
125 void* message_bytes,
126 int32_t message_byte_count,
127 int32_t* remaining_message_byte_count,
128 PP_WebSocketMessageType_Dev* message_type,
129 PP_CompletionCallback callback);
130
131 // Sends a message to |web_socket|. In case of immediate failure, returns an
132 // error code as specified above. Returns PP_OK otherwise. PP_OK doesn't
133 // necessarily mean that the server received the message.
134 //
135 // Message is specified as |message_bytes| of |message_type| whose length is
136 // |message_byte_count|.
137 int32_t (*SendMessage)(PP_Resource web_socket,
138 void* message_bytes,
139 int32_t message_byte_count,
140 PP_WebSocketMessageType_Dev message_type);
141
142 // Returns the number of bytes of text and binary messages that have been
143 // queued for |web_socket| for sending but have not been transmitted to the
144 // network yet.
145 uint64_t (*GetBufferedAmount)(PP_Resource web_socket);
146
147 // Returns the connection close code for |web_socket|. Returns 0 if called
148 // before the close code is set.
149 uint16_t (*GetCloseCode)(PP_Resource web_socket);
150
151 // Returns the connection close reason for |web_socket|. Returns an empty
brettw 2011/09/08 16:39:36 Can you change this to "Returns a PP_VARTYPE_NULL
Yuzo 2011/09/29 06:20:31 Done, for all the methods that return PP_Var.
152 // string if called before the close reason is set.
153 PP_Var (*GetCloseReason)(PP_Resource web_socket);
154
155 // Returns if the connection was closed cleanly for |web_socket|. Returns
156 // false if called before the connection is closed.
157 PP_Bool (*GetCloseWasClean)(PP_Resource web_socket);
158
159 // Returns the extension selected by the server for |web_socket|.
160 // Returns an empty string if called before the connection is established.
161 PP_Var (*GetExtensions)(PP_Resource web_socket);
162
163 // Returns the sub-protocol chosen by the server for |web_socket|.
164 // Returns an empty string if called before the connection is established.
165 PP_Var (*GetProtocol)(PP_Resource web_socket);
166
167 // Returns the ready state of |web_socket|. Returns
168 // PP_WEBSOCKETREADYSTATE_CONNECTING if called before the connection is
169 // established.
170 PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket);
171
172 // Returns the URL associated with |web_socket|. Returns an empty string if
173 // called before the connection is established.
174 PP_Var (*GetUrl)(PP_Resource web_socket);
175 };
176
177 #endif // PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_
OLDNEW
« no previous file with comments | « no previous file | ppapi/ppapi_cpp.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698