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 * deviceMissingUrl: string,
49 * sinks: !Array<!media_router.Sink>,
50 * routes: !Array<!media_router.Route>,
51 * castModes: !Array<!media_router.CastMode>} data
53 * headerText - text to be displayed in the header of the WebUI.
54 * headerTextTooltip - tooltip to be displayed for the header of the WebUI.
55 * deviceMissingUrl - url to be opened on "Device missing?" clicked.
56 * sinks - list of sinks to be displayed.
57 * routes - list of routes that are associated with the sinks.
58 * castModes - list of available cast modes.
60 function setInitialData(data) {
61 container.headerText = data['headerText'];
62 container.headerTextTooltip = data['headerTextTooltip'];
63 container.deviceMissingUrl = data['deviceMissingUrl'];
64 container.sinkList = data['sinks'];
65 container.routeList = data['routes'];
66 container.castModeList = data['castModes'];
70 * Sets current issue to |issue|, or clears the current issue if |issue| is
73 * @param {?media_router.Issue} issue
75 function setIssue(issue) {
76 container.issue = issue;
80 * Sets the list of currently active routes.
82 * @param {!Array<!media_router.Route>} routeList
84 function setRouteList(routeList) {
85 container.routeList = routeList;
89 * Sets the list of discovered sinks.
91 * @param {!Array<!media_router.Sink>} sinkList
93 function setSinkList(sinkList) {
94 container.sinkList = sinkList;
98 onCreateRouteResponseReceived: onCreateRouteResponseReceived,
99 setCastModeList: setCastModeList,
100 setContainer: setContainer,
101 setInitialData: setInitialData,
103 setRouteList: setRouteList,
104 setSinkList: setSinkList,
108 // API invoked by this UI to communicate with the browser WebUI message handler.
109 cr.define('media_router.browserApi', function() {
113 * Acts on the given issue.
115 * @param {string} issueId
116 * @param {number} actionType Type of action that the user clicked.
117 * @param {?number} helpPageId The numeric help center ID.
119 function actOnIssue(issueId, actionType, helpPageId) {
120 chrome.send('actOnIssue', [{issueId: issueId, actionType: actionType,
121 helpPageId: helpPageId}]);
127 function closeDialog() {
128 chrome.send('closeDialog');
132 * Closes the given route.
134 * @param {!media_router.Route} route
136 function closeRoute(route) {
137 chrome.send('closeRoute', [{routeId: route.id}]);
141 * Requests data to initialize the WebUI with.
142 * The data will be returned via media_router.ui.setInitialData.
144 function requestInitialData() {
145 chrome.send('requestInitialData');
149 * Requests that a media route be started with the given sink.
151 * @param {string} sinkId The sink ID.
152 * @param {number} selectedCastMode The value of the cast mode the user
153 * selected, or -1 if the user has not explicitly selected a mode.
155 function requestRoute(sinkId, selectedCastMode) {
156 chrome.send('requestRoute',
157 [{sinkId: sinkId, selectedCastMode: selectedCastMode}]);
161 actOnIssue: actOnIssue,
162 closeDialog: closeDialog,
163 closeRoute: closeRoute,
164 requestInitialData: requestInitialData,
165 requestRoute: requestRoute,