Back out 3 changesets (bug 885982, bug 1118063) for b2g mochitest-6 bustage
CLOSED TREE Backed out changeset 865e7bc208df (bug 885982) Backed out changeset 9ede577f5ada (bug 885982) Backed out changeset 6ccc86f7429e (bug 1118063)
This commit is contained in:
2
CLOBBER
2
CLOBBER
@@ -22,4 +22,4 @@
|
|||||||
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
|
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
|
||||||
# don't change CLOBBER for WebIDL changes any more.
|
# don't change CLOBBER for WebIDL changes any more.
|
||||||
|
|
||||||
Renaming nsIDOMTCPSocket.idl and nsIDOMTCPServerSocket.idl for bug 885982 and bug 1118063.
|
Bug 1121297 - Converted VolatileBuffer's CPP tests to GTests
|
||||||
|
|||||||
@@ -1878,8 +1878,6 @@ addExternalIface('nsIDocShell', nativeType='nsIDocShell', notflattened=True)
|
|||||||
addExternalIface('nsIEditor', nativeType='nsIEditor', notflattened=True)
|
addExternalIface('nsIEditor', nativeType='nsIEditor', notflattened=True)
|
||||||
addExternalIface('nsIVariant', nativeType='nsIVariant', notflattened=True)
|
addExternalIface('nsIVariant', nativeType='nsIVariant', notflattened=True)
|
||||||
addExternalIface('nsIScriptableRegion', nativeType='nsIScriptableRegion', notflattened=True)
|
addExternalIface('nsIScriptableRegion', nativeType='nsIScriptableRegion', notflattened=True)
|
||||||
addExternalIface('nsITCPServerSocketInternal', nativeType='nsITCPServerSocketInternal', notflattened=True)
|
|
||||||
addExternalIface('nsITCPSocketInternal', nativeType='nsITCPSocketInternal', notflattened=True)
|
|
||||||
addExternalIface('OutputStream', nativeType='nsIOutputStream',
|
addExternalIface('OutputStream', nativeType='nsIOutputStream',
|
||||||
notflattened=True)
|
notflattened=True)
|
||||||
addExternalIface('Principal', nativeType='nsIPrincipal',
|
addExternalIface('Principal', nativeType='nsIPrincipal',
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ const Cr = Components.results;
|
|||||||
const CC = Components.Constructor;
|
const CC = Components.Constructor;
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
|
||||||
|
|
||||||
const ServerSocket = CC(
|
const ServerSocket = CC(
|
||||||
'@mozilla.org/network/server-socket;1', 'nsIServerSocket', 'init'),
|
'@mozilla.org/network/server-socket;1', 'nsIServerSocket', 'init'),
|
||||||
@@ -22,7 +21,7 @@ const ServerSocket = CC(
|
|||||||
* Debug logging function
|
* Debug logging function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let debug = false;
|
let debug = true;
|
||||||
function LOG(msg) {
|
function LOG(msg) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
dump("TCPServerSocket: " + msg + "\n");
|
dump("TCPServerSocket: " + msg + "\n");
|
||||||
@@ -34,89 +33,59 @@ function LOG(msg) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function TCPServerSocket() {
|
function TCPServerSocket() {
|
||||||
this.makeGetterSetterEH("onconnect");
|
|
||||||
this.makeGetterSetterEH("onerror");
|
|
||||||
|
|
||||||
this._localPort = 0;
|
this._localPort = 0;
|
||||||
this._binaryType = null;
|
this._binaryType = null;
|
||||||
|
|
||||||
|
this._onconnect = null;
|
||||||
|
this._onerror = null;
|
||||||
|
|
||||||
this._inChild = false;
|
this._inChild = false;
|
||||||
this._neckoTCPServerSocket = null;
|
this._neckoTCPServerSocket = null;
|
||||||
this._serverBridge = null;
|
this._serverBridge = null;
|
||||||
|
this.useWin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When this API moves to WebIDL and these __exposedProps__ go away, remove
|
||||||
|
// this call here and remove the API from XPConnect.
|
||||||
|
Cu.skipCOWCallableChecks();
|
||||||
|
|
||||||
TCPServerSocket.prototype = {
|
TCPServerSocket.prototype = {
|
||||||
|
__exposedProps__: {
|
||||||
|
localPort: 'r',
|
||||||
|
onconnect: 'rw',
|
||||||
|
onerror: 'rw'
|
||||||
|
},
|
||||||
get localPort() {
|
get localPort() {
|
||||||
return this._localPort;
|
return this._localPort;
|
||||||
},
|
},
|
||||||
|
get onconnect() {
|
||||||
getEH: function(type) {
|
return this._onconnect;
|
||||||
return this.__DOM_IMPL__.getEventHandler(type);
|
|
||||||
},
|
},
|
||||||
setEH: function(type, handler) {
|
set onconnect(f) {
|
||||||
this.__DOM_IMPL__.setEventHandler(type, handler);
|
this._onconnect = f;
|
||||||
},
|
},
|
||||||
makeGetterSetterEH: function(name) {
|
get onerror() {
|
||||||
Object.defineProperty(this, name,
|
return this._onerror;
|
||||||
{
|
},
|
||||||
get:function() { return this.getEH(name); },
|
set onerror(f) {
|
||||||
set:function(h) { return this.setEH(name, h); }
|
this._onerror = f;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_callListenerAcceptCommon: function tss_callListenerAcceptCommon(socket) {
|
_callListenerAcceptCommon: function tss_callListenerAcceptCommon(socket) {
|
||||||
|
if (this._onconnect) {
|
||||||
try {
|
try {
|
||||||
this.__DOM_IMPL__.dispatchEvent(new this.useGlobal.TCPServerSocketEvent("connect", {socket: socket}));
|
this["onconnect"].call(null, socket);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
LOG('exception in _callListenerAcceptCommon: ' + e);
|
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
socket.close();
|
||||||
|
dump("Received unexpected connection!");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
init: function tss_init(aWindowObj) {
|
init: function tss_init(aWindowObj) {
|
||||||
this.useGlobal = aWindowObj;
|
this.useWin = aWindowObj;
|
||||||
|
|
||||||
if (aWindowObj) {
|
|
||||||
Services.obs.addObserver(this, "inner-window-destroyed", true);
|
|
||||||
|
|
||||||
let util = aWindowObj.QueryInterface(
|
|
||||||
Ci.nsIInterfaceRequestor
|
|
||||||
).getInterface(Ci.nsIDOMWindowUtils);
|
|
||||||
this.innerWindowID = util.currentInnerWindowID;
|
|
||||||
|
|
||||||
LOG("window init: " + this.innerWindowID);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
__init: function(port, options, backlog) {
|
|
||||||
this.listen(port, options, backlog);
|
|
||||||
},
|
|
||||||
|
|
||||||
initWithGlobal: function(global) {
|
|
||||||
this.useGlobal = global;
|
|
||||||
},
|
|
||||||
|
|
||||||
observe: function(aSubject, aTopic, aData) {
|
|
||||||
let wId;
|
|
||||||
try {
|
|
||||||
wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
||||||
} catch(x) {
|
|
||||||
wId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wId == this.innerWindowID) {
|
|
||||||
LOG("inner-window-destroyed: " + this.innerWindowID);
|
|
||||||
|
|
||||||
// This window is now dead, so we want to clear the callbacks
|
|
||||||
// so that we don't get a "can't access dead object" when the
|
|
||||||
// underlying stream goes to tell us that we are closed
|
|
||||||
this.onconnect = null;
|
|
||||||
this.onerror = null;
|
|
||||||
|
|
||||||
this.useGlobal = null;
|
|
||||||
|
|
||||||
// Clean up our socket
|
|
||||||
this.close();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/* nsITCPServerSocketInternal method */
|
/* nsITCPServerSocketInternal method */
|
||||||
@@ -149,19 +118,17 @@ TCPServerSocket.prototype = {
|
|||||||
|
|
||||||
callListenerAccept: function tss_callListenerSocket(socketChild) {
|
callListenerAccept: function tss_callListenerSocket(socketChild) {
|
||||||
// this method is called at child process when the socket is accepted at parent process.
|
// this method is called at child process when the socket is accepted at parent process.
|
||||||
let socket = new this.useGlobal.mozTCPSocket("", 0, {doNotConnect: true});
|
let socket = TCPSocketInternal.createAcceptedChild(socketChild, this._binaryType, this.useWin);
|
||||||
socket.getInternalSocket().initAcceptedChild(socketChild, this._binaryType, this.useGlobal);
|
|
||||||
this._callListenerAcceptCommon(socket);
|
this._callListenerAcceptCommon(socket);
|
||||||
},
|
},
|
||||||
|
|
||||||
callListenerError: function tss_callListenerError(message, filename, lineNumber, columnNumber) {
|
callListenerError: function tss_callListenerError(message, filename, lineNumber, columnNumber) {
|
||||||
let init = {
|
if (this._onerror) {
|
||||||
message: message,
|
var type = "error";
|
||||||
filename: filename,
|
var error = new Error(message, filename, lineNumber, columnNumber);
|
||||||
lineno: lineNumber,
|
|
||||||
colno: columnNumber,
|
this["onerror"].call(null, new TCPSocketEvent(type, this, error));
|
||||||
};
|
}
|
||||||
this.__DOM_IMPL__.dispatchEvent(new this.useGlobal.ErrorEvent("error", init));
|
|
||||||
},
|
},
|
||||||
/* end nsITCPServerSocketInternal method */
|
/* end nsITCPServerSocketInternal method */
|
||||||
|
|
||||||
@@ -181,12 +148,11 @@ TCPServerSocket.prototype = {
|
|||||||
onSocketAccepted: function tss_onSocketAccepted(server, trans) {
|
onSocketAccepted: function tss_onSocketAccepted(server, trans) {
|
||||||
// precondition: this._inChild == false
|
// precondition: this._inChild == false
|
||||||
try {
|
try {
|
||||||
let that = new this.useGlobal.mozTCPSocket("", 0, {doNotConnect: true});
|
let that = TCPSocketInternal.createAcceptedParent(trans, this._binaryType,
|
||||||
that.getInternalSocket().initAcceptedParent(trans, this._binaryType, this.useGlobal);
|
this.useWin);
|
||||||
this._callListenerAcceptCommon(that);
|
this._callListenerAcceptCommon(that);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
LOG('exception in onSocketAccepted: ' + e);
|
|
||||||
trans.close(Cr.NS_BINDING_ABORTED);
|
trans.close(Cr.NS_BINDING_ABORTED);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -199,18 +165,22 @@ TCPServerSocket.prototype = {
|
|||||||
this._neckoTCPServerSocket = null;
|
this._neckoTCPServerSocket = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getInternalSocket: function() {
|
|
||||||
return this.QueryInterface(Ci.nsITCPServerSocketInternal);
|
|
||||||
},
|
|
||||||
|
|
||||||
classID: Components.ID("{73065eae-27dc-11e2-895a-000c29987aa2}"),
|
classID: Components.ID("{73065eae-27dc-11e2-895a-000c29987aa2}"),
|
||||||
|
|
||||||
contractID: "@mozilla.org/tcp-server-socket;1",
|
classInfo: XPCOMUtils.generateCI({
|
||||||
|
classID: Components.ID("{73065eae-27dc-11e2-895a-000c29987aa2}"),
|
||||||
|
classDescription: "Server TCP Socket",
|
||||||
|
interfaces: [
|
||||||
|
Ci.nsIDOMTCPServerSocket,
|
||||||
|
Ci.nsISupportsWeakReference
|
||||||
|
],
|
||||||
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
||||||
|
}),
|
||||||
|
|
||||||
QueryInterface: XPCOMUtils.generateQI([
|
QueryInterface: XPCOMUtils.generateQI([
|
||||||
|
Ci.nsIDOMTCPServerSocket,
|
||||||
Ci.nsITCPServerSocketInternal,
|
Ci.nsITCPServerSocketInternal,
|
||||||
Ci.nsIDOMGlobalPropertyInitializer,
|
Ci.nsISupportsWeakReference
|
||||||
Ci.nsISupportsWeakReference,
|
|
||||||
Ci.nsIObserver
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "mozilla/net/NeckoChild.h"
|
#include "mozilla/net/NeckoChild.h"
|
||||||
#include "mozilla/dom/PBrowserChild.h"
|
#include "mozilla/dom/PBrowserChild.h"
|
||||||
#include "mozilla/dom/TabChild.h"
|
#include "mozilla/dom/TabChild.h"
|
||||||
#include "nsITCPServerSocketInternal.h"
|
#include "nsIDOMTCPSocket.h"
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,8 @@
|
|||||||
#include "TCPSocketParent.h"
|
#include "TCPSocketParent.h"
|
||||||
#include "mozilla/unused.h"
|
#include "mozilla/unused.h"
|
||||||
#include "mozilla/AppProcessChecker.h"
|
#include "mozilla/AppProcessChecker.h"
|
||||||
#include "mozilla/dom/BindingUtils.h"
|
|
||||||
#include "mozilla/dom/ContentParent.h"
|
#include "mozilla/dom/ContentParent.h"
|
||||||
#include "mozilla/dom/TabParent.h"
|
#include "mozilla/dom/TabParent.h"
|
||||||
#include "nsGlobalWindow.h"
|
|
||||||
#include "nsITCPServerSocketInternal.h"
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@@ -34,16 +31,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketParent)
|
|||||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
TCPServerSocketParent::TCPServerSocketParent()
|
|
||||||
: mNeckoParent(nullptr)
|
|
||||||
, mIPCOpen(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TCPServerSocketParent::~TCPServerSocketParent()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TCPServerSocketParent::ReleaseIPDLReference()
|
TCPServerSocketParent::ReleaseIPDLReference()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,17 +2,13 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
* 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/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef mozilla_dom_TCPServerSocketParent_h
|
|
||||||
#define mozilla_dom_TCPServerSocketParent_h
|
|
||||||
|
|
||||||
#include "mozilla/net/PNeckoParent.h"
|
#include "mozilla/net/PNeckoParent.h"
|
||||||
#include "mozilla/net/PTCPServerSocketParent.h"
|
#include "mozilla/net/PTCPServerSocketParent.h"
|
||||||
#include "nsITCPSocketParent.h"
|
#include "nsITCPSocketParent.h"
|
||||||
#include "nsITCPServerSocketParent.h"
|
#include "nsITCPServerSocketParent.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIDOMTCPSocket.h"
|
||||||
class nsITCPServerSocketInternal;
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@@ -27,7 +23,7 @@ public:
|
|||||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
NS_DECL_NSITCPSERVERSOCKETPARENT
|
NS_DECL_NSITCPSERVERSOCKETPARENT
|
||||||
|
|
||||||
TCPServerSocketParent();
|
TCPServerSocketParent() : mNeckoParent(nullptr), mIPCOpen(false) {}
|
||||||
|
|
||||||
bool Init(PNeckoParent* neckoParent, const uint16_t& aLocalPort, const uint16_t& aBacklog,
|
bool Init(PNeckoParent* neckoParent, const uint16_t& aLocalPort, const uint16_t& aBacklog,
|
||||||
const nsString& aBinaryType);
|
const nsString& aBinaryType);
|
||||||
@@ -42,17 +38,15 @@ public:
|
|||||||
void ReleaseIPDLReference();
|
void ReleaseIPDLReference();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~TCPServerSocketParent();
|
~TCPServerSocketParent() {}
|
||||||
|
|
||||||
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
|
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
|
||||||
|
|
||||||
PNeckoParent* mNeckoParent;
|
PNeckoParent* mNeckoParent;
|
||||||
nsCOMPtr<nsITCPSocketIntermediary> mIntermediary;
|
nsCOMPtr<nsITCPSocketIntermediary> mIntermediary;
|
||||||
nsCOMPtr<nsITCPServerSocketInternal> mServerSocket;
|
nsCOMPtr<nsIDOMTCPServerSocket> mServerSocket;
|
||||||
bool mIPCOpen;
|
bool mIPCOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
#endif // mozilla_dom_TCPServerSocketParent_h
|
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ const CC = Components.Constructor;
|
|||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "gSocketTransportService",
|
|
||||||
"@mozilla.org/network/socket-transport-service;1",
|
|
||||||
"nsISocketTransportService");
|
|
||||||
|
|
||||||
const InputStreamPump = CC(
|
const InputStreamPump = CC(
|
||||||
"@mozilla.org/network/input-stream-pump;1", "nsIInputStreamPump", "init"),
|
"@mozilla.org/network/input-stream-pump;1", "nsIInputStreamPump", "init"),
|
||||||
AsyncStreamCopier = CC(
|
AsyncStreamCopier = CC(
|
||||||
@@ -49,7 +45,7 @@ const NETWORK_STATS_THRESHOLD = 65536;
|
|||||||
// contains a documented TCPError.webidl that maps all the error codes we use in
|
// contains a documented TCPError.webidl that maps all the error codes we use in
|
||||||
// this file to slightly more readable explanations.
|
// this file to slightly more readable explanations.
|
||||||
function createTCPError(aWindow, aErrorName, aErrorType) {
|
function createTCPError(aWindow, aErrorName, aErrorType) {
|
||||||
return new DOMError(aErrorName);
|
return new (aWindow ? aWindow.DOMError : DOMError)(aErrorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,30 +59,94 @@ function LOG(msg) {
|
|||||||
dump("TCPSocket: " + msg + "\n");
|
dump("TCPSocket: " + msg + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nsITCPSocketEvent object
|
||||||
|
*/
|
||||||
|
|
||||||
|
function TCPSocketEvent(type, sock, data) {
|
||||||
|
this._type = type;
|
||||||
|
this._target = sock;
|
||||||
|
this._data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When this API moves to WebIDL and these __exposedProps__ go away, remove
|
||||||
|
// this call here and remove the API from XPConnect.
|
||||||
|
Cu.skipCOWCallableChecks();
|
||||||
|
|
||||||
|
TCPSocketEvent.prototype = {
|
||||||
|
__exposedProps__: {
|
||||||
|
type: 'r',
|
||||||
|
target: 'r',
|
||||||
|
data: 'r',
|
||||||
|
// Promise::ResolveInternal tries to check if the thing being resolved is
|
||||||
|
// itself a promise through the presence of "then". Accordingly, we list
|
||||||
|
// it as an exposed property, although we return undefined for it.
|
||||||
|
// Bug 882123 covers making TCPSocket be a proper event target with proper
|
||||||
|
// events.
|
||||||
|
then: 'r'
|
||||||
|
},
|
||||||
|
get type() {
|
||||||
|
return this._type;
|
||||||
|
},
|
||||||
|
get target() {
|
||||||
|
return this._target;
|
||||||
|
},
|
||||||
|
get data() {
|
||||||
|
return this._data;
|
||||||
|
},
|
||||||
|
get then() {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nsIDOMTCPSocket object
|
* nsIDOMTCPSocket object
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function TCPSocket() {
|
function TCPSocket() {
|
||||||
this.makeGetterSetterEH("onopen");
|
|
||||||
this.makeGetterSetterEH("onclose");
|
|
||||||
this.makeGetterSetterEH("ondrain");
|
|
||||||
this.makeGetterSetterEH("ondata");
|
|
||||||
this.makeGetterSetterEH("onerror");
|
|
||||||
|
|
||||||
this._readyState = kCLOSED;
|
this._readyState = kCLOSED;
|
||||||
|
|
||||||
|
this._onopen = null;
|
||||||
|
this._ondrain = null;
|
||||||
|
this._ondata = null;
|
||||||
|
this._onerror = null;
|
||||||
|
this._onclose = null;
|
||||||
|
|
||||||
this._binaryType = "string";
|
this._binaryType = "string";
|
||||||
|
|
||||||
this._host = "";
|
this._host = "";
|
||||||
this._port = 0;
|
this._port = 0;
|
||||||
this._ssl = false;
|
this._ssl = false;
|
||||||
|
|
||||||
|
this.useWin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPSocket.prototype = {
|
TCPSocket.prototype = {
|
||||||
|
__exposedProps__: {
|
||||||
|
open: 'r',
|
||||||
|
host: 'r',
|
||||||
|
port: 'r',
|
||||||
|
ssl: 'r',
|
||||||
|
bufferedAmount: 'r',
|
||||||
|
suspend: 'r',
|
||||||
|
resume: 'r',
|
||||||
|
close: 'r',
|
||||||
|
send: 'r',
|
||||||
|
readyState: 'r',
|
||||||
|
binaryType: 'r',
|
||||||
|
listen: 'r',
|
||||||
|
onopen: 'rw',
|
||||||
|
ondrain: 'rw',
|
||||||
|
ondata: 'rw',
|
||||||
|
onerror: 'rw',
|
||||||
|
onclose: 'rw'
|
||||||
|
},
|
||||||
// The binary type, "string" or "arraybuffer"
|
// The binary type, "string" or "arraybuffer"
|
||||||
_binaryType: null,
|
_binaryType: null,
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
_hasPrivileges: null,
|
||||||
|
|
||||||
// Raw socket streams
|
// Raw socket streams
|
||||||
_transport: null,
|
_transport: null,
|
||||||
_socketInputStream: null,
|
_socketInputStream: null,
|
||||||
@@ -150,21 +210,36 @@ TCPSocket.prototype = {
|
|||||||
}
|
}
|
||||||
return this._multiplexStream.available();
|
return this._multiplexStream.available();
|
||||||
},
|
},
|
||||||
|
get onopen() {
|
||||||
getEH: function(type) {
|
return this._onopen;
|
||||||
return this.__DOM_IMPL__.getEventHandler(type);
|
|
||||||
},
|
},
|
||||||
setEH: function(type, handler) {
|
set onopen(f) {
|
||||||
this.__DOM_IMPL__.setEventHandler(type, handler);
|
this._onopen = f;
|
||||||
},
|
},
|
||||||
makeGetterSetterEH: function(name) {
|
get ondrain() {
|
||||||
Object.defineProperty(this, name,
|
return this._ondrain;
|
||||||
{
|
},
|
||||||
get:function() { return this.getEH(name); },
|
set ondrain(f) {
|
||||||
set:function(h) { return this.setEH(name, h); }
|
this._ondrain = f;
|
||||||
});
|
},
|
||||||
|
get ondata() {
|
||||||
|
return this._ondata;
|
||||||
|
},
|
||||||
|
set ondata(f) {
|
||||||
|
this._ondata = f;
|
||||||
|
},
|
||||||
|
get onerror() {
|
||||||
|
return this._onerror;
|
||||||
|
},
|
||||||
|
set onerror(f) {
|
||||||
|
this._onerror = f;
|
||||||
|
},
|
||||||
|
get onclose() {
|
||||||
|
return this._onclose;
|
||||||
|
},
|
||||||
|
set onclose(f) {
|
||||||
|
this._onclose = f;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
_activateTLS: function() {
|
_activateTLS: function() {
|
||||||
let securityInfo = this._transport.securityInfo
|
let securityInfo = this._transport.securityInfo
|
||||||
@@ -180,7 +255,9 @@ TCPSocket.prototype = {
|
|||||||
} else {
|
} else {
|
||||||
options = ['starttls'];
|
options = ['starttls'];
|
||||||
}
|
}
|
||||||
return gSocketTransportService.createTransport(options, 1, host, port, null);
|
return Cc["@mozilla.org/network/socket-transport-service;1"]
|
||||||
|
.getService(Ci.nsISocketTransportService)
|
||||||
|
.createTransport(options, 1, host, port, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
_sendBufferedAmount: function ts_sendBufferedAmount() {
|
_sendBufferedAmount: function ts_sendBufferedAmount() {
|
||||||
@@ -307,7 +384,10 @@ TCPSocket.prototype = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
callListener: function ts_callListener(type, data) {
|
callListener: function ts_callListener(type, data) {
|
||||||
this.__DOM_IMPL__.dispatchEvent(new this.useWin.TCPSocketEvent(type, {data: data || ""}));
|
if (!this["on" + type])
|
||||||
|
return;
|
||||||
|
|
||||||
|
this["on" + type].call(null, new TCPSocketEvent(type, this, data || ""));
|
||||||
},
|
},
|
||||||
|
|
||||||
/* nsITCPSocketInternal methods */
|
/* nsITCPSocketInternal methods */
|
||||||
@@ -361,6 +441,39 @@ TCPSocket.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
createAcceptedParent: function ts_createAcceptedParent(transport, binaryType, windowObject) {
|
||||||
|
let that = new TCPSocket();
|
||||||
|
that._transport = transport;
|
||||||
|
that._initStream(binaryType);
|
||||||
|
|
||||||
|
// ReadyState is kOpen since accepted transport stream has already been connected
|
||||||
|
that._readyState = kOPEN;
|
||||||
|
that._inputStreamPump = new InputStreamPump(that._socketInputStream, -1, -1, 0, 0, false);
|
||||||
|
that._inputStreamPump.asyncRead(that, null);
|
||||||
|
|
||||||
|
// Grab host/port from SocketTransport.
|
||||||
|
that._host = transport.host;
|
||||||
|
that._port = transport.port;
|
||||||
|
that.useWin = windowObject;
|
||||||
|
|
||||||
|
return that;
|
||||||
|
},
|
||||||
|
|
||||||
|
createAcceptedChild: function ts_createAcceptedChild(socketChild, binaryType, windowObject) {
|
||||||
|
let that = new TCPSocket();
|
||||||
|
|
||||||
|
that._binaryType = binaryType;
|
||||||
|
that._inChild = true;
|
||||||
|
that._readyState = kOPEN;
|
||||||
|
socketChild.setSocketAndWindow(that, windowObject);
|
||||||
|
that._socketBridge = socketChild;
|
||||||
|
that._host = socketChild.host;
|
||||||
|
that._port = socketChild.port;
|
||||||
|
that.useWin = windowObject;
|
||||||
|
|
||||||
|
return that;
|
||||||
|
},
|
||||||
|
|
||||||
setAppId: function ts_setAppId(appId) {
|
setAppId: function ts_setAppId(appId) {
|
||||||
#ifdef MOZ_WIDGET_GONK
|
#ifdef MOZ_WIDGET_GONK
|
||||||
this._appId = appId;
|
this._appId = appId;
|
||||||
@@ -398,68 +511,36 @@ TCPSocket.prototype = {
|
|||||||
|
|
||||||
/* end nsITCPSocketInternal methods */
|
/* end nsITCPSocketInternal methods */
|
||||||
|
|
||||||
init: function(aWindow) {
|
initWindowless: function ts_initWindowless() {
|
||||||
this._inChild = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
try {
|
||||||
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
return Services.prefs.getBoolPref("dom.mozTCPSocket.enabled");
|
||||||
LOG("content process: " + (this._inChild ? "true" : "false"));
|
} catch (e) {
|
||||||
|
// no pref means return false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
init: function ts_init(aWindow) {
|
||||||
|
if (!this.initWindowless())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
let principal = aWindow.document.nodePrincipal;
|
||||||
|
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||||
|
.getService(Ci.nsIScriptSecurityManager);
|
||||||
|
|
||||||
|
let perm = principal == secMan.getSystemPrincipal()
|
||||||
|
? Ci.nsIPermissionManager.ALLOW_ACTION
|
||||||
|
: Services.perms.testExactPermissionFromPrincipal(principal, "tcp-socket");
|
||||||
|
|
||||||
|
this._hasPrivileges = perm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
||||||
|
|
||||||
if (aWindow) {
|
|
||||||
let util = aWindow.QueryInterface(
|
let util = aWindow.QueryInterface(
|
||||||
Ci.nsIInterfaceRequestor
|
Ci.nsIInterfaceRequestor
|
||||||
).getInterface(Ci.nsIDOMWindowUtils);
|
).getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
|
||||||
this.useWin = aWindow;
|
this.useWin = XPCNativeWrapper.unwrap(aWindow);
|
||||||
this.innerWindowID = util.currentInnerWindowID;
|
this.innerWindowID = util.currentInnerWindowID;
|
||||||
LOG("window init: " + this.innerWindowID);
|
LOG("window init: " + this.innerWindowID);
|
||||||
Services.obs.addObserver(this, "inner-window-destroyed", true);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
__init: function(host, port, options) {
|
|
||||||
if (options.doNotConnect) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG("Host info: " + host + ":" + port);
|
|
||||||
this._readyState = kCONNECTING;
|
|
||||||
this._host = host;
|
|
||||||
this._port = port;
|
|
||||||
if (options) {
|
|
||||||
if (options.useSSL) {
|
|
||||||
this._ssl = 'ssl';
|
|
||||||
} else {
|
|
||||||
this._ssl = false;
|
|
||||||
}
|
|
||||||
this._binaryType = options.binaryType || this._binaryType;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG("SSL: " + this.ssl);
|
|
||||||
|
|
||||||
if (this._inChild) {
|
|
||||||
this._socketBridge = Cc["@mozilla.org/tcp-socket-child;1"]
|
|
||||||
.createInstance(Ci.nsITCPSocketChild);
|
|
||||||
this._socketBridge.sendOpen(this, host, port, !!this._ssl,
|
|
||||||
this._binaryType, this.useWin, this.useWin || this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let transport = this._transport = this._createTransport(host, port, this._ssl);
|
|
||||||
transport.setEventSink(this, Services.tm.currentThread);
|
|
||||||
this._initStream(this._binaryType);
|
|
||||||
|
|
||||||
#ifdef MOZ_WIDGET_GONK
|
|
||||||
// Set _activeNetwork, which is only required for network statistics.
|
|
||||||
// Note that nsINetworkManager, as well as nsINetworkStatsServiceProxy, is
|
|
||||||
// Gonk-specific.
|
|
||||||
let networkManager = Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager);
|
|
||||||
if (networkManager) {
|
|
||||||
this._activeNetwork = networkManager.active;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
|
|
||||||
initWithGlobal: function(global) {
|
|
||||||
this.useWin = global;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
observe: function(aSubject, aTopic, aData) {
|
observe: function(aSubject, aTopic, aData) {
|
||||||
@@ -485,33 +566,68 @@ TCPSocket.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initAcceptedParent: function(transport, binaryType, global) {
|
|
||||||
this.useWin = global;
|
|
||||||
this._transport = transport;
|
|
||||||
this._initStream(binaryType);
|
|
||||||
|
|
||||||
// ReadyState is kOpen since accepted transport stream has already been connected
|
|
||||||
this._readyState = kOPEN;
|
|
||||||
this._inputStreamPump = new InputStreamPump(this._socketInputStream, -1, -1, 0, 0, false);
|
|
||||||
this._inputStreamPump.asyncRead(this, null);
|
|
||||||
|
|
||||||
// Grab host/port from SocketTransport.
|
|
||||||
this._host = transport.host;
|
|
||||||
this._port = transport.port;
|
|
||||||
},
|
|
||||||
|
|
||||||
initAcceptedChild: function(socketChild, binaryType, global) {
|
|
||||||
this.useWin = global;
|
|
||||||
this._binaryType = binaryType;
|
|
||||||
this._inChild = true;
|
|
||||||
this._readyState = kOPEN;
|
|
||||||
socketChild.setSocketAndWindow(this.getInternalSocket(), this.useWin);
|
|
||||||
this._socketBridge = socketChild;
|
|
||||||
this._host = socketChild.host;
|
|
||||||
this._port = socketChild.port;
|
|
||||||
},
|
|
||||||
|
|
||||||
// nsIDOMTCPSocket
|
// nsIDOMTCPSocket
|
||||||
|
open: function ts_open(host, port, options) {
|
||||||
|
this._inChild = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
||||||
|
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||||
|
LOG("content process: " + (this._inChild ? "true" : "false"));
|
||||||
|
|
||||||
|
// in the testing case, init won't be called and
|
||||||
|
// hasPrivileges will be null. We want to proceed to test.
|
||||||
|
if (this._hasPrivileges !== true && this._hasPrivileges !== null) {
|
||||||
|
throw new Error("TCPSocket does not have permission in this context.\n");
|
||||||
|
}
|
||||||
|
let that = new TCPSocket();
|
||||||
|
|
||||||
|
that.useWin = this.useWin;
|
||||||
|
that.innerWindowID = this.innerWindowID;
|
||||||
|
that._inChild = this._inChild;
|
||||||
|
|
||||||
|
LOG("window init: " + that.innerWindowID);
|
||||||
|
Services.obs.addObserver(that, "inner-window-destroyed", true);
|
||||||
|
|
||||||
|
LOG("startup called");
|
||||||
|
LOG("Host info: " + host + ":" + port);
|
||||||
|
|
||||||
|
that._readyState = kCONNECTING;
|
||||||
|
that._host = host;
|
||||||
|
that._port = port;
|
||||||
|
if (options !== undefined) {
|
||||||
|
if (options.useSecureTransport) {
|
||||||
|
that._ssl = 'ssl';
|
||||||
|
} else {
|
||||||
|
that._ssl = false;
|
||||||
|
}
|
||||||
|
that._binaryType = options.binaryType || that._binaryType;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG("SSL: " + that.ssl);
|
||||||
|
|
||||||
|
if (this._inChild) {
|
||||||
|
that._socketBridge = Cc["@mozilla.org/tcp-socket-child;1"]
|
||||||
|
.createInstance(Ci.nsITCPSocketChild);
|
||||||
|
that._socketBridge.sendOpen(that, host, port, !!that._ssl,
|
||||||
|
that._binaryType, this.useWin, this.useWin || this);
|
||||||
|
return that;
|
||||||
|
}
|
||||||
|
|
||||||
|
let transport = that._transport = this._createTransport(host, port, that._ssl);
|
||||||
|
transport.setEventSink(that, Services.tm.currentThread);
|
||||||
|
that._initStream(that._binaryType);
|
||||||
|
|
||||||
|
#ifdef MOZ_WIDGET_GONK
|
||||||
|
// Set _activeNetwork, which is only required for network statistics.
|
||||||
|
// Note that nsINetworkManager, as well as nsINetworkStatsServiceProxy, is
|
||||||
|
// Gonk-specific.
|
||||||
|
let networkManager = Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager);
|
||||||
|
if (networkManager) {
|
||||||
|
that._activeNetwork = networkManager.active;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return that;
|
||||||
|
},
|
||||||
|
|
||||||
upgradeToSecure: function ts_upgradeToSecure() {
|
upgradeToSecure: function ts_upgradeToSecure() {
|
||||||
if (this._readyState !== kOPEN) {
|
if (this._readyState !== kOPEN) {
|
||||||
throw new Error("Socket not open.");
|
throw new Error("Socket not open.");
|
||||||
@@ -535,6 +651,20 @@ TCPSocket.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
listen: function ts_listen(localPort, options, backlog) {
|
||||||
|
// in the testing case, init won't be called and
|
||||||
|
// hasPrivileges will be null. We want to proceed to test.
|
||||||
|
if (this._hasPrivileges !== true && this._hasPrivileges !== null) {
|
||||||
|
throw new Error("TCPSocket does not have permission in this context.\n");
|
||||||
|
}
|
||||||
|
let that = new TCPServerSocket(this.useWin);
|
||||||
|
|
||||||
|
options = options || { binaryType : this.binaryType };
|
||||||
|
backlog = backlog || -1;
|
||||||
|
that.listen(localPort, options, backlog);
|
||||||
|
return that;
|
||||||
|
},
|
||||||
|
|
||||||
close: function ts_close() {
|
close: function ts_close() {
|
||||||
if (this._readyState === kCLOSED || this._readyState === kCLOSING)
|
if (this._readyState === kCLOSED || this._readyState === kCLOSING)
|
||||||
return;
|
return;
|
||||||
@@ -560,15 +690,14 @@ TCPSocket.prototype = {
|
|||||||
|
|
||||||
if (this._binaryType === "arraybuffer") {
|
if (this._binaryType === "arraybuffer") {
|
||||||
byteLength = byteLength || data.byteLength;
|
byteLength = byteLength || data.byteLength;
|
||||||
} else {
|
|
||||||
byteLength = data.length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._inChild) {
|
if (this._inChild) {
|
||||||
this._socketBridge.sendSend(data, byteOffset, byteLength, ++this._trackingNumber);
|
this._socketBridge.sendSend(data, byteOffset, byteLength, ++this._trackingNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
let newBufferedAmount = this.bufferedAmount + byteLength;
|
let length = this._binaryType === "arraybuffer" ? byteLength : data.length;
|
||||||
|
let newBufferedAmount = this.bufferedAmount + length;
|
||||||
let bufferFull = newBufferedAmount >= BUFFER_SIZE;
|
let bufferFull = newBufferedAmount >= BUFFER_SIZE;
|
||||||
|
|
||||||
if (bufferFull) {
|
if (bufferFull) {
|
||||||
@@ -593,7 +722,7 @@ TCPSocket.prototype = {
|
|||||||
new_stream.setData(data, byteOffset, byteLength);
|
new_stream.setData(data, byteOffset, byteLength);
|
||||||
} else {
|
} else {
|
||||||
new_stream = new StringInputStream();
|
new_stream = new StringInputStream();
|
||||||
new_stream.setData(data, byteLength);
|
new_stream.setData(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._waitingForStartTLS) {
|
if (this._waitingForStartTLS) {
|
||||||
@@ -836,7 +965,7 @@ TCPSocket.prototype = {
|
|||||||
// nsIStreamListener (Triggered by _inputStreamPump.asyncRead)
|
// nsIStreamListener (Triggered by _inputStreamPump.asyncRead)
|
||||||
onDataAvailable: function ts_onDataAvailable(request, context, inputStream, offset, count) {
|
onDataAvailable: function ts_onDataAvailable(request, context, inputStream, offset, count) {
|
||||||
if (this._binaryType === "arraybuffer") {
|
if (this._binaryType === "arraybuffer") {
|
||||||
let buffer = new (this.useWin.ArrayBuffer)(count);
|
let buffer = new (this.useWin ? this.useWin.ArrayBuffer : ArrayBuffer)(count);
|
||||||
this._inputStreamBinary.readArrayBuffer(count, buffer);
|
this._inputStreamBinary.readArrayBuffer(count, buffer);
|
||||||
this.callListener("data", buffer);
|
this.callListener("data", buffer);
|
||||||
} else {
|
} else {
|
||||||
@@ -850,19 +979,25 @@ TCPSocket.prototype = {
|
|||||||
#endif
|
#endif
|
||||||
},
|
},
|
||||||
|
|
||||||
getInternalSocket: function() {
|
|
||||||
return this.QueryInterface(Ci.nsITCPSocketInternal);
|
|
||||||
},
|
|
||||||
|
|
||||||
classID: Components.ID("{cda91b22-6472-11e1-aa11-834fec09cd0a}"),
|
classID: Components.ID("{cda91b22-6472-11e1-aa11-834fec09cd0a}"),
|
||||||
|
|
||||||
|
classInfo: XPCOMUtils.generateCI({
|
||||||
|
classID: Components.ID("{cda91b22-6472-11e1-aa11-834fec09cd0a}"),
|
||||||
contractID: "@mozilla.org/tcp-socket;1",
|
contractID: "@mozilla.org/tcp-socket;1",
|
||||||
|
classDescription: "Client TCP Socket",
|
||||||
|
interfaces: [
|
||||||
|
Ci.nsIDOMTCPSocket,
|
||||||
|
],
|
||||||
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
||||||
|
}),
|
||||||
|
|
||||||
QueryInterface: XPCOMUtils.generateQI([
|
QueryInterface: XPCOMUtils.generateQI([
|
||||||
|
Ci.nsIDOMTCPSocket,
|
||||||
Ci.nsITCPSocketInternal,
|
Ci.nsITCPSocketInternal,
|
||||||
Ci.nsIDOMGlobalPropertyInitializer,
|
Ci.nsIDOMGlobalPropertyInitializer,
|
||||||
Ci.nsIObserver,
|
Ci.nsIObserver,
|
||||||
Ci.nsISupportsWeakReference
|
Ci.nsISupportsWeakReference
|
||||||
])
|
])
|
||||||
};
|
}
|
||||||
|
|
||||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TCPSocket]);
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TCPSocket]);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# TCPSocket.js
|
# TCPSocket.js
|
||||||
component {cda91b22-6472-11e1-aa11-834fec09cd0a} TCPSocket.js
|
component {cda91b22-6472-11e1-aa11-834fec09cd0a} TCPSocket.js
|
||||||
contract @mozilla.org/tcp-socket;1 {cda91b22-6472-11e1-aa11-834fec09cd0a}
|
contract @mozilla.org/tcp-socket;1 {cda91b22-6472-11e1-aa11-834fec09cd0a}
|
||||||
|
category JavaScript-navigator-property mozTCPSocket @mozilla.org/tcp-socket;1
|
||||||
|
|
||||||
# TCPSocketParentIntermediary.js
|
# TCPSocketParentIntermediary.js
|
||||||
component {afa42841-a6cb-4a91-912f-93099f6a3d18} TCPSocketParentIntermediary.js
|
component {afa42841-a6cb-4a91-912f-93099f6a3d18} TCPSocketParentIntermediary.js
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "mozilla/net/NeckoChild.h"
|
#include "mozilla/net/NeckoChild.h"
|
||||||
#include "mozilla/dom/PBrowserChild.h"
|
#include "mozilla/dom/PBrowserChild.h"
|
||||||
#include "mozilla/dom/TabChild.h"
|
#include "mozilla/dom/TabChild.h"
|
||||||
#include "nsITCPSocketInternal.h"
|
#include "nsIDOMTCPSocket.h"
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "nsITCPSocketInternal.h"
|
#include "nsIDOMTCPSocket.h"
|
||||||
#include "mozilla/unused.h"
|
#include "mozilla/unused.h"
|
||||||
#include "mozilla/AppProcessChecker.h"
|
#include "mozilla/AppProcessChecker.h"
|
||||||
#include "mozilla/net/NeckoCommon.h"
|
#include "mozilla/net/NeckoCommon.h"
|
||||||
@@ -350,11 +350,12 @@ TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
TCPSocketParent::SetSocketAndIntermediary(nsITCPSocketInternal *aSocket,
|
TCPSocketParent::SetSocketAndIntermediary(nsIDOMTCPSocket *socket,
|
||||||
nsITCPSocketIntermediary *aIntermediary)
|
nsITCPSocketIntermediary *intermediary,
|
||||||
|
JSContext* cx)
|
||||||
{
|
{
|
||||||
mSocket = aSocket;
|
mSocket = socket;
|
||||||
mIntermediary = aIntermediary;
|
mIntermediary = intermediary;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,13 @@
|
|||||||
#include "nsITCPSocketParent.h"
|
#include "nsITCPSocketParent.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIDOMTCPSocket.h"
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
#include "mozilla/net/OfflineObserver.h"
|
#include "mozilla/net/OfflineObserver.h"
|
||||||
|
|
||||||
#define TCPSOCKETPARENT_CID \
|
#define TCPSOCKETPARENT_CID \
|
||||||
{ 0x4e7246c6, 0xa8b3, 0x426d, { 0x9c, 0x17, 0x76, 0xda, 0xb1, 0xe1, 0xe1, 0x4a } }
|
{ 0x4e7246c6, 0xa8b3, 0x426d, { 0x9c, 0x17, 0x76, 0xda, 0xb1, 0xe1, 0xe1, 0x4a } }
|
||||||
|
|
||||||
class nsITCPSocketInternal;
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ protected:
|
|||||||
|
|
||||||
JS::Heap<JSObject*> mIntermediaryObj;
|
JS::Heap<JSObject*> mIntermediaryObj;
|
||||||
nsCOMPtr<nsITCPSocketIntermediary> mIntermediary;
|
nsCOMPtr<nsITCPSocketIntermediary> mIntermediary;
|
||||||
nsCOMPtr<nsITCPSocketInternal> mSocket;
|
nsCOMPtr<nsIDOMTCPSocket> mSocket;
|
||||||
nsRefPtr<mozilla::net::OfflineObserver> mObserver;
|
nsRefPtr<mozilla::net::OfflineObserver> mObserver;
|
||||||
bool mIPCOpen;
|
bool mIPCOpen;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ const Ci = Components.interfaces;
|
|||||||
const Cu = Components.utils;
|
const Cu = Components.utils;
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
|
||||||
|
|
||||||
let global = this;
|
|
||||||
|
|
||||||
function TCPSocketParentIntermediary() {
|
function TCPSocketParentIntermediary() {
|
||||||
}
|
}
|
||||||
@@ -19,7 +16,7 @@ function TCPSocketParentIntermediary() {
|
|||||||
TCPSocketParentIntermediary.prototype = {
|
TCPSocketParentIntermediary.prototype = {
|
||||||
_setCallbacks: function(aParentSide, socket) {
|
_setCallbacks: function(aParentSide, socket) {
|
||||||
aParentSide.initJS(this);
|
aParentSide.initJS(this);
|
||||||
this._socket = socket.getInternalSocket();
|
this._socket = socket;
|
||||||
|
|
||||||
// Create handlers for every possible callback that attempt to trigger
|
// Create handlers for every possible callback that attempt to trigger
|
||||||
// corresponding callbacks on the child object.
|
// corresponding callbacks on the child object.
|
||||||
@@ -41,10 +38,12 @@ TCPSocketParentIntermediary.prototype = {
|
|||||||
|
|
||||||
open: function(aParentSide, aHost, aPort, aUseSSL, aBinaryType,
|
open: function(aParentSide, aHost, aPort, aUseSSL, aBinaryType,
|
||||||
aAppId, aInBrowser) {
|
aAppId, aInBrowser) {
|
||||||
let socket = new global.mozTCPSocket(aHost, aPort, {useSecureTransport: aUseSSL, binaryType: aBinaryType});
|
let baseSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
|
||||||
|
let socket = baseSocket.open(aHost, aPort, {useSecureTransport: aUseSSL, binaryType: aBinaryType});
|
||||||
|
if (!socket)
|
||||||
|
return null;
|
||||||
|
|
||||||
let socketInternal = socket.getInternalSocket();
|
let socketInternal = socket.QueryInterface(Ci.nsITCPSocketInternal);
|
||||||
socketInternal.initWithGlobal(global);
|
|
||||||
socketInternal.setAppId(aAppId);
|
socketInternal.setAppId(aAppId);
|
||||||
socketInternal.setInBrowser(aInBrowser);
|
socketInternal.setInBrowser(aInBrowser);
|
||||||
|
|
||||||
@@ -54,23 +53,24 @@ TCPSocketParentIntermediary.prototype = {
|
|||||||
|
|
||||||
// Handlers are set to the JS-implemented socket object on the parent side.
|
// Handlers are set to the JS-implemented socket object on the parent side.
|
||||||
this._setCallbacks(aParentSide, socket);
|
this._setCallbacks(aParentSide, socket);
|
||||||
return socketInternal;
|
return socket;
|
||||||
},
|
},
|
||||||
|
|
||||||
listen: function(aTCPServerSocketParent, aLocalPort, aBacklog, aBinaryType,
|
listen: function(aTCPServerSocketParent, aLocalPort, aBacklog, aBinaryType,
|
||||||
aAppId, aInBrowser) {
|
aAppId, aInBrowser) {
|
||||||
let serverSocket = new global.mozTCPServerSocket(aLocalPort, { binaryType: aBinaryType }, aBacklog);
|
let baseSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
|
||||||
let serverSocketInternal = serverSocket.getInternalSocket();
|
let serverSocket = baseSocket.listen(aLocalPort, { binaryType: aBinaryType }, aBacklog);
|
||||||
serverSocketInternal.initWithGlobal(global);
|
if (!serverSocket)
|
||||||
|
return null;
|
||||||
|
|
||||||
let localPort = serverSocket.localPort;
|
let localPort = serverSocket.localPort;
|
||||||
|
|
||||||
serverSocket["onconnect"] = function(event) {
|
serverSocket["onconnect"] = function(socket) {
|
||||||
var socketParent = Cc["@mozilla.org/tcp-socket-parent;1"]
|
var socketParent = Cc["@mozilla.org/tcp-socket-parent;1"]
|
||||||
.createInstance(Ci.nsITCPSocketParent);
|
.createInstance(Ci.nsITCPSocketParent);
|
||||||
var intermediary = new TCPSocketParentIntermediary();
|
var intermediary = new TCPSocketParentIntermediary();
|
||||||
|
|
||||||
let socketInternal = event.socket.getInternalSocket();
|
let socketInternal = socket.QueryInterface(Ci.nsITCPSocketInternal);
|
||||||
socketInternal.setAppId(aAppId);
|
socketInternal.setAppId(aAppId);
|
||||||
socketInternal.setInBrowser(aInBrowser);
|
socketInternal.setInBrowser(aInBrowser);
|
||||||
socketInternal.setOnUpdateBufferedAmountHandler(
|
socketInternal.setOnUpdateBufferedAmountHandler(
|
||||||
@@ -79,11 +79,11 @@ TCPSocketParentIntermediary.prototype = {
|
|||||||
// Handlers are set to the JS-implemented socket object on the parent side,
|
// Handlers are set to the JS-implemented socket object on the parent side,
|
||||||
// so that the socket parent object can communicate data
|
// so that the socket parent object can communicate data
|
||||||
// with the corresponding socket child object through IPC.
|
// with the corresponding socket child object through IPC.
|
||||||
intermediary._setCallbacks(socketParent, event.socket);
|
intermediary._setCallbacks(socketParent, socket);
|
||||||
// The members in the socket parent object are set with arguments,
|
// The members in the socket parent object are set with arguments,
|
||||||
// so that the socket parent object can communicate data
|
// so that the socket parent object can communicate data
|
||||||
// with the JS socket object on the parent side via the intermediary object.
|
// with the JS socket object on the parent side via the intermediary object.
|
||||||
socketParent.setSocketAndIntermediary(socketInternal, intermediary);
|
socketParent.setSocketAndIntermediary(socket, intermediary);
|
||||||
aTCPServerSocketParent.sendCallbackAccept(socketParent);
|
aTCPServerSocketParent.sendCallbackAccept(socketParent);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ TCPSocketParentIntermediary.prototype = {
|
|||||||
error.lineNumber, error.columnNumber);
|
error.lineNumber, error.columnNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
return serverSocketInternal;
|
return serverSocket;
|
||||||
},
|
},
|
||||||
|
|
||||||
onRecvSendString: function(aData, aTrackingNumber) {
|
onRecvSendString: function(aData, aTrackingNumber) {
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/* 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 "TCPSocketUtils.h"
|
|
||||||
#include "mozilla/dom/BindingUtils.h"
|
|
||||||
#include "mozilla/Preferences.h"
|
|
||||||
#include "nsGlobalWindow.h"
|
|
||||||
|
|
||||||
namespace TCPSocketUtils {
|
|
||||||
|
|
||||||
using mozilla::Preferences;
|
|
||||||
using mozilla::dom::CheckPermissions;
|
|
||||||
|
|
||||||
bool
|
|
||||||
SocketEnabled(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
|
|
||||||
{
|
|
||||||
if (!Preferences::GetBool("dom.mozTCPSocket.enabled")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsPIDOMWindow* window = xpc::WindowGlobalOrNull(aGlobal);
|
|
||||||
if (!window) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* permissions[] = {"tcp-socket", nullptr};
|
|
||||||
return CheckPermissions(aCx, aGlobal, permissions);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
/* 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/. */
|
|
||||||
|
|
||||||
#ifndef TCPSocketUtils_h
|
|
||||||
#define TCPSocketUtils_h
|
|
||||||
|
|
||||||
#include "js/RootingAPI.h"
|
|
||||||
|
|
||||||
namespace TCPSocketUtils {
|
|
||||||
|
|
||||||
extern bool
|
|
||||||
SocketEnabled(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TCPSocketUtils_h
|
|
||||||
@@ -5,12 +5,12 @@
|
|||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
XPIDL_SOURCES += [
|
XPIDL_SOURCES += [
|
||||||
|
'nsIDOMTCPServerSocket.idl',
|
||||||
|
'nsIDOMTCPSocket.idl',
|
||||||
'nsIMozNavigatorNetwork.idl',
|
'nsIMozNavigatorNetwork.idl',
|
||||||
'nsITCPServerSocketChild.idl',
|
'nsITCPServerSocketChild.idl',
|
||||||
'nsITCPServerSocketInternal.idl',
|
|
||||||
'nsITCPServerSocketParent.idl',
|
'nsITCPServerSocketParent.idl',
|
||||||
'nsITCPSocketChild.idl',
|
'nsITCPSocketChild.idl',
|
||||||
'nsITCPSocketInternal.idl',
|
|
||||||
'nsITCPSocketParent.idl',
|
'nsITCPSocketParent.idl',
|
||||||
'nsIUDPSocketChild.idl',
|
'nsIUDPSocketChild.idl',
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -3,8 +3,41 @@
|
|||||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "domstubs.idl"
|
#include "domstubs.idl"
|
||||||
|
#include "nsITCPSocketChild.idl"
|
||||||
|
|
||||||
interface nsITCPSocketChild;
|
// Bug 797561 - Expose a server tcp socket API to web applications
|
||||||
|
/**
|
||||||
|
* nsIDOMTCPServerSocket
|
||||||
|
*
|
||||||
|
* An interface to a server socket that can accept incoming connections for gaia apps.
|
||||||
|
*/
|
||||||
|
[scriptable, uuid(821638a1-5327-416d-8031-668764f2ec04)]
|
||||||
|
interface nsIDOMTCPServerSocket : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The port of this server socket object.
|
||||||
|
*/
|
||||||
|
readonly attribute unsigned short localPort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onconnect event handler is called when a client connection is accepted.
|
||||||
|
* The data attribute of the event passed to the onconnect handler will be a TCPSocket
|
||||||
|
* instance, which is used for communication between client and server.
|
||||||
|
*/
|
||||||
|
attribute jsval onconnect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onerror handler will be called when the listen of a server socket is aborted.
|
||||||
|
* The data attribute of the event passed to the onerror handler will have a
|
||||||
|
* description of the kind of error.
|
||||||
|
*/
|
||||||
|
attribute jsval onerror;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the server socket.
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal interfaces for use in cross-process server-socket implementation.
|
* Internal interfaces for use in cross-process server-socket implementation.
|
||||||
@@ -15,13 +48,16 @@ interface nsITCPSocketChild;
|
|||||||
* on the parent and child side for an IPC protocol implementation.
|
* on the parent and child side for an IPC protocol implementation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[scriptable, uuid(03520F9E-7989-4604-870A-A67DFFD846DC)]
|
[scriptable, uuid(b64b1e68-4efa-497c-b0d8-69f067ad5ec8)]
|
||||||
interface nsITCPServerSocketInternal : nsISupports
|
interface nsITCPServerSocketInternal : nsISupports
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Close the server socket.
|
* Initialization after creating a TCP server socket object.
|
||||||
|
*
|
||||||
|
* @param windowVal
|
||||||
|
* An object to create ArrayBuffer for this window. See Bug 831107.
|
||||||
*/
|
*/
|
||||||
void close();
|
void init(in jsval windowVal);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen on a port
|
* Listen on a port
|
||||||
@@ -53,9 +89,4 @@ interface nsITCPServerSocketInternal : nsISupports
|
|||||||
*/
|
*/
|
||||||
void callListenerError(in DOMString message, in DOMString filename,
|
void callListenerError(in DOMString message, in DOMString filename,
|
||||||
in uint32_t lineNumber, in uint32_t columnNumber);
|
in uint32_t lineNumber, in uint32_t columnNumber);
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the parent process when there is no DOM window available.
|
|
||||||
*/
|
|
||||||
void initWithGlobal(in nsISupports global);
|
|
||||||
};
|
};
|
||||||
333
dom/network/interfaces/nsIDOMTCPSocket.idl
Normal file
333
dom/network/interfaces/nsIDOMTCPSocket.idl
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MozTCPSocket exposes a TCP client and server sockets
|
||||||
|
* to highly privileged apps. It provides a buffered, non-blocking
|
||||||
|
* interface for sending. For receiving, it uses an asynchronous,
|
||||||
|
* event handler based interface.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "domstubs.idl"
|
||||||
|
#include "nsIDOMEvent.idl"
|
||||||
|
#include "nsITCPSocketChild.idl"
|
||||||
|
#include "nsIDOMTCPServerSocket.idl"
|
||||||
|
|
||||||
|
interface nsISocketTransport;
|
||||||
|
|
||||||
|
// Bug 731746 - Allow chrome JS object to implement nsIDOMEventTarget
|
||||||
|
// nsITCPSocket should be an nsIEventTarget but js objects
|
||||||
|
// cannot be an nsIEventTarget yet
|
||||||
|
// #include "nsIEventTarget.idl"
|
||||||
|
|
||||||
|
// Bug 723206 - Constructors implemented in JS from IDL should be
|
||||||
|
// allowed to have arguments
|
||||||
|
//
|
||||||
|
// Once bug 723206 will be fixed, this method could be replaced by
|
||||||
|
// arguments when instantiating a TCPSocket object. For example it will
|
||||||
|
// be possible to do (similarly to the WebSocket API):
|
||||||
|
// var s = new MozTCPSocket(host, port);
|
||||||
|
|
||||||
|
// Bug 797561 - Expose a server tcp socket API to web applications
|
||||||
|
|
||||||
|
|
||||||
|
[scriptable, uuid(65f6d2c8-4be6-4695-958d-0735e8935289)]
|
||||||
|
interface nsIDOMTCPSocket : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create and return a socket object which will attempt to connect to
|
||||||
|
* the given host and port.
|
||||||
|
*
|
||||||
|
* @param host The hostname of the server to connect to.
|
||||||
|
* @param port The port to connect to.
|
||||||
|
* @param options An object specifying one or more parameters which
|
||||||
|
* determine the details of the socket.
|
||||||
|
*
|
||||||
|
* useSecureTransport: true to create an SSL socket. Defaults to false.
|
||||||
|
*
|
||||||
|
* binaryType: "arraybuffer" to use ArrayBuffer
|
||||||
|
* instances in the ondata callback and as the argument
|
||||||
|
* to send. Defaults to "string", to use JavaScript strings.
|
||||||
|
*
|
||||||
|
* @return The new TCPSocket instance.
|
||||||
|
*/
|
||||||
|
nsIDOMTCPSocket open(in DOMString host, in unsigned short port, [optional] in jsval options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen on a port
|
||||||
|
*
|
||||||
|
* @param localPort The port of the server socket. Pass -1 to indicate no preference,
|
||||||
|
* and a port will be selected automatically.
|
||||||
|
* @param options An object specifying one or more parameters which
|
||||||
|
* determine the details of the socket.
|
||||||
|
*
|
||||||
|
* binaryType: "arraybuffer" to use ArrayBuffer
|
||||||
|
* instances in the ondata callback and as the argument
|
||||||
|
* to send. Defaults to "string", to use JavaScript strings.
|
||||||
|
* @param backlog The maximum length the queue of pending connections may grow to.
|
||||||
|
* This parameter may be silently limited by the operating system.
|
||||||
|
* Pass -1 to use the default value.
|
||||||
|
*
|
||||||
|
* @return The new TCPServerSocket instance.
|
||||||
|
*/
|
||||||
|
nsIDOMTCPServerSocket listen(in unsigned short localPort, [optional] in jsval options,
|
||||||
|
[optional] in unsigned short backlog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable secure on channel.
|
||||||
|
*/
|
||||||
|
void upgradeToSecure();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The host of this socket object.
|
||||||
|
*/
|
||||||
|
readonly attribute DOMString host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The port of this socket object.
|
||||||
|
*/
|
||||||
|
readonly attribute unsigned short port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if this socket object is an SSL socket.
|
||||||
|
*/
|
||||||
|
readonly attribute boolean ssl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of bytes which have previously been buffered by calls to
|
||||||
|
* send on this socket.
|
||||||
|
*/
|
||||||
|
readonly attribute unsigned long bufferedAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause reading incoming data and invocations of the ondata handler until
|
||||||
|
* resume is called.
|
||||||
|
*/
|
||||||
|
void suspend();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resume reading incoming data and invoking ondata as usual.
|
||||||
|
*/
|
||||||
|
void resume();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the socket.
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write data to the socket.
|
||||||
|
*
|
||||||
|
* @param data The data to write to the socket. If
|
||||||
|
* binaryType: "arraybuffer" was passed in the options
|
||||||
|
* object, then this object should be an ArrayBuffer instance.
|
||||||
|
* If binaryType: "string" was passed, or if no binaryType
|
||||||
|
* option was specified, then this object should be an
|
||||||
|
* ordinary JavaScript string.
|
||||||
|
* @param byteOffset The offset within the data from which to begin writing.
|
||||||
|
* Has no effect on non-ArrayBuffer data.
|
||||||
|
* @param byteLength The number of bytes to write. Has no effect on
|
||||||
|
* non-ArrayBuffer data.
|
||||||
|
*
|
||||||
|
* @return Send returns true or false as a hint to the caller that
|
||||||
|
* they may either continue sending more data immediately, or
|
||||||
|
* may want to wait until the other side has read some of the
|
||||||
|
* data which has already been written to the socket before
|
||||||
|
* buffering more. If send returns true, then less than 64k
|
||||||
|
* has been buffered and it's safe to immediately write more.
|
||||||
|
* If send returns false, then more than 64k has been buffered,
|
||||||
|
* and the caller may wish to wait until the ondrain event
|
||||||
|
* handler has been called before buffering more data by more
|
||||||
|
* calls to send.
|
||||||
|
*/
|
||||||
|
boolean send(in jsval data, [optional] in unsigned long byteOffset, [optional] in unsigned long byteLength);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The readyState attribute indicates which state the socket is currently
|
||||||
|
* in. The state will be either "connecting", "open", "closing", or "closed".
|
||||||
|
*/
|
||||||
|
readonly attribute DOMString readyState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The binaryType attribute indicates which mode this socket uses for
|
||||||
|
* sending and receiving data. If the binaryType: "arraybuffer" option
|
||||||
|
* was passed to the open method that created this socket, binaryType
|
||||||
|
* will be "arraybuffer". Otherwise, it will be "string".
|
||||||
|
*/
|
||||||
|
readonly attribute DOMString binaryType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onopen event handler is called when the connection to the server
|
||||||
|
* has been established. If the connection is refused, onerror will be
|
||||||
|
* called, instead.
|
||||||
|
*/
|
||||||
|
attribute jsval onopen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After send has buffered more than 64k of data, it returns false to
|
||||||
|
* indicate that the client should pause before sending more data, to
|
||||||
|
* avoid accumulating large buffers. This is only advisory, and the client
|
||||||
|
* is free to ignore it and buffer as much data as desired, but if reducing
|
||||||
|
* the size of buffers is important (especially for a streaming application)
|
||||||
|
* ondrain will be called once the previously-buffered data has been written
|
||||||
|
* to the network, at which point the client can resume calling send again.
|
||||||
|
*/
|
||||||
|
attribute jsval ondrain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ondata handler will be called repeatedly and asynchronously after
|
||||||
|
* onopen has been called, every time some data was available from the server
|
||||||
|
* and was read. If binaryType: "arraybuffer" was passed to open, the data
|
||||||
|
* attribute of the event object will be an ArrayBuffer. If not, it will be a
|
||||||
|
* normal JavaScript string.
|
||||||
|
*
|
||||||
|
* At any time, the client may choose to pause reading and receiving ondata
|
||||||
|
* callbacks, by calling the socket's suspend() method. Further invocations
|
||||||
|
* of ondata will be paused until resume() is called.
|
||||||
|
*/
|
||||||
|
attribute jsval ondata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onerror handler will be called when there is an error. The data
|
||||||
|
* attribute of the event passed to the onerror handler will have a
|
||||||
|
* description of the kind of error.
|
||||||
|
*
|
||||||
|
* If onerror is called before onopen, the error was connection refused,
|
||||||
|
* and onclose will not be called. If onerror is called after onopen,
|
||||||
|
* the connection was lost, and onclose will be called after onerror.
|
||||||
|
*/
|
||||||
|
attribute jsval onerror;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onclose handler is called once the underlying network socket
|
||||||
|
* has been closed, either by the server, or by the client calling
|
||||||
|
* close.
|
||||||
|
*
|
||||||
|
* If onerror was not called before onclose, then either side cleanly
|
||||||
|
* closed the connection.
|
||||||
|
*/
|
||||||
|
attribute jsval onclose;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This interface is implemented in TCPSocket.js as an internal interfaces
|
||||||
|
* for use in cross-process socket implementation.
|
||||||
|
* Needed to account for multiple possible types that can be provided to
|
||||||
|
* the socket callbacks as arguments.
|
||||||
|
*/
|
||||||
|
[scriptable, uuid(ac2c4b69-cb79-4767-b1ce-bcf62945cd39)]
|
||||||
|
interface nsITCPSocketInternal : nsISupports {
|
||||||
|
// Trigger the callback for |type| and provide a DOMError() object with the given data
|
||||||
|
void callListenerError(in DOMString type, in DOMString name);
|
||||||
|
|
||||||
|
// Trigger the callback for |type| and provide a string argument
|
||||||
|
void callListenerData(in DOMString type, in DOMString data);
|
||||||
|
|
||||||
|
// Trigger the callback for |type| and provide an ArrayBuffer argument
|
||||||
|
void callListenerArrayBuffer(in DOMString type, in jsval data);
|
||||||
|
|
||||||
|
// Trigger the callback for |type| with no argument
|
||||||
|
void callListenerVoid(in DOMString type);
|
||||||
|
|
||||||
|
// Update the DOM object's readyState.
|
||||||
|
// @param readyState
|
||||||
|
// new ready state to be set to TCPSocket.
|
||||||
|
void updateReadyState(in DOMString readyState);
|
||||||
|
|
||||||
|
// Update the DOM object's bufferedAmount value with a tracking number to
|
||||||
|
// ensure the update request is sent after child's send() invocation.
|
||||||
|
// @param bufferedAmount
|
||||||
|
// TCPSocket parent's bufferedAmount.
|
||||||
|
// @param trackingNumber
|
||||||
|
// A number to ensure the bufferedAmount is updated after data
|
||||||
|
// from child are sent to parent.
|
||||||
|
void updateBufferedAmount(in uint32_t bufferedAmount,
|
||||||
|
in uint32_t trackingNumber);
|
||||||
|
|
||||||
|
// Create a socket object on the parent side.
|
||||||
|
// This is called in accepting any open request on the parent side.
|
||||||
|
//
|
||||||
|
// @param transport
|
||||||
|
// The accepted socket transport.
|
||||||
|
// @param binaryType
|
||||||
|
// "arraybuffer" to use ArrayBuffer instances
|
||||||
|
// in the ondata callback and as the argument to send.
|
||||||
|
// @param window
|
||||||
|
// An object to create ArrayBuffer for this window. See Bug 831107.
|
||||||
|
nsIDOMTCPSocket createAcceptedParent(in nsISocketTransport transport,
|
||||||
|
in DOMString binaryType,
|
||||||
|
in nsIDOMWindow window);
|
||||||
|
|
||||||
|
// Create a DOM socket on the child side
|
||||||
|
// This is called when the socket is accepted on the parent side.
|
||||||
|
//
|
||||||
|
// @param socketChild
|
||||||
|
// The socket child object for the IPC implementation.
|
||||||
|
// @param binaryType
|
||||||
|
// "arraybuffer" to use ArrayBuffer instances
|
||||||
|
// in the ondata callback and as the argument to send.
|
||||||
|
// @param window
|
||||||
|
// An object to create ArrayBuffer for this window. See Bug 831107.
|
||||||
|
nsIDOMTCPSocket createAcceptedChild(in nsITCPSocketChild socketChild,
|
||||||
|
in DOMString binaryType,
|
||||||
|
in nsIDOMWindow window);
|
||||||
|
|
||||||
|
// Set App ID.
|
||||||
|
void setAppId(in unsigned long appId);
|
||||||
|
|
||||||
|
// Set inBrowser.
|
||||||
|
void setInBrowser(in boolean inBrowser);
|
||||||
|
|
||||||
|
// Set a callback that handles the request from a TCP socket parent when that
|
||||||
|
// socket parent wants to notify that its bufferedAmount is updated.
|
||||||
|
void setOnUpdateBufferedAmountHandler(in jsval handler);
|
||||||
|
|
||||||
|
// Providing child process with ability to pass more arguments to parent's
|
||||||
|
// send() function.
|
||||||
|
// @param trackingNumber
|
||||||
|
// To ensure the request to update bufferedAmount in child is after
|
||||||
|
// lastest send() invocation from child.
|
||||||
|
void onRecvSendFromChild(in jsval data, in unsigned long byteOffset,
|
||||||
|
in unsigned long byteLength, in unsigned long trackingNumber);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nsITCPSocketEvent is the event object which is passed as the
|
||||||
|
* first argument to all the event handler callbacks. It contains
|
||||||
|
* the socket that was associated with the event, the type of event,
|
||||||
|
* and the data associated with the event (if any).
|
||||||
|
*/
|
||||||
|
|
||||||
|
[scriptable, uuid(0f2abcca-b483-4539-a3e8-345707f75c44)]
|
||||||
|
interface nsITCPSocketEvent : nsISupports {
|
||||||
|
/**
|
||||||
|
* The socket object which produced this event.
|
||||||
|
*/
|
||||||
|
readonly attribute nsIDOMTCPSocket target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of this event. One of:
|
||||||
|
*
|
||||||
|
* open
|
||||||
|
* error
|
||||||
|
* data
|
||||||
|
* drain
|
||||||
|
* close
|
||||||
|
*/
|
||||||
|
readonly attribute DOMString type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The data related to this event, if any. In the ondata callback,
|
||||||
|
* data will be the bytes read from the network; if the binaryType
|
||||||
|
* of the socket was "arraybuffer", this value will be of type ArrayBuffer;
|
||||||
|
* otherwise, it will be a normal JavaScript string.
|
||||||
|
*
|
||||||
|
* In the onerror callback, data will be a string with a description
|
||||||
|
* of the error.
|
||||||
|
*
|
||||||
|
* In the other callbacks, data will be an empty string.
|
||||||
|
*/
|
||||||
|
readonly attribute jsval data;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "domstubs.idl"
|
#include "domstubs.idl"
|
||||||
|
#include "nsIDOMTCPServerSocket.idl"
|
||||||
|
|
||||||
interface nsITCPServerSocketInternal;
|
interface nsITCPServerSocketInternal;
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "domstubs.idl"
|
#include "domstubs.idl"
|
||||||
|
#include "nsITCPSocketParent.idl"
|
||||||
|
|
||||||
interface nsITCPSocketParent;
|
interface nsIDOMTCPServerSocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface required to allow the TCP server-socket object in the parent process
|
* Interface required to allow the TCP server-socket object in the parent process
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
/* 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/. */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MozTCPSocket exposes a TCP client and server sockets
|
|
||||||
* to highly privileged apps. It provides a buffered, non-blocking
|
|
||||||
* interface for sending. For receiving, it uses an asynchronous,
|
|
||||||
* event handler based interface.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "domstubs.idl"
|
|
||||||
|
|
||||||
interface nsISocketTransport;
|
|
||||||
interface nsITCPSocketChild;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This interface is implemented in TCPSocket.js as an internal interfaces
|
|
||||||
* for use in cross-process socket implementation.
|
|
||||||
* Needed to account for multiple possible types that can be provided to
|
|
||||||
* the socket callbacks as arguments.
|
|
||||||
*/
|
|
||||||
[scriptable, uuid(E79C5F3C-0B54-44B9-B0D7-6930EF9126DC)]
|
|
||||||
interface nsITCPSocketInternal : nsISupports {
|
|
||||||
/**
|
|
||||||
* Enable secure on channel.
|
|
||||||
*/
|
|
||||||
void upgradeToSecure();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The host of this socket object.
|
|
||||||
*/
|
|
||||||
readonly attribute DOMString host;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The port of this socket object.
|
|
||||||
*/
|
|
||||||
readonly attribute unsigned short port;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pause reading incoming data and invocations of the ondata handler until
|
|
||||||
* resume is called.
|
|
||||||
*/
|
|
||||||
void suspend();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resume reading incoming data and invoking ondata as usual.
|
|
||||||
*/
|
|
||||||
void resume();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the socket.
|
|
||||||
*/
|
|
||||||
void close();
|
|
||||||
|
|
||||||
// Trigger the callback for |type| and provide a DOMError() object with the given data
|
|
||||||
void callListenerError(in DOMString type, in DOMString name);
|
|
||||||
|
|
||||||
// Trigger the callback for |type| and provide a string argument
|
|
||||||
void callListenerData(in DOMString type, in DOMString data);
|
|
||||||
|
|
||||||
// Trigger the callback for |type| and provide an ArrayBuffer argument
|
|
||||||
void callListenerArrayBuffer(in DOMString type, in jsval data);
|
|
||||||
|
|
||||||
// Trigger the callback for |type| with no argument
|
|
||||||
void callListenerVoid(in DOMString type);
|
|
||||||
|
|
||||||
// Update the DOM object's readyState.
|
|
||||||
// @param readyState
|
|
||||||
// new ready state to be set to TCPSocket.
|
|
||||||
void updateReadyState(in DOMString readyState);
|
|
||||||
|
|
||||||
// Update the DOM object's bufferedAmount value with a tracking number to
|
|
||||||
// ensure the update request is sent after child's send() invocation.
|
|
||||||
// @param bufferedAmount
|
|
||||||
// TCPSocket parent's bufferedAmount.
|
|
||||||
// @param trackingNumber
|
|
||||||
// A number to ensure the bufferedAmount is updated after data
|
|
||||||
// from child are sent to parent.
|
|
||||||
void updateBufferedAmount(in uint32_t bufferedAmount,
|
|
||||||
in uint32_t trackingNumber);
|
|
||||||
|
|
||||||
// Initialize a socket object on the parent side.
|
|
||||||
// This is called in accepting any open request on the parent side.
|
|
||||||
//
|
|
||||||
// @param transport
|
|
||||||
// The accepted socket transport.
|
|
||||||
// @param binaryType
|
|
||||||
// "arraybuffer" to use ArrayBuffer instances
|
|
||||||
// in the ondata callback and as the argument to send.
|
|
||||||
// @param global
|
|
||||||
// An object to create ArrayBuffer for this global. See Bug 831107.
|
|
||||||
void initAcceptedParent(in nsISocketTransport transport,
|
|
||||||
in DOMString binaryType,
|
|
||||||
in nsISupports global);
|
|
||||||
|
|
||||||
// Initialize a DOM socket on the child side
|
|
||||||
// This is called when the socket is accepted on the parent side.
|
|
||||||
//
|
|
||||||
// @param socketChild
|
|
||||||
// The socket child object for the IPC implementation.
|
|
||||||
// @param binaryType
|
|
||||||
// "arraybuffer" to use ArrayBuffer instances
|
|
||||||
// in the ondata callback and as the argument to send.
|
|
||||||
// @param global
|
|
||||||
// An object to create ArrayBuffer for this global. See Bug 831107.
|
|
||||||
void initAcceptedChild(in nsITCPSocketChild socketChild,
|
|
||||||
in DOMString binaryType,
|
|
||||||
in nsISupports global);
|
|
||||||
|
|
||||||
// Set App ID.
|
|
||||||
void setAppId(in unsigned long appId);
|
|
||||||
|
|
||||||
// Set inBrowser.
|
|
||||||
void setInBrowser(in boolean inBrowser);
|
|
||||||
|
|
||||||
// Set a callback that handles the request from a TCP socket parent when that
|
|
||||||
// socket parent wants to notify that its bufferedAmount is updated.
|
|
||||||
void setOnUpdateBufferedAmountHandler(in jsval handler);
|
|
||||||
|
|
||||||
// Providing child process with ability to pass more arguments to parent's
|
|
||||||
// send() function.
|
|
||||||
// @param trackingNumber
|
|
||||||
// To ensure the request to update bufferedAmount in child is after
|
|
||||||
// lastest send() invocation from child.
|
|
||||||
void onRecvSendFromChild(in jsval data, in unsigned long byteOffset,
|
|
||||||
in unsigned long byteLength, in unsigned long trackingNumber);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the parent process when there is no DOM window available.
|
|
||||||
*/
|
|
||||||
void initWithGlobal(in nsISupports global);
|
|
||||||
};
|
|
||||||
@@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
#include "domstubs.idl"
|
#include "domstubs.idl"
|
||||||
|
|
||||||
interface nsITCPSocketInternal;
|
interface nsIDOMTCPSocket;
|
||||||
interface nsITCPServerSocketInternal;
|
interface nsIDOMTCPServerSocket;
|
||||||
interface nsITCPServerSocketParent;
|
interface nsITCPServerSocketParent;
|
||||||
interface nsITCPSocketIntermediary;
|
interface nsITCPSocketIntermediary;
|
||||||
|
|
||||||
// Interface required to allow the TCP socket object (TCPSocket.js) in the
|
// Interface required to allow the TCP socket object (TCPSocket.js) in the
|
||||||
// parent process to talk to the parent IPC actor, TCPSocketParent, which
|
// parent process to talk to the parent IPC actor, TCPSocketParent, which
|
||||||
// is written in C++.
|
// is written in C++.
|
||||||
[scriptable, uuid(03B864C8-AAA9-4062-943E-AE6397070E0D)]
|
[scriptable, uuid(6f040bf0-6852-11e3-949a-0800200c9a66)]
|
||||||
interface nsITCPSocketParent : nsISupports
|
interface nsITCPSocketParent : nsISupports
|
||||||
{
|
{
|
||||||
[implicit_jscontext] void initJS(in jsval intermediary);
|
[implicit_jscontext] void initJS(in jsval intermediary);
|
||||||
@@ -40,7 +40,7 @@ interface nsITCPSocketParent : nsISupports
|
|||||||
// The socket on the parent side.
|
// The socket on the parent side.
|
||||||
// @param intermediary
|
// @param intermediary
|
||||||
// Intermediate class object. See nsITCPSocketIntermediary.
|
// Intermediate class object. See nsITCPSocketIntermediary.
|
||||||
void setSocketAndIntermediary(in nsITCPSocketInternal socket,
|
[implicit_jscontext] void setSocketAndIntermediary(in nsIDOMTCPSocket socket,
|
||||||
in nsITCPSocketIntermediary intermediary);
|
in nsITCPSocketIntermediary intermediary);
|
||||||
|
|
||||||
// When parent's buffered amount is updated and it wants to inform child to
|
// When parent's buffered amount is updated and it wants to inform child to
|
||||||
@@ -68,14 +68,14 @@ interface nsITCPSocketParent : nsISupports
|
|||||||
[scriptable, uuid(aa9bd46d-26bf-4ba8-9c18-ba02482c02f0)]
|
[scriptable, uuid(aa9bd46d-26bf-4ba8-9c18-ba02482c02f0)]
|
||||||
interface nsITCPSocketIntermediary : nsISupports {
|
interface nsITCPSocketIntermediary : nsISupports {
|
||||||
// Open the connection to the server with the given parameters
|
// Open the connection to the server with the given parameters
|
||||||
nsITCPSocketInternal open(in nsITCPSocketParent parent,
|
nsIDOMTCPSocket open(in nsITCPSocketParent parent,
|
||||||
in DOMString host, in unsigned short port,
|
in DOMString host, in unsigned short port,
|
||||||
in boolean useSSL, in DOMString binaryType,
|
in boolean useSSL, in DOMString binaryType,
|
||||||
in unsigned long appId,
|
in unsigned long appId,
|
||||||
in boolean inBrowser);
|
in boolean inBrowser);
|
||||||
|
|
||||||
// Listen on a port
|
// Listen on a port
|
||||||
nsITCPServerSocketInternal listen(in nsITCPServerSocketParent parent,
|
nsIDOMTCPServerSocket listen(in nsITCPServerSocketParent parent,
|
||||||
in unsigned short port, in unsigned short backlog,
|
in unsigned short port, in unsigned short backlog,
|
||||||
in DOMString binaryType,
|
in DOMString binaryType,
|
||||||
in unsigned long appId,
|
in unsigned long appId,
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ if CONFIG['MOZ_B2G_RIL']:
|
|||||||
|
|
||||||
MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
|
MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
|
||||||
|
|
||||||
EXPORTS += [
|
|
||||||
'TCPSocketUtils.h',
|
|
||||||
]
|
|
||||||
|
|
||||||
EXPORTS.mozilla.dom += [
|
EXPORTS.mozilla.dom += [
|
||||||
'UDPSocket.h',
|
'UDPSocket.h',
|
||||||
]
|
]
|
||||||
@@ -42,7 +38,6 @@ UNIFIED_SOURCES += [
|
|||||||
'TCPServerSocketParent.cpp',
|
'TCPServerSocketParent.cpp',
|
||||||
'TCPSocketChild.cpp',
|
'TCPSocketChild.cpp',
|
||||||
'TCPSocketParent.cpp',
|
'TCPSocketParent.cpp',
|
||||||
'TCPSocketUtils.cpp',
|
|
||||||
'UDPSocket.cpp',
|
'UDPSocket.cpp',
|
||||||
'UDPSocketChild.cpp',
|
'UDPSocketChild.cpp',
|
||||||
'UDPSocketParent.cpp',
|
'UDPSocketParent.cpp',
|
||||||
@@ -86,8 +81,6 @@ IPDL_SOURCES += [
|
|||||||
|
|
||||||
FAIL_ON_WARNINGS = True
|
FAIL_ON_WARNINGS = True
|
||||||
|
|
||||||
LOCAL_INCLUDES += ['/dom/base']
|
|
||||||
|
|
||||||
include('/ipc/chromium/chromium-config.mozbuild')
|
include('/ipc/chromium/chromium-config.mozbuild')
|
||||||
|
|
||||||
FINAL_LIBRARY = 'xul'
|
FINAL_LIBRARY = 'xul'
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ skip-if = toolkit == "gonk" || toolkit == 'android'
|
|||||||
[test_tcpsocket_client_and_server_basics.html]
|
[test_tcpsocket_client_and_server_basics.html]
|
||||||
[test_tcpsocket_default_permissions.html]
|
[test_tcpsocket_default_permissions.html]
|
||||||
skip-if = toolkit == "gonk"
|
skip-if = toolkit == "gonk"
|
||||||
|
[test_tcpsocket_enabled_no_perm.html]
|
||||||
|
skip-if = toolkit == "gonk"
|
||||||
[test_tcpsocket_enabled_with_perm.html]
|
[test_tcpsocket_enabled_with_perm.html]
|
||||||
skip-if = toolkit == "gonk" || e10s
|
skip-if = toolkit == "gonk" || e10s
|
||||||
[test_networkstats_alarms.html]
|
[test_networkstats_alarms.html]
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ function waitForConnection(listeningServer) {
|
|||||||
// Because of the event model of sockets, we can't use the
|
// Because of the event model of sockets, we can't use the
|
||||||
// listenForEventsOnSocket mechanism; we need to hook up listeners during
|
// listenForEventsOnSocket mechanism; we need to hook up listeners during
|
||||||
// the connect event.
|
// the connect event.
|
||||||
listeningServer.onconnect = function(ev) {
|
listeningServer.onconnect = function(socket) {
|
||||||
// Clobber the listener to get upset if it receives any more connections
|
// Clobber the listener to get upset if it receives any more connections
|
||||||
// after this.
|
// after this.
|
||||||
listeningServer.onconnect = function() {
|
listeningServer.onconnect = function() {
|
||||||
@@ -135,14 +135,10 @@ function waitForConnection(listeningServer) {
|
|||||||
};
|
};
|
||||||
ok(true, 'Listening server accepted socket');
|
ok(true, 'Listening server accepted socket');
|
||||||
resolve({
|
resolve({
|
||||||
socket: ev.socket,
|
socket: socket,
|
||||||
queue: listenForEventsOnSocket(ev.socket, 'server')
|
queue: listenForEventsOnSocket(socket, 'server')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
listeningServer.onerror = function(ev) {
|
|
||||||
ok(false, 'Received an error when not expecting one.');
|
|
||||||
reject();
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,15 +171,16 @@ function* test_basics() {
|
|||||||
// test was using.
|
// test was using.
|
||||||
let serverPort = 8085;
|
let serverPort = 8085;
|
||||||
|
|
||||||
|
let TCPSocket = navigator.mozTCPSocket;
|
||||||
// - Start up a listening socket.
|
// - Start up a listening socket.
|
||||||
let listeningServer = new mozTCPServerSocket(serverPort,
|
let listeningServer = TCPSocket.listen(serverPort,
|
||||||
{ binaryType: 'arraybuffer' },
|
{ binaryType: 'arraybuffer' },
|
||||||
SERVER_BACKLOG);
|
SERVER_BACKLOG);
|
||||||
|
|
||||||
let connectedPromise = waitForConnection(listeningServer);
|
let connectedPromise = waitForConnection(listeningServer);
|
||||||
|
|
||||||
// -- Open a connection to the server
|
// -- Open a connection to the server
|
||||||
let clientSocket = new mozTCPSocket('127.0.0.1', serverPort,
|
let clientSocket = TCPSocket.open('127.0.0.1', serverPort,
|
||||||
{ binaryType: 'arraybuffer' });
|
{ binaryType: 'arraybuffer' });
|
||||||
let clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
let clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
||||||
|
|
||||||
@@ -290,7 +287,7 @@ function* test_basics() {
|
|||||||
|
|
||||||
// -- Re-establish connection
|
// -- Re-establish connection
|
||||||
connectedPromise = waitForConnection(listeningServer);
|
connectedPromise = waitForConnection(listeningServer);
|
||||||
clientSocket = new mozTCPSocket('127.0.0.1', serverPort,
|
clientSocket = TCPSocket.open('127.0.0.1', serverPort,
|
||||||
{ binaryType: 'arraybuffer' });
|
{ binaryType: 'arraybuffer' });
|
||||||
clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
||||||
is((yield clientQueue.waitForEvent()).type, 'open', 'got open event');
|
is((yield clientQueue.waitForEvent()).type, 'open', 'got open event');
|
||||||
@@ -317,7 +314,7 @@ function* test_basics() {
|
|||||||
|
|
||||||
// -- Re-establish connection
|
// -- Re-establish connection
|
||||||
connectedPromise = waitForConnection(listeningServer);
|
connectedPromise = waitForConnection(listeningServer);
|
||||||
clientSocket = new mozTCPSocket('127.0.0.1', serverPort,
|
clientSocket = TCPSocket.open('127.0.0.1', serverPort,
|
||||||
{ binaryType: 'arraybuffer' });
|
{ binaryType: 'arraybuffer' });
|
||||||
clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
||||||
is((yield clientQueue.waitForEvent()).type, 'open', 'got open event');
|
is((yield clientQueue.waitForEvent()).type, 'open', 'got open event');
|
||||||
@@ -346,7 +343,7 @@ function* test_basics() {
|
|||||||
'server received/client sent');
|
'server received/client sent');
|
||||||
// And a close.
|
// And a close.
|
||||||
is((yield serverQueue.waitForEvent()).type, 'close',
|
is((yield serverQueue.waitForEvent()).type, 'close',
|
||||||
'The close event should fire after a large send that returned true.');
|
'The drain event should fire after a large send that returned true.');
|
||||||
|
|
||||||
|
|
||||||
// -- Close the listening server (and try to connect)
|
// -- Close the listening server (and try to connect)
|
||||||
@@ -355,7 +352,7 @@ function* test_basics() {
|
|||||||
listeningServer.close();
|
listeningServer.close();
|
||||||
|
|
||||||
// - try and connect, get an error
|
// - try and connect, get an error
|
||||||
clientSocket = new mozTCPSocket('127.0.0.1', serverPort,
|
clientSocket = TCPSocket.open('127.0.0.1', serverPort,
|
||||||
{ binaryType: 'arraybuffer' });
|
{ binaryType: 'arraybuffer' });
|
||||||
clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
clientQueue = listenForEventsOnSocket(clientSocket, 'client');
|
||||||
is((yield clientQueue.waitForEvent()).type, 'error', 'fail to connect');
|
is((yield clientQueue.waitForEvent()).type, 'error', 'fail to connect');
|
||||||
|
|||||||
@@ -14,7 +14,12 @@
|
|||||||
|
|
||||||
/** Test to ensure TCPSocket permission is disabled by default **/
|
/** Test to ensure TCPSocket permission is disabled by default **/
|
||||||
|
|
||||||
ok(!("mozTCPSocket" in window), "mozTCPSocket should not exist by default");
|
try {
|
||||||
|
navigator.mozTCPSocket;
|
||||||
|
throw new Error("Error: navigator.mozTCPSocket should not exist by default");
|
||||||
|
} catch (e) {
|
||||||
|
ok(true, "navigator.mozTCPSocket should not exist by default");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
35
dom/network/tests/test_tcpsocket_enabled_no_perm.html
Normal file
35
dom/network/tests/test_tcpsocket_enabled_no_perm.html
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test to ensure TCPSocket permission enabled and no tcp-socket perm does not allow open</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
<script type="application/javascript">
|
||||||
|
|
||||||
|
/** Test to ensure TCPSocket permission being turned on enables
|
||||||
|
navigator.mozTCPSocket, but mozTCPSocket.open does not work
|
||||||
|
in content.
|
||||||
|
**/
|
||||||
|
SpecialPowers.setBoolPref("dom.mozTCPSocket.enabled", true);
|
||||||
|
|
||||||
|
ok('mozTCPSocket' in navigator, "navigator.mozTCPSocket should be accessible if dom.mozTCPSocket.enabled is true");
|
||||||
|
|
||||||
|
try {
|
||||||
|
navigator.mozTCPSocket.open('localhost', 80);
|
||||||
|
throw new Error("Error: navigator.mozTCPSocket.open should raise for content that does not have the tcp-socket permission");
|
||||||
|
} catch (e) {
|
||||||
|
ok(true, "navigator.mozTCPSocket.open should raise for content that does not have the tcp-socket permission");
|
||||||
|
}
|
||||||
|
|
||||||
|
SpecialPowers.setBoolPref("dom.mozTCPSocket.enabled", false);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
|
|
||||||
/** Test to ensure TCPSocket permission being turned on enables
|
/** Test to ensure TCPSocket permission being turned on enables
|
||||||
mozTCPSocket, and mozTCPSocket constructor works when
|
navigator.mozTCPSocket, and mozTCPSocket.open works when
|
||||||
the tcp-socket permission has been granted.
|
the tcp-socket permission has been granted.
|
||||||
**/
|
**/
|
||||||
SpecialPowers.setBoolPref("dom.mozTCPSocket.enabled", true);
|
SpecialPowers.setBoolPref("dom.mozTCPSocket.enabled", true);
|
||||||
SpecialPowers.addPermission("tcp-socket", true, document);
|
SpecialPowers.addPermission("tcp-socket", true, document);
|
||||||
|
|
||||||
ok('mozTCPSocket' in window, "window.mozTCPSocket should be accessible if dom.mozTCPSocket.enabled is true");
|
ok('mozTCPSocket' in navigator, "navigator.mozTCPSocket should be accessible if dom.mozTCPSocket.enabled is true");
|
||||||
|
|
||||||
ok(new mozTCPSocket('localhost', 80), "window.mozTCPSocket ctor should work for content that has the tcp-socket permission");
|
ok(navigator.mozTCPSocket.open('localhost', 80), "navigator.mozTCPSocket.open should work for content that has the tcp-socket permission");
|
||||||
|
|
||||||
SpecialPowers.setBoolPref("dom.mozTCPSocket.enabled", false);
|
SpecialPowers.setBoolPref("dom.mozTCPSocket.enabled", false);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ const ServerSocket = CC("@mozilla.org/network/server-socket;1",
|
|||||||
"nsIBinaryOutputStream",
|
"nsIBinaryOutputStream",
|
||||||
"setOutputStream"),
|
"setOutputStream"),
|
||||||
TCPSocket = new (CC("@mozilla.org/tcp-socket;1",
|
TCPSocket = new (CC("@mozilla.org/tcp-socket;1",
|
||||||
"nsITCPSocketInternal"))();
|
"nsIDOMTCPSocket"))();
|
||||||
|
|
||||||
const gInChild = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
const gInChild = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
||||||
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||||
@@ -269,10 +269,9 @@ function connectSock() {
|
|||||||
server.reset();
|
server.reset();
|
||||||
var yayFuncs = makeJointSuccess(['serveropen', 'clientopen']);
|
var yayFuncs = makeJointSuccess(['serveropen', 'clientopen']);
|
||||||
|
|
||||||
sock = new mozTCPSocket(
|
sock = TCPSocket.open(
|
||||||
'127.0.0.1', server.listener.port,
|
'127.0.0.1', server.listener.port,
|
||||||
{ binaryType: 'arraybuffer' });
|
{ binaryType: 'arraybuffer' });
|
||||||
sock.getInternalSocket().initWithGlobal(this);
|
|
||||||
|
|
||||||
sock.onopen = yayFuncs.clientopen;
|
sock.onopen = yayFuncs.clientopen;
|
||||||
sock.ondrain = null;
|
sock.ondrain = null;
|
||||||
@@ -311,7 +310,7 @@ function childbuffered() {
|
|||||||
server.ondata = makeExpectData(
|
server.ondata = makeExpectData(
|
||||||
'ondata', DATA_ARRAY, false, yays.serverdata);
|
'ondata', DATA_ARRAY, false, yays.serverdata);
|
||||||
|
|
||||||
let internalSocket = sock.getInternalSocket();
|
let internalSocket = sock.QueryInterface(Ci.nsITCPSocketInternal);
|
||||||
internalSocket.updateBufferedAmount(65535, // almost reach buffering threshold
|
internalSocket.updateBufferedAmount(65535, // almost reach buffering threshold
|
||||||
0);
|
0);
|
||||||
if (sock.send(DATA_ARRAY_BUFFER)) {
|
if (sock.send(DATA_ARRAY_BUFFER)) {
|
||||||
@@ -336,7 +335,7 @@ function childnotbuffered() {
|
|||||||
if (sock.send(BIG_ARRAY_BUFFER)) {
|
if (sock.send(BIG_ARRAY_BUFFER)) {
|
||||||
do_throw("sock.send(BIG_TYPED_ARRAY) did not return false to indicate buffering");
|
do_throw("sock.send(BIG_TYPED_ARRAY) did not return false to indicate buffering");
|
||||||
}
|
}
|
||||||
let internalSocket = sock.getInternalSocket();
|
let internalSocket = sock.QueryInterface(Ci.nsITCPSocketInternal);
|
||||||
internalSocket.updateBufferedAmount(0, // setting zero will clear waitForDrain in sock.
|
internalSocket.updateBufferedAmount(0, // setting zero will clear waitForDrain in sock.
|
||||||
1);
|
1);
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=815105
|
|||||||
*/
|
*/
|
||||||
function verifier(success, failure) {
|
function verifier(success, failure) {
|
||||||
try {
|
try {
|
||||||
var conn = new mozTCPSocket("http://mochi.test/", 80);
|
var conn = this.getObj().open("http://mochi.test/", 80);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
success("Opened connection");
|
success("Opened connection");
|
||||||
|
} else {
|
||||||
|
failure("failed to open connection");
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
failure("Got an exception " + e);
|
failure("Got an exception " + e);
|
||||||
}
|
}
|
||||||
@@ -32,7 +37,8 @@ var gData = [
|
|||||||
{
|
{
|
||||||
perm: ["tcp-socket"],
|
perm: ["tcp-socket"],
|
||||||
needParentPerm: true,
|
needParentPerm: true,
|
||||||
webidl: "mozTCPSocket",
|
obj: "mozTCPSocket",
|
||||||
|
idl: "nsIDOMTCPSocket",
|
||||||
settings: [["dom.mozTCPSocket.enabled", true]],
|
settings: [["dom.mozTCPSocket.enabled", true]],
|
||||||
verifier: verifier.toSource(),
|
verifier: verifier.toSource(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
||||||
/* 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/. */
|
|
||||||
|
|
||||||
interface nsITCPServerSocketInternal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mozTCPServerSocket
|
|
||||||
*
|
|
||||||
* An interface to a server socket that can accept incoming connections for gaia apps.
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum TCPServerSocketBinaryType {
|
|
||||||
"arraybuffer",
|
|
||||||
"string"
|
|
||||||
};
|
|
||||||
|
|
||||||
dictionary ServerSocketOptions {
|
|
||||||
TCPServerSocketBinaryType binaryType = "string";
|
|
||||||
};
|
|
||||||
|
|
||||||
[Constructor(unsigned short port, optional ServerSocketOptions options, optional unsigned short backlog),
|
|
||||||
JSImplementation="@mozilla.org/tcp-server-socket;1", Func="TCPSocketUtils::SocketEnabled",
|
|
||||||
Exposed=(Window,System)]
|
|
||||||
interface mozTCPServerSocket : EventTarget {
|
|
||||||
/**
|
|
||||||
* The port of this server socket object.
|
|
||||||
*/
|
|
||||||
readonly attribute unsigned short localPort;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The onconnect event handler is called when a client connection is accepted.
|
|
||||||
* The socket attribute of the event passed to the onconnect handler will be a TCPSocket
|
|
||||||
* instance, which is used for communication between client and server.
|
|
||||||
*/
|
|
||||||
attribute EventHandler onconnect;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The onerror handler will be called when the listen of a server socket is aborted.
|
|
||||||
* The data attribute of the event passed to the onerror handler will have a
|
|
||||||
* description of the kind of error.
|
|
||||||
*/
|
|
||||||
attribute EventHandler onerror;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the server socket.
|
|
||||||
*/
|
|
||||||
void close();
|
|
||||||
|
|
||||||
[ChromeOnly]
|
|
||||||
nsITCPServerSocketInternal getInternalSocket();
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/* 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/. */
|
|
||||||
|
|
||||||
interface nsIDOMTCPSocket;
|
|
||||||
|
|
||||||
[Constructor(DOMString type, optional TCPServerSocketEventInit eventInitDict),
|
|
||||||
Func="TCPSocketUtils::SocketEnabled", Exposed=(Window,System)]
|
|
||||||
interface TCPServerSocketEvent : Event {
|
|
||||||
readonly attribute mozTCPSocket socket;
|
|
||||||
};
|
|
||||||
|
|
||||||
dictionary TCPServerSocketEventInit : EventInit {
|
|
||||||
mozTCPSocket? socket = null;
|
|
||||||
};
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
||||||
/* 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/. */
|
|
||||||
|
|
||||||
interface nsITCPSocketInternal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MozTCPSocket exposes a TCP client socket (no server sockets yet)
|
|
||||||
* to highly privileged apps. It provides a buffered, non-blocking
|
|
||||||
* interface for sending. For receiving, it uses an asynchronous,
|
|
||||||
* event handler based interface.
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum TCPSocketBinaryType {
|
|
||||||
"arraybuffer",
|
|
||||||
"string"
|
|
||||||
};
|
|
||||||
|
|
||||||
dictionary SocketOptions {
|
|
||||||
boolean useSSL = false;
|
|
||||||
TCPSocketBinaryType binaryType = "string";
|
|
||||||
boolean doNotConnect = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
[Constructor(DOMString host, unsigned short port, optional SocketOptions options),
|
|
||||||
Func="TCPSocketUtils::SocketEnabled",
|
|
||||||
JSImplementation="@mozilla.org/tcp-socket;1", Exposed=(Window,System)]
|
|
||||||
interface mozTCPSocket : EventTarget {
|
|
||||||
/**
|
|
||||||
* The host of this socket object.
|
|
||||||
*/
|
|
||||||
readonly attribute USVString host;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The port of this socket object.
|
|
||||||
*/
|
|
||||||
readonly attribute unsigned short port;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* True if this socket object is an SSL socket.
|
|
||||||
*/
|
|
||||||
readonly attribute boolean ssl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of bytes which have previously been buffered by calls to
|
|
||||||
* send on this socket.
|
|
||||||
*/
|
|
||||||
readonly attribute unsigned long bufferedAmount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pause reading incoming data and invocations of the ondata handler until
|
|
||||||
* resume is called.
|
|
||||||
*/
|
|
||||||
void suspend();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resume reading incoming data and invoking ondata as usual.
|
|
||||||
*/
|
|
||||||
void resume();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the socket.
|
|
||||||
*/
|
|
||||||
void close();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write data to the socket.
|
|
||||||
*
|
|
||||||
* @param data The data to write to the socket. If
|
|
||||||
* binaryType: "arraybuffer" was passed in the options
|
|
||||||
* object, then this object should be an ArrayBuffer instance.
|
|
||||||
* If binaryType: "string" was passed, or if no binaryType
|
|
||||||
* option was specified, then this object should be an
|
|
||||||
* ordinary JavaScript string.
|
|
||||||
* @param byteOffset The offset within the data from which to begin writing.
|
|
||||||
* Has no effect on non-ArrayBuffer data.
|
|
||||||
* @param byteLength The number of bytes to write. Has no effect on
|
|
||||||
* non-ArrayBuffer data.
|
|
||||||
*
|
|
||||||
* @return Send returns true or false as a hint to the caller that
|
|
||||||
* they may either continue sending more data immediately, or
|
|
||||||
* may want to wait until the other side has read some of the
|
|
||||||
* data which has already been written to the socket before
|
|
||||||
* buffering more. If send returns true, then less than 64k
|
|
||||||
* has been buffered and it's safe to immediately write more.
|
|
||||||
* If send returns false, then more than 64k has been buffered,
|
|
||||||
* and the caller may wish to wait until the ondrain event
|
|
||||||
* handler has been called before buffering more data by more
|
|
||||||
* calls to send.
|
|
||||||
*/
|
|
||||||
boolean send((USVString or ArrayBuffer) data, optional unsigned long byteOffset, optional unsigned long byteLength);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The readyState attribute indicates which state the socket is currently
|
|
||||||
* in. The state will be either "connecting", "open", "closing", or "closed".
|
|
||||||
*/
|
|
||||||
readonly attribute DOMString readyState;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The binaryType attribute indicates which mode this socket uses for
|
|
||||||
* sending and receiving data. If the binaryType: "arraybuffer" option
|
|
||||||
* was passed to the open method that created this socket, binaryType
|
|
||||||
* will be "arraybuffer". Otherwise, it will be "string".
|
|
||||||
*/
|
|
||||||
readonly attribute TCPSocketBinaryType binaryType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The onopen event handler is called when the connection to the server
|
|
||||||
* has been established. If the connection is refused, onerror will be
|
|
||||||
* called, instead.
|
|
||||||
*/
|
|
||||||
attribute EventHandler onopen;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* After send has buffered more than 64k of data, it returns false to
|
|
||||||
* indicate that the client should pause before sending more data, to
|
|
||||||
* avoid accumulating large buffers. This is only advisory, and the client
|
|
||||||
* is free to ignore it and buffer as much data as desired, but if reducing
|
|
||||||
* the size of buffers is important (especially for a streaming application)
|
|
||||||
* ondrain will be called once the previously-buffered data has been written
|
|
||||||
* to the network, at which point the client can resume calling send again.
|
|
||||||
*/
|
|
||||||
attribute EventHandler ondrain;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ondata handler will be called repeatedly and asynchronously after
|
|
||||||
* onopen has been called, every time some data was available from the server
|
|
||||||
* and was read. If binaryType: "arraybuffer" was passed to open, the data
|
|
||||||
* attribute of the event object will be an ArrayBuffer. If not, it will be a
|
|
||||||
* normal JavaScript string.
|
|
||||||
*
|
|
||||||
* At any time, the client may choose to pause reading and receiving ondata
|
|
||||||
* callbacks, by calling the socket's suspend() method. Further invocations
|
|
||||||
* of ondata will be paused until resume() is called.
|
|
||||||
*/
|
|
||||||
attribute EventHandler ondata;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The onerror handler will be called when there is an error. The data
|
|
||||||
* attribute of the event passed to the onerror handler will have a
|
|
||||||
* description of the kind of error.
|
|
||||||
*
|
|
||||||
* If onerror is called before onopen, the error was connection refused,
|
|
||||||
* and onclose will not be called. If onerror is called after onopen,
|
|
||||||
* the connection was lost, and onclose will be called after onerror.
|
|
||||||
*/
|
|
||||||
attribute EventHandler onerror;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The onclose handler is called once the underlying network socket
|
|
||||||
* has been closed, either by the server, or by the client calling
|
|
||||||
* close.
|
|
||||||
*
|
|
||||||
* If onerror was not called before onclose, then either side cleanly
|
|
||||||
* closed the connection.
|
|
||||||
*/
|
|
||||||
attribute EventHandler onclose;
|
|
||||||
|
|
||||||
[ChromeOnly]
|
|
||||||
nsITCPSocketInternal getInternalSocket();
|
|
||||||
};
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
||||||
/* 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/. */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TCPSocketEvent is the event object which is passed as the
|
|
||||||
* first argument to all the event handler callbacks. It contains
|
|
||||||
* the socket that was associated with the event, the type of event,
|
|
||||||
* and the data associated with the event (if any).
|
|
||||||
*/
|
|
||||||
|
|
||||||
[Constructor(DOMString type, optional TCPSocketEventInit eventInitDict),
|
|
||||||
Func="TCPSocketUtils::SocketEnabled", Exposed=(Window,System)]
|
|
||||||
interface TCPSocketEvent : Event {
|
|
||||||
/**
|
|
||||||
* The data related to this event, if any. In the ondata callback,
|
|
||||||
* data will be the bytes read from the network; if the binaryType
|
|
||||||
* of the socket was "arraybuffer", this value will be of type ArrayBuffer;
|
|
||||||
* otherwise, it will be a normal JavaScript string.
|
|
||||||
*
|
|
||||||
* In the onerror callback, data will be a string with a description
|
|
||||||
* of the error.
|
|
||||||
*
|
|
||||||
* In the other callbacks, data will be an empty string.
|
|
||||||
*/
|
|
||||||
//TODO: make this (ArrayBuffer or DOMString) after sorting out the rooting required. bug 1121634
|
|
||||||
readonly attribute any data;
|
|
||||||
};
|
|
||||||
|
|
||||||
dictionary TCPSocketEventInit : EventInit {
|
|
||||||
//TODO: make this (ArrayBuffer or DOMString) after sorting out the rooting required. bug 1121634
|
|
||||||
any data = null;
|
|
||||||
};
|
|
||||||
@@ -493,10 +493,6 @@ WEBIDL_FILES = [
|
|||||||
'SVGViewElement.webidl',
|
'SVGViewElement.webidl',
|
||||||
'SVGZoomAndPan.webidl',
|
'SVGZoomAndPan.webidl',
|
||||||
'SVGZoomEvent.webidl',
|
'SVGZoomEvent.webidl',
|
||||||
'TCPServerSocket.webidl',
|
|
||||||
'TCPServerSocketEvent.webidl',
|
|
||||||
'TCPSocket.webidl',
|
|
||||||
'TCPSocketEvent.webidl',
|
|
||||||
'Telephony.webidl',
|
'Telephony.webidl',
|
||||||
'TelephonyCall.webidl',
|
'TelephonyCall.webidl',
|
||||||
'TelephonyCallGroup.webidl',
|
'TelephonyCallGroup.webidl',
|
||||||
@@ -740,8 +736,6 @@ GENERATED_EVENTS_WEBIDL_FILES = [
|
|||||||
'StyleRuleChangeEvent.webidl',
|
'StyleRuleChangeEvent.webidl',
|
||||||
'StyleSheetApplicableStateChangeEvent.webidl',
|
'StyleSheetApplicableStateChangeEvent.webidl',
|
||||||
'StyleSheetChangeEvent.webidl',
|
'StyleSheetChangeEvent.webidl',
|
||||||
'TCPServerSocketEvent.webidl',
|
|
||||||
'TCPSocketEvent.webidl',
|
|
||||||
'TrackEvent.webidl',
|
'TrackEvent.webidl',
|
||||||
'TVCurrentChannelChangedEvent.webidl',
|
'TVCurrentChannelChangedEvent.webidl',
|
||||||
'TVCurrentSourceChangedEvent.webidl',
|
'TVCurrentSourceChangedEvent.webidl',
|
||||||
|
|||||||
Reference in New Issue
Block a user