dom/network/interfaces/nsIDOMTCPSocket.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * MozTCPSocket exposes a TCP client and server sockets
michael@0 7 * to highly privileged apps. It provides a buffered, non-blocking
michael@0 8 * interface for sending. For receiving, it uses an asynchronous,
michael@0 9 * event handler based interface.
michael@0 10 */
michael@0 11
michael@0 12 #include "domstubs.idl"
michael@0 13 #include "nsIDOMEvent.idl"
michael@0 14 #include "nsITCPSocketChild.idl"
michael@0 15 #include "nsIDOMTCPServerSocket.idl"
michael@0 16
michael@0 17 interface nsISocketTransport;
michael@0 18
michael@0 19 // Bug 731746 - Allow chrome JS object to implement nsIDOMEventTarget
michael@0 20 // nsITCPSocket should be an nsIEventTarget but js objects
michael@0 21 // cannot be an nsIEventTarget yet
michael@0 22 // #include "nsIEventTarget.idl"
michael@0 23
michael@0 24 // Bug 723206 - Constructors implemented in JS from IDL should be
michael@0 25 // allowed to have arguments
michael@0 26 //
michael@0 27 // Once bug 723206 will be fixed, this method could be replaced by
michael@0 28 // arguments when instantiating a TCPSocket object. For example it will
michael@0 29 // be possible to do (similarly to the WebSocket API):
michael@0 30 // var s = new MozTCPSocket(host, port);
michael@0 31
michael@0 32 // Bug 797561 - Expose a server tcp socket API to web applications
michael@0 33
michael@0 34
michael@0 35 [scriptable, uuid(65f6d2c8-4be6-4695-958d-0735e8935289)]
michael@0 36 interface nsIDOMTCPSocket : nsISupports
michael@0 37 {
michael@0 38 /**
michael@0 39 * Create and return a socket object which will attempt to connect to
michael@0 40 * the given host and port.
michael@0 41 *
michael@0 42 * @param host The hostname of the server to connect to.
michael@0 43 * @param port The port to connect to.
michael@0 44 * @param options An object specifying one or more parameters which
michael@0 45 * determine the details of the socket.
michael@0 46 *
michael@0 47 * useSecureTransport: true to create an SSL socket. Defaults to false.
michael@0 48 *
michael@0 49 * binaryType: "arraybuffer" to use ArrayBuffer
michael@0 50 * instances in the ondata callback and as the argument
michael@0 51 * to send. Defaults to "string", to use JavaScript strings.
michael@0 52 *
michael@0 53 * @return The new TCPSocket instance.
michael@0 54 */
michael@0 55 nsIDOMTCPSocket open(in DOMString host, in unsigned short port, [optional] in jsval options);
michael@0 56
michael@0 57 /**
michael@0 58 * Listen on a port
michael@0 59 *
michael@0 60 * @param localPort The port of the server socket. Pass -1 to indicate no preference,
michael@0 61 * and a port will be selected automatically.
michael@0 62 * @param options An object specifying one or more parameters which
michael@0 63 * determine the details of the socket.
michael@0 64 *
michael@0 65 * binaryType: "arraybuffer" to use ArrayBuffer
michael@0 66 * instances in the ondata callback and as the argument
michael@0 67 * to send. Defaults to "string", to use JavaScript strings.
michael@0 68 * @param backlog The maximum length the queue of pending connections may grow to.
michael@0 69 * This parameter may be silently limited by the operating system.
michael@0 70 * Pass -1 to use the default value.
michael@0 71 *
michael@0 72 * @return The new TCPServerSocket instance.
michael@0 73 */
michael@0 74 nsIDOMTCPServerSocket listen(in unsigned short localPort, [optional] in jsval options,
michael@0 75 [optional] in unsigned short backlog);
michael@0 76
michael@0 77 /**
michael@0 78 * Enable secure on channel.
michael@0 79 */
michael@0 80 void upgradeToSecure();
michael@0 81
michael@0 82 /**
michael@0 83 * The host of this socket object.
michael@0 84 */
michael@0 85 readonly attribute DOMString host;
michael@0 86
michael@0 87 /**
michael@0 88 * The port of this socket object.
michael@0 89 */
michael@0 90 readonly attribute unsigned short port;
michael@0 91
michael@0 92 /**
michael@0 93 * True if this socket object is an SSL socket.
michael@0 94 */
michael@0 95 readonly attribute boolean ssl;
michael@0 96
michael@0 97 /**
michael@0 98 * The number of bytes which have previously been buffered by calls to
michael@0 99 * send on this socket.
michael@0 100 */
michael@0 101 readonly attribute unsigned long bufferedAmount;
michael@0 102
michael@0 103 /**
michael@0 104 * Pause reading incoming data and invocations of the ondata handler until
michael@0 105 * resume is called.
michael@0 106 */
michael@0 107 void suspend();
michael@0 108
michael@0 109 /**
michael@0 110 * Resume reading incoming data and invoking ondata as usual.
michael@0 111 */
michael@0 112 void resume();
michael@0 113
michael@0 114 /**
michael@0 115 * Close the socket.
michael@0 116 */
michael@0 117 void close();
michael@0 118
michael@0 119 /**
michael@0 120 * Write data to the socket.
michael@0 121 *
michael@0 122 * @param data The data to write to the socket. If
michael@0 123 * binaryType: "arraybuffer" was passed in the options
michael@0 124 * object, then this object should be an ArrayBuffer instance.
michael@0 125 * If binaryType: "string" was passed, or if no binaryType
michael@0 126 * option was specified, then this object should be an
michael@0 127 * ordinary JavaScript string.
michael@0 128 * @param byteOffset The offset within the data from which to begin writing.
michael@0 129 * Has no effect on non-ArrayBuffer data.
michael@0 130 * @param byteLength The number of bytes to write. Has no effect on
michael@0 131 * non-ArrayBuffer data.
michael@0 132 *
michael@0 133 * @return Send returns true or false as a hint to the caller that
michael@0 134 * they may either continue sending more data immediately, or
michael@0 135 * may want to wait until the other side has read some of the
michael@0 136 * data which has already been written to the socket before
michael@0 137 * buffering more. If send returns true, then less than 64k
michael@0 138 * has been buffered and it's safe to immediately write more.
michael@0 139 * If send returns false, then more than 64k has been buffered,
michael@0 140 * and the caller may wish to wait until the ondrain event
michael@0 141 * handler has been called before buffering more data by more
michael@0 142 * calls to send.
michael@0 143 */
michael@0 144 boolean send(in jsval data, [optional] in unsigned long byteOffset, [optional] in unsigned long byteLength);
michael@0 145
michael@0 146 /**
michael@0 147 * The readyState attribute indicates which state the socket is currently
michael@0 148 * in. The state will be either "connecting", "open", "closing", or "closed".
michael@0 149 */
michael@0 150 readonly attribute DOMString readyState;
michael@0 151
michael@0 152 /**
michael@0 153 * The binaryType attribute indicates which mode this socket uses for
michael@0 154 * sending and receiving data. If the binaryType: "arraybuffer" option
michael@0 155 * was passed to the open method that created this socket, binaryType
michael@0 156 * will be "arraybuffer". Otherwise, it will be "string".
michael@0 157 */
michael@0 158 readonly attribute DOMString binaryType;
michael@0 159
michael@0 160 /**
michael@0 161 * The onopen event handler is called when the connection to the server
michael@0 162 * has been established. If the connection is refused, onerror will be
michael@0 163 * called, instead.
michael@0 164 */
michael@0 165 attribute jsval onopen;
michael@0 166
michael@0 167 /**
michael@0 168 * After send has buffered more than 64k of data, it returns false to
michael@0 169 * indicate that the client should pause before sending more data, to
michael@0 170 * avoid accumulating large buffers. This is only advisory, and the client
michael@0 171 * is free to ignore it and buffer as much data as desired, but if reducing
michael@0 172 * the size of buffers is important (especially for a streaming application)
michael@0 173 * ondrain will be called once the previously-buffered data has been written
michael@0 174 * to the network, at which point the client can resume calling send again.
michael@0 175 */
michael@0 176 attribute jsval ondrain;
michael@0 177
michael@0 178 /**
michael@0 179 * The ondata handler will be called repeatedly and asynchronously after
michael@0 180 * onopen has been called, every time some data was available from the server
michael@0 181 * and was read. If binaryType: "arraybuffer" was passed to open, the data
michael@0 182 * attribute of the event object will be an ArrayBuffer. If not, it will be a
michael@0 183 * normal JavaScript string.
michael@0 184 *
michael@0 185 * At any time, the client may choose to pause reading and receiving ondata
michael@0 186 * callbacks, by calling the socket's suspend() method. Further invocations
michael@0 187 * of ondata will be paused until resume() is called.
michael@0 188 */
michael@0 189 attribute jsval ondata;
michael@0 190
michael@0 191 /**
michael@0 192 * The onerror handler will be called when there is an error. The data
michael@0 193 * attribute of the event passed to the onerror handler will have a
michael@0 194 * description of the kind of error.
michael@0 195 *
michael@0 196 * If onerror is called before onopen, the error was connection refused,
michael@0 197 * and onclose will not be called. If onerror is called after onopen,
michael@0 198 * the connection was lost, and onclose will be called after onerror.
michael@0 199 */
michael@0 200 attribute jsval onerror;
michael@0 201
michael@0 202 /**
michael@0 203 * The onclose handler is called once the underlying network socket
michael@0 204 * has been closed, either by the server, or by the client calling
michael@0 205 * close.
michael@0 206 *
michael@0 207 * If onerror was not called before onclose, then either side cleanly
michael@0 208 * closed the connection.
michael@0 209 */
michael@0 210 attribute jsval onclose;
michael@0 211 };
michael@0 212
michael@0 213 /*
michael@0 214 * This interface is implemented in TCPSocket.js as an internal interfaces
michael@0 215 * for use in cross-process socket implementation.
michael@0 216 * Needed to account for multiple possible types that can be provided to
michael@0 217 * the socket callbacks as arguments.
michael@0 218 */
michael@0 219 [scriptable, uuid(017f130f-2477-4215-8783-57eada957699)]
michael@0 220 interface nsITCPSocketInternal : nsISupports {
michael@0 221 // Trigger the callback for |type| and provide a DOMError() object with the given data
michael@0 222 void callListenerError(in DOMString type, in DOMString name);
michael@0 223
michael@0 224 // Trigger the callback for |type| and provide a string argument
michael@0 225 void callListenerData(in DOMString type, in DOMString data);
michael@0 226
michael@0 227 // Trigger the callback for |type| and provide an ArrayBuffer argument
michael@0 228 void callListenerArrayBuffer(in DOMString type, in jsval data);
michael@0 229
michael@0 230 // Trigger the callback for |type| with no argument
michael@0 231 void callListenerVoid(in DOMString type);
michael@0 232
michael@0 233 // Update the DOM object's readyState.
michael@0 234 // @param readyState
michael@0 235 // new ready state to be set to TCPSocket.
michael@0 236 void updateReadyState(in DOMString readyState);
michael@0 237
michael@0 238 // Update the DOM object's bufferedAmount value with a tracking number to
michael@0 239 // ensure the update request is sent after child's send() invocation.
michael@0 240 // @param bufferedAmount
michael@0 241 // TCPSocket parent's bufferedAmount.
michael@0 242 // @param trackingNumber
michael@0 243 // A number to ensure the bufferedAmount is updated after data
michael@0 244 // from child are sent to parent.
michael@0 245 void updateBufferedAmount(in uint32_t bufferedAmount,
michael@0 246 in uint32_t trackingNumber);
michael@0 247
michael@0 248 // Create a socket object on the parent side.
michael@0 249 // This is called in accepting any open request on the parent side.
michael@0 250 //
michael@0 251 // @param transport
michael@0 252 // The accepted socket transport.
michael@0 253 // @param binaryType
michael@0 254 // "arraybuffer" to use ArrayBuffer instances
michael@0 255 // in the ondata callback and as the argument to send.
michael@0 256 nsIDOMTCPSocket createAcceptedParent(in nsISocketTransport transport,
michael@0 257 in DOMString binaryType);
michael@0 258
michael@0 259 // Create a DOM socket on the child side
michael@0 260 // This is called when the socket is accepted on the parent side.
michael@0 261 //
michael@0 262 // @param socketChild
michael@0 263 // The socket child object for the IPC implementation.
michael@0 264 // @param binaryType
michael@0 265 // "arraybuffer" to use ArrayBuffer instances
michael@0 266 // in the ondata callback and as the argument to send.
michael@0 267 // @param window
michael@0 268 // An object to create ArrayBuffer for this window. See Bug 831107.
michael@0 269 nsIDOMTCPSocket createAcceptedChild(in nsITCPSocketChild socketChild,
michael@0 270 in DOMString binaryType,
michael@0 271 in nsIDOMWindow window);
michael@0 272
michael@0 273 // Set App ID.
michael@0 274 void setAppId(in unsigned long appId);
michael@0 275
michael@0 276 // Set a callback that handles the request from a TCP socket parent when that
michael@0 277 // socket parent wants to notify that its bufferedAmount is updated.
michael@0 278 void setOnUpdateBufferedAmountHandler(in jsval handler);
michael@0 279
michael@0 280 // Providing child process with ability to pass more arguments to parent's
michael@0 281 // send() function.
michael@0 282 // @param trackingNumber
michael@0 283 // To ensure the request to update bufferedAmount in child is after
michael@0 284 // lastest send() invocation from child.
michael@0 285 void onRecvSendFromChild(in jsval data, in unsigned long byteOffset,
michael@0 286 in unsigned long byteLength, in unsigned long trackingNumber);
michael@0 287 };
michael@0 288
michael@0 289 /**
michael@0 290 * nsITCPSocketEvent is the event object which is passed as the
michael@0 291 * first argument to all the event handler callbacks. It contains
michael@0 292 * the socket that was associated with the event, the type of event,
michael@0 293 * and the data associated with the event (if any).
michael@0 294 */
michael@0 295
michael@0 296 [scriptable, uuid(0f2abcca-b483-4539-a3e8-345707f75c44)]
michael@0 297 interface nsITCPSocketEvent : nsISupports {
michael@0 298 /**
michael@0 299 * The socket object which produced this event.
michael@0 300 */
michael@0 301 readonly attribute nsIDOMTCPSocket target;
michael@0 302
michael@0 303 /**
michael@0 304 * The type of this event. One of:
michael@0 305 *
michael@0 306 * open
michael@0 307 * error
michael@0 308 * data
michael@0 309 * drain
michael@0 310 * close
michael@0 311 */
michael@0 312 readonly attribute DOMString type;
michael@0 313
michael@0 314 /**
michael@0 315 * The data related to this event, if any. In the ondata callback,
michael@0 316 * data will be the bytes read from the network; if the binaryType
michael@0 317 * of the socket was "arraybuffer", this value will be of type ArrayBuffer;
michael@0 318 * otherwise, it will be a normal JavaScript string.
michael@0 319 *
michael@0 320 * In the onerror callback, data will be a string with a description
michael@0 321 * of the error.
michael@0 322 *
michael@0 323 * In the other callbacks, data will be an empty string.
michael@0 324 */
michael@0 325 readonly attribute jsval data;
michael@0 326 };
michael@0 327

mercurial