Roll src/third_party/WebKit b3f094a:f697bbd (svn 194310:194313)
[chromium-blink-merge.git] / extensions / common / api / cast_channel.idl
blob003e3884c8efec821c1fb2040e8e34a032c8531c
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // API for communicating with a Google Cast device over an authenticated
6 // channel.
7 namespace cast.channel {
8 // The state of the channel.
9 enum ReadyState {
10 // The channel is connecting.
11 connecting,
12 // The channel is open and available for messaging.
13 open,
14 // The channel is closing.
15 closing,
16 // The channel is closed.
17 closed
20 // Error conditions that the channel may encounter. All error conditions
21 // are terminal. When an error condition is encountered the API will:
22 // (1) Transition the channel to readyState == 'closed'.
23 // (2) Set ChannelInfo.lastError to the error condition.
24 // (3) Fire an onError event with the error condition.
25 // (4) Fire an onClose event.
26 enum ChannelError {
27 // cast.channel.send() was called when ChannelInfo.readyState != 'open'.
28 channel_not_open,
29 // Authentication was requested and the receiver could not be
30 // authenticated (invalid signature, invalid handhake, TLS error, etc.)
31 authentication_error,
32 // A new channel could not be created for reasons unrelated to
33 // authentication (e.g., there is already an open channel to the same URL).
34 connect_error,
35 // There was an error writing or reading from the underlying socket.
36 socket_error,
37 // A transport level occurred (like an unparseable message).
38 transport_error,
39 // The client attempted to send an unsupported message type through the
40 // channel.
41 invalid_message,
42 // An invalid channel id was passed.
43 invalid_channel_id,
44 // The connection could not be established before timing out.
45 connect_timeout,
46 // The receiving end became unresponsive.
47 ping_timeout,
48 // Unspecified error.
49 unknown
52 // Authentication methods that may be required to connect to a Cast receiver.
53 enum ChannelAuthType {
54 // SSL over TCP.
55 ssl,
56 // SSL over TCP with challenge and receiver signature verification.
57 ssl_verified
60 // Describes the information needed to connect to a Cast receiver.
61 // This replaces the prior use of cast:// and casts:// URLs.
62 dictionary ConnectInfo {
63 // The IPV4 address of the Cast receiver, e.g. '198.1.0.2'.
64 // TODO(mfoltz): Investigate whether IPV6 addresses "just work."
65 DOMString ipAddress;
67 // The port number to connect to, 0-65535.
68 long port;
70 // The amount of time to wait in milliseconds before stopping the
71 // connection process. Timeouts are disabled if the value is zero.
72 // The default timeout is 8000ms.
73 long? timeout;
75 // The authentication method required for the channel.
76 ChannelAuthType auth;
78 // ------------------------------------------------------------------------
79 // Both pingInterval and livenessTimeout must be set to enable keep-alive
80 // handling.
82 // The amount of time to wait in milliseconds before sending pings
83 // to idle channels.
84 long? pingInterval;
86 // The maximum amount of idle time allowed before a channel is closed.
87 long? livenessTimeout;
89 // If set, CastDeviceCapability bitmask values describing capability of the
90 // cast device.
91 long? capabilities;
94 // Describes the state of a channel to a Cast receiver.
95 dictionary ChannelInfo {
96 // Id for the channel.
97 long channelId;
99 // DEPRECATED: The URL to the receiver. This field will be removed in a
100 // future release.
101 DOMString url;
103 // Connection information that was used to establish the channel to the
104 // receiver.
105 ConnectInfo connectInfo;
107 // The current state of the channel.
108 ReadyState readyState;
110 // If set, the last error condition encountered by the channel.
111 ChannelError? errorState;
113 // If true, keep-alive messages are handled automatically by the channel.
114 boolean keepAlive;
117 // Describes a message sent or received over the channel. Currently only
118 // string messages are supported, although ArrayBuffer and Blob types may be
119 // supported in the future.
120 dictionary MessageInfo {
121 // The message namespace. A namespace is a URN of the form
122 // urn:cast-x:<namespace> that is used to interpret and route Cast messages.
123 DOMString namespace_;
125 // source and destination ids identify the origin and destination of the
126 // message. They are used to route messages between endpoints that share a
127 // device-to-device channel.
129 // For messages between applications:
130 // - The sender application id is a unique identifier generated on behalf
131 // of the sender application.
132 // - The receiver id is always the the session id for the application.
134 // For messages to or from the sender or receiver platform, the special ids
135 // 'sender-0' and 'receiver-0' can be used.
137 // For messages intended for all endpoints using a given channel, the
138 // wildcard destination_id '*' can be used.
139 DOMString sourceId;
140 DOMString destinationId;
142 // The content of the message. Must be either a string or an ArrayBuffer.
143 any data;
146 // Describes a terminal error encountered by the channel with details of the
147 // error that caused the channel to be closed. One or more of the optional
148 // fields may be set with specific error codes from the underlying
149 // implementation.
150 dictionary ErrorInfo {
151 // The type of error encountered by the channel.
152 ChannelError errorState;
154 // The event that was occurring when the error happened. Values are defined
155 // in the enum EventType in logging.proto.
156 long? eventType;
158 // An error encountered when processing the authentication handshake.
159 // Values are defined in the enum ChallengeReplyErrorType in logging.proto.
160 long? challengeReplyErrorType;
162 // A return value from the underlying net:: socket libraries. Values are
163 // defined in net/base/net_error_list.h.
164 long? netReturnValue;
166 // An error code returned by NSS. Values are defined in secerr.h.
167 long? nssErrorCode;
170 // Callback holding the result of a channel operation.
171 callback ChannelInfoCallback = void (ChannelInfo result);
173 // Callback from <code>getLogs</code> method.
174 // |log|: compressed serialized raw bytes containing the logs.
175 // The log is formatted using protocol buffer.
176 // See extensions/browser/api/cast_channel/logging.proto for definition.
177 // Compression is in gzip format.
178 callback GetLogsCallback = void (ArrayBuffer log);
180 // Callback from <code>setAuthorityKeys</code> method.
181 callback SetAuthorityKeysCallback = void ();
183 interface Functions {
184 // Opens a new channel to the Cast receiver specified by connectInfo. Only
185 // one channel may be connected to same receiver from the same extension at
186 // a time. If the open request is successful, the callback will be invoked
187 // with a ChannelInfo with readyState == 'connecting'. If unsuccessful, the
188 // callback will be invoked with a ChannelInfo with channel.readyState ==
189 // 'closed', channel.errorState will be set to the error condition, and
190 // onError will be fired with error details.
192 // TODO(mfoltz): Convert 'any' to ConnectInfo once all clients are updated
193 // to not send URLs.
194 static void open(any connectInfo,
195 ChannelInfoCallback callback);
197 // Sends a message on the channel and invokes callback with the resulting
198 // channel status. The channel must be in readyState == 'open'. If
199 // unsuccessful, channel.readyState will be set to 'closed',
200 // channel.errorState will be set to the error condition, and onError will
201 // be fired with error details.
202 static void send(ChannelInfo channel,
203 MessageInfo message,
204 ChannelInfoCallback callback);
206 // Requests that the channel be closed and invokes callback with the
207 // resulting channel status. The channel must be in readyState == 'open' or
208 // 'connecting'. If successful, onClose will be fired with readyState ==
209 // 'closed'. If unsuccessful, channel.readyState will be set to 'closed',
210 // and channel.errorState will be set to the error condition.
211 static void close(ChannelInfo channel,
212 ChannelInfoCallback callback);
214 // Get logs in compressed serialized format. See GetLogsCallback for
215 // details.
216 // |callback|: If successful, |callback| is invoked with data. Otherwise,
217 // an error will be raised.
218 static void getLogs(GetLogsCallback callback);
220 // Sets trusted certificate authorities where |signature| is a base64
221 // encoded RSA-PSS signature and |keys| is base64 encoded AuthorityKeys
222 // protobuf.
223 static void setAuthorityKeys(DOMString keys,
224 DOMString signature,
225 SetAuthorityKeysCallback callback);
228 // Events on the channel.
229 interface Events {
230 // Fired when a message is received on an open channel.
231 static void onMessage(ChannelInfo channel,
232 MessageInfo message);
234 // Fired when an error occurs as a result of a channel operation or a
235 // network event. |error| contains details of the error.
236 static void onError(ChannelInfo channel, ErrorInfo error);