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 | |
| 21 * events. | |
| 22 * @private {boolean} | |
| 23 */ | |
| 24 changeRouteSourceAvailable_: { | |
| 25 type: Boolean, | |
| 26 computed: 'computeChangeRouteSourceAvailable_(route, sink,' + | |
| 27 'isAnySinkCurrentlyLaunching, shownCastModeValue)', | |
| 28 }, | |
| 29 | |
| 30 /** | |
| 20 * Whether a sink is currently launching in the container. | 31 * Whether a sink is currently launching in the container. |
| 21 * @type {boolean} | 32 * @type {boolean} |
| 22 */ | 33 */ |
| 23 isAnySinkCurrentlyLaunching: { | 34 isAnySinkCurrentlyLaunching: { |
| 24 type: Boolean, | 35 type: Boolean, |
| 25 value: false, | 36 value: false, |
| 26 }, | 37 }, |
| 27 | 38 |
| 28 /** | 39 /** |
| 29 * Whether the external container will accept replace-route-click events. | |
| 30 * @private {boolean} | |
| 31 */ | |
| 32 replaceRouteAvailable_: { | |
| 33 type: Boolean, | |
| 34 computed: 'computeReplaceRouteAvailable_(route, sink,' + | |
| 35 'isAnySinkCurrentlyLaunching, shownCastModeValue)', | |
| 36 }, | |
| 37 | |
| 38 /** | |
| 39 * The route to show. | 40 * The route to show. |
| 40 * @type {?media_router.Route|undefined} | 41 * @type {?media_router.Route|undefined} |
| 41 */ | 42 */ |
| 42 route: { | 43 route: { |
| 43 type: Object, | 44 type: Object, |
| 44 observer: 'maybeLoadCustomController_', | 45 observer: 'maybeLoadCustomController_', |
| 45 }, | 46 }, |
| 46 | 47 |
| 47 /** | 48 /** |
| 48 * The cast mode shown to the user. Initially set to auto mode. (See | 49 * The cast mode shown to the user. Initially set to auto mode. (See |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 * the current route is clicked. | 85 * the current route is clicked. |
| 85 * | 86 * |
| 86 * @private | 87 * @private |
| 87 */ | 88 */ |
| 88 closeRoute_: function() { | 89 closeRoute_: function() { |
| 89 this.fire('close-route', {route: this.route}); | 90 this.fire('close-route', {route: this.route}); |
| 90 }, | 91 }, |
| 91 | 92 |
| 92 /** | 93 /** |
| 93 * @param {?media_router.Route|undefined} route | 94 * @param {?media_router.Route|undefined} route |
| 94 * @param {boolean} replaceRouteAvailable | 95 * @param {boolean} changeRouteSourceAvailable |
| 95 * @return {boolean} Whether to show the button that allows casting to the | 96 * @return {boolean} Whether to show the button that allows casting to the |
| 96 * current route or the current route's sink. | 97 * current route or the current route's sink. |
| 97 */ | 98 */ |
| 98 computeCastButtonHidden_: function(route, replaceRouteAvailable) { | 99 computeCastButtonHidden_: function(route, changeRouteSourceAvailable) { |
| 99 return !((route && route.canJoin) || replaceRouteAvailable); | 100 return !((route && route.canJoin) || changeRouteSourceAvailable); |
| 100 }, | 101 }, |
| 101 | 102 |
| 102 /** | 103 /** |
| 103 * @param {?media_router.Route|undefined} route The current route for the | 104 * @param {?media_router.Route|undefined} route The current route for the |
| 104 * route details view. | 105 * route details view. |
| 105 * @param {?media_router.Sink|undefined} sink Sink associated with |route|. | 106 * @param {?media_router.Sink|undefined} sink Sink associated with |route|. |
| 106 * @param {boolean} isAnySinkCurrentlyLaunching Whether a sink is launching | 107 * @param {boolean} isAnySinkCurrentlyLaunching Whether a sink is launching |
| 107 * now. | 108 * now. |
| 108 * @param {number} shownCastModeValue Currently selected cast mode value or | 109 * @param {number} shownCastModeValue Currently selected cast mode value or |
| 109 * AUTO if no value has been explicitly selected. | 110 * AUTO if no value has been explicitly selected. |
| 110 * @return {boolean} Whether the replace route function should be available | 111 * @return {boolean} Whether the change route source function should be |
| 111 * when displaying |currentRoute| in the route details view. Replace route | 112 * available when displaying |currentRoute| in the route details view. |
| 112 * should not be available when the source that would be cast from when | 113 * Changing the route source should not be available when the currently |
| 113 * creating a new route would be the same as the route's current source. | 114 * selected source that would be cast is the same as the route's current |
| 115 * source. | |
| 114 * @private | 116 * @private |
| 115 */ | 117 */ |
| 116 computeReplaceRouteAvailable_: function( | 118 computeChangeRouteSourceAvailable_: function( |
| 117 route, sink, isAnySinkCurrentlyLaunching, shownCastModeValue) { | 119 route, sink, isAnySinkCurrentlyLaunching, shownCastModeValue) { |
| 118 if (isAnySinkCurrentlyLaunching || !route || !sink) { | 120 if (isAnySinkCurrentlyLaunching || !route || !sink) { |
| 119 return false; | 121 return false; |
| 120 } | 122 } |
| 121 if (!route.currentCastMode) { | 123 if (!route.currentCastMode) { |
| 122 return true; | 124 return true; |
| 123 } | 125 } |
| 124 var selectedCastMode = shownCastModeValue; | 126 var selectedCastMode = |
| 125 if (selectedCastMode == media_router.CastModeType.AUTO) { | 127 this.computeSelectedCastMode_(shownCastModeValue, sink); |
| 126 selectedCastMode = sink.castModes & -sink.castModes; | 128 return (selectedCastMode != 0) && |
| 127 } | |
| 128 return ((selectedCastMode & sink.castModes) != 0) && | |
| 129 (selectedCastMode != route.currentCastMode); | 129 (selectedCastMode != route.currentCastMode); |
| 130 }, | 130 }, |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * @param {number} castMode User selected cast mode or AUTO. | |
| 134 * @param {?media_router.Sink} sink Sink to which we will cast. | |
| 135 * @return {number} The selected cast mode when |castMode| is selected in the | |
| 136 * dialog and casting to |sink|. | |
| 137 */ | |
| 138 computeSelectedCastMode_: function(castMode, sink) { | |
| 139 if (!sink) { | |
|
imcheng
2016/07/27 20:30:37
Is this case possible since sink has to be non-nul
btolsch
2016/07/27 22:16:41
0 means there is no cast mode selected/available t
imcheng
2016/08/01 17:36:31
So firing the change-route-source-click event with
btolsch
2016/08/02 19:23:39
It's actually already impossible to fire the event
| |
| 140 return 0; | |
| 141 } | |
| 142 if (castMode == media_router.CastModeType.AUTO) { | |
| 143 return sink.castModes & -sink.castModes; | |
| 144 } | |
| 145 return castMode & sink.castModes; | |
| 146 }, | |
| 147 | |
| 148 /** | |
| 133 * Fires a join-route-click event if the current route is joinable, otherwise | 149 * Fires a join-route-click event if the current route is joinable, otherwise |
| 134 * it fires a replace-route-click event, which stops the current route and | 150 * it fires a change-route-source-click event, which changes the source of the |
| 135 * immediately launches a new route to the same sink. This is called when the | 151 * current route. This may cause the current route to be closed and a new |
| 136 * button to start casting to the current route is clicked. | 152 * route to be started. This is called when the button to start casting to the |
| 153 * current route is clicked. | |
| 137 * | 154 * |
| 138 * @private | 155 * @private |
| 139 */ | 156 */ |
| 140 startCastingToRoute_: function() { | 157 startCastingToRoute_: function() { |
| 141 if (this.route.canJoin) { | 158 if (this.route.canJoin) { |
| 142 this.fire('join-route-click', {route: this.route}); | 159 this.fire('join-route-click', {route: this.route}); |
| 143 } else { | 160 } else { |
| 144 this.fire('replace-route-click', {route: this.route}); | 161 this.fire('change-route-source-click', { |
| 162 route: this.route, | |
| 163 selectedCastMode: | |
| 164 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) | |
| 165 }); | |
| 145 } | 166 } |
| 146 }, | 167 }, |
| 147 | 168 |
| 148 /** | 169 /** |
| 149 * Loads the custom controller if |route.customControllerPath| exists. | 170 * Loads the custom controller if |route.customControllerPath| exists. |
| 150 * Falls back to the default route details view otherwise, or if load fails. | 171 * Falls back to the default route details view otherwise, or if load fails. |
| 151 * Updates |activityStatus_| for the default view. | 172 * Updates |activityStatus_| for the default view. |
| 152 * | 173 * |
| 153 * @private | 174 * @private |
| 154 */ | 175 */ |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 175 extensionview.load(this.route.customControllerPath) | 196 extensionview.load(this.route.customControllerPath) |
| 176 .then(function() { | 197 .then(function() { |
| 177 // Load was successful; show the custom controller. | 198 // Load was successful; show the custom controller. |
| 178 that.isCustomControllerHidden_ = false; | 199 that.isCustomControllerHidden_ = false; |
| 179 }, function() { | 200 }, function() { |
| 180 // Load was unsuccessful; fall back to default view. | 201 // Load was unsuccessful; fall back to default view. |
| 181 that.isCustomControllerHidden_ = true; | 202 that.isCustomControllerHidden_ = true; |
| 182 }); | 203 }); |
| 183 }, | 204 }, |
| 184 }); | 205 }); |
| OLD | NEW |