OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // API invoked by the browser MediaRouterWebUIMessageHandler to communicate | |
6 // with this UI. | |
7 cr.define('media_router.ui', function() { | |
8 'use strict'; | |
9 | |
10 // The media-router-container element. | |
11 var container = null; | |
12 | |
13 // The media-router-header element. | |
14 var header = null; | |
15 | |
16 /** | |
17 * Handles response of previous create route attempt. | |
18 * | |
19 * @param {string} sinkId The ID of the sink to which the Media Route was | |
20 * creating a route. | |
21 * @param {?media_router.Route} route The newly created route that | |
22 * corresponds to the sink if route creation succeeded; null otherwise. | |
23 * @param {boolean} isForDisplay Whether or not |route| is for display. | |
24 */ | |
25 function onCreateRouteResponseReceived(sinkId, route, isForDisplay) { | |
26 container.onCreateRouteResponseReceived(sinkId, route, isForDisplay); | |
27 } | |
28 | |
29 /** | |
30 * Handles the search response by forwarding |sinkId| to the container. | |
31 * | |
32 * @param {string} sinkId The ID of the sink found by search. | |
33 */ | |
34 function receiveSearchResult(sinkId) { | |
35 container.onReceiveSearchResult(sinkId); | |
36 } | |
37 | |
38 /** | |
39 * Sets the cast mode list. | |
40 * | |
41 * @param {!Array<!media_router.CastMode>} castModeList | |
42 */ | |
43 function setCastModeList(castModeList) { | |
44 container.castModeList = castModeList; | |
45 } | |
46 | |
47 /** | |
48 * Sets |container| and |header|. | |
49 * | |
50 * @param {!MediaRouterContainerElement} mediaRouterContainer | |
51 * @param {!MediaRouterHeaderElement} mediaRouterHeader | |
52 */ | |
53 function setElements(mediaRouterContainer, mediaRouterHeader) { | |
54 container = mediaRouterContainer; | |
55 header = mediaRouterHeader; | |
56 } | |
57 | |
58 /** | |
59 * Populates the WebUI with data obtained about the first run flow. | |
60 * | |
61 * @param {{firstRunFlowCloudPrefLearnMoreUrl: string, | |
62 * firstRunFlowLearnMoreUrl: string, | |
63 * wasFirstRunFlowAcknowledged: boolean, | |
64 * showFirstRunFlowCloudPref: boolean}} data | |
65 * Parameters in data: | |
66 * firstRunFlowCloudPrefLearnMoreUrl - url to open when the cloud services | |
67 * pref learn more link is clicked. | |
68 * firstRunFlowLearnMoreUrl - url to open when the first run flow learn | |
69 * more link is clicked. | |
70 * wasFirstRunFlowAcknowledged - true if first run flow was previously | |
71 * acknowledged by user. | |
72 * showFirstRunFlowCloudPref - true if the cloud pref option should be | |
73 * shown. | |
74 */ | |
75 function setFirstRunFlowData(data) { | |
76 container.firstRunFlowCloudPrefLearnMoreUrl = | |
77 data['firstRunFlowCloudPrefLearnMoreUrl']; | |
78 container.firstRunFlowLearnMoreUrl = | |
79 data['firstRunFlowLearnMoreUrl']; | |
80 container.showFirstRunFlowCloudPref = | |
81 data['showFirstRunFlowCloudPref']; | |
82 // Some users acknowledged the first run flow before the cloud prefs | |
83 // setting was implemented. These users will see the first run flow | |
84 // again. | |
85 container.showFirstRunFlow = !data['wasFirstRunFlowAcknowledged'] || | |
86 container.showFirstRunFlowCloudPref; | |
87 } | |
88 | |
89 /** | |
90 * Populates the WebUI with data obtained from Media Router. | |
91 * | |
92 * @param {{deviceMissingUrl: string, | |
93 * sinksAndIdentity: { | |
94 * sinks: !Array<!media_router.Sink>, | |
95 * showEmail: boolean, | |
96 * userEmail: string, | |
97 * showDomain: boolean | |
98 * }, | |
99 * routes: !Array<!media_router.Route>, | |
100 * castModes: !Array<!media_router.CastMode>, | |
101 * useTabMirroring: boolean}} data | |
102 * Parameters in data: | |
103 * deviceMissingUrl - url to be opened on "Device missing?" clicked. | |
104 * sinksAndIdentity - list of sinks to be displayed and user identity. | |
105 * routes - list of routes that are associated with the sinks. | |
106 * castModes - list of available cast modes. | |
107 * useTabMirroring - whether the cast mode should be set to TAB_MIRROR. | |
108 */ | |
109 function setInitialData(data) { | |
110 container.deviceMissingUrl = data['deviceMissingUrl']; | |
111 container.castModeList = data['castModes']; | |
112 this.setSinkListAndIdentity(data['sinksAndIdentity']); | |
113 container.routeList = data['routes']; | |
114 container.maybeShowRouteDetailsOnOpen(); | |
115 if (data['useTabMirroring']) | |
116 container.selectCastMode(media_router.CastModeType.TAB_MIRROR); | |
117 media_router.browserApi.onInitialDataReceived(); | |
118 } | |
119 | |
120 /** | |
121 * Sets current issue to |issue|, or clears the current issue if |issue| is | |
122 * null. | |
123 * | |
124 * @param {?media_router.Issue} issue | |
125 */ | |
126 function setIssue(issue) { | |
127 container.issue = issue; | |
128 } | |
129 | |
130 /** | |
131 * Sets the list of currently active routes. | |
132 * | |
133 * @param {!Array<!media_router.Route>} routeList | |
134 */ | |
135 function setRouteList(routeList) { | |
136 container.routeList = routeList; | |
137 } | |
138 | |
139 /** | |
140 * Sets the list of discovered sinks along with properties of whether to hide | |
141 * identity of the user email and domain. | |
142 * | |
143 * @param {{sinks: !Array<!media_router.Sink>, | |
144 * showEmail: boolean, | |
145 * userEmail: string, | |
146 * showDomain: boolean}} data | |
147 * Parameters in data: | |
148 * sinks - list of sinks to be displayed. | |
149 * showEmail - true if the user email should be shown. | |
150 * userEmail - email of the user if the user is signed in. | |
151 * showDomain - true if the user domain should be shown. | |
152 */ | |
153 function setSinkListAndIdentity(data) { | |
154 container.showDomain = data['showDomain']; | |
155 container.allSinks = data['sinks']; | |
156 header.userEmail = data['userEmail']; | |
157 header.showEmail = data['showEmail']; | |
158 } | |
159 | |
160 /** | |
161 * Updates the max height of the dialog | |
162 * | |
163 * @param {number} height | |
164 */ | |
165 function updateMaxHeight(height) { | |
166 container.updateMaxDialogHeight(height); | |
167 } | |
168 | |
169 return { | |
170 onCreateRouteResponseReceived: onCreateRouteResponseReceived, | |
171 receiveSearchResult: receiveSearchResult, | |
172 setCastModeList: setCastModeList, | |
173 setElements: setElements, | |
174 setFirstRunFlowData: setFirstRunFlowData, | |
175 setInitialData: setInitialData, | |
176 setIssue: setIssue, | |
177 setRouteList: setRouteList, | |
178 setSinkListAndIdentity: setSinkListAndIdentity, | |
179 updateMaxHeight: updateMaxHeight, | |
180 }; | |
181 }); | |
182 | |
183 // API invoked by this UI to communicate with the browser WebUI message handler. | 5 // API invoked by this UI to communicate with the browser WebUI message handler. |
184 cr.define('media_router.browserApi', function() { | 6 cr.define('media_router.browserApi', function() { |
185 'use strict'; | 7 'use strict'; |
186 | 8 |
187 /** | 9 /** |
188 * Indicates that the user has acknowledged the first run flow. | 10 * Indicates that the user has acknowledged the first run flow. |
189 * | 11 * |
190 * @param {boolean} optedIntoCloudServices Whether or not the user opted into | 12 * @param {boolean} optedIntoCloudServices Whether or not the user opted into |
191 * cloud services. | 13 * cloud services. |
192 */ | 14 */ |
193 function acknowledgeFirstRunFlow(optedIntoCloudServices) { | 15 function acknowledgeFirstRunFlow(optedIntoCloudServices) { |
194 chrome.send('acknowledgeFirstRunFlow', [optedIntoCloudServices]); | 16 chrome.send('acknowledgeFirstRunFlow', [optedIntoCloudServices]); |
195 } | 17 } |
196 | 18 |
197 /** | 19 /** |
198 * Acts on the given issue. | 20 * Acts on the given issue. |
199 * | 21 * |
200 * @param {number} issueId | 22 * @param {number} issueId |
201 * @param {number} actionType Type of action that the user clicked. | 23 * @param {number} actionType Type of action that the user clicked. |
202 * @param {?number} helpPageId The numeric help center ID. | 24 * @param {?number} helpPageId The numeric help center ID. |
203 */ | 25 */ |
204 function actOnIssue(issueId, actionType, helpPageId) { | 26 function actOnIssue(issueId, actionType, helpPageId) { |
205 chrome.send('actOnIssue', [{issueId: issueId, actionType: actionType, | 27 chrome.send( |
206 helpPageId: helpPageId}]); | 28 'actOnIssue', |
| 29 [{issueId: issueId, actionType: actionType, helpPageId: helpPageId}]); |
207 } | 30 } |
208 | 31 |
209 /** | 32 /** |
210 * Modifies |route| by changing its source to the one identified by | 33 * Modifies |route| by changing its source to the one identified by |
211 * |selectedCastMode|. | 34 * |selectedCastMode|. |
212 * | 35 * |
213 * @param {!media_router.Route} route The route being modified. | 36 * @param {!media_router.Route} route The route being modified. |
214 * @param {number} selectedCastMode The value of the cast mode the user | 37 * @param {number} selectedCastMode The value of the cast mode the user |
215 * selected. | 38 * selected. |
216 */ | 39 */ |
217 function changeRouteSource(route, selectedCastMode) { | 40 function changeRouteSource(route, selectedCastMode) { |
218 chrome.send('requestRoute', | 41 chrome.send( |
219 [{sinkId: route.sinkId, selectedCastMode: selectedCastMode}]); | 42 'requestRoute', |
| 43 [{sinkId: route.sinkId, selectedCastMode: selectedCastMode}]); |
220 } | 44 } |
221 | 45 |
222 /** | 46 /** |
223 * Closes the dialog. | 47 * Closes the dialog. |
224 * | 48 * |
225 * @param {boolean} pressEscToClose Whether the user pressed ESC to close the | 49 * @param {boolean} pressEscToClose Whether the user pressed ESC to close the |
226 * dialog. | 50 * dialog. |
227 */ | 51 */ |
228 function closeDialog(pressEscToClose) { | 52 function closeDialog(pressEscToClose) { |
229 chrome.send('closeDialog', [pressEscToClose]); | 53 chrome.send('closeDialog', [pressEscToClose]); |
(...skipping 18 matching lines...) Expand all Loading... |
248 } | 72 } |
249 | 73 |
250 /** | 74 /** |
251 * Indicates that the initial data has been received. | 75 * Indicates that the initial data has been received. |
252 */ | 76 */ |
253 function onInitialDataReceived() { | 77 function onInitialDataReceived() { |
254 chrome.send('onInitialDataReceived'); | 78 chrome.send('onInitialDataReceived'); |
255 } | 79 } |
256 | 80 |
257 /** | 81 /** |
| 82 * Reports that the route details view was closed. |
| 83 */ |
| 84 function onMediaControllerClosed() { |
| 85 chrome.send('onMediaControllerClosed'); |
| 86 } |
| 87 |
| 88 /** |
| 89 * Reports that the route details view was opened for |routeId|. |
| 90 * |
| 91 * @param {string} routeId |
| 92 */ |
| 93 function onMediaControllerAvailable(routeId) { |
| 94 chrome.send('onMediaControllerAvailable', [{routeId: routeId}]); |
| 95 } |
| 96 |
| 97 /** |
| 98 * Sends a command to pause the route shown in the route details view. |
| 99 */ |
| 100 function pauseCurrentMedia() { |
| 101 chrome.send('pauseCurrentMedia'); |
| 102 } |
| 103 |
| 104 /** |
| 105 * Sends a command to play the route shown in the route details view. |
| 106 */ |
| 107 function playCurrentMedia() { |
| 108 chrome.send('playCurrentMedia'); |
| 109 } |
| 110 |
| 111 /** |
258 * Reports when the user clicks outside the dialog. | 112 * Reports when the user clicks outside the dialog. |
259 */ | 113 */ |
260 function reportBlur() { | 114 function reportBlur() { |
261 chrome.send('reportBlur'); | 115 chrome.send('reportBlur'); |
262 } | 116 } |
263 | 117 |
264 /** | 118 /** |
265 * Reports the index of the selected sink. | 119 * Reports the index of the selected sink. |
266 * | 120 * |
267 * @param {number} sinkIndex | 121 * @param {number} sinkIndex |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 223 } |
370 | 224 |
371 /** | 225 /** |
372 * Requests that a media route be started with the given sink. | 226 * Requests that a media route be started with the given sink. |
373 * | 227 * |
374 * @param {string} sinkId The sink ID. | 228 * @param {string} sinkId The sink ID. |
375 * @param {number} selectedCastMode The value of the cast mode the user | 229 * @param {number} selectedCastMode The value of the cast mode the user |
376 * selected. | 230 * selected. |
377 */ | 231 */ |
378 function requestRoute(sinkId, selectedCastMode) { | 232 function requestRoute(sinkId, selectedCastMode) { |
379 chrome.send('requestRoute', | 233 chrome.send( |
380 [{sinkId: sinkId, selectedCastMode: selectedCastMode}]); | 234 'requestRoute', [{sinkId: sinkId, selectedCastMode: selectedCastMode}]); |
381 } | 235 } |
382 | 236 |
383 /** | 237 /** |
384 * Requests that the media router search all providers for a sink matching | 238 * Requests that the media router search all providers for a sink matching |
385 * |searchCriteria| that can be used with the media source associated with the | 239 * |searchCriteria| that can be used with the media source associated with the |
386 * cast mode |selectedCastMode|. If such a sink is found, a route is also | 240 * cast mode |selectedCastMode|. If such a sink is found, a route is also |
387 * created between the sink and the media source. | 241 * created between the sink and the media source. |
388 * | 242 * |
389 * @param {string} sinkId Sink ID of the pseudo sink generating the request. | 243 * @param {string} sinkId Sink ID of the pseudo sink generating the request. |
390 * @param {string} searchCriteria Search criteria for the route providers. | 244 * @param {string} searchCriteria Search criteria for the route providers. |
391 * @param {string} domain User's current hosted domain. | 245 * @param {string} domain User's current hosted domain. |
392 * @param {number} selectedCastMode The value of the cast mode to be used with | 246 * @param {number} selectedCastMode The value of the cast mode to be used with |
393 * the sink. | 247 * the sink. |
394 */ | 248 */ |
395 function searchSinksAndCreateRoute( | 249 function searchSinksAndCreateRoute( |
396 sinkId, searchCriteria, domain, selectedCastMode) { | 250 sinkId, searchCriteria, domain, selectedCastMode) { |
397 chrome.send('searchSinksAndCreateRoute', | 251 chrome.send('searchSinksAndCreateRoute', [{ |
398 [{sinkId: sinkId, | 252 sinkId: sinkId, |
399 searchCriteria: searchCriteria, | 253 searchCriteria: searchCriteria, |
400 domain: domain, | 254 domain: domain, |
401 selectedCastMode: selectedCastMode}]); | 255 selectedCastMode: selectedCastMode |
| 256 }]); |
| 257 } |
| 258 |
| 259 /** |
| 260 * Sends a command to seek the route shown in the route details view. |
| 261 * |
| 262 * @param {number} time The new current time in seconds. |
| 263 */ |
| 264 function seekCurrentMedia(time) { |
| 265 chrome.send('seekCurrentMedia', [{time: time}]); |
| 266 } |
| 267 |
| 268 /** |
| 269 * Sends a command to mute or unmute the route shown in the route details |
| 270 * view. |
| 271 * |
| 272 * @param {boolean} mute Mute the route if true, unmute it if false. |
| 273 */ |
| 274 function setCurrentMediaMute(mute) { |
| 275 chrome.send('setCurrentMediaMute', [{mute: mute}]); |
| 276 } |
| 277 |
| 278 /** |
| 279 * Sends a command to change the volume of the route shown in the route |
| 280 * details view. |
| 281 * |
| 282 * @param {number} volume The volume between 0 and 1. |
| 283 */ |
| 284 function setCurrentMediaVolume(volume) { |
| 285 chrome.send('setCurrentMediaVolume', [{volume: volume}]); |
402 } | 286 } |
403 | 287 |
404 return { | 288 return { |
405 acknowledgeFirstRunFlow: acknowledgeFirstRunFlow, | 289 acknowledgeFirstRunFlow: acknowledgeFirstRunFlow, |
406 actOnIssue: actOnIssue, | 290 actOnIssue: actOnIssue, |
407 changeRouteSource: changeRouteSource, | 291 changeRouteSource: changeRouteSource, |
408 closeDialog: closeDialog, | 292 closeDialog: closeDialog, |
409 closeRoute: closeRoute, | 293 closeRoute: closeRoute, |
410 joinRoute: joinRoute, | 294 joinRoute: joinRoute, |
411 onInitialDataReceived: onInitialDataReceived, | 295 onInitialDataReceived: onInitialDataReceived, |
| 296 onMediaControllerClosed: onMediaControllerClosed, |
| 297 onMediaControllerAvailable: onMediaControllerAvailable, |
| 298 pauseCurrentMedia: pauseCurrentMedia, |
| 299 playCurrentMedia: playCurrentMedia, |
412 reportBlur: reportBlur, | 300 reportBlur: reportBlur, |
413 reportClickedSinkIndex: reportClickedSinkIndex, | 301 reportClickedSinkIndex: reportClickedSinkIndex, |
414 reportFilter: reportFilter, | 302 reportFilter: reportFilter, |
415 reportInitialAction: reportInitialAction, | 303 reportInitialAction: reportInitialAction, |
416 reportInitialState: reportInitialState, | 304 reportInitialState: reportInitialState, |
417 reportNavigateToView: reportNavigateToView, | 305 reportNavigateToView: reportNavigateToView, |
418 reportRouteCreation: reportRouteCreation, | 306 reportRouteCreation: reportRouteCreation, |
419 reportRouteCreationOutcome: reportRouteCreationOutcome, | 307 reportRouteCreationOutcome: reportRouteCreationOutcome, |
420 reportSelectedCastMode: reportSelectedCastMode, | 308 reportSelectedCastMode: reportSelectedCastMode, |
421 reportSinkCount: reportSinkCount, | 309 reportSinkCount: reportSinkCount, |
422 reportTimeToClickSink: reportTimeToClickSink, | 310 reportTimeToClickSink: reportTimeToClickSink, |
423 reportTimeToInitialActionClose: reportTimeToInitialActionClose, | 311 reportTimeToInitialActionClose: reportTimeToInitialActionClose, |
424 requestInitialData: requestInitialData, | 312 requestInitialData: requestInitialData, |
425 requestRoute: requestRoute, | 313 requestRoute: requestRoute, |
426 searchSinksAndCreateRoute: searchSinksAndCreateRoute, | 314 searchSinksAndCreateRoute: searchSinksAndCreateRoute, |
| 315 seekCurrentMedia: seekCurrentMedia, |
| 316 setCurrentMediaMute: setCurrentMediaMute, |
| 317 setCurrentMediaVolume: setCurrentMediaVolume, |
427 }; | 318 }; |
428 }); | 319 }); |
OLD | NEW |