One more round of extensions code ifdefing in profiles code.
[chromium-blink-merge.git] / chrome / common / extensions / api / cast_channel.idl
blob9ea213688ffb296efffcf9ec462597d33405c6a7
1 // Copyright 2013 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 {
9 // The state of the channel.
10 enum ReadyState {
11 // The channel is connecting.
12 connecting,
13 // The channel is open and available for messaging.
14 open,
15 // The channel is closing.
16 closing,
17 // The channel is closed.
18 closed
21 // Error conditions that the channel may encounter. All error conditions
22 // are terminal. When an error condition is encountered the API will:
23 // (1) Transition the channel to readyState == 'closed'.
24 // (2) Set ChannelInfo.lastError to the error condition.
25 // (3) Fire an onError event with the error condition.
26 // (4) Fire an onClose event.
27 enum ChannelError {
28 // cast.channel.send() was called when ChannelInfo.readyState != 'open'.
29 channel_not_open,
30 // Authentication was requested and the receiver could not be
31 // authenticated (invalid signature, invalid handhake, TLS error, etc.)
32 authentication_error,
33 // A new channel could not be created for reasons unrelated to
34 // authentication (e.g., there is already an open channel to the same URL).
35 connect_error,
36 // There was an error writing or reading from the underlying socket.
37 socket_error,
38 // A transport level occurred (like an unparseable message).
39 transport_error,
40 // The client attempted to send an unsupported message type through the
41 // channel.
42 invalid_message,
43 // An invalid channel id was passed.
44 invalid_channel_id,
45 // The connection could not be established before timing out.
46 connect_timeout,
47 // Unspecified error.
48 unknown
51 // Authentication methods that may be required to connect to a Cast receiver.
52 enum ChannelAuthType {
53 // SSL over TCP.
54 ssl,
55 // SSL over TCP with challenge and receiver signature verification.
56 ssl_verified
59 // Describes the information needed to connect to a Cast receiver.
60 // This replaces the prior use of cast:// and casts:// URLs.
61 dictionary ConnectInfo {
62 // The IPV4 address of the Cast receiver, e.g. '198.1.0.2'.
63 // TODO(mfoltz): Investigate whether IPV6 addresses "just work."
64 DOMString ipAddress;
66 // The port number to connect to, 0-65535.
67 long port;
69 // The amount of time to wait in milliseconds before stopping the
70 // connection process. Timeouts are disabled if the value is zero.
71 // The default timeout is 8000ms.
72 long? timeout;
74 // The authentication method required for the channel.
75 ChannelAuthType auth;
78 // Describes the state of a channel to a Cast receiver.
79 dictionary ChannelInfo {
80 // Id for the channel.
81 long channelId;
83 // DEPRECATED: The URL to the receiver. This field will be removed in a
84 // future release.
85 DOMString url;
87 // Connection information that was used to establish the channel to the
88 // receiver.
89 ConnectInfo connectInfo;
91 // The current state of the channel.
92 ReadyState readyState;
94 // If set, the last error condition encountered by the channel.
95 ChannelError? errorState;
98 // Describes a message sent or received over the channel. Currently only
99 // string messages are supported, although ArrayBuffer and Blob types may be
100 // supported in the future.
101 dictionary MessageInfo {
102 // The message namespace. A namespace is a URN of the form
103 // urn:cast-x:<namespace> that is used to interpret and route Cast messages.
104 DOMString namespace_;
106 // source and destination ids identify the origin and destination of the
107 // message. They are used to route messages between endpoints that share a
108 // device-to-device channel.
110 // For messages between applications:
111 // - The sender application id is a unique identifier generated on behalf
112 // of the sender application.
113 // - The receiver id is always the the session id for the application.
115 // For messages to or from the sender or receiver platform, the special ids
116 // 'sender-0' and 'receiver-0' can be used.
118 // For messages intended for all endpoints using a given channel, the
119 // wildcard destination_id '*' can be used.
120 DOMString sourceId;
121 DOMString destinationId;
123 // The content of the message. Must be either a string or an ArrayBuffer.
124 any data;
127 // Callback holding the result of a channel operation.
128 callback ChannelInfoCallback = void (ChannelInfo result);
130 interface Functions {
131 // Opens a new channel to the Cast receiver specified by connectInfo. Only
132 // one channel may be connected to same receiver from the same extension at
133 // a time. If the open request is successful, the callback will be invoked
134 // with a ChannelInfo with readyState == 'connecting'. If unsuccessful, the
135 // callback will be invoked with a ChannelInfo with channel.readyState ==
136 // 'closed' and channel.errorState will be set to the error condition.
138 // TODO(mfoltz): Convert 'any' to ConnectInfo once all clients are updated
139 // to not send URLs.
140 static void open(any connectInfo,
141 ChannelInfoCallback callback);
143 // Sends a message on the channel and invokes callback with the resulting
144 // channel status. The channel must be in readyState == 'open'. If
145 // unsuccessful, channel.readyState will be set to 'closed',
146 // channel.errorState will be set to the error condition.
147 static void send(ChannelInfo channel,
148 MessageInfo message,
149 ChannelInfoCallback callback);
151 // Requests that the channel be closed and invokes callback with the
152 // resulting channel status. The channel must be in readyState == 'open' or
153 // 'connecting'. If successful, onClose will be fired with readyState ==
154 // 'closed'. If unsuccessful, channel.readyState will be set to 'closed',
155 // and channel.errorState will be set to the error condition.
156 static void close(ChannelInfo channel,
157 ChannelInfoCallback callback);
160 // Events on the channel.
161 interface Events {
162 // Fired when a message is received on an open channel.
163 static void onMessage(ChannelInfo channel,
164 MessageInfo message);
166 // Fired when an error occurs as a result of a channel method or a network
167 // event.
168 static void onError(ChannelInfo channel);