OLD | NEW |
| (Empty) |
1 // Copyright 2015 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. | |
4 | |
5 module media_router.mojom; | |
6 | |
7 import "chrome/browser/media/router/mojo/media_controller.mojom"; | |
8 import "chrome/browser/media/router/mojo/media_status.mojom"; | |
9 import "mojo/common/time.mojom"; | |
10 import "net/interfaces/ip_address.mojom"; | |
11 import "url/mojo/origin.mojom"; | |
12 import "url/mojo/url.mojom"; | |
13 | |
14 // Represents an output sink to which media can be routed. | |
15 struct MediaSink { | |
16 enum IconType { | |
17 CAST, | |
18 CAST_AUDIO, | |
19 CAST_AUDIO_GROUP, | |
20 MEETING, | |
21 HANGOUT, | |
22 GENERIC | |
23 }; | |
24 | |
25 // The sink identifier, e.g. "rs71w7mFzYLFlabir_qO4NHl6SUc." | |
26 string sink_id; | |
27 // The human-readable name, e.g. "Janet's Chromecast". | |
28 string name; | |
29 // Optional description of the sink. | |
30 string? description; | |
31 // Optional domain of the sink if this sink is associated with an identity. | |
32 string? domain; | |
33 // The type of icon to show in the UI for this media sink. | |
34 IconType icon_type; | |
35 // This is currently only set by MediaRouter in OnSinksDiscovered(). | |
36 MediaSinkExtraData? extra_data; | |
37 }; | |
38 | |
39 union MediaSinkExtraData { | |
40 DialMediaSink dial_media_sink; | |
41 CastMediaSink cast_media_sink; | |
42 }; | |
43 | |
44 struct DialMediaSink { | |
45 net.interfaces.IPAddress ip_address; | |
46 | |
47 // Model name of the sink, if it represents a physical device. | |
48 string model_name; | |
49 | |
50 // Used for DIAL launch | |
51 url.mojom.Url app_url; | |
52 }; | |
53 | |
54 struct CastMediaSink { | |
55 net.interfaces.IPAddress ip_address; | |
56 | |
57 // Model name of the sink, if it represents a physical device. | |
58 string model_name; | |
59 | |
60 // A bit vector representing capabilities of the sink. Meaning of capacity | |
61 // value for each bit: | |
62 // NONE: 0, | |
63 // VIDEO_OUT: 1 << 0, | |
64 // VIDEO_IN: 1 << 1, | |
65 // AUDIO_OUT: 1 << 2, | |
66 // AUDIO_IN: 1 << 3, | |
67 // DEV_MODE: 1 << 4, | |
68 // MULTIZONE_GROUP: 1 << 5 | |
69 uint8 capabilities; | |
70 | |
71 // ID of Cast channel opened by Media Router. The ID is defined by the | |
72 // chrome.cast.channel API. | |
73 int32 cast_channel_id; | |
74 }; | |
75 | |
76 // Should be kept in sync with media_route.h. | |
77 struct MediaRoute { | |
78 // The ID of this media route, e.g. "r_PR1O_blkC9dsKp-tb1ti8qurOo". | |
79 string media_route_id; | |
80 // The ID of the media source being sent through this media route. | |
81 // May be missing if route is not local. | |
82 string? media_source; | |
83 // The ID of sink that is rendering the media content. | |
84 string media_sink_id; | |
85 // Human readable description of this route, e.g. "Tab casting". | |
86 string description; | |
87 // Specifies that the route is requested locally. | |
88 bool is_local; | |
89 // An optional path to an HTML page bundled bundled with the media router | |
90 // component extension. When set, the route can have custom route detail as | |
91 // well as its own route controls in the media router dialog. | |
92 string? custom_controller_path; | |
93 // Set to true if this route should be displayed for |media_sink_id| in UI. | |
94 bool for_display; | |
95 // Set to true if this route was created by an incognito profile. | |
96 bool is_incognito; | |
97 // Set to true if this route corresponds to an offscreen presentation. | |
98 bool is_offscreen_presentation; | |
99 }; | |
100 | |
101 // Notifications or an actionable events to be shown to the user. | |
102 // When is_blocking is true, media router UI shows issue only: | |
103 // | |
104 // Title | |
105 // Message | |
106 // default_action_button secondary_action_button | |
107 // | |
108 // When is_blocking is false, media router UI uses banner: | |
109 // | |
110 // Title default_action_link secondary_action_link | |
111 // | |
112 // above receiver list if route_id is not provided; otherwise it is | |
113 // above route detail and controls. | |
114 struct Issue { | |
115 enum Severity { | |
116 FATAL, | |
117 WARNING, | |
118 NOTIFICATION | |
119 }; | |
120 | |
121 enum ActionType { | |
122 DISMISS, | |
123 LEARN_MORE | |
124 }; | |
125 | |
126 // If set, the ID of the route to which this issue pertains. | |
127 // If not set (default), then this is a global issue. | |
128 string? route_id; | |
129 | |
130 Severity severity; | |
131 | |
132 // When true, the issue must be presented to the user and resolved | |
133 // before other actions are allowed. | |
134 bool is_blocking; | |
135 | |
136 // Short description about the issue. | |
137 string title; | |
138 | |
139 // Message about issue detail or how to handle issue. | |
140 // Messages should be suitable for end users to decide which actions to take. | |
141 string? message; | |
142 | |
143 ActionType default_action; | |
144 | |
145 array<ActionType>? secondary_actions; | |
146 | |
147 // The ID of the help page to be opened if users select learn_more. | |
148 int32 help_page_id; | |
149 }; | |
150 | |
151 struct RouteMessage { | |
152 enum Type { | |
153 TEXT, | |
154 BINARY | |
155 }; | |
156 // The type of this message. | |
157 Type type; | |
158 // Used when the |type| is TEXT. | |
159 string? message; | |
160 // Used when the |type| is BINARY. | |
161 array<uint8>? data; | |
162 }; | |
163 | |
164 struct SinkSearchCriteria { | |
165 // Input to the search method which each Media Route Provider may interpret | |
166 // differently. | |
167 string input; | |
168 // The user's current hosted domain. | |
169 string domain; | |
170 }; | |
171 | |
172 // Keep in sync with: | |
173 // - RouteRequestResult::ResultCode in route_request_result.h | |
174 // - MediaRouteProviderResult enum in tools/metrics/histograms.xml. | |
175 // - mr.RouteRequestResultCode in route_request_error.js | |
176 // - RouteRequestResultCodeFromMojo in media_router_type_converters.cc | |
177 enum RouteRequestResultCode { | |
178 UNKNOWN_ERROR, | |
179 OK, | |
180 TIMED_OUT, | |
181 ROUTE_NOT_FOUND, | |
182 SINK_NOT_FOUND, | |
183 INVALID_ORIGIN, | |
184 INCOGNITO_MISMATCH, | |
185 NO_SUPPORTED_PROVIDER, | |
186 CANCELLED | |
187 // New values must be added here. | |
188 }; | |
189 | |
190 // Modeled after the MediaRouter interface defined in | |
191 // chrome/browser/media/router/media_router.h | |
192 interface MediaRouteProvider { | |
193 // Creates a media route from |media_source| to the sink given by |sink_id|. | |
194 // | |
195 // The presentation ID of the route created will be |presentation_id|, but it | |
196 // may be overridden by a provider implementation. The presentation ID will | |
197 // be used by the presentation API to refer to the created route. | |
198 // | |
199 // |origin| and |tab_id| may be passed in for enforcing same-origin and/or | |
200 // same-tab scopes. Use -1 as |tab_id| in cases where the request is not | |
201 // made on behalf of a tab. | |
202 // | |
203 // If |timeout| is positive, it will be used in place of the default timeout | |
204 // defined by Media Route Provider Manager. | |
205 // | |
206 // If |incognito| is true, the request was made by an incognito profile. | |
207 // | |
208 // If the operation was successful, |route| will be defined and | |
209 // |error_text| will be null. | |
210 // If the operation failed, |route| will be null and |error_text| | |
211 // will be set. | |
212 // |result| will be set to OK if successful, or an error code if an error | |
213 // occurred. | |
214 CreateRoute(string media_source, | |
215 string sink_id, | |
216 string original_presentation_id, | |
217 url.mojom.Origin origin, | |
218 int32 tab_id, | |
219 mojo.common.mojom.TimeDelta timeout, | |
220 bool incognito) => | |
221 (MediaRoute? route, | |
222 string? error_text, | |
223 RouteRequestResultCode result_code); | |
224 | |
225 // Requests a connection to an established route for |media_source| given | |
226 // by |presentation_id|. | |
227 // | |
228 // |origin| and |tab_id| are used for validating same-origin/tab scopes; | |
229 // see CreateRoute for additional documentation. | |
230 // | |
231 // If |timeout| is positive, it will be used in place of the default timeout | |
232 // defined by Media Route Provider Manager. | |
233 // | |
234 // If the route request was created by an incognito profile, | |
235 // |incognito| must be true. | |
236 // | |
237 // If the operation was successful, |route| will be defined and | |
238 // |error_text| will be null. | |
239 // If the operation failed, |route| will be null and |error_text| | |
240 // will be set. | |
241 // |result| will be set to OK if successful, or an error code if an error | |
242 // occurred. | |
243 JoinRoute(string media_source, | |
244 string presentation_id, | |
245 url.mojom.Origin origin, | |
246 int32 tab_id, | |
247 mojo.common.mojom.TimeDelta timeout, | |
248 bool incognito) => | |
249 (MediaRoute? route, | |
250 string? error_text, | |
251 RouteRequestResultCode result_code); | |
252 | |
253 // Creates a new route for |media_source| that connects to the established | |
254 // route given by |route_id|. | |
255 // | |
256 // The presentation ID of the new route will be |presentation_id|, but it may | |
257 // be overridden by a provider implementation. The presentation ID will be | |
258 // used by the presentation API to refer to the created route. | |
259 // | |
260 // |origin| and |tab_id| are used for validating same-origin/tab scopes; see | |
261 // CreateRoute for additional documentation. | |
262 // | |
263 // If |timeout| is positive, it will be used in place of the default timeout | |
264 // defined by Media Route Provider Manager; see CreateRoute for additional | |
265 // documentation. | |
266 // | |
267 // If the route request was created by an incognito profile, | |
268 // |incognito| must be true. | |
269 // | |
270 // If the operation was successful, |route| will be defined and | |
271 // |error_text| will be null. If the operation failed, |route| will be null | |
272 // and |error_text| will be set. | |
273 // | |
274 // |result| will be set to OK if successful, or an error code if an error | |
275 // occurred. | |
276 ConnectRouteByRouteId(string media_source, | |
277 string route_id, | |
278 string presentation_id, | |
279 url.mojom.Origin origin, | |
280 int32 tab_id, | |
281 mojo.common.mojom.TimeDelta timeout, | |
282 bool incognito) => | |
283 (MediaRoute? route, | |
284 string? error_text, | |
285 RouteRequestResultCode result_code); | |
286 | |
287 // Terminates the route specified by |route_id|. If the route was terminated | |
288 // successfully, |result_code| is set to OK and |error_text| is null. | |
289 // Otherwise, |result_code| is an error code and |error_text| describes the | |
290 // error. | |
291 TerminateRoute(string route_id) => | |
292 (string? error_text, RouteRequestResultCode result_code); | |
293 | |
294 // Sends |message| via the media route |media_route_id|. | |
295 // If the operation was successful, |sent| is true; otherwise it is false. | |
296 SendRouteMessage(string media_route_id, string message) => (bool sent); | |
297 | |
298 // Sends |data| via the media route |media_route_id|. | |
299 // If the operation was successful, |sent| is true; otherwise it is false. | |
300 SendRouteBinaryMessage(string media_route_id, array<uint8> data) | |
301 => (bool sent); | |
302 | |
303 // Starts querying for sinks capable of displaying |media_source|. | |
304 StartObservingMediaSinks(string media_source); | |
305 | |
306 // Stops querying sinks for |media_source|. | |
307 StopObservingMediaSinks(string media_source); | |
308 | |
309 // Starts reporting the state of active media routes via | |
310 // OnRoutesUpdated() in the context of the |media_source|. The | |
311 // |media_source| represents the application interested in the media | |
312 // routes (usually the web page from which the content originates). | |
313 // If no |media_source| is given, this should be considered an | |
314 // observer that is not associated with a media source, and thus | |
315 // cannot connect to a remote route without showing a source. The | |
316 // |media_source| should be considered when returning joinable routes in the | |
317 // OnRoutesUpdated() call. If an empty |media_source| is given, there is no | |
318 // context in which a joinable route makes sense and therefore, there should | |
319 // not be any joinable routes returned in OnRoutesUpdated(). | |
320 // Querying will continue until StopObservingMediaRoutes() is called with | |
321 // the same |media_source| (even if it's an empty string). | |
322 StartObservingMediaRoutes(string media_source); | |
323 | |
324 // Stops querying the state of all media routes in the context of | |
325 // the |media_source|. StartObservingMediaRoutes() has | |
326 // to be called with the same |media_source| for this to have any effect even | |
327 // if it's empty. Thus, StartObservingMediaRoutes(media_source) must be | |
328 // matched with StopObservingMediaRoutes(media_source). | |
329 // Calling StopObservingMediaRoutes() without a media_source will stop | |
330 // any media routes queries associated with emtpy strings (queries | |
331 // that being with StartObservingMediaRoutes()). | |
332 StopObservingMediaRoutes(string media_source); | |
333 | |
334 // Starts listening for messages from the media sink for the route given by | |
335 // |route_id|. | |
336 // |MediaRouter::OnRouteMessagesReceived| will be invoked when a batch of | |
337 // messages arrives, or when there is an error. | |
338 // |StopListeningForRouteMessages| will stop the Media Router from receiving | |
339 // further messages for |route_id|. | |
340 StartListeningForRouteMessages(string route_id); | |
341 | |
342 // Called when there are no more listeners for messages for |route_id|. | |
343 StopListeningForRouteMessages(string route_id); | |
344 | |
345 // Indicates that a PresentationConnection that was connected to route | |
346 // |route_id| has been closed (via .close(), garbage collection or | |
347 // navigation). | |
348 DetachRoute(string route_id); | |
349 | |
350 // Enables mDNS discovery. No-op if mDNS discovery is already enabled. | |
351 // Calling this will trigger a firewall prompt on Windows if there is not | |
352 // already a firewall rule for mDNS. | |
353 EnableMdnsDiscovery(); | |
354 | |
355 // Updates media sinks capable of displaying |media_source|. | |
356 UpdateMediaSinks(string media_source); | |
357 | |
358 // Indicates that the Media Router is interested in finding a sink that | |
359 // matches |search_criteria| and is compatible with the source urn | |
360 // |media_source|. |search_criteria| should contain an exact copy of the user | |
361 // input. The user's current domain is also used to search. The domain is the | |
362 // hosted domain of the user's signed-in identity, or empty if the user has no | |
363 // domain or is not signed in. | |
364 SearchSinks(string sink_id, | |
365 string media_source, | |
366 SinkSearchCriteria search_criteria) => | |
367 (string sink_id); | |
368 | |
369 // Called when the list of MediaSinks discovered by Media Router has been | |
370 // updated. The sinks are supplied to the MediaRouteProvider so that they can | |
371 // be used for other operations, such as route creation. | |
372 ProvideSinks(string provider_name, array<MediaSink> sinks); | |
373 | |
374 // Creates a controller for the media route with given |route_id| and binds it | |
375 // to |media_controller| for receiving media commands. This method returns | |
376 // false if such a media route doesn't exist, a controller already exists | |
377 // for it, or there was an error while creating a controller. This method must | |
378 // close |media_controller| in case of such a failure. |media_controller| | |
379 // becomes invalid when the media route is terminated. The created controller | |
380 // is destroyed when |media_controller| becomes invalid, after which this | |
381 // method can be called again with the same |route_id|. This method also sets | |
382 // |observer| to be notified whenever there is a change in the status of the | |
383 // media route. | |
384 // TODO(takumif): Consider returning an enum instead of a bool to distinguish | |
385 // between error conditions for metrics/debugging. | |
386 CreateMediaRouteController(string route_id, | |
387 MediaController& media_controller, | |
388 MediaStatusObserver observer) => | |
389 (bool success); | |
390 }; | |
391 | |
392 // Interface for a service which observes state changes across media | |
393 // sources, sinks, and issues. | |
394 interface MediaRouter { | |
395 | |
396 // Represents overall media sink availability states. | |
397 // UNAVAILABLE - No sinks are available. | |
398 // PER_SOURCE - Sinks are available, but are only compatible with specific | |
399 // media sources. | |
400 // AVAILABLE - A sink is available regardless of source. | |
401 enum SinkAvailability { | |
402 UNAVAILABLE, | |
403 PER_SOURCE, | |
404 AVAILABLE | |
405 }; | |
406 | |
407 // Keep in sync with content/public/common/presentation_info.h. | |
408 enum PresentationConnectionState { | |
409 CONNECTING, | |
410 CONNECTED, | |
411 CLOSED, | |
412 TERMINATED | |
413 }; | |
414 | |
415 // Keep in sync with content/public/common/presentation_info.h. | |
416 enum PresentationConnectionCloseReason { | |
417 CONNECTION_ERROR, | |
418 CLOSED, | |
419 WENT_AWAY | |
420 }; | |
421 | |
422 // Registers a MediaRouteProvider with the MediaRouter. | |
423 // Returns a string that uniquely identifies the Media Router browser | |
424 // process. | |
425 RegisterMediaRouteProvider(MediaRouteProvider media_router_provider) => | |
426 (string instance_id); | |
427 | |
428 // Called when the Media Route Manager receives a new list of |sinks| | |
429 // compatible with |media_source|. The result is only valid for |origins|. If | |
430 // |origins| is empty, the result is valid for any origin. | |
431 OnSinksReceived(string media_source, array<MediaSink> sinks, | |
432 array<url.mojom.Origin> origins); | |
433 | |
434 // Called when issues are reported for media routes. | |
435 OnIssue(Issue issue); | |
436 | |
437 // Called when list of routes has been updated in the context of the | |
438 // calling |media_source|. The array |joinable_route_ids| should | |
439 // contain route IDs of joinable routes found in the |routes| array. | |
440 OnRoutesUpdated(array<MediaRoute> routes, string media_source, | |
441 array<string> joinable_route_ids); | |
442 | |
443 // Called when the overall availability of media sinks has been updated. | |
444 OnSinkAvailabilityUpdated(SinkAvailability availability); | |
445 | |
446 // Called when the state of presentation connected to route |route_id| has | |
447 // changed to |state|. | |
448 OnPresentationConnectionStateChanged( | |
449 string route_id, PresentationConnectionState state); | |
450 | |
451 // Called when the presentation connected to route |route_id| has closed. | |
452 OnPresentationConnectionClosed( | |
453 string route_id, PresentationConnectionCloseReason reason, | |
454 string message); | |
455 | |
456 // Called when the a batch of messages arrives from the media sink for the | |
457 // route given by |route_id|. | |
458 // |StartListeningForRouteMessages| must be called first in order to receive | |
459 // messages. | |
460 // |route_id|: ID of route of the messages. | |
461 // |messages|: A non-empty list of messages received. | |
462 OnRouteMessagesReceived(string route_id, | |
463 array<RouteMessage> messages); | |
464 }; | |
OLD | NEW |