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
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Use the <code>chrome.sockets.tcp</code> API to send and receive data over the
// network using TCP connections. This API supersedes the TCP functionality
// previously found in the <code>chrome.socket</code> API.
namespace sockets.tcp {
// The socket properties specified in the <code>create</code> or
// <code>update</code> function. Each property is optional. If a property
// value is not specified, a default value is used when calling
// <code>create</code>, or the existing value if preserved when calling
// <code>update</code>.
dictionary SocketProperties {
// Flag indicating if the socket is left open when the event page of
// the application is unloaded (see
// <a href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
// Lifecycle</a>). The default value is "false." When the application is
// loaded, any sockets previously opened with persistent=true can be fetched
// with <code>getSockets</code>.
boolean? persistent;
// An application-defined string associated with the socket.
DOMString? name;
// The size of the buffer used to receive data. The default value is 4096.
long? bufferSize;
};
// Result of <code>create</code> call.
dictionary CreateInfo {
// The ID of the newly created socket. Note that socket IDs created from
// this API are not compatible with socket IDs created from other APIs, such
// as the deprecated <code>$(ref:socket)</code> API.
long socketId;
};
// Callback from the <code>create</code> method.
// |createInfo| : The result of the socket creation.
callback CreateCallback = void (CreateInfo createInfo);
// DNS resolution preferences. The default is <code>any</code> and uses the
// current OS config which may return IPv4 or IPv6. <code>ipv4</code> forces
// IPv4, and <code>ipv6</code> forces IPv6.
enum DnsQueryType { any, ipv4, ipv6 };
// Callback from the <code>connect</code> method.
// |result| : The result code returned from the underlying network call.
// A negative value indicates an error.
callback ConnectCallback = void (long result);
// Callback from the <code>disconnect</code> method.
callback DisconnectCallback = void ();
// Result of the <code>send</code> method.
dictionary SendInfo {
// The result code returned from the underlying network call.
// A negative value indicates an error.
long resultCode;
// The number of bytes sent (if result == 0)
long? bytesSent;
};
// Callback from the <code>send</code> method.
// |sendInfo| : Result of the <code>send</code> method.
callback SendCallback = void (SendInfo sendInfo);
// Callback from the <code>close</code> method.
callback CloseCallback = void ();
// Callback from the <code>update</code> method.
callback UpdateCallback = void ();
// Callback from the <code>setPaused</code> method.
callback SetPausedCallback = void ();
// Callback from the <code>setKeepAliveCallback</code> method.
// |result| : The result code returned from the underlying network call.
// A negative value indicates an error.
callback SetKeepAliveCallback = void (long result);
// Callback from the <code>setNodeDelay</code> method.
// |result| : The result code returned from the underlying network call.
// A negative value indicates an error.
callback SetNoDelayCallback = void (long result);
dictionary TLSVersionConstraints {
// The minimum and maximum acceptable versions of TLS. Supported values are
// <code>tls1.2</code> or <code>tls1.3</code>.
//
// The values <code>tls1</code> and <code>tls1.1</code> are no longer
// supported. If |min| is set to one of these values, it will be silently
// clamped to <code>tls1.2</code>. If |max| is set to one of those values,
// or any other unrecognized value, it will be silently ignored.
DOMString? min;
DOMString? max;
};
dictionary SecureOptions {
TLSVersionConstraints? tlsVersion;
};
callback SecureCallback = void (long result);
// Result of the <code>getInfo</code> method.
dictionary SocketInfo {
// The socket identifier.
long socketId;
// Flag indicating whether the socket is left open when the application is
// suspended (see <code>SocketProperties.persistent</code>).
boolean persistent;
// Application-defined string associated with the socket.
DOMString? name;
// The size of the buffer used to receive data. If no buffer size has been
// specified explictly, the value is not provided.
long? bufferSize;
// Flag indicating whether a connected socket blocks its peer from sending
// more data (see <code>setPaused</code>).
boolean paused;
// Flag indicating whether the socket is connected to a remote peer.
boolean connected;
// If the underlying socket is connected, contains its local IPv4/6 address.
DOMString? localAddress;
// If the underlying socket is connected, contains its local port.
long? localPort;
// If the underlying socket is connected, contains the peer/ IPv4/6 address.
DOMString? peerAddress;
// If the underlying socket is connected, contains the peer port.
long? peerPort;
};
// Callback from the <code>getInfo</code> method.
// |socketInfo| : Object containing the socket information.
callback GetInfoCallback = void (SocketInfo socketInfo);
// Callback from the <code>getSockets</code> method.
// |socketInfos| : Array of object containing socket information.
callback GetSocketsCallback = void (SocketInfo[] socketInfos);
// Data from an <code>onReceive</code> event.
dictionary ReceiveInfo {
// The socket identifier.
long socketId;
// The data received, with a maxium size of <code>bufferSize</code>.
ArrayBuffer data;
};
// Data from an <code>onReceiveError</code> event.
dictionary ReceiveErrorInfo {
// The socket identifier.
long socketId;
// The result code returned from the underlying network call.
long resultCode;
};
interface Functions {
// Creates a TCP socket.
// |properties| : The socket properties (optional).
// |callback| : Called when the socket has been created.
static void create(optional SocketProperties properties,
CreateCallback callback);
// Updates the socket properties.
// |socketId| : The socket identifier.
// |properties| : The properties to update.
// |callback| : Called when the properties are updated.
static void update(long socketId,
SocketProperties properties,
optional UpdateCallback callback);
// Enables or disables the application from receiving messages from its
// peer. The default value is "false". Pausing a socket is typically used
// by an application to throttle data sent by its peer. When a socket is
// paused, no <code>onReceive</code> event is raised. When a socket is
// connected and un-paused, <code>onReceive</code> events are raised again
// when messages are received.
static void setPaused(long socketId,
boolean paused,
optional SetPausedCallback callback);
// Enables or disables the keep-alive functionality for a TCP connection.
// |socketId| : The socket identifier.
// |enable| : If true, enable keep-alive functionality.
// |delay| : Set the delay seconds between the last data packet received
// and the first keepalive probe. Default is 0.
// |callback| : Called when the setKeepAlive attempt is complete.
[doesNotSupportPromises=
"Sets error along with callback arguments crbug.com/1504372"]
static void setKeepAlive(long socketId,
boolean enable,
optional long delay,
SetKeepAliveCallback callback);
// Sets or clears <code>TCP_NODELAY</code> for a TCP connection. Nagle's
// algorithm will be disabled when <code>TCP_NODELAY</code> is set.
// |socketId| : The socket identifier.
// |noDelay| : If true, disables Nagle's algorithm.
// |callback| : Called when the setNoDelay attempt is complete.
[doesNotSupportPromises=
"Sets error along with callback arguments crbug.com/1504372"]
static void setNoDelay(long socketId,
boolean noDelay,
SetNoDelayCallback callback);
// Connects the socket to a remote machine. When the <code>connect</code>
// operation completes successfully, <code>onReceive</code> events are
// raised when data is received from the peer. If a network error occurs
// while the runtime is receiving packets, a <code>onReceiveError</code>
// event is raised, at which point no more <code>onReceive</code> event will
// be raised for this socket until the <code>resume</code> method is called.
// |socketId| : The socket identifier.
// |peerAddress| : The address of the remote machine. DNS name, IPv4 and
// IPv6 formats are supported.
// |peerPort| : The port of the remote machine.
// |dnsQueryType| : The address resolution preference.
// |callback| : Called when the connect attempt is complete.
[doesNotSupportPromises=
"Sets error along with callback arguments crbug.com/1504372"]
static void connect(long socketId,
DOMString peerAddress,
long peerPort,
optional DnsQueryType dnsQueryType,
ConnectCallback callback);
// Disconnects the socket.
// |socketId| : The socket identifier.
// |callback| : Called when the disconnect attempt is complete.
static void disconnect(long socketId,
optional DisconnectCallback callback);
// Start a TLS client connection over the connected TCP client socket.
// |socketId| : The existing, connected socket to use.
// |options| : Constraints and parameters for the TLS connection.
// |callback| : Called when the connection attempt is complete.
[doesNotSupportPromises=
"Sets error along with callback arguments crbug.com/1504372"]
static void secure(long socketId,
optional SecureOptions options,
SecureCallback callback);
// Sends data on the given TCP socket.
// |socketId| : The socket identifier.
// |data| : The data to send.
// |callback| : Called when the <code>send</code> operation completes.
[doesNotSupportPromises=
"Sets error along with callback arguments crbug.com/1504372"]
static void send(long socketId,
ArrayBuffer data,
SendCallback callback);
// Closes the socket and releases the address/port the socket is bound to.
// Each socket created should be closed after use. The socket id is no
// no longer valid as soon at the function is called. However, the socket is
// guaranteed to be closed only when the callback is invoked.
// |socketId| : The socket identifier.
// |callback| : Called when the <code>close</code> operation completes.
static void close(long socketId,
optional CloseCallback callback);
// Retrieves the state of the given socket.
// |socketId| : The socket identifier.
// |callback| : Called when the socket state is available.
static void getInfo(long socketId,
GetInfoCallback callback);
// Retrieves the list of currently opened sockets owned by the application.
// |callback| : Called when the list of sockets is available.
static void getSockets(GetSocketsCallback callback);
};
interface Events {
// Event raised when data has been received for a given socket.
// |info| : The event data.
static void onReceive(ReceiveInfo info);
// Event raised when a network error occured while the runtime was waiting
// for data on the socket address and port. Once this event is raised, the
// socket is set to <code>paused</code> and no more <code>onReceive</code>
// events are raised for this socket.
// |info| : The event data.
static void onReceiveError(ReceiveErrorInfo info);
};
};
|