Chromium Code Reviews| 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 * Whether a sink is currently launching in the container. | 31 * Whether a sink is currently launching in the container. |
| 32 * @type {boolean} | 32 * @type {boolean} |
| 33 */ | 33 */ |
| 34 isAnySinkCurrentlyLaunching: { | 34 isAnySinkCurrentlyLaunching: { |
| 35 type: Boolean, | 35 type: Boolean, |
| 36 value: false, | 36 value: false, |
| 37 }, | 37 }, |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Whether the custom controller extension view should be hidden. | |
| 41 * The extension view is shown iff |route| specifies customControllerPath, | |
| 42 * the view can be loaded, and we are not using the new controls. | |
| 43 * @private {boolean} | |
| 44 */ | |
| 45 isExtensionViewHidden_: { | |
| 46 type: Boolean, | |
| 47 value: true, | |
| 48 }, | |
| 49 | |
| 50 /** | |
| 40 * The route to show. | 51 * The route to show. |
| 41 * @type {?media_router.Route|undefined} | 52 * @type {?media_router.Route|undefined} |
| 42 */ | 53 */ |
| 43 route: { | 54 route: { |
| 44 type: Object, | 55 type: Object, |
| 45 observer: 'maybeLoadCustomController_', | 56 observer: 'onRouteChange_', |
| 46 }, | 57 }, |
| 47 | 58 |
| 48 /** | 59 /** |
| 49 * The cast mode shown to the user. Initially set to auto mode. (See | 60 * The cast mode shown to the user. Initially set to auto mode. (See |
| 50 * media_router.CastMode documentation for details on auto mode.) | 61 * media_router.CastMode documentation for details on auto mode.) |
| 51 * @type {number} | 62 * @type {number} |
| 52 */ | 63 */ |
| 53 shownCastModeValue: { | 64 shownCastModeValue: { |
| 54 type: Number, | 65 type: Number, |
| 55 value: media_router.AUTO_CAST_MODE.type, | 66 value: media_router.AUTO_CAST_MODE.type, |
| 56 }, | 67 }, |
| 57 | 68 |
| 58 /** | 69 /** |
| 59 * Sink associated with |route|. | 70 * Sink associated with |route|. |
| 60 * @type {?media_router.Sink} | 71 * @type {?media_router.Sink} |
| 61 */ | 72 */ |
| 62 sink: { | 73 sink: { |
| 63 type: Object, | 74 type: Object, |
| 64 value: null, | 75 value: null, |
| 65 }, | 76 }, |
| 66 | 77 |
| 67 /** | 78 /** |
| 68 * Whether the custom controller should be hidden. | 79 * Whether we should use the new route controls. If false, we use the |
| 69 * A custom controller is shown iff |route| specifies customControllerPath | 80 * extension view. |
| 70 * and the view can be loaded. | |
| 71 * @private {boolean} | |
| 72 */ | 81 */ |
| 73 isCustomControllerHidden_: { | 82 useNewRouteControls: { |
| 74 type: Boolean, | 83 type: Boolean, |
| 75 value: true, | 84 value: false, |
| 76 }, | 85 } |
| 77 }, | 86 }, |
| 78 | 87 |
| 79 behaviors: [ | 88 behaviors: [ |
| 80 I18nBehavior, | 89 I18nBehavior, |
| 81 ], | 90 ], |
| 82 | 91 |
| 83 /** | 92 /** |
| 84 * Fires a close-route event. This is called when the button to close | 93 * Fires a close-route event. This is called when the button to close |
| 85 * the current route is clicked. | 94 * the current route is clicked. |
| 86 * | 95 * |
| 87 * @private | 96 * @private |
| 88 */ | 97 */ |
| 89 closeRoute_: function() { | 98 closeRoute_: function() { |
| 99 this.routeStatus = null; | |
| 90 this.fire('close-route', {route: this.route}); | 100 this.fire('close-route', {route: this.route}); |
| 91 }, | 101 }, |
| 92 | 102 |
| 93 /** | 103 /** |
| 94 * @param {?media_router.Route|undefined} route | 104 * @param {?media_router.Route|undefined} route |
| 95 * @param {boolean} changeRouteSourceAvailable | 105 * @param {boolean} changeRouteSourceAvailable |
| 96 * @return {boolean} Whether to show the button that allows casting to the | 106 * @return {boolean} Whether to show the button that allows casting to the |
| 97 * current route or the current route's sink. | 107 * current route or the current route's sink. |
| 98 */ | 108 */ |
| 99 computeCastButtonHidden_: function(route, changeRouteSourceAvailable) { | 109 computeCastButtonHidden_: function(route, changeRouteSourceAvailable) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 if (!sink) { | 158 if (!sink) { |
| 149 return 0; | 159 return 0; |
| 150 } | 160 } |
| 151 if (castMode == media_router.CastModeType.AUTO) { | 161 if (castMode == media_router.CastModeType.AUTO) { |
| 152 return sink.castModes & -sink.castModes; | 162 return sink.castModes & -sink.castModes; |
| 153 } | 163 } |
| 154 return castMode & sink.castModes; | 164 return castMode & sink.castModes; |
| 155 }, | 165 }, |
| 156 | 166 |
| 157 /** | 167 /** |
| 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. | 168 * Loads the custom controller if |route.customControllerPath| exists. |
| 180 * Falls back to the default route details view otherwise, or if load fails. | 169 * Falls back to the default route details view otherwise, or if load fails. |
| 181 * Updates |activityStatus_| for the default view. | 170 * Updates |activityStatus_| for the default view. |
| 182 * | 171 * |
| 183 * @private | 172 * @private |
| 184 */ | 173 */ |
| 185 maybeLoadCustomController_: function() { | 174 maybeLoadExtensionView_: function() { |
| 186 this.activityStatus_ = this.route ? | 175 this.activityStatus_ = this.route ? |
| 187 loadTimeData.getStringF('castingActivityStatus', | 176 loadTimeData.getStringF('castingActivityStatus', |
| 188 this.route.description) : | 177 this.route.description) : |
| 189 ''; | 178 ''; |
| 190 | 179 |
| 191 if (!this.route || !this.route.customControllerPath) { | 180 if (!this.route || !this.route.customControllerPath) { |
| 192 this.isCustomControllerHidden_ = true; | 181 this.isExtensionViewHidden_ = true; |
| 193 return; | 182 return; |
| 194 } | 183 } |
| 195 | 184 |
| 196 // Show custom controller | 185 // Show custom controller |
| 197 var extensionview = this.$['custom-controller']; | 186 var extensionview = this.$['custom-controller']; |
| 198 | 187 |
| 199 // Do nothing if the url is the same and the view is not hidden. | 188 // Do nothing if the url is the same and the view is not hidden. |
| 200 if (this.route.customControllerPath == extensionview.src && | 189 if (this.route.customControllerPath == extensionview.src && |
| 201 !this.isCustomControllerHidden_) | 190 !this.isExtensionViewHidden_) |
| 202 return; | 191 return; |
| 203 | 192 |
| 204 var that = this; | 193 var that = this; |
| 205 extensionview.load(this.route.customControllerPath) | 194 extensionview.load(this.route.customControllerPath) |
| 206 .then(function() { | 195 .then(function() { |
| 207 // Load was successful; show the custom controller. | 196 // Load was successful; show the custom controller. |
| 208 that.isCustomControllerHidden_ = false; | 197 that.isExtensionViewHidden_ = false; |
| 209 }, function() { | 198 }, function() { |
| 210 // Load was unsuccessful; fall back to default view. | 199 // Load was unsuccessful; fall back to default view. |
| 211 that.isCustomControllerHidden_ = true; | 200 that.isExtensionViewHidden_ = true; |
| 212 }); | 201 }); |
| 213 }, | 202 }, |
| 203 | |
| 204 /** | |
| 205 * Called when the route details view is closed. | |
| 206 */ | |
| 207 onClosed: function() { | |
| 208 this.$$('route-controls').onRouteDetailsClosed(); | |
| 209 }, | |
| 210 | |
| 211 /** | |
| 212 * Called when the route details view is opened. | |
| 213 */ | |
| 214 onOpened: function() { | |
| 215 media_router.ui.setRouteControls(this.$$('route-controls')); | |
| 216 }, | |
| 217 | |
| 218 /** | |
| 219 * Updates either the extension view or the new route controller, depending on | |
| 220 * which should be shown. | |
| 221 * @private | |
| 222 */ | |
| 223 onRouteChange_: function(newRoute) { | |
| 224 if (!this.useNewRouteControls) | |
| 225 this.maybeLoadExtensionView_(); | |
| 226 | |
| 227 if (newRoute) | |
| 228 this.$$('route-controls').route = newRoute; | |
| 229 }, | |
| 230 | |
| 231 /** | |
| 232 * @param {bool} useNewRouteControls | |
| 233 * @param {bool} isExtensionViewHidden | |
| 234 * @return {bool} Whether the extension view should be shown instead of the | |
| 235 * default route info element or the new route controller. | |
| 236 * @private | |
| 237 */ | |
| 238 shouldShowExtensionView_: function(useNewRouteControls, | |
| 239 isExtensionViewHidden) { | |
| 240 return !useNewRouteControls && !isExtensionViewHidden; | |
|
mark a. foltz
2017/05/03 21:27:01
If !isExtensionViewHidden is it already being show
takumif
2017/05/05 18:57:40
Renamed the variable to isExtensionViewReady
| |
| 241 }, | |
| 242 | |
| 243 /** | |
| 244 * @param {bool} useNewRouteControls | |
| 245 * @param {bool} isExtensionViewHidden | |
| 246 * @return {bool} Whether the route info element should be shown instead of | |
| 247 * the extension view or the new route controller. | |
| 248 * @private | |
| 249 */ | |
| 250 shouldShowRouteInfo_: function(useNewRouteControls, isExtensionViewHidden) { | |
|
mark a. foltz
2017/05/03 21:27:01
Is this for routes that have no media controls?
It
takumif
2017/05/05 18:57:40
This is for when extension view is enabled but the
| |
| 251 return !useNewRouteControls && isExtensionViewHidden; | |
| 252 }, | |
| 253 | |
| 254 /** | |
| 255 * Fires a join-route-click event if the current route is joinable, otherwise | |
| 256 * it fires a change-route-source-click event, which changes the source of the | |
| 257 * current route. This may cause the current route to be closed and a new | |
| 258 * route to be started. This is called when the button to start casting to the | |
| 259 * current route is clicked. | |
| 260 * | |
| 261 * @private | |
| 262 */ | |
| 263 startCastingToRoute_: function() { | |
| 264 if (this.route.canJoin) { | |
|
mark a. foltz
2017/05/03 21:27:01
"Joining" or "changing source" should just be anot
takumif
2017/05/05 18:57:40
Acknowledged.
| |
| 265 this.fire('join-route-click', {route: this.route}); | |
| 266 } else { | |
| 267 this.fire('change-route-source-click', { | |
| 268 route: this.route, | |
| 269 selectedCastMode: | |
| 270 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) | |
| 271 }); | |
| 272 } | |
| 273 }, | |
| 214 }); | 274 }); |
| OLD | NEW |