| 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.interfaces; | |
| 6 | |
| 7 // Represents an output sink to which media can be routed. | |
| 8 struct MediaSink { | |
| 9 enum IconType { | |
| 10 CAST, | |
| 11 CAST_AUDIO, | |
| 12 CAST_AUDIO_GROUP, | |
| 13 GENERIC, | |
| 14 HANGOUT | |
| 15 }; | |
| 16 | |
| 17 // The sink identifier, e.g. "rs71w7mFzYLFlabir_qO4NHl6SUc." | |
| 18 string sink_id; | |
| 19 // The human-readable name, e.g. "Janet's Chromecast". | |
| 20 string name; | |
| 21 // Optional description of the sink. | |
| 22 string? description; | |
| 23 // Optional domain of the sink if this sink is associated with an identity. | |
| 24 string? domain; | |
| 25 // The type of icon to show in the UI for this media sink. | |
| 26 IconType icon_type; | |
| 27 }; | |
| 28 | |
| 29 // Should be kept in sync with media_route.h. | |
| 30 struct MediaRoute { | |
| 31 // The ID of this media route, e.g. "r_PR1O_blkC9dsKp-tb1ti8qurOo". | |
| 32 string media_route_id; | |
| 33 // The ID of the media source being sent through this media route. | |
| 34 // May be missing if route is not local. | |
| 35 string? media_source; | |
| 36 // The ID of sink that is rendering the media content. | |
| 37 string media_sink_id; | |
| 38 // Human readable description of this route, e.g. | |
| 39 // "Tab casting". | |
| 40 string description; | |
| 41 // Specifies that the route is requested locally. | |
| 42 bool is_local; | |
| 43 // An optional path to an HTML page bundled bundled with the media router | |
| 44 // component extension. When set, the route can have custom route detail as | |
| 45 // well as its own route controls in the media router dialog. | |
| 46 string? custom_controller_path; | |
| 47 // Set to true if this route should be displayed for |media_sink_id| in UI. | |
| 48 bool for_display; | |
| 49 // Set to true if this route was created by an off the record (incognito) | |
| 50 // profile. | |
| 51 bool off_the_record; | |
| 52 }; | |
| 53 | |
| 54 // Notifications or an actionable events to be shown to the user. | |
| 55 // When is_blocking is true, media router UI shows issue only: | |
| 56 // | |
| 57 // Title | |
| 58 // Message | |
| 59 // default_action_button secondary_action_button | |
| 60 // | |
| 61 // When is_blocking is false, media router UI uses banner: | |
| 62 // | |
| 63 // Title default_action_link secondary_action_link | |
| 64 // | |
| 65 // above receiver list if route_id is not provided; otherwise it is | |
| 66 // above route detail and controls. | |
| 67 struct Issue { | |
| 68 enum Severity { | |
| 69 FATAL, | |
| 70 WARNING, | |
| 71 NOTIFICATION | |
| 72 }; | |
| 73 | |
| 74 enum ActionType { | |
| 75 DISMISS, | |
| 76 LEARN_MORE | |
| 77 }; | |
| 78 | |
| 79 // If set, the ID of the route to which this issue pertains. | |
| 80 // If not set (default), then this is a global issue. | |
| 81 string? route_id; | |
| 82 | |
| 83 Severity severity; | |
| 84 | |
| 85 // When true, the issue must be presented to the user and resolved | |
| 86 // before other actions are allowed. | |
| 87 bool is_blocking; | |
| 88 | |
| 89 // Short description about the issue. | |
| 90 string title; | |
| 91 | |
| 92 // Message about issue detail or how to handle issue. | |
| 93 // Messages should be suitable for end users to decide which actions to take. | |
| 94 string? message; | |
| 95 | |
| 96 ActionType default_action; | |
| 97 | |
| 98 array<ActionType>? secondary_actions; | |
| 99 | |
| 100 // A help page to be opened if users select learn_more. | |
| 101 string? help_url; | |
| 102 }; | |
| 103 | |
| 104 struct RouteMessage { | |
| 105 enum Type { | |
| 106 TEXT, | |
| 107 BINARY | |
| 108 }; | |
| 109 // The type of this message. | |
| 110 Type type; | |
| 111 // Used when the |type| is TEXT. | |
| 112 string? message; | |
| 113 // Used when the |type| is BINARY. | |
| 114 array<uint8>? data; | |
| 115 }; | |
| 116 | |
| 117 // Maps to a ResultCode value in route_request_result.h | |
| 118 // The enum defined here is a subset of those defined in route_request_result.h. | |
| 119 enum RouteRequestResultCode { | |
| 120 UNKNOWN_ERROR, | |
| 121 OK, | |
| 122 TIMED_OUT | |
| 123 }; | |
| 124 | |
| 125 // Modeled after the MediaRouter interface defined in | |
| 126 // chrome/browser/media/router/media_router.h | |
| 127 interface MediaRouteProvider { | |
| 128 // Creates a media route from |media_source| to the sink given by |sink_id|. | |
| 129 // | |
| 130 // The presentation ID of the route created will be |presentation_id|, but it | |
| 131 // may be overridden by a provider implementation. The presentation ID will | |
| 132 // be used by the presentation API to refer to the created route. | |
| 133 // | |
| 134 // |origin| and |tab_id| may be passed in for enforcing same-origin and/or | |
| 135 // same-tab scopes. Use -1 as |tab_id| in cases where the request is not | |
| 136 // made on behalf of a tab. | |
| 137 // | |
| 138 // If |timeout_millis| is positive, it will be used in place of the default | |
| 139 // timeout defined by Media Route Provider Manager. | |
| 140 // | |
| 141 // If |off_the_record| is true, the request was made by an off the record | |
| 142 // (incognito) profile. | |
| 143 // | |
| 144 // If the operation was successful, |route| will be defined and | |
| 145 // |error_text| will be null. | |
| 146 // If the operation failed, |route| will be null and |error_text| | |
| 147 // will be set. | |
| 148 // |result| will be set to OK if successful, or an error code if an error | |
| 149 // occurred. | |
| 150 CreateRoute(string media_source, | |
| 151 string sink_id, | |
| 152 string original_presentation_id, | |
| 153 string origin, | |
| 154 int32 tab_id, | |
| 155 int64 timeout_millis, | |
| 156 bool off_the_record) => | |
| 157 (MediaRoute? route, | |
| 158 string? error_text, | |
| 159 RouteRequestResultCode result_code); | |
| 160 | |
| 161 // Requests a connection to an established route for |media_source| given | |
| 162 // by |presentation_id|. | |
| 163 // | |
| 164 // |origin| and |tab_id| are used for validating same-origin/tab scopes; | |
| 165 // see CreateRoute for additional documentation. | |
| 166 // | |
| 167 // If |timeout_millis| is positive, it will be used in place of the default | |
| 168 // timeout defined by Media Route Provider Manager. | |
| 169 // | |
| 170 // If the route request was created by an off the record (incognito) profile, | |
| 171 // |off_the_record| must be true. | |
| 172 // | |
| 173 // If the operation was successful, |route| will be defined and | |
| 174 // |error_text| will be null. | |
| 175 // If the operation failed, |route| will be null and |error_text| | |
| 176 // will be set. | |
| 177 // |result| will be set to OK if successful, or an error code if an error | |
| 178 // occurred. | |
| 179 JoinRoute(string media_source, | |
| 180 string presentation_id, | |
| 181 string origin, | |
| 182 int32 tab_id, | |
| 183 int64 timeout_millis, | |
| 184 bool off_the_record) => | |
| 185 (MediaRoute? route, | |
| 186 string? error_text, | |
| 187 RouteRequestResultCode result_code); | |
| 188 | |
| 189 // Creates a new route for |media_source| that connects to the established | |
| 190 // route given by |route_id|. | |
| 191 // | |
| 192 // The presentation ID of the new route will be |presentation_id|, but it may | |
| 193 // be overridden by a provider implementation. The presentation ID will be | |
| 194 // used by the presentation API to refer to the created route. | |
| 195 // | |
| 196 // |origin| and |tab_id| are used for validating same-origin/tab scopes; see | |
| 197 // CreateRoute for additional documentation. | |
| 198 // | |
| 199 // If |timeout_millis| is positive, it will be used in place of the default | |
| 200 // timeout defined by Media Route Provider Manager; see CreateRoute for additi
onal | |
| 201 // documentation. | |
| 202 // | |
| 203 // If the route request was created by an off the record (incognito) profile, | |
| 204 // |off_the_record| must be true. | |
| 205 // | |
| 206 // If the operation was successful, |route| will be defined and | |
| 207 // |error_text| will be null. If the operation failed, |route| will be null | |
| 208 // and |error_text| will be set. | |
| 209 // | |
| 210 // |result| will be set to OK if successful, or an error code if an error | |
| 211 // occurred. | |
| 212 ConnectRouteByRouteId(string media_source, | |
| 213 string route_id, | |
| 214 string presentation_id, | |
| 215 string origin, | |
| 216 int32 tab_id, | |
| 217 int64 timeout_millis, | |
| 218 bool off_the_record) => | |
| 219 (MediaRoute? route, | |
| 220 string? error_text, | |
| 221 RouteRequestResultCode result_code); | |
| 222 | |
| 223 // Terminates the route specified by |route_id|. | |
| 224 TerminateRoute(string route_id); | |
| 225 | |
| 226 // Sends |message| via the media route |media_route_id|. | |
| 227 // If the operation was successful, |sent| is true; otherwise it is false. | |
| 228 SendRouteMessage(string media_route_id, string message) => (bool sent); | |
| 229 | |
| 230 // Sends |data| via the media route |media_route_id|. | |
| 231 // If the operation was successful, |sent| is true; otherwise it is false. | |
| 232 SendRouteBinaryMessage(string media_route_id, array<uint8> data) | |
| 233 => (bool sent); | |
| 234 | |
| 235 // Starts querying for sinks capable of displaying |media_source|. | |
| 236 StartObservingMediaSinks(string media_source); | |
| 237 | |
| 238 // Stops querying sinks for |media_source|. | |
| 239 StopObservingMediaSinks(string media_source); | |
| 240 | |
| 241 // Starts reporting the state of active media routes via | |
| 242 // OnRoutesUpdated() in the context of the |media_source|. The | |
| 243 // |media_source| represents the application interested in the media | |
| 244 // routes (usually the web page from which the content originates). | |
| 245 // If no |media_source| is given, this should be considered an | |
| 246 // observer that is not associated with a media source, and thus | |
| 247 // cannot connect to a remote route without showing a source. The | |
| 248 // |media_source| should be considered when returning joinable routes in the | |
| 249 // OnRoutesUpdated() call. If an empty |media_source| is given, there is no | |
| 250 // context in which a joinable route makes sense and therefore, there should | |
| 251 // not be any joinable routes returned in OnRoutesUpdated(). | |
| 252 // Querying will continue until StopObservingMediaRoutes() is called with | |
| 253 // the same |media_source| (even if it's an empty string). | |
| 254 StartObservingMediaRoutes(string media_source); | |
| 255 | |
| 256 // Stops querying the state of all media routes in the context of | |
| 257 // the |media_source|. StartObservingMediaRoutes() has | |
| 258 // to be called with the same |media_source| for this to have any effect even | |
| 259 // if it's empty. Thus, StartObservingMediaRoutes(media_source) must be | |
| 260 // matched with StopObservingMediaRoutes(media_source). | |
| 261 // Calling StopObservingMediaRoutes() without a media_source will stop | |
| 262 // any media routes queries associated with emtpy strings (queries | |
| 263 // that being with StartObservingMediaRoutes()). | |
| 264 StopObservingMediaRoutes(string media_source); | |
| 265 | |
| 266 // Called when the MediaRouter is ready to get the next batch of messages | |
| 267 // associated with |route_id|. | |
| 268 // |messages| returned will contain the batch of messages. | |
| 269 // |messages| will be empty if |StopListeningForRouteMessages| was invoked. | |
| 270 // |error| indicates if a permanent error occurred. If true, then subsequent | |
| 271 // calls will also return with |error| being true. | |
| 272 ListenForRouteMessages(string route_id) => | |
| 273 (array<RouteMessage> messages, bool error); | |
| 274 | |
| 275 // Called when there are no more listeners for messages for |route_id|. | |
| 276 // Calling this will resolve the pending |ListenForRouteMessages| callback | |
| 277 // with an empty list. | |
| 278 StopListeningForRouteMessages(string route_id); | |
| 279 | |
| 280 // Indicates that a PresentationConnection that was connected to route | |
| 281 // |route_id| has been closed (via .close(), garbage collection or | |
| 282 // navigation). | |
| 283 DetachRoute(string route_id); | |
| 284 | |
| 285 // Enables mDNS discovery. No-op if mDNS discovery is already enabled. | |
| 286 // Calling this will trigger a firewall prompt on Windows if there is not | |
| 287 // already a firewall rule for mDNS. | |
| 288 EnableMdnsDiscovery(); | |
| 289 }; | |
| 290 | |
| 291 // Interface for a service which observes state changes across media | |
| 292 // sources, sinks, and issues. | |
| 293 interface MediaRouter { | |
| 294 | |
| 295 // Represents overall media sink availability states. | |
| 296 // UNAVAILABLE - No sinks are available. | |
| 297 // PER_SOURCE - Sinks are available, but are only compatible with specific | |
| 298 // media sources. | |
| 299 // AVAILABLE - A sink is available regardless of source. | |
| 300 enum SinkAvailability { | |
| 301 UNAVAILABLE, | |
| 302 PER_SOURCE, | |
| 303 AVAILABLE | |
| 304 }; | |
| 305 | |
| 306 // Keep in sync with content/public/browser/presentation_session.h. | |
| 307 enum PresentationConnectionState { | |
| 308 CONNECTING, | |
| 309 CONNECTED, | |
| 310 CLOSED, | |
| 311 TERMINATED | |
| 312 }; | |
| 313 | |
| 314 // Keep in sync with content/public/browser/presentation_session.h. | |
| 315 enum PresentationConnectionCloseReason { | |
| 316 CONNECTION_ERROR, | |
| 317 CLOSED, | |
| 318 WENT_AWAY | |
| 319 }; | |
| 320 | |
| 321 // Registers a MediaRouteProvider with the MediaRouter. | |
| 322 // Returns a string that uniquely identifies the Media Router browser | |
| 323 // process. | |
| 324 RegisterMediaRouteProvider(MediaRouteProvider media_router_provider) => | |
| 325 (string instance_id); | |
| 326 | |
| 327 // Called when the Media Route Manager receives a new list of |sinks| | |
| 328 // compatible with |media_source|. The result is only valid for |origins|. If | |
| 329 // |origins| is empty, the result is valid for any origin. | |
| 330 OnSinksReceived(string media_source, array<MediaSink> sinks, | |
| 331 array<string> origins); | |
| 332 | |
| 333 // Called when issues are reported for media routes. | |
| 334 OnIssue(Issue issue); | |
| 335 | |
| 336 // Called when list of routes has been updated in the context of the | |
| 337 // calling |media_source|. The array |joinable_route_ids| should | |
| 338 // contain route IDs of joinable routes found in the |routes| array. | |
| 339 OnRoutesUpdated(array<MediaRoute> routes, string media_source, | |
| 340 array<string> joinable_route_ids); | |
| 341 | |
| 342 // Called when the overall availability of media sinks has been updated. | |
| 343 OnSinkAvailabilityUpdated(SinkAvailability availability); | |
| 344 | |
| 345 // Called when the state of presentation connected to route |route_id| has | |
| 346 // changed to |state|. | |
| 347 OnPresentationConnectionStateChanged( | |
| 348 string route_id, PresentationConnectionState state); | |
| 349 | |
| 350 // Called when the presentation connected to route |route_id| has closed. | |
| 351 OnPresentationConnectionClosed( | |
| 352 string route_id, PresentationConnectionCloseReason reason, | |
| 353 string message); | |
| 354 }; | |
| 355 | |
| OLD | NEW |