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

Unified Diff: chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js

Issue 2862393002: [Media Router] Force DEFAULT cast mode when starting presentations from content. (Closed)
Patch Set: Fix bug found by closure compiler 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/media_router_container/media_router_container.js
diff --git a/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js b/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
index ff9296814a7eeddcf8752044bf520113b037fe76..48a1d0ee376b4a48679079f60808fde666859460 100644
--- a/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
+++ b/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
@@ -530,6 +530,11 @@ Polymer({
if (!this.castModeList.length)
return;
+ // If there is a forced mode make sure it is shown.
+ if (this.findForcedCastMode_()) {
+ this.rebuildSinksToShow_();
+ }
+
// If we are currently showing auto mode, then nothing needs to be done.
// Otherwise, if the cast mode currently shown no longer exists (regardless
// of whether it was selected by user), then switch back to auto cast mode.
@@ -611,13 +616,18 @@ Polymer({
},
/**
- * If |allSinks| supports only a single cast mode, returns that cast mode.
- * Otherwise, returns AUTO_MODE. Only called if |userHasSelectedCastMode_| is
- * |false|.
+ * If there is a forced cast mode, returns that cast mode. If |allSinks|
+ * supports only a single cast mode, returns that cast mode. Otherwise,
+ * returns AUTO_MODE. Only called if |userHasSelectedCastMode_| is |false|.
+ *
* @return {!media_router.CastMode} The single cast mode supported by
* |allSinks|, or AUTO_MODE.
*/
computeCastMode_: function() {
+ /** @const */ var forcedMode = this.findForcedCastMode_();
+ if (forcedMode)
+ return forcedMode;
+
var allCastModes = this.allSinks.reduce(function(castModesSoFar, sink) {
return castModesSoFar | sink.castModes;
}, 0);
@@ -1149,6 +1159,17 @@ Polymer({
},
/**
+ * Helper function to return a forced CastMode, if any.
+ *
+ * @return {media_router.CastMode|undefined} CastMode object with
+ * isForced = true, or undefined if not found.
+ */
+ findForcedCastMode_: function() {
+ return this.castModeList &&
+ this.castModeList.find(element => element.isForced);
+ },
+
+ /**
* @param {?Element} element Element to compute padding for.
* @return {!Array<number>} Array containing the element's bottom padding
* value and the element's top padding value, in that order.
@@ -1978,20 +1999,21 @@ Polymer({
updatedSinkList.unshift(pendingPseudoSink);
}
}
- if (this.userHasSelectedCastMode_) {
- // If user explicitly selected a cast mode, then we show only sinks that
- // are compatible with current cast mode or sinks that are active.
+ // If user did not select a cast mode, then:
+ // - If there is a forced cast mode, it is shown.
+ // - If all sinks support only a single cast mode, then the cast mode is
+ // switched to that mode.
+ // - Otherwise, the cast mode becomes AUTO mode.
+ if (!this.userHasSelectedCastMode_)
+ this.setShownCastMode_(this.computeCastMode_());
+
+ // Non-AUTO modes may show a subset of sinks based on compatibility with the
+ // shown value.
+ if (this.shownCastModeValue_ != media_router.CastModeType.AUTO) {
updatedSinkList = updatedSinkList.filter(function(element) {
return (element.castModes & this.shownCastModeValue_) ||
- this.sinkToRouteMap_[element.id];
+ this.sinkToRouteMap_[element.id];
}, this);
- } else {
- // If user did not select a cast mode, then:
- // - If all sinks support only a single cast mode, then the cast mode is
- // switched to that mode.
- // - Otherwise, the cast mode becomes auto mode.
- // Either way, all sinks will be shown.
- this.setShownCastMode_(this.computeCastMode_());
}
// When there's an updated list of sinks, append any new sinks to the end

Powered by Google App Engine
This is Rietveld 408576698