Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim: set sw=4 ts=4 et tw=80 : */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | interface nsIURI; |
michael@0 | 8 | interface nsIInterfaceRequestor; |
michael@0 | 9 | interface nsILoadGroup; |
michael@0 | 10 | interface nsIWebSocketListener; |
michael@0 | 11 | interface nsIInputStream; |
michael@0 | 12 | |
michael@0 | 13 | #include "nsISupports.idl" |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Low-level websocket API: handles network protocol. |
michael@0 | 17 | * |
michael@0 | 18 | * This is primarly intended for use by the higher-level nsIWebSocket.idl. |
michael@0 | 19 | * We are also making it scriptable for now, but this may change once we have |
michael@0 | 20 | * WebSockets for Workers. |
michael@0 | 21 | */ |
michael@0 | 22 | [scriptable, uuid(9ee5874c-ec39-4bc2-b2d7-194a4c98c9d2)] |
michael@0 | 23 | interface nsIWebSocketChannel : nsISupports |
michael@0 | 24 | { |
michael@0 | 25 | /** |
michael@0 | 26 | * The original URI used to construct the protocol connection. This is used |
michael@0 | 27 | * in the case of a redirect or URI "resolution" (e.g. resolving a |
michael@0 | 28 | * resource: URI to a file: URI) so that the original pre-redirect |
michael@0 | 29 | * URI can still be obtained. This is never null. |
michael@0 | 30 | */ |
michael@0 | 31 | readonly attribute nsIURI originalURI; |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * The readonly URI corresponding to the protocol connection after any |
michael@0 | 35 | * redirections are completed. |
michael@0 | 36 | */ |
michael@0 | 37 | readonly attribute nsIURI URI; |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * The notification callbacks for authorization, etc.. |
michael@0 | 41 | */ |
michael@0 | 42 | attribute nsIInterfaceRequestor notificationCallbacks; |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Transport-level security information (if any) |
michael@0 | 46 | */ |
michael@0 | 47 | readonly attribute nsISupports securityInfo; |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * The load group of the websockets code. |
michael@0 | 51 | */ |
michael@0 | 52 | attribute nsILoadGroup loadGroup; |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Sec-Websocket-Protocol value |
michael@0 | 56 | */ |
michael@0 | 57 | attribute ACString protocol; |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Sec-Websocket-Extensions response header value |
michael@0 | 61 | */ |
michael@0 | 62 | readonly attribute ACString extensions; |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Asynchronously open the websocket connection. Received messages are fed |
michael@0 | 66 | * to the socket listener as they arrive. The socket listener's methods |
michael@0 | 67 | * are called on the thread that calls asyncOpen and are not called until |
michael@0 | 68 | * after asyncOpen returns. If asyncOpen returns successfully, the |
michael@0 | 69 | * protocol implementation promises to call at least onStop on the listener. |
michael@0 | 70 | * |
michael@0 | 71 | * NOTE: Implementations should throw NS_ERROR_ALREADY_OPENED if the |
michael@0 | 72 | * websocket connection is reopened. |
michael@0 | 73 | * |
michael@0 | 74 | * @param aURI the uri of the websocket protocol - may be redirected |
michael@0 | 75 | * @param aOrigin the uri of the originating resource |
michael@0 | 76 | * @param aListener the nsIWebSocketListener implementation |
michael@0 | 77 | * @param aContext an opaque parameter forwarded to aListener's methods |
michael@0 | 78 | */ |
michael@0 | 79 | void asyncOpen(in nsIURI aURI, |
michael@0 | 80 | in ACString aOrigin, |
michael@0 | 81 | in nsIWebSocketListener aListener, |
michael@0 | 82 | in nsISupports aContext); |
michael@0 | 83 | |
michael@0 | 84 | /* |
michael@0 | 85 | * Close the websocket connection for writing - no more calls to sendMsg |
michael@0 | 86 | * or sendBinaryMsg should be made after calling this. The listener object |
michael@0 | 87 | * may receive more messages if a server close has not yet been received. |
michael@0 | 88 | * |
michael@0 | 89 | * @param aCode the websocket closing handshake close code. Set to 0 if |
michael@0 | 90 | * you are not providing a code. |
michael@0 | 91 | * @param aReason the websocket closing handshake close reason |
michael@0 | 92 | */ |
michael@0 | 93 | void close(in unsigned short aCode, in AUTF8String aReason); |
michael@0 | 94 | |
michael@0 | 95 | // section 7.4.1 defines these close codes |
michael@0 | 96 | const unsigned short CLOSE_NORMAL = 1000; |
michael@0 | 97 | const unsigned short CLOSE_GOING_AWAY = 1001; |
michael@0 | 98 | const unsigned short CLOSE_PROTOCOL_ERROR = 1002; |
michael@0 | 99 | const unsigned short CLOSE_UNSUPPORTED_DATATYPE = 1003; |
michael@0 | 100 | // code 1004 is reserved |
michael@0 | 101 | const unsigned short CLOSE_NO_STATUS = 1005; |
michael@0 | 102 | const unsigned short CLOSE_ABNORMAL = 1006; |
michael@0 | 103 | const unsigned short CLOSE_INVALID_PAYLOAD = 1007; |
michael@0 | 104 | const unsigned short CLOSE_POLICY_VIOLATION = 1008; |
michael@0 | 105 | const unsigned short CLOSE_TOO_LARGE = 1009; |
michael@0 | 106 | const unsigned short CLOSE_EXTENSION_MISSING = 1010; |
michael@0 | 107 | // Initially used just for server-side internal errors: adopted later for |
michael@0 | 108 | // client-side errors too (not clear if will make into spec: see |
michael@0 | 109 | // http://www.ietf.org/mail-archive/web/hybi/current/msg09372.html |
michael@0 | 110 | const unsigned short CLOSE_INTERNAL_ERROR = 1011; |
michael@0 | 111 | // MUST NOT be set as a status code in Close control frame by an endpoint: |
michael@0 | 112 | // To be used if TLS handshake failed (ex: server certificate unverifiable) |
michael@0 | 113 | const unsigned short CLOSE_TLS_FAILED = 1015; |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Use to send text message down the connection to WebSocket peer. |
michael@0 | 117 | * |
michael@0 | 118 | * @param aMsg the utf8 string to send |
michael@0 | 119 | */ |
michael@0 | 120 | void sendMsg(in AUTF8String aMsg); |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * Use to send binary message down the connection to WebSocket peer. |
michael@0 | 124 | * |
michael@0 | 125 | * @param aMsg the data to send |
michael@0 | 126 | */ |
michael@0 | 127 | void sendBinaryMsg(in ACString aMsg); |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Use to send a binary stream (Blob) to Websocket peer. |
michael@0 | 131 | * |
michael@0 | 132 | * @param aStream The input stream to be sent. |
michael@0 | 133 | */ |
michael@0 | 134 | void sendBinaryStream(in nsIInputStream aStream, |
michael@0 | 135 | in unsigned long length); |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * This value determines how often (in seconds) websocket keepalive |
michael@0 | 139 | * pings are sent. If set to 0 (the default), no pings are ever sent. |
michael@0 | 140 | * |
michael@0 | 141 | * This value can currently only be set before asyncOpen is called, else |
michael@0 | 142 | * NS_ERROR_IN_PROGRESS is thrown. |
michael@0 | 143 | * |
michael@0 | 144 | * Be careful using this setting: ping traffic can consume lots of power and |
michael@0 | 145 | * bandwidth over time. |
michael@0 | 146 | */ |
michael@0 | 147 | attribute unsigned long pingInterval; |
michael@0 | 148 | |
michael@0 | 149 | /** |
michael@0 | 150 | * This value determines how long (in seconds) the websocket waits for |
michael@0 | 151 | * the server to reply to a ping that has been sent before considering the |
michael@0 | 152 | * connection broken. |
michael@0 | 153 | * |
michael@0 | 154 | * This value can currently only be set before asyncOpen is called, else |
michael@0 | 155 | * NS_ERROR_IN_PROGRESS is thrown. |
michael@0 | 156 | */ |
michael@0 | 157 | attribute unsigned long pingTimeout; |
michael@0 | 158 | |
michael@0 | 159 | }; |