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

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

Issue 2725503002: [Media Router] Custom Controls 4 - Implement details view WebUI (Closed)
Patch Set: Address Derek's comments, don't load extensionview unnecessarily Created 3 years, 7 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 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,' +
mark a. foltz 2017/05/12 00:02:46 Can the parameters be pulled from the element inst
takumif 2017/05/15 17:13:12 They are passed in here so that when they change,
mark a. foltz 2017/05/15 20:43:22 Acknowledged.
37 'isExtensionViewReady)',
38 },
mark a. foltz 2017/05/12 00:02:46 Do you need an observer to update this value if is
takumif 2017/05/15 17:13:12 The method in the "computed" attribute gets called
mark a. foltz 2017/05/15 20:43:22 Acknowledged.
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 * @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. If false, we use the
69 * A custom controller is shown iff |route| specifies customControllerPath 88 * extension view.
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
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() {
mark a. foltz 2017/05/12 00:02:47 This seems to duplicate displayedDescription_. Wha
takumif 2017/05/15 17:13:12 |activityStatus_| is the fallback route descriptio
198 this.activityStatus_ = this.route ?
199 loadTimeData.getStringF('castingActivityStatus',
200 this.route.description) :
201 '';
202 },
203
204 /**
205 * Called when the route details view is closed.
206 */
207 onClosed: function() {
208 if (this.useWebUiRouteControls) {
mark a. foltz 2017/05/12 00:02:46 This could use controllerType_ == WEBUI as logical
takumif 2017/05/15 17:13:12 Done.
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.useWebUiRouteControls) {
218 media_router.ui.setRouteControls(this.$['route-controls']);
219 }
220 },
221
222 /**
223 * Updates either the extension view or the new route controller, depending on
224 * which should be shown.
225 * @private
226 */
227 onRouteChange_: function(newRoute) {
228 if (!this.useWebUiRouteControls) {
229 this.updateActivityStatus_();
230 }
231 if (newRoute && this.useWebUiRouteControls) {
232 this.$['route-controls'].onRouteUpdated(newRoute);
233 }
234 },
235
236 /**
237 * Called by Polymer when this element is ready.
238 */
239 ready: function() {
240 this.onOpened();
241 },
242
243 /**
244 * @param {number} controllerType
245 * @return {boolean} Whether the extension view should be shown instead of the
246 * default route info element or the new web UI route controller.
247 * @private
248 */
249 shouldShowExtensionView_: function(controllerType) {
250 return controllerType === media_router.ControllerType.EXTENSION;
251 },
252
253 /**
254 * @param {number} controllerType
255 * @return {boolean} Whether the route info element should be shown instead of
256 * the extension view or the new web UI route controller.
257 * @private
258 */
259 shouldShowRouteInfoOnly_: function(controllerType) {
260 return controllerType === media_router.ControllerType.NONE;
261 },
262
263 /**
264 * @param {number} controllerType
265 * @return {boolean} Whether new web UI route controller should be shown
266 * instead of the default route info element or the extension view.
267 * @private
268 */
269 shouldShowWebUiControls_: function(controllerType) {
270 return controllerType === media_router.ControllerType.WEBUI;
271 },
272
273 /**
158 * Fires a join-route-click event if the current route is joinable, otherwise 274 * 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 275 * 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 276 * 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 277 * route to be started. This is called when the button to start casting to the
162 * current route is clicked. 278 * current route is clicked.
163 * 279 *
164 * @private 280 * @private
165 */ 281 */
166 startCastingToRoute_: function() { 282 startCastingToRoute_: function() {
167 if (this.route.canJoin) { 283 if (this.route.canJoin) {
168 this.fire('join-route-click', {route: this.route}); 284 this.fire('join-route-click', {route: this.route});
169 } else { 285 } else {
170 this.fire('change-route-source-click', { 286 this.fire('change-route-source-click', {
171 route: this.route, 287 route: this.route,
172 selectedCastMode: 288 selectedCastMode:
173 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink) 289 this.computeSelectedCastMode_(this.shownCastModeValue, this.sink)
174 }); 290 });
175 } 291 }
176 }, 292 },
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 }); 293 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698