/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "domstubs.idl"

interface nsIDOMTCPSocket;
interface nsIDOMTCPServerSocket;
interface nsITCPServerSocketParent;
interface nsITCPSocketIntermediary;

// Interface required to allow the TCP socket object in the parent process
// to talk to the parent IPC actor
[scriptable, uuid(123f654b-4435-43c8-8447-db1b5420a1c2)]
interface nsITCPSocketParent : nsISupports
{
  [implicit_jscontext] void initJS(in jsval intermediary);

  // Trigger a callback in the content process for |type|, providing a serialized
  // argument of |data|, and update the child's readyState and bufferedAmount values
  // with the given values.
  [implicit_jscontext] void sendCallback(in DOMString type,
                                         in jsval data,
                                         in DOMString readyState,
                                         in uint32_t bufferedAmount);

  // Initialize a parent socket object. It is called from the parent side socket,
  // which is generated in accepting any open request on the parent side.
  // The socket after being initialized will be established.
  //
  // @param socket
  //        The socket on the parent side.
  // @param intermediary
  //        Intermediate class object. See nsITCPSocketIntermediary.
  [implicit_jscontext] void setSocketAndIntermediary(in nsIDOMTCPSocket socket,
                                                     in nsITCPSocketIntermediary intermediary);
};

// Intermediate class to handle sending multiple possible data types
// and kicking off the chrome process socket object's connection.
[scriptable, uuid(be67b1b8-03b0-4171-a791-d004458021b6)]
interface nsITCPSocketIntermediary : nsISupports {
  // Open the connection to the server with the given parameters
  nsIDOMTCPSocket open(in nsITCPSocketParent parent,
                       in DOMString host, in unsigned short port,
                       in boolean useSSL, in DOMString binaryType,
                       in unsigned long appId);

  // Listen on a port
  nsIDOMTCPServerSocket listen(in nsITCPServerSocketParent parent,
                               in unsigned short port, in unsigned short backlog,
                               in DOMString binaryType);

  // Send a basic string along the connection
  void sendString(in DOMString data);

  // Send a typed array
  void sendArrayBuffer(in jsval data);
};
