| OLD | NEW |
| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 media_router_ui_(media_router_ui) {} | 234 media_router_ui_(media_router_ui) {} |
| 235 | 235 |
| 236 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { | 236 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { |
| 237 } | 237 } |
| 238 | 238 |
| 239 void MediaRouterWebUIMessageHandler::UpdateSinks( | 239 void MediaRouterWebUIMessageHandler::UpdateSinks( |
| 240 const std::vector<MediaSinkWithCastModes>& sinks) { | 240 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 241 DVLOG(2) << "UpdateSinks"; | 241 DVLOG(2) << "UpdateSinks"; |
| 242 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( | 242 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( |
| 243 SinksAndIdentityToValue(sinks, GetAccountInfo())); | 243 SinksAndIdentityToValue(sinks, GetAccountInfo())); |
| 244 web_ui()->CallJavascriptFunction(kSetSinkListAndIdentity, | 244 web_ui()->CallJavascriptFunctionUnsafe(kSetSinkListAndIdentity, |
| 245 *sinks_and_identity_val); | 245 *sinks_and_identity_val); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 248 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 249 const std::vector<MediaRoute>& routes, | 249 const std::vector<MediaRoute>& routes, |
| 250 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 250 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 251 std::unique_ptr<base::ListValue> routes_val( | 251 std::unique_ptr<base::ListValue> routes_val( |
| 252 RoutesToValue(routes, joinable_route_ids)); | 252 RoutesToValue(routes, joinable_route_ids)); |
| 253 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 253 web_ui()->CallJavascriptFunctionUnsafe(kSetRouteList, *routes_val); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void MediaRouterWebUIMessageHandler::UpdateCastModes( | 256 void MediaRouterWebUIMessageHandler::UpdateCastModes( |
| 257 const CastModeSet& cast_modes, | 257 const CastModeSet& cast_modes, |
| 258 const std::string& source_host) { | 258 const std::string& source_host) { |
| 259 DVLOG(2) << "UpdateCastModes"; | 259 DVLOG(2) << "UpdateCastModes"; |
| 260 std::unique_ptr<base::ListValue> cast_modes_val( | 260 std::unique_ptr<base::ListValue> cast_modes_val( |
| 261 CastModesToValue(cast_modes, source_host)); | 261 CastModesToValue(cast_modes, source_host)); |
| 262 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); | 262 web_ui()->CallJavascriptFunctionUnsafe(kSetCastModeList, *cast_modes_val); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( | 265 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 266 const MediaSink::Id& sink_id, | 266 const MediaSink::Id& sink_id, |
| 267 const MediaRoute* route) { | 267 const MediaRoute* route) { |
| 268 DVLOG(2) << "OnCreateRouteResponseReceived"; | 268 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 269 if (route) { | 269 if (route) { |
| 270 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( | 270 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( |
| 271 *route, false, media_router_ui_->GetRouteProviderExtensionId(), | 271 *route, false, media_router_ui_->GetRouteProviderExtensionId(), |
| 272 off_the_record_)); | 272 off_the_record_)); |
| 273 web_ui()->CallJavascriptFunction( | 273 web_ui()->CallJavascriptFunctionUnsafe( |
| 274 kOnCreateRouteResponseReceived, | 274 kOnCreateRouteResponseReceived, base::StringValue(sink_id), |
| 275 base::StringValue(sink_id), *route_value, | 275 *route_value, base::FundamentalValue(route->for_display())); |
| 276 base::FundamentalValue(route->for_display())); | |
| 277 } else { | 276 } else { |
| 278 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 277 web_ui()->CallJavascriptFunctionUnsafe( |
| 279 base::StringValue(sink_id), | 278 kOnCreateRouteResponseReceived, base::StringValue(sink_id), |
| 280 *base::Value::CreateNullValue(), | 279 *base::Value::CreateNullValue(), base::FundamentalValue(false)); |
| 281 base::FundamentalValue(false)); | |
| 282 } | 280 } |
| 283 } | 281 } |
| 284 | 282 |
| 285 void MediaRouterWebUIMessageHandler::ReturnSearchResult( | 283 void MediaRouterWebUIMessageHandler::ReturnSearchResult( |
| 286 const std::string& sink_id) { | 284 const std::string& sink_id) { |
| 287 DVLOG(2) << "ReturnSearchResult"; | 285 DVLOG(2) << "ReturnSearchResult"; |
| 288 web_ui()->CallJavascriptFunction(kReceiveSearchResult, | 286 web_ui()->CallJavascriptFunctionUnsafe(kReceiveSearchResult, |
| 289 base::StringValue(sink_id)); | 287 base::StringValue(sink_id)); |
| 290 } | 288 } |
| 291 | 289 |
| 292 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 290 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 293 DVLOG(2) << "UpdateIssue"; | 291 DVLOG(2) << "UpdateIssue"; |
| 294 web_ui()->CallJavascriptFunction(kSetIssue, | 292 web_ui()->CallJavascriptFunctionUnsafe( |
| 293 kSetIssue, |
| 295 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); | 294 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); |
| 296 } | 295 } |
| 297 | 296 |
| 298 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { | 297 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { |
| 299 DVLOG(2) << "UpdateMaxDialogHeight"; | 298 DVLOG(2) << "UpdateMaxDialogHeight"; |
| 300 web_ui()->CallJavascriptFunction(kUpdateMaxHeight, | 299 web_ui()->CallJavascriptFunctionUnsafe(kUpdateMaxHeight, |
| 301 base::FundamentalValue(height)); | 300 base::FundamentalValue(height)); |
| 302 } | 301 } |
| 303 | 302 |
| 304 void MediaRouterWebUIMessageHandler::RegisterMessages() { | 303 void MediaRouterWebUIMessageHandler::RegisterMessages() { |
| 305 web_ui()->RegisterMessageCallback( | 304 web_ui()->RegisterMessageCallback( |
| 306 kRequestInitialData, | 305 kRequestInitialData, |
| 307 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, | 306 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, |
| 308 base::Unretained(this))); | 307 base::Unretained(this))); |
| 309 web_ui()->RegisterMessageCallback( | 308 web_ui()->RegisterMessageCallback( |
| 310 kCreateRoute, | 309 kCreateRoute, |
| 311 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, | 310 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 404 |
| 406 std::unique_ptr<base::ListValue> routes(RoutesToValue( | 405 std::unique_ptr<base::ListValue> routes(RoutesToValue( |
| 407 media_router_ui_->routes(), media_router_ui_->joinable_route_ids())); | 406 media_router_ui_->routes(), media_router_ui_->joinable_route_ids())); |
| 408 initial_data.Set("routes", routes.release()); | 407 initial_data.Set("routes", routes.release()); |
| 409 | 408 |
| 410 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 409 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 411 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( | 410 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( |
| 412 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); | 411 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); |
| 413 initial_data.Set("castModes", cast_modes_list.release()); | 412 initial_data.Set("castModes", cast_modes_list.release()); |
| 414 | 413 |
| 415 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); | 414 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data); |
| 416 media_router_ui_->UIInitialized(); | 415 media_router_ui_->UIInitialized(); |
| 417 } | 416 } |
| 418 | 417 |
| 419 void MediaRouterWebUIMessageHandler::OnCreateRoute( | 418 void MediaRouterWebUIMessageHandler::OnCreateRoute( |
| 420 const base::ListValue* args) { | 419 const base::ListValue* args) { |
| 421 DVLOG(1) << "OnCreateRoute"; | 420 DVLOG(1) << "OnCreateRoute"; |
| 422 const base::DictionaryValue* args_dict = nullptr; | 421 const base::DictionaryValue* args_dict = nullptr; |
| 423 std::string sink_id; | 422 std::string sink_id; |
| 424 int cast_mode_num = -1; | 423 int cast_mode_num = -1; |
| 425 if (!args->GetDictionary(0, &args_dict) || | 424 if (!args->GetDictionary(0, &args_dict) || |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 771 |
| 773 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 772 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 774 const IssueAction::Type& action_type, | 773 const IssueAction::Type& action_type, |
| 775 const base::DictionaryValue* args) { | 774 const base::DictionaryValue* args) { |
| 776 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 775 if (action_type == IssueAction::TYPE_LEARN_MORE) { |
| 777 std::string learn_more_url = GetLearnMoreUrl(args); | 776 std::string learn_more_url = GetLearnMoreUrl(args); |
| 778 if (learn_more_url.empty()) | 777 if (learn_more_url.empty()) |
| 779 return false; | 778 return false; |
| 780 std::unique_ptr<base::ListValue> open_args(new base::ListValue); | 779 std::unique_ptr<base::ListValue> open_args(new base::ListValue); |
| 781 open_args->AppendString(learn_more_url); | 780 open_args->AppendString(learn_more_url); |
| 782 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 781 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); |
| 783 return true; | 782 return true; |
| 784 } else { | 783 } else { |
| 785 // Do nothing; no other issue action types require any other action. | 784 // Do nothing; no other issue action types require any other action. |
| 786 return true; | 785 return true; |
| 787 } | 786 } |
| 788 } | 787 } |
| 789 | 788 |
| 790 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { | 789 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { |
| 791 base::DictionaryValue first_run_flow_data; | 790 base::DictionaryValue first_run_flow_data; |
| 792 | 791 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 // Return early if the first run flow won't be surfaced. | 828 // Return early if the first run flow won't be surfaced. |
| 830 if (first_run_flow_acknowledged && !show_cloud_pref) | 829 if (first_run_flow_acknowledged && !show_cloud_pref) |
| 831 return; | 830 return; |
| 832 | 831 |
| 833 // General Chromecast learn more page. | 832 // General Chromecast learn more page. |
| 834 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", | 833 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", |
| 835 kCastLearnMorePageUrl); | 834 kCastLearnMorePageUrl); |
| 836 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", | 835 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", |
| 837 first_run_flow_acknowledged); | 836 first_run_flow_acknowledged); |
| 838 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); | 837 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); |
| 839 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); | 838 web_ui()->CallJavascriptFunctionUnsafe(kSetFirstRunFlowData, |
| 839 first_run_flow_data); |
| 840 } | 840 } |
| 841 | 841 |
| 842 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { | 842 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { |
| 843 #if defined(GOOGLE_CHROME_BUILD) | 843 #if defined(GOOGLE_CHROME_BUILD) |
| 844 SigninManagerBase* signin_manager = | 844 SigninManagerBase* signin_manager = |
| 845 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 845 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 846 if (signin_manager) | 846 if (signin_manager) |
| 847 return signin_manager->GetAuthenticatedAccountInfo(); | 847 return signin_manager->GetAuthenticatedAccountInfo(); |
| 848 #endif // defined(GOOGLE_CHROME_BUILD) | 848 #endif // defined(GOOGLE_CHROME_BUILD) |
| 849 | 849 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 865 } | 865 } |
| 866 | 866 |
| 867 return value; | 867 return value; |
| 868 } | 868 } |
| 869 | 869 |
| 870 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 870 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 871 set_web_ui(web_ui); | 871 set_web_ui(web_ui); |
| 872 } | 872 } |
| 873 | 873 |
| 874 } // namespace media_router | 874 } // namespace media_router |
| OLD | NEW |