PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/common/api/sockets_tcp.idl

https://gitlab.com/jonnialva90/iridium-browser
IDL | 273 lines | 91 code | 48 blank | 134 comment | 0 complexity | 5425318a6fbe32b733da1666358a5ff2 MD5 | raw file
  1. // Copyright 2014 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. // Use the <code>chrome.sockets.tcp</code> API to send and receive data over the
  5. // network using TCP connections. This API supersedes the TCP functionality
  6. // previously found in the <code>chrome.socket</code> API.
  7. namespace sockets.tcp {
  8. // The socket properties specified in the <code>create</code> or
  9. // <code>update</code> function. Each property is optional. If a property
  10. // value is not specified, a default value is used when calling
  11. // <code>create</code>, or the existing value if preserved when calling
  12. // <code>update</code>.
  13. dictionary SocketProperties {
  14. // Flag indicating if the socket is left open when the event page of
  15. // the application is unloaded (see
  16. // <a href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
  17. // Lifecycle</a>). The default value is "false." When the application is
  18. // loaded, any sockets previously opened with persistent=true can be fetched
  19. // with <code>getSockets</code>.
  20. boolean? persistent;
  21. // An application-defined string associated with the socket.
  22. DOMString? name;
  23. // The size of the buffer used to receive data. The default value is 4096.
  24. long? bufferSize;
  25. };
  26. // Result of <code>create</code> call.
  27. dictionary CreateInfo {
  28. // The ID of the newly created socket. Note that socket IDs created from
  29. // this API are not compatible with socket IDs created from other APIs, such
  30. // as the deprecated <code>$(ref:socket)</code> API.
  31. long socketId;
  32. };
  33. // Callback from the <code>create</code> method.
  34. // |createInfo| : The result of the socket creation.
  35. callback CreateCallback = void (CreateInfo createInfo);
  36. // Callback from the <code>connect</code> method.
  37. // |result| : The result code returned from the underlying network call.
  38. // A negative value indicates an error.
  39. callback ConnectCallback = void (long result);
  40. // Callback from the <code>disconnect</code> method.
  41. callback DisconnectCallback = void ();
  42. // Result of the <code>send</code> method.
  43. dictionary SendInfo {
  44. // The result code returned from the underlying network call.
  45. // A negative value indicates an error.
  46. long resultCode;
  47. // The number of bytes sent (if result == 0)
  48. long? bytesSent;
  49. };
  50. // Callback from the <code>send</code> method.
  51. // |sendInfo| : Result of the <code>send</code> method.
  52. callback SendCallback = void (SendInfo sendInfo);
  53. // Callback from the <code>close</code> method.
  54. callback CloseCallback = void ();
  55. // Callback from the <code>update</code> method.
  56. callback UpdateCallback = void ();
  57. // Callback from the <code>setPaused</code> method.
  58. callback SetPausedCallback = void ();
  59. // Callback from the <code>setKeepAliveCallback</code> method.
  60. // |result| : The result code returned from the underlying network call.
  61. // A negative value indicates an error.
  62. callback SetKeepAliveCallback = void (long result);
  63. // Callback from the <code>setNodeDelay</code> method.
  64. // |result| : The result code returned from the underlying network call.
  65. // A negative value indicates an error.
  66. callback SetNoDelayCallback = void (long result);
  67. dictionary TLSVersionConstraints {
  68. // The minimum and maximum acceptable versions of TLS. These will
  69. // be <code>tls1</code>, <code>tls1.1</code>, or <code>tls1.2</code>.
  70. DOMString? min;
  71. DOMString? max;
  72. };
  73. dictionary SecureOptions {
  74. TLSVersionConstraints? tlsVersion;
  75. };
  76. callback SecureCallback = void (long result);
  77. // Result of the <code>getInfo</code> method.
  78. dictionary SocketInfo {
  79. // The socket identifier.
  80. long socketId;
  81. // Flag indicating whether the socket is left open when the application is
  82. // suspended (see <code>SocketProperties.persistent</code>).
  83. boolean persistent;
  84. // Application-defined string associated with the socket.
  85. DOMString? name;
  86. // The size of the buffer used to receive data. If no buffer size has been
  87. // specified explictly, the value is not provided.
  88. long? bufferSize;
  89. // Flag indicating whether a connected socket blocks its peer from sending
  90. // more data (see <code>setPaused</code>).
  91. boolean paused;
  92. // Flag indicating whether the socket is connected to a remote peer.
  93. boolean connected;
  94. // If the underlying socket is connected, contains its local IPv4/6 address.
  95. DOMString? localAddress;
  96. // If the underlying socket is connected, contains its local port.
  97. long? localPort;
  98. // If the underlying socket is connected, contains the peer/ IPv4/6 address.
  99. DOMString? peerAddress;
  100. // If the underlying socket is connected, contains the peer port.
  101. long? peerPort;
  102. };
  103. // Callback from the <code>getInfo</code> method.
  104. // |socketInfo| : Object containing the socket information.
  105. callback GetInfoCallback = void (SocketInfo socketInfo);
  106. // Callback from the <code>getSockets</code> method.
  107. // |socketInfos| : Array of object containing socket information.
  108. callback GetSocketsCallback = void (SocketInfo[] socketInfos);
  109. // Data from an <code>onReceive</code> event.
  110. dictionary ReceiveInfo {
  111. // The socket identifier.
  112. long socketId;
  113. // The data received, with a maxium size of <code>bufferSize</code>.
  114. ArrayBuffer data;
  115. };
  116. // Data from an <code>onReceiveError</code> event.
  117. dictionary ReceiveErrorInfo {
  118. // The socket identifier.
  119. long socketId;
  120. // The result code returned from the underlying network call.
  121. long resultCode;
  122. };
  123. interface Functions {
  124. // Creates a TCP socket.
  125. // |properties| : The socket properties (optional).
  126. // |callback| : Called when the socket has been created.
  127. static void create(optional SocketProperties properties,
  128. CreateCallback callback);
  129. // Updates the socket properties.
  130. // |socketId| : The socket identifier.
  131. // |properties| : The properties to update.
  132. // |callback| : Called when the properties are updated.
  133. static void update(long socketId,
  134. SocketProperties properties,
  135. optional UpdateCallback callback);
  136. // Enables or disables the application from receiving messages from its
  137. // peer. The default value is "false". Pausing a socket is typically used
  138. // by an application to throttle data sent by its peer. When a socket is
  139. // paused, no <code>onReceive</code> event is raised. When a socket is
  140. // connected and un-paused, <code>onReceive</code> events are raised again
  141. // when messages are received.
  142. static void setPaused(long socketId,
  143. boolean paused,
  144. optional SetPausedCallback callback);
  145. // Enables or disables the keep-alive functionality for a TCP connection.
  146. // |socketId| : The socket identifier.
  147. // |enable| : If true, enable keep-alive functionality.
  148. // |delay| : Set the delay seconds between the last data packet received
  149. // and the first keepalive probe. Default is 0.
  150. // |callback| : Called when the setKeepAlive attempt is complete.
  151. static void setKeepAlive(long socketId,
  152. boolean enable,
  153. optional long delay,
  154. SetKeepAliveCallback callback);
  155. // Sets or clears <code>TCP_NODELAY</code> for a TCP connection. Nagle's
  156. // algorithm will be disabled when <code>TCP_NODELAY</code> is set.
  157. // |socketId| : The socket identifier.
  158. // |noDelay| : If true, disables Nagle's algorithm.
  159. // |callback| : Called when the setNoDelay attempt is complete.
  160. static void setNoDelay(long socketId,
  161. boolean noDelay,
  162. SetNoDelayCallback callback);
  163. // Connects the socket to a remote machine. When the <code>connect</code>
  164. // operation completes successfully, <code>onReceive</code> events are
  165. // raised when data is received from the peer. If a network error occurs
  166. // while the runtime is receiving packets, a <code>onReceiveError</code>
  167. // event is raised, at which point no more <code>onReceive</code> event will
  168. // be raised for this socket until the <code>resume</code> method is called.
  169. // |socketId| : The socket identifier.
  170. // |peerAddress| : The address of the remote machine. DNS name, IPv4 and
  171. // IPv6 formats are supported.
  172. // |peerPort| : The port of the remote machine.
  173. // |callback| : Called when the connect attempt is complete.
  174. static void connect(long socketId,
  175. DOMString peerAddress,
  176. long peerPort,
  177. ConnectCallback callback);
  178. // Disconnects the socket.
  179. // |socketId| : The socket identifier.
  180. // |callback| : Called when the disconnect attempt is complete.
  181. static void disconnect(long socketId,
  182. optional DisconnectCallback callback);
  183. // Start a TLS client connection over the connected TCP client socket.
  184. // |socketId| : The existing, connected socket to use.
  185. // |options| : Constraints and parameters for the TLS connection.
  186. // |callback| : Called when the connection attempt is complete.
  187. static void secure(long socketId,
  188. optional SecureOptions options,
  189. SecureCallback callback);
  190. // Sends data on the given TCP socket.
  191. // |socketId| : The socket identifier.
  192. // |data| : The data to send.
  193. // |callback| : Called when the <code>send</code> operation completes.
  194. static void send(long socketId,
  195. ArrayBuffer data,
  196. SendCallback callback);
  197. // Closes the socket and releases the address/port the socket is bound to.
  198. // Each socket created should be closed after use. The socket id is no
  199. // no longer valid as soon at the function is called. However, the socket is
  200. // guaranteed to be closed only when the callback is invoked.
  201. // |socketId| : The socket identifier.
  202. // |callback| : Called when the <code>close</code> operation completes.
  203. static void close(long socketId,
  204. optional CloseCallback callback);
  205. // Retrieves the state of the given socket.
  206. // |socketId| : The socket identifier.
  207. // |callback| : Called when the socket state is available.
  208. static void getInfo(long socketId,
  209. GetInfoCallback callback);
  210. // Retrieves the list of currently opened sockets owned by the application.
  211. // |callback| : Called when the list of sockets is available.
  212. static void getSockets(GetSocketsCallback callback);
  213. };
  214. interface Events {
  215. // Event raised when data has been received for a given socket.
  216. // |info| : The event data.
  217. static void onReceive(ReceiveInfo info);
  218. // Event raised when a network error occured while the runtime was waiting
  219. // for data on the socket address and port. Once this event is raised, the
  220. // socket is set to <code>paused</code> and no more <code>onReceive</code>
  221. // events are raised for this socket.
  222. // |info| : The event data.
  223. static void onReceiveError(ReceiveErrorInfo info);
  224. };
  225. };