Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 const char kReportFilter[] = "reportFilter"; | 52 const char kReportFilter[] = "reportFilter"; |
| 53 const char kReportInitialAction[] = "reportInitialAction"; | 53 const char kReportInitialAction[] = "reportInitialAction"; |
| 54 const char kReportInitialState[] = "reportInitialState"; | 54 const char kReportInitialState[] = "reportInitialState"; |
| 55 const char kReportNavigateToView[] = "reportNavigateToView"; | 55 const char kReportNavigateToView[] = "reportNavigateToView"; |
| 56 const char kReportRouteCreationOutcome[] = "reportRouteCreationOutcome"; | 56 const char kReportRouteCreationOutcome[] = "reportRouteCreationOutcome"; |
| 57 const char kReportRouteCreation[] = "reportRouteCreation"; | 57 const char kReportRouteCreation[] = "reportRouteCreation"; |
| 58 const char kReportSelectedCastMode[] = "reportSelectedCastMode"; | 58 const char kReportSelectedCastMode[] = "reportSelectedCastMode"; |
| 59 const char kReportSinkCount[] = "reportSinkCount"; | 59 const char kReportSinkCount[] = "reportSinkCount"; |
| 60 const char kReportTimeToClickSink[] = "reportTimeToClickSink"; | 60 const char kReportTimeToClickSink[] = "reportTimeToClickSink"; |
| 61 const char kReportTimeToInitialActionClose[] = "reportTimeToInitialActionClose"; | 61 const char kReportTimeToInitialActionClose[] = "reportTimeToInitialActionClose"; |
| 62 const char kSearchSinksAndCreateRoute[] = "searchSinksAndCreateRoute"; | |
| 62 const char kOnInitialDataReceived[] = "onInitialDataReceived"; | 63 const char kOnInitialDataReceived[] = "onInitialDataReceived"; |
| 63 | 64 |
| 64 // JS function names. | 65 // JS function names. |
| 65 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 66 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 66 const char kOnCreateRouteResponseReceived[] = | 67 const char kOnCreateRouteResponseReceived[] = |
| 67 "media_router.ui.onCreateRouteResponseReceived"; | 68 "media_router.ui.onCreateRouteResponseReceived"; |
| 69 const char kReceiveSearchResult[] = "media_router.ui.receiveSearchResult"; | |
| 68 const char kSetFirstRunFlowData[] = "media_router.ui.setFirstRunFlowData"; | 70 const char kSetFirstRunFlowData[] = "media_router.ui.setFirstRunFlowData"; |
| 69 const char kSetIssue[] = "media_router.ui.setIssue"; | 71 const char kSetIssue[] = "media_router.ui.setIssue"; |
| 70 const char kSetSinkListAndIdentity[] = "media_router.ui.setSinkListAndIdentity"; | 72 const char kSetSinkListAndIdentity[] = "media_router.ui.setSinkListAndIdentity"; |
| 71 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 73 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| 72 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; | 74 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; |
| 73 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight"; | 75 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight"; |
| 74 const char kWindowOpen[] = "window.open"; | 76 const char kWindowOpen[] = "window.open"; |
| 75 | 77 |
| 76 scoped_ptr<base::DictionaryValue> SinksAndIdentityToValue( | 78 scoped_ptr<base::DictionaryValue> SinksAndIdentityToValue( |
| 77 const std::vector<MediaSinkWithCastModes>& sinks, | 79 const std::vector<MediaSinkWithCastModes>& sinks, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 base::StringValue(sink_id), *route_value, | 281 base::StringValue(sink_id), *route_value, |
| 280 base::FundamentalValue(route->for_display())); | 282 base::FundamentalValue(route->for_display())); |
| 281 } else { | 283 } else { |
| 282 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 284 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 283 base::StringValue(sink_id), | 285 base::StringValue(sink_id), |
| 284 *base::Value::CreateNullValue(), | 286 *base::Value::CreateNullValue(), |
| 285 base::FundamentalValue(false)); | 287 base::FundamentalValue(false)); |
| 286 } | 288 } |
| 287 } | 289 } |
| 288 | 290 |
| 291 void MediaRouterWebUIMessageHandler::ReturnSearchResult( | |
| 292 const std::string& sink_id) { | |
| 293 DVLOG(2) << "ReturnSearchResult"; | |
| 294 web_ui()->CallJavascriptFunction(kReceiveSearchResult, | |
| 295 base::StringValue(sink_id)); | |
| 296 } | |
| 297 | |
| 289 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 298 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 290 DVLOG(2) << "UpdateIssue"; | 299 DVLOG(2) << "UpdateIssue"; |
| 291 web_ui()->CallJavascriptFunction(kSetIssue, | 300 web_ui()->CallJavascriptFunction(kSetIssue, |
| 292 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); | 301 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); |
| 293 } | 302 } |
| 294 | 303 |
| 295 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { | 304 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { |
| 296 DVLOG(2) << "UpdateMaxDialogHeight"; | 305 DVLOG(2) << "UpdateMaxDialogHeight"; |
| 297 web_ui()->CallJavascriptFunction(kUpdateMaxHeight, | 306 web_ui()->CallJavascriptFunction(kUpdateMaxHeight, |
| 298 base::FundamentalValue(height)); | 307 base::FundamentalValue(height)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 web_ui()->RegisterMessageCallback( | 379 web_ui()->RegisterMessageCallback( |
| 371 kReportTimeToClickSink, | 380 kReportTimeToClickSink, |
| 372 base::Bind(&MediaRouterWebUIMessageHandler::OnReportTimeToClickSink, | 381 base::Bind(&MediaRouterWebUIMessageHandler::OnReportTimeToClickSink, |
| 373 base::Unretained(this))); | 382 base::Unretained(this))); |
| 374 web_ui()->RegisterMessageCallback( | 383 web_ui()->RegisterMessageCallback( |
| 375 kReportTimeToInitialActionClose, | 384 kReportTimeToInitialActionClose, |
| 376 base::Bind( | 385 base::Bind( |
| 377 &MediaRouterWebUIMessageHandler::OnReportTimeToInitialActionClose, | 386 &MediaRouterWebUIMessageHandler::OnReportTimeToInitialActionClose, |
| 378 base::Unretained(this))); | 387 base::Unretained(this))); |
| 379 web_ui()->RegisterMessageCallback( | 388 web_ui()->RegisterMessageCallback( |
| 389 kSearchSinksAndCreateRoute, | |
| 390 base::Bind(&MediaRouterWebUIMessageHandler::OnSearchSinksAndCreateRoute, | |
| 391 base::Unretained(this))); | |
| 392 web_ui()->RegisterMessageCallback( | |
| 380 kOnInitialDataReceived, | 393 kOnInitialDataReceived, |
| 381 base::Bind(&MediaRouterWebUIMessageHandler::OnInitialDataReceived, | 394 base::Bind(&MediaRouterWebUIMessageHandler::OnInitialDataReceived, |
| 382 base::Unretained(this))); | 395 base::Unretained(this))); |
| 383 } | 396 } |
| 384 | 397 |
| 385 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 398 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 386 const base::ListValue* args) { | 399 const base::ListValue* args) { |
| 387 DVLOG(1) << "OnRequestInitialData"; | 400 DVLOG(1) << "OnRequestInitialData"; |
| 388 media_router_ui_->OnUIInitiallyLoaded(); | 401 media_router_ui_->OnUIInitiallyLoaded(); |
| 389 base::DictionaryValue initial_data; | 402 base::DictionaryValue initial_data; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 DVLOG(1) << "OnReportTimeToInitialActionClose"; | 735 DVLOG(1) << "OnReportTimeToInitialActionClose"; |
| 723 double time_to_close; | 736 double time_to_close; |
| 724 if (!args->GetDouble(0, &time_to_close)) { | 737 if (!args->GetDouble(0, &time_to_close)) { |
| 725 VLOG(0) << "Unable to extract args."; | 738 VLOG(0) << "Unable to extract args."; |
| 726 return; | 739 return; |
| 727 } | 740 } |
| 728 UMA_HISTOGRAM_TIMES("MediaRouter.Ui.Action.CloseLatency", | 741 UMA_HISTOGRAM_TIMES("MediaRouter.Ui.Action.CloseLatency", |
| 729 base::TimeDelta::FromMillisecondsD(time_to_close)); | 742 base::TimeDelta::FromMillisecondsD(time_to_close)); |
| 730 } | 743 } |
| 731 | 744 |
| 745 void MediaRouterWebUIMessageHandler::OnSearchSinksAndCreateRoute( | |
| 746 const base::ListValue* args) { | |
| 747 DVLOG(1) << "OnSearchSinksAndCreateRoute"; | |
| 748 const base::DictionaryValue* args_dict = nullptr; | |
| 749 std::string sink_id; | |
| 750 std::string search_criteria; | |
| 751 std::string domain; | |
| 752 int cast_mode_num = -1; | |
| 753 if (!args->GetDictionary(0, &args_dict) || | |
| 754 !args_dict->GetString("sinkId", &sink_id) || | |
| 755 !args_dict->GetString("searchCriteria", &search_criteria) || | |
| 756 !args_dict->GetString("domain", &domain) || | |
| 757 !args_dict->GetInteger("selectedCastMode", &cast_mode_num)) { | |
| 758 DVLOG(1) << "Unable to extract args"; | |
| 759 return; | |
| 760 } | |
| 761 | |
| 762 if (search_criteria.empty()) { | |
| 763 DVLOG(1) << "Media Router UI did not provide valid search criteria. " | |
| 764 "Aborting."; | |
|
apacible
2016/04/06 21:27:02
return;
btolsch
2016/04/08 09:31:25
Done.
| |
| 765 } | |
| 766 | |
| 767 if (!IsValidCastModeNum(cast_mode_num)) { | |
| 768 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; | |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 // TODO(btolsch): Check result and add an issue if it failed. | |
| 773 media_router_ui_->SearchSinksAndCreateRoute( | |
| 774 sink_id, search_criteria, domain, | |
| 775 static_cast<MediaCastMode>(cast_mode_num)); | |
| 776 } | |
| 777 | |
| 732 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( | 778 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( |
| 733 const base::ListValue* args) { | 779 const base::ListValue* args) { |
| 734 DVLOG(1) << "OnInitialDataReceived"; | 780 DVLOG(1) << "OnInitialDataReceived"; |
| 735 media_router_ui_->OnUIInitialDataReceived(); | 781 media_router_ui_->OnUIInitialDataReceived(); |
| 736 MaybeUpdateFirstRunFlowData(); | 782 MaybeUpdateFirstRunFlowData(); |
| 737 } | 783 } |
| 738 | 784 |
| 739 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 785 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 740 const IssueAction::Type& action_type, | 786 const IssueAction::Type& action_type, |
| 741 const base::DictionaryValue* args) { | 787 const base::DictionaryValue* args) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 #endif // defined(GOOGLE_CHROME_BUILD) | 860 #endif // defined(GOOGLE_CHROME_BUILD) |
| 815 | 861 |
| 816 return AccountInfo(); | 862 return AccountInfo(); |
| 817 } | 863 } |
| 818 | 864 |
| 819 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 865 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 820 set_web_ui(web_ui); | 866 set_web_ui(web_ui); |
| 821 } | 867 } |
| 822 | 868 |
| 823 } // namespace media_router | 869 } // namespace media_router |
| OLD | NEW |