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

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: 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
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|. The instance is
62 // initially in PP_WEBSOCKETREADYSTATE_CONNECTING state (even before Connect
63 // method is called).
64 PP_Resource (*Create)(PP_Instance instance);
65
66 // Returns PP_TRUE if |resource| is a WebSocket instance, PP_FALSE otherwise.
67 PP_Bool (*IsWebSocket)(PP_Resource resource);
68
69 // Connects |web_socket| to null-terminate |url| specifying |protocols|.
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 terminated
Yuzo 2011/09/08 06:08:15 Done.
70 // |protocols| points to an array of null-terminated protocol strings. In case
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 protocol -> sub-protocol
Yuzo 2011/09/08 06:08:15 Done: protocol strings -> sub-protocols.
71 // of immediate failure, returns an error code as specified above. Returns
72 // PP_OK_COMPLETIONPENDING otherwise. Calls |callback| when the connection is
73 // established or an error occurs.
74 //
75 // Callers responsibilities:
76 // - Caller can call this method at most once for a |web_socket|.
77 // - |protocols| can be null only if |protocol_count| is 0.
78 int32_t (*Connect)(PP_Resource web_socket,
79 const char* url,
80 const char* const* protocols,
81 int32_t protocol_count,
82 PP_CompletionCallback callback);
83
84 // Closes |web_socket| specifying |code| and null-terminated |reason|. |code|
85 // is ignored if it is 0. |reason| is ignored if it is null. In case of
86 // immediate failure, returns an error code as specified above. Returns
87 // PP_OK_COMPLETIONPENDING otherwise. Calls |callback| when the connection is
88 // closed or an error occurs.
89 int32_t (*Close)(PP_Resource web_socket,
90 uint16_t code,
91 const char* reason,
92 PP_CompletionCallback callback);
93
94 // Receives a message from |web_socket|. In case of immediate failure, returns
95 // an error code as specified above. Returns PP_OK_COMPLETIONPENDING
96 // otherwise.
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 If successful, it's notified only by callback? PP_
Yuzo 2011/09/08 06:08:15 Good point. Changed the method such that the numb
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 // Calls |callback| when the message is available. The message is copied to
104 // |*message_bytes| up to |message_byte_count| bytes. |message_bytes| can be
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 remove *
Yuzo 2011/09/08 06:08:15 Done.
105 // null only if |message_byte_count| is 0. The number of bytes copied is
106 // passed to the |callback| as its second argument. The number of remaining
107 // bytes, if any, or 0, if not, is set to |*remaining_message_byte_count| if
108 // |remaining_message_byte_count| is not null. The remaining message bytes are
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 I'd suggest s/remaining message bytes/remaining by
Yuzo 2011/09/08 06:08:15 Done.
109 // returned for subsequent call(s) to this method. Bytes from a message are
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 from -> of? I'm not sure.
Yuzo 2011/09/08 06:08:15 I'm not sure either but changed to "of".
110 // never returned together with those from other messages. That is, this
111 // method must be called at least N times to receive N messages, no matter how
112 // small each message is. The message type is set to |*message_type| if
113 // |message_type| is not null. If the message is text, it is encoded in UTF-8.
114 // In copying message to |message_bytes|, character boundary is not
115 // considered. Hence if the message is larger than |message_bytes|, the last
116 // character may have incomplete bytes, and subsequent call my return
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 may
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 Do you mean part of UTF-8 sequence by "incomplete
Yuzo 2011/09/08 06:08:15 Done.
Yuzo 2011/09/08 06:08:15 Rewrote as: In copying message to |message_bytes|
Yuzo 2011/09/08 06:08:15 Done.
Yuzo 2011/09/08 06:08:15 Done.
Yuzo 2011/09/08 06:08:15 Done.
117 // incomplete bytes for the first character.
118 //
119 // Callers responsibilities:
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 Caller's
Yuzo 2011/09/08 06:08:15 Done.
120 // - Caller must keep |message_bytes| and |message_type| valid until
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 and remaining_message_bytes_count?
Yuzo 2011/09/08 06:08:15 Good catch! Done.
Yuzo 2011/09/08 06:08:15 Done.
121 // |callback| is called.
122 // - |message_bytes| can be null only if |message_byte_count| is 0.
123 int32_t (*ReceiveMessage)(PP_Resource web_socket,
124 void* message_bytes,
125 int32_t message_byte_count,
126 int32_t* remaining_message_byte_count,
127 PP_WebSocketMessageType_Dev* message_type,
128 PP_CompletionCallback callback);
129
130 // Sends a message to |web_socket|. In case of immediate failure, returns an
131 // error code as specified above. Returns PP_OK otherwise. PP_OK doesn't
132 // necessarily mean that the server received the message.
133 //
134 // Message is specified as |message_bytes| of |message_type| whose length is
135 // |message_byte_count|.
136 int32_t (*SendMessage)(PP_Resource web_socket,
137 void* message_bytes,
138 int32_t message_byte_count,
139 PP_WebSocketMessageType_Dev message_type);
140
141 // Gets the buffered (for sending) amount for |web_socket|.
142 uint64_t (*GetBufferedAmount)(PP_Resource web_socket);
143
144 // Gets the connection close code for |web_socket|.
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 It would be nice if you add some text to say when
Yuzo 2011/09/08 06:08:15 Done.
145 uint16_t (*GetCloseCode)(PP_Resource web_socket);
146
147 // Gets the connection close reason for |web_socket|.
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 ditto
Yuzo 2011/09/08 06:08:15 Done.
148 PP_Var (*GetCloseReason)(PP_Resource web_socket);
149
150 // Gets if the connection was closed cleanly for |web_socket|.
tyoshino (SeeGerritForStatus) 2011/09/07 13:07:58 ditto
Yuzo 2011/09/08 06:08:15 Done.
151 PP_Bool (*GetCloseWasClean)(PP_Resource web_socket);
152
153 // Gets the extension selected by the server for |web_socket|.
154 // Returns an empty string if called before the connection is established.
155 PP_Var (*GetExtensions)(PP_Resource web_socket);
156
157 // Gets the sub-protocol chosen by the server for |web_socket|.
158 // Returns an empty string if called before the connection is established.
159 PP_Var (*GetProtocol)(PP_Resource web_socket);
160
161 // Gets the ready state of |web_socket|.
162 PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket);
163
164 // Gets the URL associated with |web_socket|.
165 // Returns an empty string if called before the connection is established.
166 PP_Var (*GetUrl)(PP_Resource web_socket);
167 };
168
169 #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