diff --git a/dom/network/interfaces/nsITCPSocketChild.idl b/dom/network/interfaces/nsITCPSocketChild.idl index aa725918e9d..ba3a88af6a8 100644 --- a/dom/network/interfaces/nsITCPSocketChild.idl +++ b/dom/network/interfaces/nsITCPSocketChild.idl @@ -8,22 +8,26 @@ interface nsITCPSocketInternal; interface nsIDOMWindow; // Interface to allow the content process socket to reach the IPC bridge. -[scriptable, uuid(ada5342d-6d45-4ff1-a7d3-6a4b150d0385)] +// Implemented in C++ as TCPSocketChild, referenced as _socketBridge in TCPSocket.js +[scriptable, uuid(292ebb3a-beac-4e06-88b0-b5b4e88ebd1c)] interface nsITCPSocketChild : nsISupports { // Tell the chrome process to open a corresponding connection with the given parameters [implicit_jscontext] - void open(in nsITCPSocketInternal socket, in DOMString host, - in unsigned short port, in boolean ssl, in DOMString binaryType, - in nsIDOMWindow window, in jsval windowVal); + void sendOpen(in nsITCPSocketInternal socket, in DOMString host, + in unsigned short port, in boolean ssl, in DOMString binaryType, + in nsIDOMWindow window, in jsval windowVal); + + // Tell the chrome process to perform send and update the tracking number. + [implicit_jscontext] + void sendSend(in jsval data, in unsigned long byteOffset, + in unsigned long byteLength, in unsigned long trackingNumber); // Tell the chrome process to perform equivalent operations to all following methods - [implicit_jscontext] - void send(in jsval data, in unsigned long byteOffset, in unsigned long byteLength); - void resume(); - void suspend(); - void close(); - void startTLS(); + void sendResume(); + void sendSuspend(); + void sendClose(); + void sendStartTLS(); /** * Initialize the TCP socket on the child side for IPC. It is called from the child side, diff --git a/dom/network/interfaces/nsITCPSocketParent.idl b/dom/network/interfaces/nsITCPSocketParent.idl index 1433eaa68d6..341c9d159b1 100644 --- a/dom/network/interfaces/nsITCPSocketParent.idl +++ b/dom/network/interfaces/nsITCPSocketParent.idl @@ -9,20 +9,29 @@ 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 required to allow the TCP socket object (TCPSocket.js) in the +// parent process to talk to the parent IPC actor, TCPSocketParent, which +// is written in C++. +[scriptable, uuid(868662a4-681c-4b89-9f02-6fe5b7ace265)] 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); + // argument of |data|, and update the child's readyState value with the given + // values. + // + // @param type + // Event type: 'onopen', 'ondata', 'onerror' or 'onclose'. 'odrain' is + // controlled by child. + // @param data + // Serialized data that is passed to event handler. + // @param readyState + // Current ready state. + [implicit_jscontext] void sendEvent(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. @@ -38,7 +47,10 @@ interface nsITCPSocketParent : nsISupports // 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)] +// This interface is the bridge of TCPSocketParent, which is written in C++, +// and TCPSocket, which is written in Javascript. TCPSocketParentIntermediary +// implements nsITCPSocketIntermediary in Javascript. +[scriptable, uuid(c434224a-dbb7-4869-8b2b-e49cee990e85)] interface nsITCPSocketIntermediary : nsISupports { // Open the connection to the server with the given parameters nsIDOMTCPSocket open(in nsITCPSocketParent parent, @@ -51,9 +63,9 @@ interface nsITCPSocketIntermediary : nsISupports { in unsigned short port, in unsigned short backlog, in DOMString binaryType); - // Send a basic string along the connection - void sendString(in DOMString data); + // Called when received a child request to send a string. + void onRecvSendString(in DOMString data); - // Send a typed array - void sendArrayBuffer(in jsval data); + // Called when received a child request to send an array buffer. + void onRecvSendArrayBuffer(in jsval data); }; diff --git a/dom/network/src/PTCPSocket.ipdl b/dom/network/src/PTCPSocket.ipdl index d66291e8f11..6f104ea1cc3 100644 --- a/dom/network/src/PTCPSocket.ipdl +++ b/dom/network/src/PTCPSocket.ipdl @@ -35,14 +35,27 @@ protocol PTCPSocket manager PNecko; parent: + // Forward calling to child's open() method to parent, expect TCPOptions + // is expanded to |useSSL| (from TCPOptions.useSecureTransport) and + // |binaryType| (from TCPOption.binaryType). Open(nsString host, uint16_t port, bool useSSL, nsString binaryType); + Data(SendableData data); + + // Forward calling to child's upgradeToSecure() method to parent. StartTLS(); + + // Forward calling to child's send() method to parent. Suspend(); + + // Forward calling to child's resume() method to parent. Resume(); + + // Forward calling to child's close() method to parent. Close(); child: + // Forward events that are dispatched by parent. Callback(nsString type, CallbackData data, nsString readyState, uint32_t bufferedAmount); diff --git a/dom/network/src/TCPSocket.js b/dom/network/src/TCPSocket.js index 4a6b36007cc..6ea65ede375 100644 --- a/dom/network/src/TCPSocket.js +++ b/dom/network/src/TCPSocket.js @@ -517,8 +517,8 @@ TCPSocket.prototype = { if (this._inChild) { that._socketBridge = Cc["@mozilla.org/tcp-socket-child;1"] .createInstance(Ci.nsITCPSocketChild); - that._socketBridge.open(that, host, port, !!that._ssl, - that._binaryType, this.useWin, this.useWin || this); + that._socketBridge.sendOpen(that, host, port, !!that._ssl, + that._binaryType, this.useWin, this.useWin || this); return that; } @@ -551,7 +551,7 @@ TCPSocket.prototype = { this._ssl = 'ssl'; if (this._inChild) { - this._socketBridge.startTLS(); + this._socketBridge.sendStartTLS(); return; } @@ -585,7 +585,7 @@ TCPSocket.prototype = { this._readyState = kCLOSING; if (this._inChild) { - this._socketBridge.close(); + this._socketBridge.sendClose(); return; } @@ -605,7 +605,7 @@ TCPSocket.prototype = { } if (this._inChild) { - this._socketBridge.send(data, byteOffset, byteLength); + this._socketBridge.sendSend(data, byteOffset, byteLength); } let length = this._binaryType === "arraybuffer" ? byteLength : data.length; @@ -655,7 +655,7 @@ TCPSocket.prototype = { suspend: function ts_suspend() { if (this._inChild) { - this._socketBridge.suspend(); + this._socketBridge.sendSuspend(); return; } @@ -668,7 +668,7 @@ TCPSocket.prototype = { resume: function ts_resume() { if (this._inChild) { - this._socketBridge.resume(); + this._socketBridge.sendResume(); return; } diff --git a/dom/network/src/TCPSocketChild.cpp b/dom/network/src/TCPSocketChild.cpp index 9a3576ccf64..d5303a4eb3e 100644 --- a/dom/network/src/TCPSocketChild.cpp +++ b/dom/network/src/TCPSocketChild.cpp @@ -77,10 +77,11 @@ TCPSocketChild::TCPSocketChild() } NS_IMETHODIMP -TCPSocketChild::Open(nsITCPSocketInternal* aSocket, const nsAString& aHost, - uint16_t aPort, bool aUseSSL, const nsAString& aBinaryType, - nsIDOMWindow* aWindow, const JS::Value& aWindowObj, - JSContext* aCx) +TCPSocketChild::SendOpen(nsITCPSocketInternal* aSocket, + const nsAString& aHost, uint16_t aPort, + bool aUseSSL, const nsAString& aBinaryType, + nsIDOMWindow* aWindow, const JS::Value& aWindowObj, + JSContext* aCx) { mSocket = aSocket; @@ -91,7 +92,8 @@ TCPSocketChild::Open(nsITCPSocketInternal* aSocket, const nsAString& aHost, } AddIPDLReference(); gNeckoChild->SendPTCPSocketConstructor(this); - SendOpen(nsString(aHost), aPort, aUseSSL, nsString(aBinaryType)); + PTCPSocketChild::SendOpen(nsString(aHost), aPort, + aUseSSL, nsString(aBinaryType)); return NS_OK; } @@ -159,38 +161,38 @@ TCPSocketChild::RecvCallback(const nsString& aType, } NS_IMETHODIMP -TCPSocketChild::StartTLS() +TCPSocketChild::SendStartTLS() { - SendStartTLS(); + PTCPSocketChild::SendStartTLS(); return NS_OK; } NS_IMETHODIMP -TCPSocketChild::Suspend() +TCPSocketChild::SendSuspend() { - SendSuspend(); + PTCPSocketChild::SendSuspend(); return NS_OK; } NS_IMETHODIMP -TCPSocketChild::Resume() +TCPSocketChild::SendResume() { - SendResume(); + PTCPSocketChild::SendResume(); return NS_OK; } NS_IMETHODIMP -TCPSocketChild::Close() +TCPSocketChild::SendClose() { - SendClose(); + PTCPSocketChild::SendClose(); return NS_OK; } NS_IMETHODIMP -TCPSocketChild::Send(const JS::Value& aData, - uint32_t aByteOffset, - uint32_t aByteLength, - JSContext* aCx) +TCPSocketChild::SendSend(const JS::Value& aData, + uint32_t aByteOffset, + uint32_t aByteLength, + JSContext* aCx) { if (aData.isString()) { JSString* jsstr = aData.toString(); @@ -223,8 +225,8 @@ TCPSocketChild::Send(const JS::Value& aData, NS_IMETHODIMP TCPSocketChild::SetSocketAndWindow(nsITCPSocketInternal *aSocket, - const JS::Value& aWindowObj, - JSContext* aCx) + const JS::Value& aWindowObj, + JSContext* aCx) { mSocket = aSocket; MOZ_ASSERT(aWindowObj.isObject()); diff --git a/dom/network/src/TCPSocketParent.cpp b/dom/network/src/TCPSocketParent.cpp index a911d753f76..43ea83ecf49 100644 --- a/dom/network/src/TCPSocketParent.cpp +++ b/dom/network/src/TCPSocketParent.cpp @@ -168,13 +168,13 @@ TCPSocketParent::RecvData(const SendableData& aData) JS::Rooted val(cx); JS::Rooted obj(cx, mIntermediaryObj); IPC::DeserializeArrayBuffer(obj, aData.get_ArrayOfuint8_t(), &val); - rv = mIntermediary->SendArrayBuffer(val); + rv = mIntermediary->OnRecvSendArrayBuffer(val); NS_ENSURE_SUCCESS(rv, true); break; } case SendableData::TnsString: - rv = mIntermediary->SendString(aData.get_nsString()); + rv = mIntermediary->OnRecvSendString(aData.get_nsString()); NS_ENSURE_SUCCESS(rv, true); break; @@ -194,9 +194,8 @@ TCPSocketParent::RecvClose() } NS_IMETHODIMP -TCPSocketParent::SendCallback(const nsAString& aType, const JS::Value& aDataVal, - const nsAString& aReadyState, uint32_t aBuffered, - JSContext* aCx) +TCPSocketParent::SendEvent(const nsAString& aType, const JS::Value& aDataVal, + const nsAString& aReadyState, JSContext* aCx) { if (!mIPCOpen) { NS_WARNING("Dropping callback due to no IPC connection"); diff --git a/dom/network/src/TCPSocketParentIntermediary.js b/dom/network/src/TCPSocketParentIntermediary.js index 11ff0658d17..1624ed4bfd5 100644 --- a/dom/network/src/TCPSocketParentIntermediary.js +++ b/dom/network/src/TCPSocketParentIntermediary.js @@ -23,8 +23,8 @@ TCPSocketParentIntermediary.prototype = { ["open", "drain", "data", "error", "close"].forEach( function(p) { socket["on" + p] = function(data) { - aParentSide.sendCallback(p, data.data, socket.readyState, - socket.bufferedAmount); + aParentSide.sendEvent(p, data.data, socket.readyState, + socket.bufferedAmount); }; } ); @@ -79,11 +79,11 @@ TCPSocketParentIntermediary.prototype = { return serverSocket; }, - sendString: function(aData) { + onRecvSendString: function(aData) { return this._socket.send(aData); }, - sendArrayBuffer: function(aData) { + onRecvSendArrayBuffer: function(aData) { return this._socket.send(aData, 0, aData.byteLength); },