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

Unified 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 Mark's comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/media_router/elements/route_details/route_details.js
diff --git a/chrome/browser/resources/media_router/elements/route_details/route_details.js b/chrome/browser/resources/media_router/elements/route_details/route_details.js
index ae7ebcca5e1d63a66b704f13ce420e12c896879c..a2e3b801c390c40dc2197274378a953d5e5c5016 100644
--- a/chrome/browser/resources/media_router/elements/route_details/route_details.js
+++ b/chrome/browser/resources/media_router/elements/route_details/route_details.js
@@ -24,7 +24,17 @@ Polymer({
changeRouteSourceAvailable_: {
type: Boolean,
computed: 'computeChangeRouteSourceAvailable_(route, sink,' +
- 'isAnySinkCurrentlyLaunching, shownCastModeValue)',
+ 'isAnySinkCurrentlyLaunching, shownCastModeValue)',
+ },
+
+ /**
+ * An enum value to represent the controller to show.
+ * @private {number}
+ */
+ controllerType_: {
+ type: Number,
+ computed: 'computeControllerType_(useWebUiRouteControls,' +
+ 'isExtensionViewReady_)',
},
/**
@@ -37,12 +47,21 @@ Polymer({
},
/**
+ * Whether the custom controller extension view is ready to be shown.
+ * @private {boolean}
+ */
+ isExtensionViewReady_: {
+ type: Boolean,
+ value: false,
+ },
+
+ /**
* The route to show.
* @type {?media_router.Route|undefined}
*/
route: {
type: Object,
- observer: 'maybeLoadCustomController_',
+ observer: 'onRouteChange_',
},
/**
@@ -65,15 +84,13 @@ Polymer({
},
/**
- * Whether the custom controller should be hidden.
- * A custom controller is shown iff |route| specifies customControllerPath
- * and the view can be loaded.
- * @private {boolean}
+ * Whether we should use the new route controls. If false, we use the
+ * extension view.
imcheng 2017/05/05 21:36:40 @type {boolean}
takumif 2017/05/09 00:14:57 Done.
*/
- isCustomControllerHidden_: {
+ useWebUiRouteControls: {
type: Boolean,
- value: true,
- },
+ value: false,
+ }
},
behaviors: [
@@ -130,6 +147,23 @@ Polymer({
},
/**
+ * @param {bool} useWebUiRouteControls
imcheng 2017/05/05 21:36:41 s/bool/boolean here and below
takumif 2017/05/09 00:14:57 Done.
+ * @param {bool} isExtensionViewReady_
+ * @return {number} An enum value to represent the controller to show.
+ * @private
+ */
+ computeControllerType_: function(useWebUiRouteControls,
+ isExtensionViewReady_) {
+ if (useWebUiRouteControls) {
+ return media_router.ControllerType.WEBUI;
+ }
+ if (isExtensionViewReady_) {
+ return media_router.ControllerType.EXTENSION;
+ }
+ return media_router.ControllerType.NONE;
+ },
+
+ /**
* @param {number} castMode User selected cast mode or AUTO.
* @param {?media_router.Sink} sink Sink to which we will cast.
* @return {number} The selected cast mode when |castMode| is selected in the
@@ -155,41 +189,20 @@ Polymer({
},
/**
- * Fires a join-route-click event if the current route is joinable, otherwise
- * it fires a change-route-source-click event, which changes the source of the
- * current route. This may cause the current route to be closed and a new
- * route to be started. This is called when the button to start casting to the
- * current route is clicked.
- *
- * @private
- */
- startCastingToRoute_: function() {
- if (this.route.canJoin) {
- this.fire('join-route-click', {route: this.route});
- } else {
- this.fire('change-route-source-click', {
- route: this.route,
- selectedCastMode:
- this.computeSelectedCastMode_(this.shownCastModeValue, this.sink)
- });
- }
- },
-
- /**
* Loads the custom controller if |route.customControllerPath| exists.
* Falls back to the default route details view otherwise, or if load fails.
* Updates |activityStatus_| for the default view.
*
* @private
*/
- maybeLoadCustomController_: function() {
+ maybeLoadExtensionView_: function() {
this.activityStatus_ = this.route ?
loadTimeData.getStringF('castingActivityStatus',
this.route.description) :
'';
if (!this.route || !this.route.customControllerPath) {
- this.isCustomControllerHidden_ = true;
+ this.isExtensionViewReady_ = false;
return;
}
@@ -198,17 +211,99 @@ Polymer({
// Do nothing if the url is the same and the view is not hidden.
if (this.route.customControllerPath == extensionview.src &&
- !this.isCustomControllerHidden_)
+ this.shouldShowExtensionView_) {
return;
+ }
var that = this;
extensionview.load(this.route.customControllerPath)
.then(function() {
// Load was successful; show the custom controller.
- that.isCustomControllerHidden_ = false;
+ that.isExtensionViewReady_ = true;
}, function() {
// Load was unsuccessful; fall back to default view.
- that.isCustomControllerHidden_ = true;
+ that.isExtensionViewReady_ = false;
});
},
+
+ /**
+ * Called when the route details view is closed.
+ */
+ onClosed: function() {
+ if (this.$$('route-controls')) {
+ this.$$('route-controls').onRouteDetailsClosed();
+ }
+ },
+
+ /**
+ * Called when the route details view is opened.
+ */
+ onOpened: function() {
+ 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
+ },
+
+ /**
+ * Updates either the extension view or the new route controller, depending on
+ * which should be shown.
+ * @private
+ */
+ onRouteChange_: function(newRoute) {
+ if (!this.useWebUiRouteControls) {
+ this.maybeLoadExtensionView_();
+ }
+ if (newRoute && this.$$('route-controls')) {
+ this.$$('route-controls').onRouteUpdated(newRoute);
+ }
+ },
+
+ /**
+ * @param {number} controllerType
+ * @return {bool} Whether the extension view should be shown instead of the
+ * default route info element or the new web UI route controller.
+ * @private
+ */
+ shouldShowExtensionView_: function(controllerType) {
+ return controllerType === media_router.ControllerType.EXTENSION;
+ },
+
+ /**
+ * @param {number} controllerType
+ * @return {bool} Whether the route info element should be shown instead of
+ * the extension view or the new web UI route controller.
+ * @private
+ */
+ shouldShowRouteInfoOnly_: function(controllerType) {
+ return controllerType === media_router.ControllerType.NONE;
+ },
+
+ /**
+ * @param {number} controllerType
+ * @return {bool} Whether new web UI route controller should be shown instead
+ * of the default route info element or the extension view.
+ * @private
+ */
+ shouldShowWebUiControls_: function(controllerType) {
+ return controllerType === media_router.ControllerType.WEBUI;
+ },
+
+ /**
+ * Fires a join-route-click event if the current route is joinable, otherwise
+ * it fires a change-route-source-click event, which changes the source of the
+ * current route. This may cause the current route to be closed and a new
+ * route to be started. This is called when the button to start casting to the
+ * current route is clicked.
+ *
+ * @private
+ */
+ startCastingToRoute_: function() {
+ if (this.route.canJoin) {
+ this.fire('join-route-click', {route: this.route});
+ } else {
+ this.fire('change-route-source-click', {
+ route: this.route,
+ selectedCastMode:
+ this.computeSelectedCastMode_(this.shownCastModeValue, this.sink)
+ });
+ }
+ },
});

Powered by Google App Engine
This is Rietveld 408576698