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 extension view is ready to be shown. | |
51 * @private {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. If false, we use the |
69 * A custom controller is shown iff |route| specifies customControllerPath | 88 * extension view. |
imcheng
2017/05/05 21:36:40
@type {boolean}
takumif
2017/05/09 00:14:57
Done.
| |
70 * and the view can be loaded. | |
71 * @private {boolean} | |
72 */ | 89 */ |
73 isCustomControllerHidden_: { | 90 useWebUiRouteControls: { |
74 type: Boolean, | 91 type: Boolean, |
75 value: true, | 92 value: false, |
76 }, | 93 } |
77 }, | 94 }, |
78 | 95 |
79 behaviors: [ | 96 behaviors: [ |
80 I18nBehavior, | 97 I18nBehavior, |
81 ], | 98 ], |
82 | 99 |
83 /** | 100 /** |
84 * Fires a close-route event. This is called when the button to close | 101 * Fires a close-route event. This is called when the button to close |
85 * the current route is clicked. | 102 * the current route is clicked. |
86 * | 103 * |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 if (!route.currentCastMode) { | 140 if (!route.currentCastMode) { |
124 return true; | 141 return true; |
125 } | 142 } |
126 var selectedCastMode = | 143 var selectedCastMode = |
127 this.computeSelectedCastMode_(shownCastModeValue, sink); | 144 this.computeSelectedCastMode_(shownCastModeValue, sink); |
128 return (selectedCastMode != 0) && | 145 return (selectedCastMode != 0) && |
129 (selectedCastMode != route.currentCastMode); | 146 (selectedCastMode != route.currentCastMode); |
130 }, | 147 }, |
131 | 148 |
132 /** | 149 /** |
150 * @param {bool} useWebUiRouteControls | |
imcheng
2017/05/05 21:36:41
s/bool/boolean here and below
takumif
2017/05/09 00:14:57
Done.
| |
151 * @param {bool} isExtensionViewReady_ | |
152 * @return {number} An enum value to represent the controller to show. | |
153 * @private | |
154 */ | |
155 computeControllerType_: function(useWebUiRouteControls, | |
156 isExtensionViewReady_) { | |
157 if (useWebUiRouteControls) { | |
158 return media_router.ControllerType.WEBUI; | |
159 } | |
160 if (isExtensionViewReady_) { | |
161 return media_router.ControllerType.EXTENSION; | |
162 } | |
163 return media_router.ControllerType.NONE; | |
164 }, | |
165 | |
166 /** | |
133 * @param {number} castMode User selected cast mode or AUTO. | 167 * @param {number} castMode User selected cast mode or AUTO. |
134 * @param {?media_router.Sink} sink Sink to which we will cast. | 168 * @param {?media_router.Sink} sink Sink to which we will cast. |
135 * @return {number} The selected cast mode when |castMode| is selected in the | 169 * @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 | 170 * 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 | 171 * available to |sink| and therefore the start-casting-to-route button |
138 * will not be shown. | 172 * will not be shown. |
139 */ | 173 */ |
140 computeSelectedCastMode_: function(castMode, sink) { | 174 computeSelectedCastMode_: function(castMode, sink) { |
141 // |sink| can be null when there is a local route, which is shown in the | 175 // |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 | 176 // 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 | 177 // 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 | 178 // 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 | 179 // 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 | 180 // 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|. | 181 // you arrive at this function with a null |sink|. |
148 if (!sink) { | 182 if (!sink) { |
149 return 0; | 183 return 0; |
150 } | 184 } |
151 if (castMode == media_router.CastModeType.AUTO) { | 185 if (castMode == media_router.CastModeType.AUTO) { |
152 return sink.castModes & -sink.castModes; | 186 return sink.castModes & -sink.castModes; |
153 } | 187 } |
154 return castMode & sink.castModes; | 188 return castMode & sink.castModes; |
155 }, | 189 }, |
156 | 190 |
157 /** | 191 /** |
158 * 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 | |
160 * 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 | |
162 * current route is clicked. | |
163 * | |
164 * @private | |
165 */ | |
166 startCastingToRoute_: function() { | |
167 if (this.route.canJoin) { | |
168 this.fire('join-route-click', {route: this.route}); | |
169 } else { | |
170 this.fire('change-route-source-click', { | |
171 route: this.route, | |
172 selectedCastMode: | |
173 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) | |
174 }); | |
175 } | |
176 }, | |
177 | |
178 /** | |
179 * Loads the custom controller if |route.customControllerPath| exists. | 192 * Loads the custom controller if |route.customControllerPath| exists. |
180 * Falls back to the default route details view otherwise, or if load fails. | 193 * Falls back to the default route details view otherwise, or if load fails. |
181 * Updates |activityStatus_| for the default view. | 194 * Updates |activityStatus_| for the default view. |
182 * | 195 * |
183 * @private | 196 * @private |
184 */ | 197 */ |
185 maybeLoadCustomController_: function() { | 198 maybeLoadExtensionView_: function() { |
186 this.activityStatus_ = this.route ? | 199 this.activityStatus_ = this.route ? |
187 loadTimeData.getStringF('castingActivityStatus', | 200 loadTimeData.getStringF('castingActivityStatus', |
188 this.route.description) : | 201 this.route.description) : |
189 ''; | 202 ''; |
190 | 203 |
191 if (!this.route || !this.route.customControllerPath) { | 204 if (!this.route || !this.route.customControllerPath) { |
192 this.isCustomControllerHidden_ = true; | 205 this.isExtensionViewReady_ = false; |
193 return; | 206 return; |
194 } | 207 } |
195 | 208 |
196 // Show custom controller | 209 // Show custom controller |
197 var extensionview = this.$['custom-controller']; | 210 var extensionview = this.$['custom-controller']; |
198 | 211 |
199 // Do nothing if the url is the same and the view is not hidden. | 212 // Do nothing if the url is the same and the view is not hidden. |
200 if (this.route.customControllerPath == extensionview.src && | 213 if (this.route.customControllerPath == extensionview.src && |
201 !this.isCustomControllerHidden_) | 214 this.shouldShowExtensionView_) { |
202 return; | 215 return; |
216 } | |
203 | 217 |
204 var that = this; | 218 var that = this; |
205 extensionview.load(this.route.customControllerPath) | 219 extensionview.load(this.route.customControllerPath) |
206 .then(function() { | 220 .then(function() { |
207 // Load was successful; show the custom controller. | 221 // Load was successful; show the custom controller. |
208 that.isCustomControllerHidden_ = false; | 222 that.isExtensionViewReady_ = true; |
209 }, function() { | 223 }, function() { |
210 // Load was unsuccessful; fall back to default view. | 224 // Load was unsuccessful; fall back to default view. |
211 that.isCustomControllerHidden_ = true; | 225 that.isExtensionViewReady_ = false; |
212 }); | 226 }); |
213 }, | 227 }, |
228 | |
229 /** | |
230 * Called when the route details view is closed. | |
231 */ | |
232 onClosed: function() { | |
233 if (this.$$('route-controls')) { | |
234 this.$$('route-controls').onRouteDetailsClosed(); | |
235 } | |
236 }, | |
237 | |
238 /** | |
239 * Called when the route details view is opened. | |
240 */ | |
241 onOpened: function() { | |
242 media_router.ui.setRouteControls(this.$$('route-controls')); | |
imcheng
2017/05/05 21:36:40
Similar comment to the one in media_router_contain
takumif
2017/05/09 00:14:57
Thinking about this, since route-controls isn't a
| |
243 }, | |
244 | |
245 /** | |
246 * Updates either the extension view or the new route controller, depending on | |
247 * which should be shown. | |
248 * @private | |
249 */ | |
250 onRouteChange_: function(newRoute) { | |
251 if (!this.useWebUiRouteControls) { | |
252 this.maybeLoadExtensionView_(); | |
253 } | |
254 if (newRoute && this.$$('route-controls')) { | |
255 this.$$('route-controls').onRouteUpdated(newRoute); | |
256 } | |
257 }, | |
258 | |
259 /** | |
260 * @param {number} controllerType | |
261 * @return {bool} Whether the extension view should be shown instead of the | |
262 * default route info element or the new web UI route controller. | |
263 * @private | |
264 */ | |
265 shouldShowExtensionView_: function(controllerType) { | |
266 return controllerType === media_router.ControllerType.EXTENSION; | |
267 }, | |
268 | |
269 /** | |
270 * @param {number} controllerType | |
271 * @return {bool} Whether the route info element should be shown instead of | |
272 * the extension view or the new web UI route controller. | |
273 * @private | |
274 */ | |
275 shouldShowRouteInfoOnly_: function(controllerType) { | |
276 return controllerType === media_router.ControllerType.NONE; | |
277 }, | |
278 | |
279 /** | |
280 * @param {number} controllerType | |
281 * @return {bool} Whether new web UI route controller should be shown instead | |
282 * of the default route info element or the extension view. | |
283 * @private | |
284 */ | |
285 shouldShowWebUiControls_: function(controllerType) { | |
286 return controllerType === media_router.ControllerType.WEBUI; | |
287 }, | |
288 | |
289 /** | |
290 * Fires a join-route-click event if the current route is joinable, otherwise | |
291 * it fires a change-route-source-click event, which changes the source of the | |
292 * current route. This may cause the current route to be closed and a new | |
293 * route to be started. This is called when the button to start casting to the | |
294 * current route is clicked. | |
295 * | |
296 * @private | |
297 */ | |
298 startCastingToRoute_: function() { | |
299 if (this.route.canJoin) { | |
300 this.fire('join-route-click', {route: this.route}); | |
301 } else { | |
302 this.fire('change-route-source-click', { | |
303 route: this.route, | |
304 selectedCastMode: | |
305 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) | |
306 }); | |
307 } | |
308 }, | |
214 }); | 309 }); |
OLD | NEW |