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.
5 // API invoked by the browser MediaRouterWebUIMessageHandler to communicate
7 cr.define('media_router.ui', function() {
10 // The media-router-container element.
14 * Handles response of previous create route attempt.
16 * @param {string} sinkId The ID of the sink to which the Media Route was
18 * @param {?media_router.Route} route The newly create route to the sink
19 * if route creation succeeded; null otherwise
21 function onCreateRouteResponseReceived(sinkId, route) {
22 container.onCreateRouteResponseReceived(sinkId, route);
26 * Sets the cast mode list.
28 * @param {!Array<!media_router.CastMode>} castModeList
30 function setCastModeList(castModeList) {
31 container.castModeList = castModeList;
37 * @param {!MediaRouterContainerElement} mediaRouterContainer
39 function setContainer(mediaRouterContainer) {
40 container = mediaRouterContainer;
44 * Populates the WebUI with data obtained from Media Router.
46 * @param {headerText: string,
47 * headerTextTooltip: string,
48 * sinks: !Array<!media_router.Sink>,
49 * routes: !Array<!media_router.Route>,
50 * castModes: !Array<!media_router.CastMode>} data
52 * headerText - text to be displayed in the header of the WebUI.
53 * headerTextTooltip - tooltip to be displayed for the header of the WebUI.
54 * sinks - list of sinks to be displayed.
55 * routes - list of routes that are associated with the sinks.
56 * castModes - list of available cast modes.
58 function setInitialData(data) {
59 container.headerText = data['headerText'];
60 container.headerTextTooltip = data['headerTextTooltip'];
61 container.sinkList = data['sinks'];
62 container.routeList = data['routes'];
63 container.castModeList = data['castModes'];
67 * Sets current issue to |issue|, or clears the current issue if |issue| is
70 * @param {?media_router.Issue} issue
72 function setIssue(issue) {
73 container.issue = issue;
77 * Sets the list of currently active routes.
79 * @param {!Array<!media_router.Route>} routeList
81 function setRouteList(routeList) {
82 container.routeList = routeList;
86 * Sets the list of discovered sinks.
88 * @param {!Array<!media_router.Sink>} sinkList
90 function setSinkList(sinkList) {
91 container.sinkList = sinkList;
95 onCreateRouteResponseReceived: onCreateRouteResponseReceived,
96 setCastModeList: setCastModeList,
97 setContainer: setContainer,
98 setInitialData: setInitialData,
100 setRouteList: setRouteList,
101 setSinkList: setSinkList,
105 // API invoked by this UI to communicate with the browser WebUI message handler.
106 cr.define('media_router.browserApi', function() {
110 * Acts on the given issue.
112 * @param {string} issueId
113 * @param {number} actionType Type of action that the user clicked.
114 * @param {?number} helpPageId The numeric help center ID.
116 function actOnIssue(issueId, actionType, helpPageId) {
117 chrome.send('actOnIssue', [{issueId: issueId, actionType: actionType,
118 helpPageId: helpPageId}]);
124 function closeDialog() {
125 chrome.send('closeDialog');
129 * Closes the given route.
131 * @param {!media_router.Route} route
133 function closeRoute(route) {
134 chrome.send('closeRoute', [{routeId: route.id}]);
138 * Requests data to initialize the WebUI with.
139 * The data will be returned via media_router.ui.setInitialData.
141 function requestInitialData() {
142 chrome.send('requestInitialData');
146 * Requests that a media route be started with the given sink.
148 * @param {string} sinkId The sink ID.
149 * @param {number} selectedCastMode The value of the cast mode the user
150 * selected, or -1 if the user has not explicitly selected a mode.
152 function requestRoute(sinkId, selectedCastMode) {
153 chrome.send('requestRoute',
154 [{sinkId: sinkId, selectedCastMode: selectedCastMode}]);
158 actOnIssue: actOnIssue,
159 closeDialog: closeDialog,
160 closeRoute: closeRoute,
161 requestInitialData: requestInitialData,
162 requestRoute: requestRoute,