Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/resources/media_router/elements/route_details/route_details.js

Issue 2142613002: [Media Router WebUI] Move replace route responsibility to extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename event name in route_details_tests.js Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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|. Returning 0 means there is no cast mode
137 * available to |sink| and therefore the start-casting-to-route button
138 * will not be shown.
139 */
140 computeSelectedCastMode_: function(castMode, sink) {
141 // |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
143 // 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
145 // 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
147 // you arrive at this function with a null |sink|.
148 if (!sink) {
149 return 0;
150 }
151 if (castMode == media_router.CastModeType.AUTO) {
152 return sink.castModes & -sink.castModes;
153 }
154 return castMode & sink.castModes;
155 },
156
157 /**
133 * Fires a join-route-click event if the current route is joinable, otherwise 158 * 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 159 * 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 160 * 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. 161 * route to be started. This is called when the button to start casting to the
162 * current route is clicked.
137 * 163 *
138 * @private 164 * @private
139 */ 165 */
140 startCastingToRoute_: function() { 166 startCastingToRoute_: function() {
141 if (this.route.canJoin) { 167 if (this.route.canJoin) {
142 this.fire('join-route-click', {route: this.route}); 168 this.fire('join-route-click', {route: this.route});
143 } else { 169 } else {
144 this.fire('replace-route-click', {route: this.route}); 170 this.fire('change-route-source-click', {
171 route: this.route,
172 selectedCastMode:
173 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink)
174 });
145 } 175 }
146 }, 176 },
147 177
148 /** 178 /**
149 * Loads the custom controller if |route.customControllerPath| exists. 179 * Loads the custom controller if |route.customControllerPath| exists.
150 * Falls back to the default route details view otherwise, or if load fails. 180 * Falls back to the default route details view otherwise, or if load fails.
151 * Updates |activityStatus_| for the default view. 181 * Updates |activityStatus_| for the default view.
152 * 182 *
153 * @private 183 * @private
154 */ 184 */
(...skipping 20 matching lines...) Expand all
175 extensionview.load(this.route.customControllerPath) 205 extensionview.load(this.route.customControllerPath)
176 .then(function() { 206 .then(function() {
177 // Load was successful; show the custom controller. 207 // Load was successful; show the custom controller.
178 that.isCustomControllerHidden_ = false; 208 that.isCustomControllerHidden_ = false;
179 }, function() { 209 }, function() {
180 // Load was unsuccessful; fall back to default view. 210 // Load was unsuccessful; fall back to default view.
181 that.isCustomControllerHidden_ = true; 211 that.isCustomControllerHidden_ = true;
182 }); 212 });
183 }, 213 },
184 }); 214 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698