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

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc

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 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 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 DCHECK(GURL(full_custom_controller_path).is_valid()); 171 DCHECK(GURL(full_custom_controller_path).is_valid());
172 dictionary->SetString("customControllerPath", 172 dictionary->SetString("customControllerPath",
173 full_custom_controller_path); 173 full_custom_controller_path);
174 } 174 }
175 175
176 return dictionary; 176 return dictionary;
177 } 177 }
178 178
179 std::unique_ptr<base::ListValue> CastModesToValue( 179 std::unique_ptr<base::ListValue> CastModesToValue(
180 const CastModeSet& cast_modes, 180 const CastModeSet& cast_modes,
181 const std::string& source_host) { 181 const std::string& source_host,
182 base::Optional<MediaCastMode> forced_cast_mode) {
182 std::unique_ptr<base::ListValue> value(new base::ListValue); 183 std::unique_ptr<base::ListValue> value(new base::ListValue);
183 184
184 for (const MediaCastMode& cast_mode : cast_modes) { 185 for (const MediaCastMode& cast_mode : cast_modes) {
185 std::unique_ptr<base::DictionaryValue> cast_mode_val( 186 std::unique_ptr<base::DictionaryValue> cast_mode_val(
186 new base::DictionaryValue); 187 new base::DictionaryValue);
187 cast_mode_val->SetInteger("type", cast_mode); 188 cast_mode_val->SetInteger("type", cast_mode);
188 cast_mode_val->SetString( 189 cast_mode_val->SetString(
189 "description", MediaCastModeToDescription(cast_mode, source_host)); 190 "description", MediaCastModeToDescription(cast_mode, source_host));
190 cast_mode_val->SetString("host", source_host); 191 cast_mode_val->SetString("host", source_host);
192 cast_mode_val->SetBoolean(
193 "isForced", forced_cast_mode && forced_cast_mode == cast_mode);
191 value->Append(std::move(cast_mode_val)); 194 value->Append(std::move(cast_mode_val));
192 } 195 }
193 196
194 return value; 197 return value;
195 } 198 }
196 199
197 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 200 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
198 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 201 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
199 const IssueInfo& issue_info = issue.info(); 202 const IssueInfo& issue_info = issue.info();
200 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 203 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 const std::vector<MediaRoute::Id>& joinable_route_ids, 271 const std::vector<MediaRoute::Id>& joinable_route_ids,
269 const std::unordered_map<MediaRoute::Id, MediaCastMode>& 272 const std::unordered_map<MediaRoute::Id, MediaCastMode>&
270 current_cast_modes) { 273 current_cast_modes) {
271 std::unique_ptr<base::ListValue> routes_val( 274 std::unique_ptr<base::ListValue> routes_val(
272 RoutesToValue(routes, joinable_route_ids, current_cast_modes)); 275 RoutesToValue(routes, joinable_route_ids, current_cast_modes));
273 web_ui()->CallJavascriptFunctionUnsafe(kSetRouteList, *routes_val); 276 web_ui()->CallJavascriptFunctionUnsafe(kSetRouteList, *routes_val);
274 } 277 }
275 278
276 void MediaRouterWebUIMessageHandler::UpdateCastModes( 279 void MediaRouterWebUIMessageHandler::UpdateCastModes(
277 const CastModeSet& cast_modes, 280 const CastModeSet& cast_modes,
278 const std::string& source_host) { 281 const std::string& source_host,
282 base::Optional<MediaCastMode> forced_cast_mode) {
279 DVLOG(2) << "UpdateCastModes"; 283 DVLOG(2) << "UpdateCastModes";
280 std::unique_ptr<base::ListValue> cast_modes_val( 284 std::unique_ptr<base::ListValue> cast_modes_val(
281 CastModesToValue(cast_modes, source_host)); 285 CastModesToValue(cast_modes, source_host, forced_cast_mode));
282 web_ui()->CallJavascriptFunctionUnsafe(kSetCastModeList, *cast_modes_val); 286 web_ui()->CallJavascriptFunctionUnsafe(kSetCastModeList, *cast_modes_val);
283 } 287 }
284 288
285 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( 289 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived(
286 const MediaSink::Id& sink_id, 290 const MediaSink::Id& sink_id,
287 const MediaRoute* route) { 291 const MediaRoute* route) {
288 DVLOG(2) << "OnCreateRouteResponseReceived"; 292 DVLOG(2) << "OnCreateRouteResponseReceived";
289 if (route) { 293 if (route) {
290 int current_cast_mode = CurrentCastModeForRouteId( 294 int current_cast_mode = CurrentCastModeForRouteId(
291 route->media_route_id(), media_router_ui_->routes_and_cast_modes()); 295 route->media_route_id(), media_router_ui_->routes_and_cast_modes());
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); 482 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo()));
479 initial_data.Set("sinksAndIdentity", std::move(sinks_and_identity)); 483 initial_data.Set("sinksAndIdentity", std::move(sinks_and_identity));
480 484
481 std::unique_ptr<base::ListValue> routes(RoutesToValue( 485 std::unique_ptr<base::ListValue> routes(RoutesToValue(
482 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(), 486 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(),
483 media_router_ui_->routes_and_cast_modes())); 487 media_router_ui_->routes_and_cast_modes()));
484 initial_data.Set("routes", std::move(routes)); 488 initial_data.Set("routes", std::move(routes));
485 489
486 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); 490 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes();
487 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( 491 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue(
488 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); 492 cast_modes, media_router_ui_->GetPresentationRequestSourceName(),
493 media_router_ui_->forced_cast_mode()));
489 initial_data.Set("castModes", std::move(cast_modes_list)); 494 initial_data.Set("castModes", std::move(cast_modes_list));
490 495
491 // If the cast mode last chosen for the current origin is tab mirroring, 496 // If the cast mode last chosen for the current origin is tab mirroring,
492 // that should be the cast mode initially selected in the dialog. Otherwise 497 // that should be the cast mode initially selected in the dialog. Otherwise
493 // the initial cast mode should be chosen automatically by the dialog. 498 // the initial cast mode should be chosen automatically by the dialog.
494 bool use_tab_mirroring = 499 bool use_tab_mirroring =
495 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) && 500 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) &&
496 media_router_ui_->UserSelectedTabMirroringForCurrentOrigin(); 501 media_router_ui_->UserSelectedTabMirroringForCurrentOrigin();
497 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring); 502 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring);
498 503
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 } 1048 }
1044 1049
1045 return value; 1050 return value;
1046 } 1051 }
1047 1052
1048 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 1053 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
1049 set_web_ui(web_ui); 1054 set_web_ui(web_ui);
1050 } 1055 }
1051 1056
1052 } // namespace media_router 1057 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698