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

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: . 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 30 matching lines...) Expand all
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 auto dictionary = base::MakeUnique<base::DictionaryValue>();
162 dictionary->SetString("id", route.media_route_id()); 161 dictionary->SetString("id", route.media_route_id());
163 dictionary->SetString("sinkId", route.media_sink_id()); 162 dictionary->SetString("sinkId", route.media_sink_id());
164 dictionary->SetString("description", route.description()); 163 dictionary->SetString("description", route.description());
165 dictionary->SetBoolean("isLocal", route.is_local()); 164 dictionary->SetBoolean("isLocal", route.is_local());
165 dictionary->SetBoolean("supportsWebUiController",
imcheng 2017/06/16 00:12:32 Since we now have this boolean per route; can we j
takumif 2017/06/16 18:16:53 Makes sense. Done.
166 route.supports_web_ui_controller());
166 dictionary->SetBoolean("canJoin", can_join); 167 dictionary->SetBoolean("canJoin", can_join);
167 if (current_cast_mode > 0) { 168 if (current_cast_mode > 0) {
168 dictionary->SetInteger("currentCastMode", current_cast_mode); 169 dictionary->SetInteger("currentCastMode", current_cast_mode);
169 } 170 }
170 171
171 const std::string& custom_path = route.custom_controller_path(); 172 const std::string& custom_path = route.custom_controller_path();
172 if (!incognito && !custom_path.empty()) { 173 if (!incognito && !custom_path.empty()) {
173 std::string full_custom_controller_path = 174 std::string full_custom_controller_path =
174 base::StringPrintf("%s://%s/%s", extensions::kExtensionScheme, 175 base::StringPrintf("%s://%s/%s", extensions::kExtensionScheme,
175 extension_id.c_str(), custom_path.c_str()); 176 extension_id.c_str(), custom_path.c_str());
176 DCHECK(GURL(full_custom_controller_path).is_valid()); 177 DCHECK(GURL(full_custom_controller_path).is_valid());
177 dictionary->SetString("customControllerPath", full_custom_controller_path); 178 dictionary->SetString("customControllerPath", full_custom_controller_path);
178 } 179 }
179 180
180 return dictionary; 181 return dictionary;
181 } 182 }
182 183
183 std::unique_ptr<base::ListValue> CastModesToValue( 184 std::unique_ptr<base::ListValue> CastModesToValue(
184 const CastModeSet& cast_modes, 185 const CastModeSet& cast_modes,
185 const std::string& source_host, 186 const std::string& source_host,
186 base::Optional<MediaCastMode> forced_cast_mode) { 187 base::Optional<MediaCastMode> forced_cast_mode) {
187 std::unique_ptr<base::ListValue> value(new base::ListValue); 188 auto value = base::MakeUnique<base::ListValue>();
188 189
189 for (const MediaCastMode& cast_mode : cast_modes) { 190 for (const MediaCastMode& cast_mode : cast_modes) {
190 std::unique_ptr<base::DictionaryValue> cast_mode_val( 191 auto cast_mode_val = base::MakeUnique<base::DictionaryValue>();
191 new base::DictionaryValue);
192 cast_mode_val->SetInteger("type", cast_mode); 192 cast_mode_val->SetInteger("type", cast_mode);
193 cast_mode_val->SetString( 193 cast_mode_val->SetString(
194 "description", MediaCastModeToDescription(cast_mode, source_host)); 194 "description", MediaCastModeToDescription(cast_mode, source_host));
195 cast_mode_val->SetString("host", source_host); 195 cast_mode_val->SetString("host", source_host);
196 cast_mode_val->SetBoolean( 196 cast_mode_val->SetBoolean(
197 "isForced", forced_cast_mode && forced_cast_mode == cast_mode); 197 "isForced", forced_cast_mode && forced_cast_mode == cast_mode);
198 value->Append(std::move(cast_mode_val)); 198 value->Append(std::move(cast_mode_val));
199 } 199 }
200 200
201 return value; 201 return value;
202 } 202 }
203 203
204 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 204 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
205 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 205 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
206 const IssueInfo& issue_info = issue.info(); 206 const IssueInfo& issue_info = issue.info();
207 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 207 auto dictionary = base::MakeUnique<base::DictionaryValue>();
208 dictionary->SetInteger("id", issue.id()); 208 dictionary->SetInteger("id", issue.id());
209 dictionary->SetString("title", issue_info.title); 209 dictionary->SetString("title", issue_info.title);
210 dictionary->SetString("message", issue_info.message); 210 dictionary->SetString("message", issue_info.message);
211 dictionary->SetInteger("defaultActionType", 211 dictionary->SetInteger("defaultActionType",
212 static_cast<int>(issue_info.default_action)); 212 static_cast<int>(issue_info.default_action));
213 if (!issue_info.secondary_actions.empty()) { 213 if (!issue_info.secondary_actions.empty()) {
214 DCHECK_EQ(1u, issue_info.secondary_actions.size()); 214 DCHECK_EQ(1u, issue_info.secondary_actions.size());
215 dictionary->SetInteger("secondaryActionType", 215 dictionary->SetInteger("secondaryActionType",
216 static_cast<int>(issue_info.secondary_actions[0])); 216 static_cast<int>(issue_info.secondary_actions[0]));
217 } 217 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 507
508 // If the cast mode last chosen for the current origin is tab mirroring, 508 // 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 509 // that should be the cast mode initially selected in the dialog. Otherwise
510 // the initial cast mode should be chosen automatically by the dialog. 510 // the initial cast mode should be chosen automatically by the dialog.
511 bool use_tab_mirroring = 511 bool use_tab_mirroring =
512 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) && 512 base::ContainsKey(cast_modes, MediaCastMode::TAB_MIRROR) &&
513 media_router_ui_->UserSelectedTabMirroringForCurrentOrigin(); 513 media_router_ui_->UserSelectedTabMirroringForCurrentOrigin();
514 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring); 514 initial_data.SetBoolean("useTabMirroring", use_tab_mirroring);
515 515
516 initial_data.SetBoolean( 516 initial_data.SetBoolean(
517 "useWebUiRouteControls", 517 "webUiRouteControlsAvailable",
518 base::FeatureList::IsEnabled(features::kMediaRouterUIRouteController)); 518 base::FeatureList::IsEnabled(features::kMediaRouterUIRouteController));
519 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;
(...skipping 442 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(RouteToValue(
1073 route, can_join, extension_id, incognito_, current_cast_mode)); 1073 route, can_join, extension_id, incognito_, current_cast_mode));
1074 value->Append(std::move(route_val)); 1074 value->Append(std::move(route_val));
1075 } 1075 }
1076 1076
1077 return value; 1077 return value;
1078 } 1078 }
1079 1079
1080 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 1080 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
1081 set_web_ui(web_ui); 1081 set_web_ui(web_ui);
1082 } 1082 }
1083 1083
1084 } // namespace media_router 1084 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698