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

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

Issue 2938173004: [Media Router] Add a supports_web_ui_controller attribute to MediaRoute (Closed)
Patch Set: Rebase Created 3 years, 6 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; 87 const char kSetCastModeList[] = "media_router.ui.setCastModeList";
88 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight"; 88 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight";
89 const char kUpdateRouteStatus[] = "media_router.ui.updateRouteStatus"; 89 const char kUpdateRouteStatus[] = "media_router.ui.updateRouteStatus";
90 const char kUserSelectedLocalMediaFile[] = 90 const char kUserSelectedLocalMediaFile[] =
91 "media_router.ui.userSelectedLocalMediaFile"; 91 "media_router.ui.userSelectedLocalMediaFile";
92 const char kWindowOpen[] = "window.open"; 92 const char kWindowOpen[] = "window.open";
93 93
94 std::unique_ptr<base::DictionaryValue> SinksAndIdentityToValue( 94 std::unique_ptr<base::DictionaryValue> SinksAndIdentityToValue(
95 const std::vector<MediaSinkWithCastModes>& sinks, 95 const std::vector<MediaSinkWithCastModes>& sinks,
96 const AccountInfo& account_info) { 96 const AccountInfo& account_info) {
97 std::unique_ptr<base::DictionaryValue> sink_list_and_identity( 97 auto sink_list_and_identity = base::MakeUnique<base::DictionaryValue>();
98 new base::DictionaryValue);
99 bool show_email = false; 98 bool show_email = false;
100 bool show_domain = false; 99 bool show_domain = false;
101 std::string user_domain; 100 std::string user_domain;
102 if (account_info.IsValid()) { 101 if (account_info.IsValid()) {
103 user_domain = account_info.hosted_domain; 102 user_domain = account_info.hosted_domain;
104 sink_list_and_identity->SetString("userEmail", account_info.email); 103 sink_list_and_identity->SetString("userEmail", account_info.email);
105 } 104 }
106 105
107 std::unique_ptr<base::ListValue> sinks_val(new base::ListValue); 106 auto sinks_val = base::MakeUnique<base::ListValue>();
108 107
109 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { 108 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) {
110 std::unique_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); 109 auto sink_val = base::MakeUnique<base::DictionaryValue>();
111 110
112 const MediaSink& sink = sink_with_cast_modes.sink; 111 const MediaSink& sink = sink_with_cast_modes.sink;
113 sink_val->SetString("id", sink.id()); 112 sink_val->SetString("id", sink.id());
114 sink_val->SetString("name", sink.name()); 113 sink_val->SetString("name", sink.name());
115 sink_val->SetInteger("iconType", sink.icon_type()); 114 sink_val->SetInteger("iconType", sink.icon_type());
116 if (sink.description()) 115 if (sink.description())
117 sink_val->SetString("description", *sink.description()); 116 sink_val->SetString("description", *sink.description());
118 117
119 bool is_pseudo_sink = 118 bool is_pseudo_sink =
120 base::StartsWith(sink.id(), "pseudo:", base::CompareCase::SENSITIVE); 119 base::StartsWith(sink.id(), "pseudo:", base::CompareCase::SENSITIVE);
(...skipping 29 matching lines...) Expand all
150 sink_list_and_identity->SetBoolean("showEmail", show_email); 149 sink_list_and_identity->SetBoolean("showEmail", show_email);
151 sink_list_and_identity->SetBoolean("showDomain", show_domain); 150 sink_list_and_identity->SetBoolean("showDomain", show_domain);
152 return sink_list_and_identity; 151 return sink_list_and_identity;
153 } 152 }
154 153
155 std::unique_ptr<base::DictionaryValue> RouteToValue( 154 std::unique_ptr<base::DictionaryValue> RouteToValue(
156 const MediaRoute& route, 155 const MediaRoute& route,
157 bool can_join, 156 bool can_join,
158 const std::string& extension_id, 157 const std::string& extension_id,
159 bool incognito, 158 bool incognito,
160 int current_cast_mode) { 159 int current_cast_mode,
161 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 160 bool is_web_ui_route_controller_available) {
161 auto dictionary = base::MakeUnique<base::DictionaryValue>();
162 dictionary->SetString("id", route.media_route_id()); 162 dictionary->SetString("id", route.media_route_id());
163 dictionary->SetString("sinkId", route.media_sink_id()); 163 dictionary->SetString("sinkId", route.media_sink_id());
164 dictionary->SetString("description", route.description()); 164 dictionary->SetString("description", route.description());
165 dictionary->SetBoolean("isLocal", route.is_local()); 165 dictionary->SetBoolean("isLocal", route.is_local());
166 dictionary->SetBoolean("supportsWebUiController",
167 is_web_ui_route_controller_available &&
168 route.supports_media_route_controller());
166 dictionary->SetBoolean("canJoin", can_join); 169 dictionary->SetBoolean("canJoin", can_join);
167 if (current_cast_mode > 0) { 170 if (current_cast_mode > 0) {
168 dictionary->SetInteger("currentCastMode", current_cast_mode); 171 dictionary->SetInteger("currentCastMode", current_cast_mode);
169 } 172 }
170 173
171 const std::string& custom_path = route.custom_controller_path(); 174 const std::string& custom_path = route.custom_controller_path();
172 if (!incognito && !custom_path.empty()) { 175 if (!incognito && !custom_path.empty()) {
173 std::string full_custom_controller_path = 176 std::string full_custom_controller_path =
174 base::StringPrintf("%s://%s/%s", extensions::kExtensionScheme, 177 base::StringPrintf("%s://%s/%s", extensions::kExtensionScheme,
175 extension_id.c_str(), custom_path.c_str()); 178 extension_id.c_str(), custom_path.c_str());
176 DCHECK(GURL(full_custom_controller_path).is_valid()); 179 DCHECK(GURL(full_custom_controller_path).is_valid());
177 dictionary->SetString("customControllerPath", full_custom_controller_path); 180 dictionary->SetString("customControllerPath", full_custom_controller_path);
178 } 181 }
179 182
180 return dictionary; 183 return dictionary;
181 } 184 }
182 185
183 std::unique_ptr<base::ListValue> CastModesToValue( 186 std::unique_ptr<base::ListValue> CastModesToValue(
184 const CastModeSet& cast_modes, 187 const CastModeSet& cast_modes,
185 const std::string& source_host, 188 const std::string& source_host,
186 base::Optional<MediaCastMode> forced_cast_mode) { 189 base::Optional<MediaCastMode> forced_cast_mode) {
187 std::unique_ptr<base::ListValue> value(new base::ListValue); 190 auto value = base::MakeUnique<base::ListValue>();
188 191
189 for (const MediaCastMode& cast_mode : cast_modes) { 192 for (const MediaCastMode& cast_mode : cast_modes) {
190 std::unique_ptr<base::DictionaryValue> cast_mode_val( 193 auto cast_mode_val = base::MakeUnique<base::DictionaryValue>();
191 new base::DictionaryValue);
192 cast_mode_val->SetInteger("type", cast_mode); 194 cast_mode_val->SetInteger("type", cast_mode);
193 cast_mode_val->SetString( 195 cast_mode_val->SetString(
194 "description", MediaCastModeToDescription(cast_mode, source_host)); 196 "description", MediaCastModeToDescription(cast_mode, source_host));
195 cast_mode_val->SetString("host", source_host); 197 cast_mode_val->SetString("host", source_host);
196 cast_mode_val->SetBoolean( 198 cast_mode_val->SetBoolean(
197 "isForced", forced_cast_mode && forced_cast_mode == cast_mode); 199 "isForced", forced_cast_mode && forced_cast_mode == cast_mode);
198 value->Append(std::move(cast_mode_val)); 200 value->Append(std::move(cast_mode_val));
199 } 201 }
200 202
201 return value; 203 return value;
202 } 204 }
203 205
204 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 206 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
205 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 207 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
206 const IssueInfo& issue_info = issue.info(); 208 const IssueInfo& issue_info = issue.info();
207 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 209 auto dictionary = base::MakeUnique<base::DictionaryValue>();
208 dictionary->SetInteger("id", issue.id()); 210 dictionary->SetInteger("id", issue.id());
209 dictionary->SetString("title", issue_info.title); 211 dictionary->SetString("title", issue_info.title);
210 dictionary->SetString("message", issue_info.message); 212 dictionary->SetString("message", issue_info.message);
211 dictionary->SetInteger("defaultActionType", 213 dictionary->SetInteger("defaultActionType",
212 static_cast<int>(issue_info.default_action)); 214 static_cast<int>(issue_info.default_action));
213 if (!issue_info.secondary_actions.empty()) { 215 if (!issue_info.secondary_actions.empty()) {
214 DCHECK_EQ(1u, issue_info.secondary_actions.size()); 216 DCHECK_EQ(1u, issue_info.secondary_actions.size());
215 dictionary->SetInteger("secondaryActionType", 217 dictionary->SetInteger("secondaryActionType",
216 static_cast<int>(issue_info.secondary_actions[0])); 218 static_cast<int>(issue_info.secondary_actions[0]));
217 } 219 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return help_url; 251 return help_url;
250 } 252 }
251 253
252 } // namespace 254 } // namespace
253 255
254 MediaRouterWebUIMessageHandler::MediaRouterWebUIMessageHandler( 256 MediaRouterWebUIMessageHandler::MediaRouterWebUIMessageHandler(
255 MediaRouterUI* media_router_ui) 257 MediaRouterUI* media_router_ui)
256 : incognito_( 258 : incognito_(
257 Profile::FromWebUI(media_router_ui->web_ui())->IsOffTheRecord()), 259 Profile::FromWebUI(media_router_ui->web_ui())->IsOffTheRecord()),
258 dialog_closing_(false), 260 dialog_closing_(false),
261 is_web_ui_route_controller_available_(base::FeatureList::IsEnabled(
262 features::kMediaRouterUIRouteController)),
259 media_router_ui_(media_router_ui) {} 263 media_router_ui_(media_router_ui) {}
260 264
261 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() {} 265 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() {}
262 266
263 void MediaRouterWebUIMessageHandler::UpdateSinks( 267 void MediaRouterWebUIMessageHandler::UpdateSinks(
264 const std::vector<MediaSinkWithCastModes>& sinks) { 268 const std::vector<MediaSinkWithCastModes>& sinks) {
265 DVLOG(2) << "UpdateSinks"; 269 DVLOG(2) << "UpdateSinks";
266 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( 270 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val(
267 SinksAndIdentityToValue(sinks, GetAccountInfo())); 271 SinksAndIdentityToValue(sinks, GetAccountInfo()));
268 web_ui()->CallJavascriptFunctionUnsafe(kSetSinkListAndIdentity, 272 web_ui()->CallJavascriptFunctionUnsafe(kSetSinkListAndIdentity,
(...skipping 22 matching lines...) Expand all
291 295
292 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( 296 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived(
293 const MediaSink::Id& sink_id, 297 const MediaSink::Id& sink_id,
294 const MediaRoute* route) { 298 const MediaRoute* route) {
295 DVLOG(2) << "OnCreateRouteResponseReceived"; 299 DVLOG(2) << "OnCreateRouteResponseReceived";
296 if (route) { 300 if (route) {
297 int current_cast_mode = CurrentCastModeForRouteId( 301 int current_cast_mode = CurrentCastModeForRouteId(
298 route->media_route_id(), media_router_ui_->routes_and_cast_modes()); 302 route->media_route_id(), media_router_ui_->routes_and_cast_modes());
299 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( 303 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue(
300 *route, false, media_router_ui_->GetRouteProviderExtensionId(), 304 *route, false, media_router_ui_->GetRouteProviderExtensionId(),
301 incognito_, current_cast_mode)); 305 incognito_, current_cast_mode, is_web_ui_route_controller_available_));
302 web_ui()->CallJavascriptFunctionUnsafe(kOnCreateRouteResponseReceived, 306 web_ui()->CallJavascriptFunctionUnsafe(kOnCreateRouteResponseReceived,
303 base::Value(sink_id), *route_value, 307 base::Value(sink_id), *route_value,
304 base::Value(route->for_display())); 308 base::Value(route->for_display()));
305 } else { 309 } else {
306 web_ui()->CallJavascriptFunctionUnsafe(kOnCreateRouteResponseReceived, 310 web_ui()->CallJavascriptFunctionUnsafe(kOnCreateRouteResponseReceived,
307 base::Value(sink_id), base::Value(), 311 base::Value(sink_id), base::Value(),
308 base::Value(false)); 312 base::Value(false));
309 } 313 }
310 } 314 }
311 315
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 initial_data.Set("castModes", std::move(cast_modes_list)); 510 initial_data.Set("castModes", std::move(cast_modes_list));
507 511
508 // If the cast mode last chosen for the current origin is tab mirroring, 512 // If the cast mode last chosen for the current origin is tab mirroring,
509 // that should be the cast mode initially selected in the dialog. Otherwise 513 // that should be the cast mode initially selected in the dialog. Otherwise
510 // the initial cast mode should be chosen automatically by the dialog. 514 // the initial cast mode should be chosen automatically by the dialog.
511 bool use_tab_mirroring = 515 bool use_tab_mirroring =
512 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) && 516 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) &&
513 media_router_ui_->UserSelectedTabMirroringForCurrentOrigin(); 517 media_router_ui_->UserSelectedTabMirroringForCurrentOrigin();
514 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring); 518 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring);
515 519
516 initial_data.SetBoolean(
517 "useWebUiRouteControls",
518 base::FeatureList::IsEnabled(features::kMediaRouterUIRouteController));
519
520 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data); 520 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data);
521 media_router_ui_->UIInitialized(); 521 media_router_ui_->UIInitialized();
522 } 522 }
523 523
524 void MediaRouterWebUIMessageHandler::OnCreateRoute( 524 void MediaRouterWebUIMessageHandler::OnCreateRoute(
525 const base::ListValue* args) { 525 const base::ListValue* args) {
526 DVLOG(1) << "OnCreateRoute"; 526 DVLOG(1) << "OnCreateRoute";
527 const base::DictionaryValue* args_dict = nullptr; 527 const base::DictionaryValue* args_dict = nullptr;
528 std::string sink_id; 528 std::string sink_id;
529 int cast_mode_num = -1; 529 int cast_mode_num = -1;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 route_controller->SetVolume(volume); 970 route_controller->SetVolume(volume);
971 } 971 }
972 972
973 bool MediaRouterWebUIMessageHandler::ActOnIssueType( 973 bool MediaRouterWebUIMessageHandler::ActOnIssueType(
974 IssueInfo::Action action_type, 974 IssueInfo::Action action_type,
975 const base::DictionaryValue* args) { 975 const base::DictionaryValue* args) {
976 if (action_type == IssueInfo::Action::LEARN_MORE) { 976 if (action_type == IssueInfo::Action::LEARN_MORE) {
977 std::string learn_more_url = GetLearnMoreUrl(args); 977 std::string learn_more_url = GetLearnMoreUrl(args);
978 if (learn_more_url.empty()) 978 if (learn_more_url.empty())
979 return false; 979 return false;
980 std::unique_ptr<base::ListValue> open_args(new base::ListValue); 980 auto open_args = base::MakeUnique<base::ListValue>();
981 open_args->AppendString(learn_more_url); 981 open_args->AppendString(learn_more_url);
982 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); 982 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args);
983 return true; 983 return true;
984 } else { 984 } else {
985 // Do nothing; no other issue action types require any other action. 985 // Do nothing; no other issue action types require any other action.
986 return true; 986 return true;
987 } 987 }
988 } 988 }
989 989
990 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { 990 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 ? current_cast_mode_entry->second 1053 ? current_cast_mode_entry->second
1054 : -1; 1054 : -1;
1055 return current_cast_mode; 1055 return current_cast_mode;
1056 } 1056 }
1057 1057
1058 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( 1058 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue(
1059 const std::vector<MediaRoute>& routes, 1059 const std::vector<MediaRoute>& routes,
1060 const std::vector<MediaRoute::Id>& joinable_route_ids, 1060 const std::vector<MediaRoute::Id>& joinable_route_ids,
1061 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) 1061 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes)
1062 const { 1062 const {
1063 std::unique_ptr<base::ListValue> value(new base::ListValue); 1063 auto value = base::MakeUnique<base::ListValue>();
1064 const std::string& extension_id = 1064 const std::string& extension_id =
1065 media_router_ui_->GetRouteProviderExtensionId(); 1065 media_router_ui_->GetRouteProviderExtensionId();
1066 1066
1067 for (const MediaRoute& route : routes) { 1067 for (const MediaRoute& route : routes) {
1068 bool can_join = 1068 bool can_join =
1069 base::ContainsValue(joinable_route_ids, route.media_route_id()); 1069 base::ContainsValue(joinable_route_ids, route.media_route_id());
1070 int current_cast_mode = 1070 int current_cast_mode =
1071 CurrentCastModeForRouteId(route.media_route_id(), current_cast_modes); 1071 CurrentCastModeForRouteId(route.media_route_id(), current_cast_modes);
1072 std::unique_ptr<base::DictionaryValue> route_val(RouteToValue( 1072 std::unique_ptr<base::DictionaryValue> route_val(
1073 route, can_join, extension_id, incognito_, current_cast_mode)); 1073 RouteToValue(route, can_join, extension_id, incognito_,
1074 current_cast_mode, is_web_ui_route_controller_available_));
1074 value->Append(std::move(route_val)); 1075 value->Append(std::move(route_val));
1075 } 1076 }
1076 1077
1077 return value; 1078 return value;
1078 } 1079 }
1079 1080
1080 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 1081 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
1081 set_web_ui(web_ui); 1082 set_web_ui(web_ui);
1082 } 1083 }
1083 1084
1084 } // namespace media_router 1085 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/media_router/media_router_webui_message_handler.h ('k') | chrome/common/media_router/media_route.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698