nsIWebSocketChannel.idl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. interface nsIURI;
  6. interface nsIInterfaceRequestor;
  7. interface nsILoadGroup;
  8. interface nsIWebSocketListener;
  9. interface nsIInputStream;
  10. interface nsILoadInfo;
  11. interface nsIDOMNode;
  12. interface nsIPrincipal;
  13. interface nsITransportProvider;
  14. #include "nsISupports.idl"
  15. /**
  16. * Low-level websocket API: handles network protocol.
  17. *
  18. * This is primarly intended for use by the higher-level nsIWebSocket.idl.
  19. * We are also making it scriptable for now, but this may change once we have
  20. * WebSockets for Workers.
  21. */
  22. [scriptable, uuid(ce71d028-322a-4105-a947-a894689b52bf)]
  23. interface nsIWebSocketChannel : nsISupports
  24. {
  25. /**
  26. * The original URI used to construct the protocol connection. This is used
  27. * in the case of a redirect or URI "resolution" (e.g. resolving a
  28. * resource: URI to a file: URI) so that the original pre-redirect
  29. * URI can still be obtained. This is never null.
  30. */
  31. readonly attribute nsIURI originalURI;
  32. /**
  33. * The readonly URI corresponding to the protocol connection after any
  34. * redirections are completed.
  35. */
  36. readonly attribute nsIURI URI;
  37. /**
  38. * The notification callbacks for authorization, etc..
  39. */
  40. attribute nsIInterfaceRequestor notificationCallbacks;
  41. /**
  42. * Transport-level security information (if any)
  43. */
  44. readonly attribute nsISupports securityInfo;
  45. /**
  46. * The load group of of the websocket
  47. */
  48. attribute nsILoadGroup loadGroup;
  49. /**
  50. * The load info of the websocket
  51. */
  52. attribute nsILoadInfo loadInfo;
  53. /**
  54. * Sec-Websocket-Protocol value
  55. */
  56. attribute ACString protocol;
  57. /**
  58. * Sec-Websocket-Extensions response header value
  59. */
  60. readonly attribute ACString extensions;
  61. /**
  62. * Init the WebSocketChannel with LoadInfo arguments.
  63. * @param aLoadingNode
  64. * @param aLoadingPrincipal
  65. * @param aTriggeringPrincipal
  66. * @param aSecurityFlags
  67. * @param aContentPolicyType
  68. * These will be used as values for the nsILoadInfo object on the
  69. * created channel. For details, see nsILoadInfo in nsILoadInfo.idl
  70. * @return reference to the new nsIChannel object
  71. *
  72. * Keep in mind that URIs coming from a webpage should *never* use the
  73. * systemPrincipal as the loadingPrincipal.
  74. *
  75. * Please note, if you provide both a loadingNode and a loadingPrincipal,
  76. * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
  77. * But less error prone is to just supply a loadingNode.
  78. */
  79. void initLoadInfo(in nsIDOMNode aLoadingNode,
  80. in nsIPrincipal aLoadingPrincipal,
  81. in nsIPrincipal aTriggeringPrincipal,
  82. in unsigned long aSecurityFlags,
  83. in unsigned long aContentPolicyType);
  84. /**
  85. * Asynchronously open the websocket connection. Received messages are fed
  86. * to the socket listener as they arrive. The socket listener's methods
  87. * are called on the thread that calls asyncOpen and are not called until
  88. * after asyncOpen returns. If asyncOpen returns successfully, the
  89. * protocol implementation promises to call at least onStop on the listener.
  90. *
  91. * NOTE: Implementations should throw NS_ERROR_ALREADY_OPENED if the
  92. * websocket connection is reopened.
  93. *
  94. * @param aURI the uri of the websocket protocol - may be redirected
  95. * @param aOrigin the uri of the originating resource
  96. * @param aInnerWindowID the inner window ID
  97. * @param aListener the nsIWebSocketListener implementation
  98. * @param aContext an opaque parameter forwarded to aListener's methods
  99. */
  100. void asyncOpen(in nsIURI aURI,
  101. in ACString aOrigin,
  102. in unsigned long long aInnerWindowID,
  103. in nsIWebSocketListener aListener,
  104. in nsISupports aContext);
  105. /*
  106. * Close the websocket connection for writing - no more calls to sendMsg
  107. * or sendBinaryMsg should be made after calling this. The listener object
  108. * may receive more messages if a server close has not yet been received.
  109. *
  110. * @param aCode the websocket closing handshake close code. Set to 0 if
  111. * you are not providing a code.
  112. * @param aReason the websocket closing handshake close reason
  113. */
  114. void close(in unsigned short aCode, in AUTF8String aReason);
  115. // section 7.4.1 defines these close codes
  116. const unsigned short CLOSE_NORMAL = 1000;
  117. const unsigned short CLOSE_GOING_AWAY = 1001;
  118. const unsigned short CLOSE_PROTOCOL_ERROR = 1002;
  119. const unsigned short CLOSE_UNSUPPORTED_DATATYPE = 1003;
  120. // code 1004 is reserved
  121. const unsigned short CLOSE_NO_STATUS = 1005;
  122. const unsigned short CLOSE_ABNORMAL = 1006;
  123. const unsigned short CLOSE_INVALID_PAYLOAD = 1007;
  124. const unsigned short CLOSE_POLICY_VIOLATION = 1008;
  125. const unsigned short CLOSE_TOO_LARGE = 1009;
  126. const unsigned short CLOSE_EXTENSION_MISSING = 1010;
  127. // Initially used just for server-side internal errors: adopted later for
  128. // client-side errors too (not clear if will make into spec: see
  129. // http://www.ietf.org/mail-archive/web/hybi/current/msg09372.html
  130. const unsigned short CLOSE_INTERNAL_ERROR = 1011;
  131. // MUST NOT be set as a status code in Close control frame by an endpoint:
  132. // To be used if TLS handshake failed (ex: server certificate unverifiable)
  133. const unsigned short CLOSE_TLS_FAILED = 1015;
  134. /**
  135. * Use to send text message down the connection to WebSocket peer.
  136. *
  137. * @param aMsg the utf8 string to send
  138. */
  139. void sendMsg(in AUTF8String aMsg);
  140. /**
  141. * Use to send binary message down the connection to WebSocket peer.
  142. *
  143. * @param aMsg the data to send
  144. */
  145. void sendBinaryMsg(in ACString aMsg);
  146. /**
  147. * Use to send a binary stream (Blob) to Websocket peer.
  148. *
  149. * @param aStream The input stream to be sent.
  150. */
  151. void sendBinaryStream(in nsIInputStream aStream,
  152. in unsigned long length);
  153. /**
  154. * This value determines how often (in seconds) websocket keepalive
  155. * pings are sent. If set to 0 (the default), no pings are ever sent.
  156. *
  157. * This value can currently only be set before asyncOpen is called, else
  158. * NS_ERROR_IN_PROGRESS is thrown.
  159. *
  160. * Be careful using this setting: ping traffic can consume lots of power and
  161. * bandwidth over time.
  162. */
  163. attribute unsigned long pingInterval;
  164. /**
  165. * This value determines how long (in seconds) the websocket waits for
  166. * the server to reply to a ping that has been sent before considering the
  167. * connection broken.
  168. *
  169. * This value can currently only be set before asyncOpen is called, else
  170. * NS_ERROR_IN_PROGRESS is thrown.
  171. */
  172. attribute unsigned long pingTimeout;
  173. /**
  174. * Unique ID for this channel. It's not readonly because when the channel is
  175. * created via IPC, the serial number is received from the child process.
  176. */
  177. attribute unsigned long serial;
  178. /**
  179. * Set a nsITransportProvider and negotated extensions to be used by this
  180. * channel. Calling this function also means that this channel will
  181. * implement the server-side part of a websocket connection rather than the
  182. * client-side part.
  183. */
  184. void setServerParameters(in nsITransportProvider aProvider,
  185. in ACString aNegotiatedExtensions);
  186. %{C++
  187. inline uint32_t Serial()
  188. {
  189. uint32_t serial;
  190. nsresult rv = GetSerial(&serial);
  191. if (NS_WARN_IF(NS_FAILED(rv))) {
  192. return 0;
  193. }
  194. return serial;
  195. }
  196. %}
  197. };