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 std::unique_ptr<base::DictionaryValue> SinksAndIdentityToValue( | 78 std::unique_ptr<base::DictionaryValue> SinksAndIdentityToValue( |
| 77 const std::vector<MediaSinkWithCastModes>& sinks, | 79 const std::vector<MediaSinkWithCastModes>& sinks, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 show_email = true; | 117 show_email = true; |
| 116 if (!domain.empty() && domain != user_domain) | 118 if (!domain.empty() && domain != user_domain) |
| 117 show_domain = true; | 119 show_domain = true; |
| 118 } | 120 } |
| 119 | 121 |
| 120 int cast_mode_bits = 0; | 122 int cast_mode_bits = 0; |
| 121 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 123 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
| 122 cast_mode_bits |= cast_mode; | 124 cast_mode_bits |= cast_mode; |
| 123 | 125 |
| 124 sink_val->SetInteger("castModes", cast_mode_bits); | 126 sink_val->SetInteger("castModes", cast_mode_bits); |
| 127 sink_val->SetBoolean("isPseudoSink", sink.id().find("pseudo:") == 0); | |
|
imcheng
2016/04/18 23:15:47
Use base::StartsWith: https://code.google.com/p/ch
btolsch
2016/04/19 01:39:43
Done.
| |
| 125 sinks_val->Append(sink_val.release()); | 128 sinks_val->Append(sink_val.release()); |
| 126 } | 129 } |
| 127 | 130 |
| 128 sink_list_and_identity->Set("sinks", sinks_val.release()); | 131 sink_list_and_identity->Set("sinks", sinks_val.release()); |
| 129 sink_list_and_identity->SetBoolean("showEmail", show_email); | 132 sink_list_and_identity->SetBoolean("showEmail", show_email); |
| 130 sink_list_and_identity->SetBoolean("showDomain", show_domain); | 133 sink_list_and_identity->SetBoolean("showDomain", show_domain); |
| 131 return sink_list_and_identity; | 134 return sink_list_and_identity; |
| 132 } | 135 } |
| 133 | 136 |
| 134 std::unique_ptr<base::DictionaryValue> RouteToValue( | 137 std::unique_ptr<base::DictionaryValue> RouteToValue( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 base::StringValue(sink_id), *route_value, | 286 base::StringValue(sink_id), *route_value, |
| 284 base::FundamentalValue(route->for_display())); | 287 base::FundamentalValue(route->for_display())); |
| 285 } else { | 288 } else { |
| 286 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 289 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 287 base::StringValue(sink_id), | 290 base::StringValue(sink_id), |
| 288 *base::Value::CreateNullValue(), | 291 *base::Value::CreateNullValue(), |
| 289 base::FundamentalValue(false)); | 292 base::FundamentalValue(false)); |
| 290 } | 293 } |
| 291 } | 294 } |
| 292 | 295 |
| 296 void MediaRouterWebUIMessageHandler::ReturnSearchResult( | |
| 297 const std::string& sink_id) { | |
| 298 DVLOG(2) << "ReturnSearchResult"; | |
| 299 web_ui()->CallJavascriptFunction(kReceiveSearchResult, | |
| 300 base::StringValue(sink_id)); | |
| 301 } | |
| 302 | |
| 293 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 303 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 294 DVLOG(2) << "UpdateIssue"; | 304 DVLOG(2) << "UpdateIssue"; |
| 295 web_ui()->CallJavascriptFunction(kSetIssue, | 305 web_ui()->CallJavascriptFunction(kSetIssue, |
| 296 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); | 306 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); |
| 297 } | 307 } |
| 298 | 308 |
| 299 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { | 309 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { |
| 300 DVLOG(2) << "UpdateMaxDialogHeight"; | 310 DVLOG(2) << "UpdateMaxDialogHeight"; |
| 301 web_ui()->CallJavascriptFunction(kUpdateMaxHeight, | 311 web_ui()->CallJavascriptFunction(kUpdateMaxHeight, |
| 302 base::FundamentalValue(height)); | 312 base::FundamentalValue(height)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 web_ui()->RegisterMessageCallback( | 384 web_ui()->RegisterMessageCallback( |
| 375 kReportTimeToClickSink, | 385 kReportTimeToClickSink, |
| 376 base::Bind(&MediaRouterWebUIMessageHandler::OnReportTimeToClickSink, | 386 base::Bind(&MediaRouterWebUIMessageHandler::OnReportTimeToClickSink, |
| 377 base::Unretained(this))); | 387 base::Unretained(this))); |
| 378 web_ui()->RegisterMessageCallback( | 388 web_ui()->RegisterMessageCallback( |
| 379 kReportTimeToInitialActionClose, | 389 kReportTimeToInitialActionClose, |
| 380 base::Bind( | 390 base::Bind( |
| 381 &MediaRouterWebUIMessageHandler::OnReportTimeToInitialActionClose, | 391 &MediaRouterWebUIMessageHandler::OnReportTimeToInitialActionClose, |
| 382 base::Unretained(this))); | 392 base::Unretained(this))); |
| 383 web_ui()->RegisterMessageCallback( | 393 web_ui()->RegisterMessageCallback( |
| 394 kSearchSinksAndCreateRoute, | |
| 395 base::Bind(&MediaRouterWebUIMessageHandler::OnSearchSinksAndCreateRoute, | |
| 396 base::Unretained(this))); | |
| 397 web_ui()->RegisterMessageCallback( | |
| 384 kOnInitialDataReceived, | 398 kOnInitialDataReceived, |
| 385 base::Bind(&MediaRouterWebUIMessageHandler::OnInitialDataReceived, | 399 base::Bind(&MediaRouterWebUIMessageHandler::OnInitialDataReceived, |
| 386 base::Unretained(this))); | 400 base::Unretained(this))); |
| 387 } | 401 } |
| 388 | 402 |
| 389 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 403 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 390 const base::ListValue* args) { | 404 const base::ListValue* args) { |
| 391 DVLOG(1) << "OnRequestInitialData"; | 405 DVLOG(1) << "OnRequestInitialData"; |
| 392 media_router_ui_->OnUIInitiallyLoaded(); | 406 media_router_ui_->OnUIInitiallyLoaded(); |
| 393 base::DictionaryValue initial_data; | 407 base::DictionaryValue initial_data; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 DVLOG(1) << "OnReportTimeToInitialActionClose"; | 739 DVLOG(1) << "OnReportTimeToInitialActionClose"; |
| 726 double time_to_close; | 740 double time_to_close; |
| 727 if (!args->GetDouble(0, &time_to_close)) { | 741 if (!args->GetDouble(0, &time_to_close)) { |
| 728 VLOG(0) << "Unable to extract args."; | 742 VLOG(0) << "Unable to extract args."; |
| 729 return; | 743 return; |
| 730 } | 744 } |
| 731 UMA_HISTOGRAM_TIMES("MediaRouter.Ui.Action.CloseLatency", | 745 UMA_HISTOGRAM_TIMES("MediaRouter.Ui.Action.CloseLatency", |
| 732 base::TimeDelta::FromMillisecondsD(time_to_close)); | 746 base::TimeDelta::FromMillisecondsD(time_to_close)); |
| 733 } | 747 } |
| 734 | 748 |
| 749 void MediaRouterWebUIMessageHandler::OnSearchSinksAndCreateRoute( | |
| 750 const base::ListValue* args) { | |
| 751 DVLOG(1) << "OnSearchSinksAndCreateRoute"; | |
| 752 const base::DictionaryValue* args_dict = nullptr; | |
| 753 std::string sink_id; | |
| 754 std::string search_criteria; | |
| 755 std::string domain; | |
| 756 int cast_mode_num = -1; | |
| 757 if (!args->GetDictionary(0, &args_dict) || | |
| 758 !args_dict->GetString("sinkId", &sink_id) || | |
| 759 !args_dict->GetString("searchCriteria", &search_criteria) || | |
| 760 !args_dict->GetString("domain", &domain) || | |
| 761 !args_dict->GetInteger("selectedCastMode", &cast_mode_num)) { | |
| 762 DVLOG(1) << "Unable to extract args"; | |
| 763 return; | |
| 764 } | |
| 765 | |
| 766 if (search_criteria.empty()) { | |
| 767 DVLOG(1) << "Media Router UI did not provide valid search criteria. " | |
| 768 "Aborting."; | |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 if (!IsValidCastModeNum(cast_mode_num)) { | |
| 773 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; | |
| 774 return; | |
| 775 } | |
| 776 | |
| 777 // TODO(btolsch): Check result and add an issue if it failed. | |
| 778 media_router_ui_->SearchSinksAndCreateRoute( | |
| 779 sink_id, search_criteria, domain, | |
| 780 static_cast<MediaCastMode>(cast_mode_num)); | |
| 781 } | |
| 782 | |
| 735 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( | 783 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( |
| 736 const base::ListValue* args) { | 784 const base::ListValue* args) { |
| 737 DVLOG(1) << "OnInitialDataReceived"; | 785 DVLOG(1) << "OnInitialDataReceived"; |
| 738 media_router_ui_->OnUIInitialDataReceived(); | 786 media_router_ui_->OnUIInitialDataReceived(); |
| 739 MaybeUpdateFirstRunFlowData(); | 787 MaybeUpdateFirstRunFlowData(); |
| 740 } | 788 } |
| 741 | 789 |
| 742 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 790 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 743 const IssueAction::Type& action_type, | 791 const IssueAction::Type& action_type, |
| 744 const base::DictionaryValue* args) { | 792 const base::DictionaryValue* args) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 #endif // defined(GOOGLE_CHROME_BUILD) | 865 #endif // defined(GOOGLE_CHROME_BUILD) |
| 818 | 866 |
| 819 return AccountInfo(); | 867 return AccountInfo(); |
| 820 } | 868 } |
| 821 | 869 |
| 822 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 870 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 823 set_web_ui(web_ui); | 871 set_web_ui(web_ui); |
| 824 } | 872 } |
| 825 | 873 |
| 826 } // namespace media_router | 874 } // namespace media_router |
| OLD | NEW |