| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 248 } |
| 249 | 249 |
| 250 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { | 250 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { |
| 251 } | 251 } |
| 252 | 252 |
| 253 void MediaRouterWebUIMessageHandler::UpdateSinks( | 253 void MediaRouterWebUIMessageHandler::UpdateSinks( |
| 254 const std::vector<MediaSinkWithCastModes>& sinks) { | 254 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 255 DVLOG(2) << "UpdateSinks"; | 255 DVLOG(2) << "UpdateSinks"; |
| 256 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( | 256 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( |
| 257 SinksAndIdentityToValue(sinks, GetAccountInfo())); | 257 SinksAndIdentityToValue(sinks, GetAccountInfo())); |
| 258 web_ui()->CallJavascriptFunction(kSetSinkListAndIdentity, | 258 web_ui()->CallJavascriptFunctionUnsafe(kSetSinkListAndIdentity, |
| 259 *sinks_and_identity_val); | 259 *sinks_and_identity_val); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 262 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 263 const std::vector<MediaRoute>& routes, | 263 const std::vector<MediaRoute>& routes, |
| 264 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 264 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 265 std::unique_ptr<base::ListValue> routes_val( | 265 std::unique_ptr<base::ListValue> routes_val( |
| 266 RoutesToValue(routes, joinable_route_ids, | 266 RoutesToValue(routes, joinable_route_ids, |
| 267 media_router_ui_->GetRouteProviderExtensionId())); | 267 media_router_ui_->GetRouteProviderExtensionId())); |
| 268 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 268 web_ui()->CallJavascriptFunctionUnsafe(kSetRouteList, *routes_val); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void MediaRouterWebUIMessageHandler::UpdateCastModes( | 271 void MediaRouterWebUIMessageHandler::UpdateCastModes( |
| 272 const CastModeSet& cast_modes, | 272 const CastModeSet& cast_modes, |
| 273 const std::string& source_host) { | 273 const std::string& source_host) { |
| 274 DVLOG(2) << "UpdateCastModes"; | 274 DVLOG(2) << "UpdateCastModes"; |
| 275 std::unique_ptr<base::ListValue> cast_modes_val( | 275 std::unique_ptr<base::ListValue> cast_modes_val( |
| 276 CastModesToValue(cast_modes, source_host)); | 276 CastModesToValue(cast_modes, source_host)); |
| 277 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); | 277 web_ui()->CallJavascriptFunctionUnsafe(kSetCastModeList, *cast_modes_val); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( | 280 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 281 const MediaSink::Id& sink_id, | 281 const MediaSink::Id& sink_id, |
| 282 const MediaRoute* route) { | 282 const MediaRoute* route) { |
| 283 DVLOG(2) << "OnCreateRouteResponseReceived"; | 283 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 284 if (route) { | 284 if (route) { |
| 285 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( | 285 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( |
| 286 *route, false, media_router_ui_->GetRouteProviderExtensionId())); | 286 *route, false, media_router_ui_->GetRouteProviderExtensionId())); |
| 287 web_ui()->CallJavascriptFunction( | 287 web_ui()->CallJavascriptFunctionUnsafe( |
| 288 kOnCreateRouteResponseReceived, | 288 kOnCreateRouteResponseReceived, base::StringValue(sink_id), |
| 289 base::StringValue(sink_id), *route_value, | 289 *route_value, base::FundamentalValue(route->for_display())); |
| 290 base::FundamentalValue(route->for_display())); | |
| 291 } else { | 290 } else { |
| 292 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 291 web_ui()->CallJavascriptFunctionUnsafe( |
| 293 base::StringValue(sink_id), | 292 kOnCreateRouteResponseReceived, base::StringValue(sink_id), |
| 294 *base::Value::CreateNullValue(), | 293 *base::Value::CreateNullValue(), base::FundamentalValue(false)); |
| 295 base::FundamentalValue(false)); | |
| 296 } | 294 } |
| 297 } | 295 } |
| 298 | 296 |
| 299 void MediaRouterWebUIMessageHandler::ReturnSearchResult( | 297 void MediaRouterWebUIMessageHandler::ReturnSearchResult( |
| 300 const std::string& sink_id) { | 298 const std::string& sink_id) { |
| 301 DVLOG(2) << "ReturnSearchResult"; | 299 DVLOG(2) << "ReturnSearchResult"; |
| 302 web_ui()->CallJavascriptFunction(kReceiveSearchResult, | 300 web_ui()->CallJavascriptFunctionUnsafe(kReceiveSearchResult, |
| 303 base::StringValue(sink_id)); | 301 base::StringValue(sink_id)); |
| 304 } | 302 } |
| 305 | 303 |
| 306 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 304 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 307 DVLOG(2) << "UpdateIssue"; | 305 DVLOG(2) << "UpdateIssue"; |
| 308 web_ui()->CallJavascriptFunction(kSetIssue, | 306 web_ui()->CallJavascriptFunctionUnsafe( |
| 307 kSetIssue, |
| 309 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); | 308 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); |
| 310 } | 309 } |
| 311 | 310 |
| 312 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { | 311 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { |
| 313 DVLOG(2) << "UpdateMaxDialogHeight"; | 312 DVLOG(2) << "UpdateMaxDialogHeight"; |
| 314 web_ui()->CallJavascriptFunction(kUpdateMaxHeight, | 313 web_ui()->CallJavascriptFunctionUnsafe(kUpdateMaxHeight, |
| 315 base::FundamentalValue(height)); | 314 base::FundamentalValue(height)); |
| 316 } | 315 } |
| 317 | 316 |
| 318 void MediaRouterWebUIMessageHandler::RegisterMessages() { | 317 void MediaRouterWebUIMessageHandler::RegisterMessages() { |
| 319 web_ui()->RegisterMessageCallback( | 318 web_ui()->RegisterMessageCallback( |
| 320 kRequestInitialData, | 319 kRequestInitialData, |
| 321 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, | 320 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, |
| 322 base::Unretained(this))); | 321 base::Unretained(this))); |
| 323 web_ui()->RegisterMessageCallback( | 322 web_ui()->RegisterMessageCallback( |
| 324 kCreateRoute, | 323 kCreateRoute, |
| 325 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, | 324 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 initial_data.Set("routes", routes.release()); | 422 initial_data.Set("routes", routes.release()); |
| 424 | 423 |
| 425 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 424 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 426 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( | 425 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( |
| 427 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); | 426 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); |
| 428 initial_data.Set("castModes", cast_modes_list.release()); | 427 initial_data.Set("castModes", cast_modes_list.release()); |
| 429 | 428 |
| 430 Profile* profile = Profile::FromWebUI(web_ui()); | 429 Profile* profile = Profile::FromWebUI(web_ui()); |
| 431 initial_data.SetBoolean("isOffTheRecord", profile->IsOffTheRecord()); | 430 initial_data.SetBoolean("isOffTheRecord", profile->IsOffTheRecord()); |
| 432 | 431 |
| 433 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); | 432 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data); |
| 434 media_router_ui_->UIInitialized(); | 433 media_router_ui_->UIInitialized(); |
| 435 } | 434 } |
| 436 | 435 |
| 437 void MediaRouterWebUIMessageHandler::OnCreateRoute( | 436 void MediaRouterWebUIMessageHandler::OnCreateRoute( |
| 438 const base::ListValue* args) { | 437 const base::ListValue* args) { |
| 439 DVLOG(1) << "OnCreateRoute"; | 438 DVLOG(1) << "OnCreateRoute"; |
| 440 const base::DictionaryValue* args_dict = nullptr; | 439 const base::DictionaryValue* args_dict = nullptr; |
| 441 std::string sink_id; | 440 std::string sink_id; |
| 442 int cast_mode_num = -1; | 441 int cast_mode_num = -1; |
| 443 if (!args->GetDictionary(0, &args_dict) || | 442 if (!args->GetDictionary(0, &args_dict) || |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 | 789 |
| 791 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 790 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 792 const IssueAction::Type& action_type, | 791 const IssueAction::Type& action_type, |
| 793 const base::DictionaryValue* args) { | 792 const base::DictionaryValue* args) { |
| 794 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 793 if (action_type == IssueAction::TYPE_LEARN_MORE) { |
| 795 std::string learn_more_url = GetLearnMoreUrl(args); | 794 std::string learn_more_url = GetLearnMoreUrl(args); |
| 796 if (learn_more_url.empty()) | 795 if (learn_more_url.empty()) |
| 797 return false; | 796 return false; |
| 798 std::unique_ptr<base::ListValue> open_args(new base::ListValue); | 797 std::unique_ptr<base::ListValue> open_args(new base::ListValue); |
| 799 open_args->AppendString(learn_more_url); | 798 open_args->AppendString(learn_more_url); |
| 800 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 799 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); |
| 801 return true; | 800 return true; |
| 802 } else { | 801 } else { |
| 803 // Do nothing; no other issue action types require any other action. | 802 // Do nothing; no other issue action types require any other action. |
| 804 return true; | 803 return true; |
| 805 } | 804 } |
| 806 } | 805 } |
| 807 | 806 |
| 808 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { | 807 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { |
| 809 base::DictionaryValue first_run_flow_data; | 808 base::DictionaryValue first_run_flow_data; |
| 810 | 809 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 // Return early if the first run flow won't be surfaced. | 846 // Return early if the first run flow won't be surfaced. |
| 848 if (first_run_flow_acknowledged && !show_cloud_pref) | 847 if (first_run_flow_acknowledged && !show_cloud_pref) |
| 849 return; | 848 return; |
| 850 | 849 |
| 851 // General Chromecast learn more page. | 850 // General Chromecast learn more page. |
| 852 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", | 851 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", |
| 853 kCastLearnMorePageUrl); | 852 kCastLearnMorePageUrl); |
| 854 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", | 853 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", |
| 855 first_run_flow_acknowledged); | 854 first_run_flow_acknowledged); |
| 856 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); | 855 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); |
| 857 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); | 856 web_ui()->CallJavascriptFunctionUnsafe(kSetFirstRunFlowData, |
| 857 first_run_flow_data); |
| 858 } | 858 } |
| 859 | 859 |
| 860 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { | 860 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { |
| 861 #if defined(GOOGLE_CHROME_BUILD) | 861 #if defined(GOOGLE_CHROME_BUILD) |
| 862 SigninManagerBase* signin_manager = | 862 SigninManagerBase* signin_manager = |
| 863 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 863 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 864 if (signin_manager) | 864 if (signin_manager) |
| 865 return signin_manager->GetAuthenticatedAccountInfo(); | 865 return signin_manager->GetAuthenticatedAccountInfo(); |
| 866 #endif // defined(GOOGLE_CHROME_BUILD) | 866 #endif // defined(GOOGLE_CHROME_BUILD) |
| 867 | 867 |
| 868 return AccountInfo(); | 868 return AccountInfo(); |
| 869 } | 869 } |
| 870 | 870 |
| 871 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 871 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 872 set_web_ui(web_ui); | 872 set_web_ui(web_ui); |
| 873 } | 873 } |
| 874 | 874 |
| 875 } // namespace media_router | 875 } // namespace media_router |
| OLD | NEW |