PageRenderTime 76ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/firefox-extensions/test/skeleton/chrome/content/connection-xpcom.js

https://github.com/Harvie/Programs
JavaScript | 723 lines | 514 code | 104 blank | 105 comment | 89 complexity | 5e21bf43575254bcdddb9c0f9592eef0 MD5 | raw file
Possible License(s): GPL-3.0
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is JSIRC Library.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * New Dimensions Consulting, Inc.
  20. * Portions created by the Initial Developer are Copyright (C) 1999
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. * Robert Ginda, rginda@ndcico.com, original author
  25. * Peter Van der Beken, peter.vanderbeken@pandora.be, necko-only version
  26. *
  27. * Alternatively, the contents of this file may be used under the terms of
  28. * either the GNU General Public License Version 2 or later (the "GPL"), or
  29. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30. * in which case the provisions of the GPL or the LGPL are applicable instead
  31. * of those above. If you wish to allow use of your version of this file only
  32. * under the terms of either the GPL or the LGPL, and not to allow others to
  33. * use your version of this file under the terms of the MPL, indicate your
  34. * decision by deleting the provisions above and replace them with the notice
  35. * and other provisions required by the GPL or the LGPL. If you do not delete
  36. * the provisions above, a recipient may use your version of this file under
  37. * the terms of any one of the MPL, the GPL or the LGPL.
  38. *
  39. * ***** END LICENSE BLOCK ***** */
  40. const NS_ERROR_MODULE_NETWORK = 2152398848;
  41. const NS_ERROR_UNKNOWN_HOST = NS_ERROR_MODULE_NETWORK + 30;
  42. const NS_ERROR_CONNECTION_REFUSED = NS_ERROR_MODULE_NETWORK + 13;
  43. const NS_ERROR_NET_TIMEOUT = NS_ERROR_MODULE_NETWORK + 14;
  44. const NS_ERROR_NET_RESET = NS_ERROR_MODULE_NETWORK + 20;
  45. const NS_ERROR_UNKNOWN_PROXY_HOST = NS_ERROR_MODULE_NETWORK + 42;
  46. const NS_ERROR_PROXY_CONNECTION_REFUSED = NS_ERROR_MODULE_NETWORK + 72;
  47. // Offline error constants:
  48. const NS_ERROR_BINDING_ABORTED = NS_ERROR_MODULE_NETWORK + 2;
  49. const NS_ERROR_ABORT = 0x80004004;
  50. const NS_NET_STATUS_RESOLVING_HOST = NS_ERROR_MODULE_NETWORK + 3;
  51. const NS_NET_STATUS_CONNECTED_TO = NS_ERROR_MODULE_NETWORK + 4;
  52. const NS_NET_STATUS_SENDING_TO = NS_ERROR_MODULE_NETWORK + 5;
  53. const NS_NET_STATUS_RECEIVING_FROM = NS_ERROR_MODULE_NETWORK + 6;
  54. const NS_NET_STATUS_CONNECTING_TO = NS_ERROR_MODULE_NETWORK + 7;
  55. // Security Constants.
  56. const STATE_IS_BROKEN = 1;
  57. const STATE_IS_SECURE = 2;
  58. const STATE_IS_INSECURE = 3;
  59. const STATE_SECURE_LOW = 1;
  60. const STATE_SECURE_HIGH = 2;
  61. const nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
  62. const nsIBinaryInputStream = Components.interfaces.nsIBinaryInputStream;
  63. const nsIBinaryOutputStream = Components.interfaces.nsIBinaryOutputStream;
  64. function toSInputStream(stream, binary)
  65. {
  66. var sstream;
  67. if (binary)
  68. {
  69. sstream = Components.classes["@mozilla.org/binaryinputstream;1"];
  70. sstream = sstream.createInstance(nsIBinaryInputStream);
  71. sstream.setInputStream(stream);
  72. }
  73. else
  74. {
  75. sstream = Components.classes["@mozilla.org/scriptableinputstream;1"];
  76. sstream = sstream.createInstance(nsIScriptableInputStream);
  77. sstream.init(stream);
  78. }
  79. return sstream;
  80. }
  81. function toSOutputStream(stream, binary)
  82. {
  83. var sstream;
  84. if (binary)
  85. {
  86. sstream = Components.classes["@mozilla.org/binaryoutputstream;1"];
  87. sstream = sstream.createInstance(Components.interfaces.nsIBinaryOutputStream);
  88. sstream.setOutputStream(stream);
  89. }
  90. else
  91. {
  92. sstream = stream;
  93. }
  94. return sstream;
  95. }
  96. function CBSConnection (binary)
  97. {
  98. /* Since 2003-01-17 18:14, Mozilla has had this contract ID for the STS.
  99. * Prior to that it didn't have one, so we also include the CID for the
  100. * STS back then - DO NOT UPDATE THE ID if it changes in Mozilla.
  101. */
  102. const sockClassByName =
  103. Components.classes["@mozilla.org/network/socket-transport-service;1"];
  104. const sockClassByID =
  105. Components.classesByID["{c07e81e0-ef12-11d2-92b6-00105a1b0d64}"];
  106. var sockServiceClass = (sockClassByName || sockClassByID);
  107. if (!sockServiceClass)
  108. throw ("Couldn't get socket service class.");
  109. var sockService = sockServiceClass.getService();
  110. if (!sockService)
  111. throw ("Couldn't get socket service.");
  112. this._sockService = sockService.QueryInterface
  113. (Components.interfaces.nsISocketTransportService);
  114. /* Note: as part of the mess from bug 315288 and bug 316178, ChatZilla now
  115. * uses the *binary* stream interfaces for all network
  116. * communications.
  117. *
  118. * However, these interfaces do not exist prior to 1999-11-05. To
  119. * make matters worse, an incompatible change to the "readBytes"
  120. * method of this interface was made on 2003-03-13; luckly, this
  121. * change also added a "readByteArray" method, which we will check
  122. * for below, to determin if we can use the binary streams.
  123. */
  124. // We want to check for working binary streams only the first time.
  125. if (CBSConnection.prototype.workingBinaryStreams == -1)
  126. {
  127. CBSConnection.prototype.workingBinaryStreams = false;
  128. if (typeof nsIBinaryInputStream != "undefined")
  129. {
  130. var isCls = Components.classes["@mozilla.org/binaryinputstream;1"];
  131. var inputStream = isCls.createInstance(nsIBinaryInputStream);
  132. if ("readByteArray" in inputStream)
  133. CBSConnection.prototype.workingBinaryStreams = true;
  134. }
  135. }
  136. this.wrappedJSObject = this;
  137. if (typeof binary != "undefined")
  138. this.binaryMode = binary;
  139. else
  140. this.binaryMode = this.workingBinaryStreams;
  141. if (!ASSERT(!this.binaryMode || this.workingBinaryStreams,
  142. "Unable to use binary streams in this build."))
  143. {
  144. throw ("Unable to use binary streams in this build.");
  145. }
  146. }
  147. CBSConnection.prototype.workingBinaryStreams = -1;
  148. CBSConnection.prototype.connect =
  149. function bc_connect(host, port, config, observer)
  150. {
  151. this.host = host.toLowerCase();
  152. this.port = port;
  153. if (typeof config != "object")
  154. config = {};
  155. // Lets get a transportInfo for this
  156. var pps = getService("@mozilla.org/network/protocol-proxy-service;1",
  157. "nsIProtocolProxyService");
  158. if (!pps)
  159. throw ("Couldn't get protocol proxy service");
  160. var ios = getService("@mozilla.org/network/io-service;1", "nsIIOService");
  161. function getProxyFor(uri)
  162. {
  163. uri = ios.newURI(uri, null, null);
  164. // As of 2005-03-25, 'examineForProxy' was replaced by 'resolve'.
  165. if ("resolve" in pps)
  166. return pps.resolve(uri, 0);
  167. if ("examineForProxy" in pps)
  168. return pps.examineForProxy(uri);
  169. return null;
  170. };
  171. var proxyInfo = null;
  172. var usingHTTPCONNECT = false;
  173. if ("proxy" in config)
  174. {
  175. /* Force Necko to supply the HTTP proxy info if desired. For none,
  176. * force no proxy. Other values will get default treatment.
  177. */
  178. if (config.proxy == "http")
  179. proxyInfo = getProxyFor("http://" + host + ":" + port);
  180. else if (config.proxy != "none")
  181. proxyInfo = getProxyFor("irc://" + host + ":" + port);
  182. /* Since the proxy info is opaque, we need to check that we got
  183. * something for our HTTP proxy - we can't just check proxyInfo.type.
  184. */
  185. usingHTTPCONNECT = ((config.proxy == "http") && proxyInfo);
  186. }
  187. else
  188. {
  189. proxyInfo = getProxyFor("irc://" + host + ":" + port);
  190. }
  191. if (jsenv.HAS_STREAM_PROVIDER)
  192. {
  193. if (("isSecure" in config) && config.isSecure)
  194. {
  195. this._transport = this._sockService.
  196. createTransportOfType("ssl", host, port,
  197. proxyInfo, 0, 0);
  198. }
  199. else
  200. {
  201. this._transport = this._sockService.
  202. createTransport(host, port, proxyInfo, 0, 0);
  203. }
  204. if (!this._transport)
  205. throw ("Error creating transport.");
  206. if (jsenv.HAS_NSPR_EVENTQ)
  207. { /* we've got an event queue, so start up an async write */
  208. this._streamProvider = new StreamProvider (observer);
  209. this._write_req =
  210. this._transport.asyncWrite (this._streamProvider, this,
  211. 0, -1, 0);
  212. }
  213. else
  214. {
  215. /* no nspr event queues in this environment, we can't use async
  216. * calls, so set up the streams. */
  217. this._outputStream = this._transport.openOutputStream(0, -1, 0);
  218. if (!this._outputStream)
  219. throw "Error getting output stream.";
  220. this._sOutputStream = toSOutputStream(this._outputStream,
  221. this.binaryMode);
  222. this._inputStream = this._transport.openInputStream(0, -1, 0);
  223. if (!this._inputStream)
  224. throw "Error getting input stream.";
  225. this._sInputStream = toSInputStream(this._inputStream,
  226. this.binaryMode);
  227. }
  228. }
  229. else
  230. {
  231. /* use new necko interfaces */
  232. if (("isSecure" in config) && config.isSecure)
  233. {
  234. this._transport = this._sockService.
  235. createTransport(["ssl"], 1, host, port,
  236. proxyInfo);
  237. }
  238. else
  239. {
  240. this._transport = this._sockService.
  241. createTransport(null, 0, host, port, proxyInfo);
  242. }
  243. if (!this._transport)
  244. throw ("Error creating transport.");
  245. /* if we don't have an event queue, then all i/o must be blocking */
  246. var openFlags;
  247. if (jsenv.HAS_NSPR_EVENTQ)
  248. openFlags = 0;
  249. else
  250. openFlags = Components.interfaces.nsITransport.OPEN_BLOCKING;
  251. /* no limit on the output stream buffer */
  252. this._outputStream =
  253. this._transport.openOutputStream(openFlags, 4096, -1);
  254. if (!this._outputStream)
  255. throw "Error getting output stream.";
  256. this._sOutputStream = toSOutputStream(this._outputStream,
  257. this.binaryMode);
  258. this._inputStream = this._transport.openInputStream(openFlags, 0, 0);
  259. if (!this._inputStream)
  260. throw "Error getting input stream.";
  261. this._sInputStream = toSInputStream(this._inputStream,
  262. this.binaryMode);
  263. }
  264. this.connectDate = new Date();
  265. this.isConnected = true;
  266. // Bootstrap the connection if we're proxying via an HTTP proxy.
  267. if (usingHTTPCONNECT)
  268. {
  269. this.sendData("CONNECT " + host + ":" + port + " HTTP/1.1\r\n\r\n");
  270. }
  271. return this.isConnected;
  272. }
  273. CBSConnection.prototype.listen =
  274. function bc_listen(port, observer)
  275. {
  276. var serverSockClass =
  277. Components.classes["@mozilla.org/network/server-socket;1"];
  278. if (!serverSockClass)
  279. throw ("Couldn't get server socket class.");
  280. var serverSock = serverSockClass.createInstance();
  281. if (!serverSock)
  282. throw ("Couldn't get server socket.");
  283. this._serverSock = serverSock.QueryInterface
  284. (Components.interfaces.nsIServerSocket);
  285. this._serverSock.init(port, false, -1);
  286. this._serverSockListener = new SocketListener(this, observer);
  287. this._serverSock.asyncListen(this._serverSockListener);
  288. this.port = this._serverSock.port;
  289. return true;
  290. }
  291. CBSConnection.prototype.accept =
  292. function bc_accept(transport, observer)
  293. {
  294. this._transport = transport;
  295. this.host = this._transport.host.toLowerCase();
  296. this.port = this._transport.port;
  297. if (jsenv.HAS_STREAM_PROVIDER)
  298. {
  299. if (jsenv.HAS_NSPR_EVENTQ)
  300. { /* we've got an event queue, so start up an async write */
  301. this._streamProvider = new StreamProvider (observer);
  302. this._write_req =
  303. this._transport.asyncWrite (this._streamProvider, this,
  304. 0, -1, 0);
  305. }
  306. else
  307. {
  308. /* no nspr event queues in this environment, we can't use async
  309. * calls, so set up the streams. */
  310. this._outputStream = this._transport.openOutputStream(0, -1, 0);
  311. if (!this._outputStream)
  312. throw "Error getting output stream.";
  313. this._sOutputStream = toSOutputStream(this._outputStream,
  314. this.binaryMode);
  315. //this._scriptableInputStream =
  316. this._inputStream = this._transport.openInputStream(0, -1, 0);
  317. if (!this._inputStream)
  318. throw "Error getting input stream.";
  319. this._sInputStream = toSInputStream(this._inputStream,
  320. this.binaryMode);
  321. }
  322. }
  323. else
  324. {
  325. /* if we don't have an event queue, then all i/o must be blocking */
  326. var openFlags;
  327. if (jsenv.HAS_NSPR_EVENTQ)
  328. openFlags = 0;
  329. else
  330. openFlags = Components.interfaces.nsITransport.OPEN_BLOCKING;
  331. /* no limit on the output stream buffer */
  332. this._outputStream =
  333. this._transport.openOutputStream(openFlags, 4096, -1);
  334. if (!this._outputStream)
  335. throw "Error getting output stream.";
  336. this._sOutputStream = toSOutputStream(this._outputStream,
  337. this.binaryMode);
  338. this._inputStream = this._transport.openInputStream(openFlags, 0, 0);
  339. if (!this._inputStream)
  340. throw "Error getting input stream.";
  341. this._sInputStream = toSInputStream(this._inputStream,
  342. this.binaryMode);
  343. }
  344. this.connectDate = new Date();
  345. this.isConnected = true;
  346. // Clean up listening socket.
  347. this.close();
  348. return this.isConnected;
  349. }
  350. CBSConnection.prototype.close =
  351. function bc_close()
  352. {
  353. if ("_serverSock" in this && this._serverSock)
  354. this._serverSock.close();
  355. }
  356. CBSConnection.prototype.disconnect =
  357. function bc_disconnect()
  358. {
  359. if ("_inputStream" in this && this._inputStream)
  360. this._inputStream.close();
  361. if ("_outputStream" in this && this._outputStream)
  362. this._outputStream.close();
  363. this.isConnected = false;
  364. /*
  365. this._streamProvider.close();
  366. if (this._streamProvider.isBlocked)
  367. this._write_req.resume();
  368. */
  369. }
  370. CBSConnection.prototype.sendData =
  371. function bc_senddata(str)
  372. {
  373. if (!this.isConnected)
  374. throw "Not Connected.";
  375. if (jsenv.HAS_NSPR_EVENTQ && jsenv.HAS_STREAM_PROVIDER)
  376. this.asyncWrite (str);
  377. else
  378. this.sendDataNow (str);
  379. }
  380. CBSConnection.prototype.readData =
  381. function bc_readdata(timeout, count)
  382. {
  383. if (!this.isConnected)
  384. throw "Not Connected.";
  385. var rv;
  386. if (!("_sInputStream" in this)) {
  387. this._sInputStream = toSInputStream(this._inputStream);
  388. dump("OMG, setting up _sInputStream!\n");
  389. }
  390. try
  391. {
  392. // XPCshell h4x
  393. if (typeof count == "undefined")
  394. count = this._sInputStream.available();
  395. if (this.binaryMode)
  396. rv = this._sInputStream.readBytes(count);
  397. else
  398. rv = this._sInputStream.read(count);
  399. }
  400. catch (ex)
  401. {
  402. dd ("*** Caught " + ex + " while reading.");
  403. this.disconnect();
  404. throw (ex);
  405. }
  406. return rv;
  407. }
  408. CBSConnection.prototype.startAsyncRead =
  409. function bc_saread (observer)
  410. {
  411. if (jsenv.HAS_STREAM_PROVIDER)
  412. {
  413. this._transport.asyncRead (new StreamListener (observer),
  414. this, 0, -1, 0);
  415. }
  416. else
  417. {
  418. var cls = Components.classes["@mozilla.org/network/input-stream-pump;1"];
  419. var pump = cls.createInstance(Components.interfaces.nsIInputStreamPump);
  420. pump.init(this._inputStream, -1, -1, 0, 0, false);
  421. pump.asyncRead(new StreamListener(observer), this);
  422. }
  423. }
  424. CBSConnection.prototype.asyncWrite =
  425. function bc_awrite (str)
  426. {
  427. this._streamProvider.pendingData += str;
  428. if (this._streamProvider.isBlocked)
  429. {
  430. this._write_req.resume();
  431. this._streamProvider.isBlocked = false;
  432. }
  433. }
  434. CBSConnection.prototype.hasPendingWrite =
  435. function bc_haspwrite ()
  436. {
  437. if (jsenv.HAS_STREAM_PROVIDER)
  438. return (this._streamProvider.pendingData != "");
  439. else
  440. return false; /* data already pushed to necko */
  441. }
  442. CBSConnection.prototype.sendDataNow =
  443. function bc_senddatanow(str)
  444. {
  445. var rv = false;
  446. try
  447. {
  448. if (this.binaryMode)
  449. this._sOutputStream.writeBytes(str, str.length);
  450. else
  451. this._sOutputStream.write(str, str.length);
  452. rv = true;
  453. }
  454. catch (ex)
  455. {
  456. dd ("*** Caught " + ex + " while sending.");
  457. this.disconnect();
  458. throw (ex);
  459. }
  460. return rv;
  461. }
  462. /* getSecurityState returns an array containing information about the security
  463. * of the connection. The array always has at least one item, which contains a
  464. * value from the STATE_IS_* enumeration at the top of this file. Iff this is
  465. * STATE_IS_SECURE, the array has a second item indicating the level of
  466. * security - a value from the STATE_SECURE_* enumeration.
  467. *
  468. * STATE_IS_BROKEN is returned if any errors occur, and STATE_IS_INSECURE is
  469. * returned for disconnected sockets.
  470. */
  471. CBSConnection.prototype.getSecurityState =
  472. function bc_getsecuritystate()
  473. {
  474. if (!this.isConnected || !this._transport.securityInfo)
  475. return [STATE_IS_INSECURE];
  476. try
  477. {
  478. var sslSp = Components.interfaces.nsISSLStatusProvider;
  479. var sslStatus = Components.interfaces.nsISSLStatus;
  480. // Get the actual SSL Status
  481. sslSp = this._transport.securityInfo.QueryInterface(sslSp);
  482. sslStatus = sslSp.SSLStatus.QueryInterface(sslStatus);
  483. // Store appropriate status
  484. if (!("keyLength" in sslStatus) || !sslStatus.keyLength)
  485. return [STATE_IS_BROKEN];
  486. else if (sslStatus.keyLength >= 90)
  487. return [STATE_IS_SECURE, STATE_SECURE_HIGH];
  488. else
  489. return [STATE_IS_SECURE, STATE_SECURE_LOW];
  490. }
  491. catch (ex)
  492. {
  493. // Something goes wrong -> broken security icon
  494. dd("Exception getting certificate for connection: " + ex.message);
  495. return [STATE_IS_BROKEN];
  496. }
  497. }
  498. CBSConnection.prototype.getCertificate =
  499. function bc_getcertificate()
  500. {
  501. if (!this.isConnected || !this._transport.securityInfo)
  502. return null;
  503. var sslSp = Components.interfaces.nsISSLStatusProvider;
  504. var sslStatus = Components.interfaces.nsISSLStatus;
  505. // Get the actual SSL Status
  506. sslSp = this._transport.securityInfo.QueryInterface(sslSp);
  507. sslStatus = sslSp.SSLStatus.QueryInterface(sslStatus);
  508. // return the certificate
  509. return sslStatus.serverCert;
  510. }
  511. function _notimpl ()
  512. {
  513. throw "Not Implemented.";
  514. }
  515. if (!jsenv.HAS_NSPR_EVENTQ)
  516. {
  517. CBSConnection.prototype.startAsyncRead = _notimpl;
  518. CBSConnection.prototype.asyncWrite = _notimpl;
  519. }
  520. else if (jsenv.HAS_STREAM_PROVIDER)
  521. {
  522. CBSConnection.prototype.sendDataNow = _notimpl;
  523. }
  524. else
  525. {
  526. CBSConnection.prototype.asyncWrite = _notimpl;
  527. }
  528. delete _notimpl;
  529. function StreamProvider(observer)
  530. {
  531. this._observer = observer;
  532. }
  533. StreamProvider.prototype.pendingData = "";
  534. StreamProvider.prototype.isBlocked = true;
  535. StreamProvider.prototype.close =
  536. function sp_close ()
  537. {
  538. this.isClosed = true;
  539. }
  540. StreamProvider.prototype.onDataWritable =
  541. function sp_datawrite (request, ctxt, ostream, offset, count)
  542. {
  543. //dd ("StreamProvider.prototype.onDataWritable");
  544. if ("isClosed" in this && this.isClosed)
  545. throw Components.results.NS_BASE_STREAM_CLOSED;
  546. if (!this.pendingData)
  547. {
  548. this.isBlocked = true;
  549. /* this is here to support pre-XPCDOM builds (0.9.0 era), which
  550. * don't have this result code mapped. */
  551. if (!Components.results.NS_BASE_STREAM_WOULD_BLOCK)
  552. throw 2152136711;
  553. throw Components.results.NS_BASE_STREAM_WOULD_BLOCK;
  554. }
  555. var len = ostream.write (this.pendingData, this.pendingData.length);
  556. this.pendingData = this.pendingData.substr (len);
  557. }
  558. StreamProvider.prototype.onStartRequest =
  559. function sp_startreq (request, ctxt)
  560. {
  561. //dd ("StreamProvider::onStartRequest: " + request + ", " + ctxt);
  562. }
  563. StreamProvider.prototype.onStopRequest =
  564. function sp_stopreq (request, ctxt, status)
  565. {
  566. //dd ("StreamProvider::onStopRequest: " + request + ", " + ctxt + ", " +
  567. // status);
  568. if (this._observer)
  569. this._observer.onStreamClose(status);
  570. }
  571. function StreamListener(observer)
  572. {
  573. this._observer = observer;
  574. }
  575. StreamListener.prototype.onStartRequest =
  576. function sl_startreq (request, ctxt)
  577. {
  578. //dd ("StreamListener::onStartRequest: " + request + ", " + ctxt);
  579. }
  580. StreamListener.prototype.onStopRequest =
  581. function sl_stopreq (request, ctxt, status)
  582. {
  583. //dd ("StreamListener::onStopRequest: " + request + ", " + ctxt + ", " +
  584. //status);
  585. if (this._observer)
  586. this._observer.onStreamClose(status);
  587. }
  588. StreamListener.prototype.onDataAvailable =
  589. function sl_dataavail (request, ctxt, inStr, sourceOffset, count)
  590. {
  591. ctxt = ctxt.wrappedJSObject;
  592. if (!ctxt)
  593. {
  594. dd ("*** Can't get wrappedJSObject from ctxt in " +
  595. "StreamListener.onDataAvailable ***");
  596. return;
  597. }
  598. if (!("_sInputStream" in ctxt))
  599. ctxt._sInputStream = toSInputStream(inStr, false);
  600. if (this._observer)
  601. this._observer.onStreamDataAvailable(request, inStr, sourceOffset,
  602. count);
  603. }
  604. function SocketListener(connection, observer)
  605. {
  606. this._connection = connection;
  607. this._observer = observer;
  608. }
  609. SocketListener.prototype.onSocketAccepted =
  610. function sl_onSocketAccepted(socket, transport)
  611. {
  612. this._observer.onSocketAccepted(socket, transport);
  613. }
  614. SocketListener.prototype.onStopListening =
  615. function sl_onStopListening(socket, status)
  616. {
  617. delete this._connection._serverSockListener;
  618. delete this._connection._serverSock;
  619. }