OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 // This Polymer element shows information from media that is currently cast | 5 // This Polymer element shows information from media that is currently cast |
6 // to a device. | 6 // to a device. |
7 Polymer({ | 7 Polymer({ |
8 is: 'route-details', | 8 is: 'route-details', |
9 | 9 |
10 properties: { | 10 properties: { |
11 /** | 11 /** |
12 * The text for the current casting activity status. | 12 * The text for the current casting activity status. |
13 * @private {string|undefined} | 13 * @private {string|undefined} |
14 */ | 14 */ |
15 activityStatus_: { | 15 activityStatus_: { |
16 type: String, | 16 type: String, |
17 }, | 17 }, |
18 | 18 |
19 /** | 19 /** |
20 * Whether the external container will accept change-route-source-click | 20 * Whether the external container will accept change-route-source-click |
21 * events. | 21 * events. |
22 * @private {boolean} | 22 * @private {boolean} |
23 */ | 23 */ |
24 changeRouteSourceAvailable_: { | 24 changeRouteSourceAvailable_: { |
25 type: Boolean, | 25 type: Boolean, |
26 computed: 'computeChangeRouteSourceAvailable_(route, sink,' + | 26 computed: 'computeChangeRouteSourceAvailable_(route, sink,' + |
27 'isAnySinkCurrentlyLaunching, shownCastModeValue)', | 27 'isAnySinkCurrentlyLaunching, shownCastModeValue)', |
28 }, | 28 }, |
29 | 29 |
30 /** | 30 /** |
31 * An enum value to represent the controller to show. | |
32 * @private {number} | |
33 */ | |
34 controllerType_: { | |
35 type: Number, | |
36 computed: 'computeControllerType_(useWebUiRouteControls,' + | |
37 'isExtensionViewReady)', | |
38 }, | |
39 | |
40 /** | |
31 * Whether a sink is currently launching in the container. | 41 * Whether a sink is currently launching in the container. |
32 * @type {boolean} | 42 * @type {boolean} |
33 */ | 43 */ |
34 isAnySinkCurrentlyLaunching: { | 44 isAnySinkCurrentlyLaunching: { |
35 type: Boolean, | 45 type: Boolean, |
36 value: false, | 46 value: false, |
37 }, | 47 }, |
38 | 48 |
39 /** | 49 /** |
50 * Whether the custom controller extensionview is ready to be shown. | |
51 * @type {boolean} | |
52 */ | |
53 isExtensionViewReady: { | |
54 type: Boolean, | |
55 value: false, | |
56 }, | |
57 | |
58 /** | |
40 * The route to show. | 59 * The route to show. |
41 * @type {?media_router.Route|undefined} | 60 * @type {?media_router.Route|undefined} |
42 */ | 61 */ |
43 route: { | 62 route: { |
44 type: Object, | 63 type: Object, |
45 observer: 'maybeLoadCustomController_', | 64 observer: 'onRouteChange_', |
46 }, | 65 }, |
47 | 66 |
48 /** | 67 /** |
49 * The cast mode shown to the user. Initially set to auto mode. (See | 68 * The cast mode shown to the user. Initially set to auto mode. (See |
50 * media_router.CastMode documentation for details on auto mode.) | 69 * media_router.CastMode documentation for details on auto mode.) |
51 * @type {number} | 70 * @type {number} |
52 */ | 71 */ |
53 shownCastModeValue: { | 72 shownCastModeValue: { |
54 type: Number, | 73 type: Number, |
55 value: media_router.AUTO_CAST_MODE.type, | 74 value: media_router.AUTO_CAST_MODE.type, |
56 }, | 75 }, |
57 | 76 |
58 /** | 77 /** |
59 * Sink associated with |route|. | 78 * Sink associated with |route|. |
60 * @type {?media_router.Sink} | 79 * @type {?media_router.Sink} |
61 */ | 80 */ |
62 sink: { | 81 sink: { |
63 type: Object, | 82 type: Object, |
64 value: null, | 83 value: null, |
65 }, | 84 }, |
66 | 85 |
67 /** | 86 /** |
68 * Whether the custom controller should be hidden. | 87 * Whether we should use the new route controls. This value is used for |
69 * A custom controller is shown iff |route| specifies customControllerPath | 88 * updating |controllerType_|, |
70 * and the view can be loaded. | 89 * @type {boolean} |
71 * @private {boolean} | |
72 */ | 90 */ |
73 isCustomControllerHidden_: { | 91 useWebUiRouteControls: { |
74 type: Boolean, | 92 type: Boolean, |
75 value: true, | 93 value: false, |
76 }, | 94 }, |
77 }, | 95 }, |
78 | 96 |
79 behaviors: [ | 97 behaviors: [ |
80 I18nBehavior, | 98 I18nBehavior, |
81 ], | 99 ], |
82 | 100 |
83 /** | 101 /** |
84 * Fires a close-route event. This is called when the button to close | 102 * Fires a close-route event. This is called when the button to close |
85 * the current route is clicked. | 103 * the current route is clicked. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 if (!route.currentCastMode) { | 141 if (!route.currentCastMode) { |
124 return true; | 142 return true; |
125 } | 143 } |
126 var selectedCastMode = | 144 var selectedCastMode = |
127 this.computeSelectedCastMode_(shownCastModeValue, sink); | 145 this.computeSelectedCastMode_(shownCastModeValue, sink); |
128 return (selectedCastMode != 0) && | 146 return (selectedCastMode != 0) && |
129 (selectedCastMode != route.currentCastMode); | 147 (selectedCastMode != route.currentCastMode); |
130 }, | 148 }, |
131 | 149 |
132 /** | 150 /** |
151 * @param {boolean} useWebUiRouteControls | |
152 * @param {boolean} isExtensionViewReady | |
153 * @return {number} An enum value to represent the controller to show. | |
154 * @private | |
155 */ | |
156 computeControllerType_: function(useWebUiRouteControls, | |
157 isExtensionViewReady) { | |
158 if (useWebUiRouteControls) { | |
159 return media_router.ControllerType.WEBUI; | |
160 } | |
161 if (isExtensionViewReady) { | |
162 return media_router.ControllerType.EXTENSION; | |
163 } | |
164 return media_router.ControllerType.NONE; | |
165 }, | |
166 | |
167 /** | |
133 * @param {number} castMode User selected cast mode or AUTO. | 168 * @param {number} castMode User selected cast mode or AUTO. |
134 * @param {?media_router.Sink} sink Sink to which we will cast. | 169 * @param {?media_router.Sink} sink Sink to which we will cast. |
135 * @return {number} The selected cast mode when |castMode| is selected in the | 170 * @return {number} The selected cast mode when |castMode| is selected in the |
136 * dialog and casting to |sink|. Returning 0 means there is no cast mode | 171 * dialog and casting to |sink|. Returning 0 means there is no cast mode |
137 * available to |sink| and therefore the start-casting-to-route button | 172 * available to |sink| and therefore the start-casting-to-route button |
138 * will not be shown. | 173 * will not be shown. |
139 */ | 174 */ |
140 computeSelectedCastMode_: function(castMode, sink) { | 175 computeSelectedCastMode_: function(castMode, sink) { |
141 // |sink| can be null when there is a local route, which is shown in the | 176 // |sink| can be null when there is a local route, which is shown in the |
142 // dialog, but the sink to which it is connected isn't in the current set of | 177 // dialog, but the sink to which it is connected isn't in the current set of |
143 // sinks known to the dialog. This can happen, for example, with DIAL | 178 // sinks known to the dialog. This can happen, for example, with DIAL |
144 // devices. A route is created to a DIAL device, but opening the dialog on | 179 // devices. A route is created to a DIAL device, but opening the dialog on |
145 // a tab that only supports mirroring will not show the DIAL device. The | 180 // a tab that only supports mirroring will not show the DIAL device. The |
146 // route will be shown in route details if it is the only local route, so | 181 // route will be shown in route details if it is the only local route, so |
147 // you arrive at this function with a null |sink|. | 182 // you arrive at this function with a null |sink|. |
148 if (!sink) { | 183 if (!sink) { |
149 return 0; | 184 return 0; |
150 } | 185 } |
151 if (castMode == media_router.CastModeType.AUTO) { | 186 if (castMode == media_router.CastModeType.AUTO) { |
152 return sink.castModes & -sink.castModes; | 187 return sink.castModes & -sink.castModes; |
153 } | 188 } |
154 return castMode & sink.castModes; | 189 return castMode & sink.castModes; |
155 }, | 190 }, |
156 | 191 |
157 /** | 192 /** |
193 * Updates |activityStatus_| for the default view. | |
194 * | |
195 * @private | |
196 */ | |
197 updateActivityStatus_: function() { | |
198 this.activityStatus_ = this.route ? | |
199 loadTimeData.getStringF('castingActivityStatus', | |
200 this.route.description) : | |
201 ''; | |
apacible
2017/05/17 21:52:17
I feel this is an awkward placement for this line,
takumif
2017/05/18 18:01:56
Since "git cl format" doesn't format JS, I copied
| |
202 }, | |
203 | |
204 /** | |
205 * Called when the route details view is closed. | |
apacible
2017/05/17 21:52:17
For onClosed/onOpened -- prefer comments be someth
takumif
2017/05/18 18:01:55
Done.
| |
206 */ | |
207 onClosed: function() { | |
208 if (this.controllerType_ === media_router.ControllerType.WEBUI) { | |
209 this.$['route-controls'].reset(); | |
210 } | |
211 }, | |
212 | |
213 /** | |
214 * Called when the route details view is opened. | |
215 */ | |
216 onOpened: function() { | |
217 if (this.controllerType_ === media_router.ControllerType.WEBUI) { | |
218 media_router.ui.setRouteControls(this.$['route-controls']); | |
219 } | |
220 }, | |
221 | |
222 /** | |
223 * Updates either the extensionview or the new route controller, depending on | |
224 * which should be shown. | |
225 * @private | |
226 */ | |
227 onRouteChange_: function(newRoute) { | |
228 if (this.controllerType_ !== media_router.ControllerType.WEBUI) { | |
229 this.updateActivityStatus_(); | |
230 } | |
231 if (newRoute && | |
232 this.controllerType_ === media_router.ControllerType.WEBUI) { | |
233 this.$['route-controls'].onRouteUpdated(newRoute); | |
234 } | |
235 }, | |
236 | |
237 /** | |
238 * Called by Polymer when this element is ready. | |
239 */ | |
240 ready: function() { | |
apacible
2017/05/17 21:52:17
nit: Move this to right after the list of behavior
takumif
2017/05/18 18:01:55
Moving this functionality to ready() in route-cont
| |
241 this.onOpened(); | |
242 }, | |
243 | |
244 /** | |
245 * @param {number} controllerType | |
246 * @return {boolean} Whether the extensionview should be shown instead of the | |
247 * default route info element or the new WebUI route controller. | |
248 * @private | |
249 */ | |
250 shouldShowExtensionView_: function(controllerType) { | |
251 return controllerType === media_router.ControllerType.EXTENSION; | |
252 }, | |
253 | |
254 /** | |
255 * @param {number} controllerType | |
256 * @return {boolean} Whether the route info element should be shown instead of | |
257 * the extensionview or the new WebUI route controller. | |
258 * @private | |
259 */ | |
260 shouldShowRouteInfoOnly_: function(controllerType) { | |
261 return controllerType === media_router.ControllerType.NONE; | |
262 }, | |
263 | |
264 /** | |
265 * @param {number} controllerType | |
266 * @return {boolean} Whether new WebUI route controller should be shown | |
267 * instead of the default route info element or the extensionview. | |
268 * @private | |
269 */ | |
270 shouldShowWebUiControls_: function(controllerType) { | |
271 return controllerType === media_router.ControllerType.WEBUI; | |
272 }, | |
273 | |
274 /** | |
158 * Fires a join-route-click event if the current route is joinable, otherwise | 275 * Fires a join-route-click event if the current route is joinable, otherwise |
159 * it fires a change-route-source-click event, which changes the source of the | 276 * it fires a change-route-source-click event, which changes the source of the |
160 * current route. This may cause the current route to be closed and a new | 277 * current route. This may cause the current route to be closed and a new |
161 * route to be started. This is called when the button to start casting to the | 278 * route to be started. This is called when the button to start casting to the |
162 * current route is clicked. | 279 * current route is clicked. |
163 * | 280 * |
164 * @private | 281 * @private |
165 */ | 282 */ |
166 startCastingToRoute_: function() { | 283 startCastingToRoute_: function() { |
167 if (this.route.canJoin) { | 284 if (this.route.canJoin) { |
168 this.fire('join-route-click', {route: this.route}); | 285 this.fire('join-route-click', {route: this.route}); |
169 } else { | 286 } else { |
170 this.fire('change-route-source-click', { | 287 this.fire('change-route-source-click', { |
171 route: this.route, | 288 route: this.route, |
172 selectedCastMode: | 289 selectedCastMode: |
173 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) | 290 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) |
174 }); | 291 }); |
175 } | 292 } |
176 }, | 293 }, |
177 | |
178 /** | |
179 * Loads the custom controller if |route.customControllerPath| exists. | |
180 * Falls back to the default route details view otherwise, or if load fails. | |
181 * Updates |activityStatus_| for the default view. | |
182 * | |
183 * @private | |
184 */ | |
185 maybeLoadCustomController_: function() { | |
186 this.activityStatus_ = this.route ? | |
187 loadTimeData.getStringF('castingActivityStatus', | |
188 this.route.description) : | |
189 ''; | |
190 | |
191 if (!this.route || !this.route.customControllerPath) { | |
192 this.isCustomControllerHidden_ = true; | |
193 return; | |
194 } | |
195 | |
196 // Show custom controller | |
197 var extensionview = this.$['custom-controller']; | |
198 | |
199 // Do nothing if the url is the same and the view is not hidden. | |
200 if (this.route.customControllerPath == extensionview.src && | |
201 !this.isCustomControllerHidden_) | |
202 return; | |
203 | |
204 var that = this; | |
205 extensionview.load(this.route.customControllerPath) | |
206 .then(function() { | |
207 // Load was successful; show the custom controller. | |
208 that.isCustomControllerHidden_ = false; | |
209 }, function() { | |
210 // Load was unsuccessful; fall back to default view. | |
211 that.isCustomControllerHidden_ = true; | |
212 }); | |
213 }, | |
214 }); | 294 }); |
OLD | NEW |