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.
16 * @param {!media_router.Route} route
18 function addRoute(route) {
19 container.addRoute(route);
23 * Sets the cast mode list.
25 * @param {!Array<!media_router.CastMode>} castModeList
27 function setCastModeList(castModeList) {
28 container.castModeList = castModeList;
34 * @param {!MediaRouterContainerElement} mediaRouterContainer
36 function setContainer(mediaRouterContainer) {
37 container = mediaRouterContainer;
41 * Populates the WebUI with data obtained from Media Router.
43 * @param {headerText: string,
44 * headerTextTooltip: string,
45 * sinks: !Array<!media_router.Sink>,
46 * routes: !Array<!media_router.Route>,
47 * castModes: !Array<!media_router.CastMode>} data
49 * headerText - text to be displayed in the header of the WebUI.
50 * headerTextTooltip - tooltip to be displayed for the header of the WebUI.
51 * sinks - list of sinks to be displayed.
52 * routes - list of routes that are associated with the sinks.
53 * castModes - list of available cast modes.
54 * routeProviderExtensionId - the ID of the media route provider extension.
56 function setInitialData(data) {
57 container.headerText = data['headerText'];
58 container.headerTextTooltip = data['headerTextTooltip'];
59 container.sinkList = data['sinks'];
60 container.routeList = data['routes'];
61 container.castModeList = data['castModes'];
62 container.routeProviderExtensionId = data['routeProviderExtensionId'];
66 * Sets current issue to |issue|, or clears the current issue if |issue| is
69 * @param {?media_router.Issue} issue
71 function setIssue(issue) {
72 container.issue = issue;
76 * Sets the list of currently active routes.
78 * @param {!Array<!media_router.Route>} routeList
80 function setRouteList(routeList) {
81 container.routeList = routeList;
85 * Sets the list of discovered sinks.
87 * @param {!Array<!media_router.Sink>} sinkList
89 function setSinkList(sinkList) {
90 container.sinkList = sinkList;
95 setCastModeList: setCastModeList,
96 setContainer: setContainer,
97 setInitialData: setInitialData,
99 setRouteList: setRouteList,
100 setSinkList: setSinkList,
104 // API invoked by this UI to communicate with the browser WebUI message handler.
105 cr.define('media_router.browserApi', function() {
109 * Acts on the given issue.
111 * @param {string} issueId
112 * @param {number} actionType Type of action that the user clicked.
113 * @param {?number} helpPageId The numeric help center ID.
115 function actOnIssue(issueId, actionType, helpPageId) {
116 chrome.send('actOnIssue', [{issueId: issueId, actionType: actionType,
117 helpPageId: helpPageId}]);
123 function closeDialog() {
124 chrome.send('closeDialog');
128 * Closes the given route.
130 * @param {!media_router.Route} route
132 function closeRoute(route) {
133 chrome.send('closeRoute', [{routeId: route.id}]);
137 * Requests data to initialize the WebUI with.
138 * The data will be returned via media_router.ui.setInitialData.
140 function requestInitialData() {
141 chrome.send('requestInitialData');
145 * Requests that a media route be started with the given sink.
147 * @param {string} sinkId The sink ID.
148 * @param {number} selectedCastMode The value of the cast mode the user
149 * selected, or -1 if the user has not explicitly selected a mode.
151 function requestRoute(sinkId, selectedCastMode) {
152 chrome.send('requestRoute',
153 [{sinkId: sinkId, selectedCastMode: selectedCastMode}]);
157 actOnIssue: actOnIssue,
158 closeDialog: closeDialog,
159 closeRoute: closeRoute,
160 requestInitialData: requestInitialData,
161 requestRoute: requestRoute,