| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 "description", MediaCastModeToDescription(cast_mode, source_host)); | 179 "description", MediaCastModeToDescription(cast_mode, source_host)); |
| 180 cast_mode_val->SetString("host", source_host); | 180 cast_mode_val->SetString("host", source_host); |
| 181 value->Append(std::move(cast_mode_val)); | 181 value->Append(std::move(cast_mode_val)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 return value; | 184 return value; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Returns an Issue dictionary created from |issue| that can be used in WebUI. | 187 // Returns an Issue dictionary created from |issue| that can be used in WebUI. |
| 188 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { | 188 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { |
| 189 const IssueInfo& issue_info = issue.info(); |
| 189 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 190 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 190 dictionary->SetString("id", issue.id()); | 191 dictionary->SetInteger("id", issue.id()); |
| 191 dictionary->SetString("title", issue.title()); | 192 dictionary->SetString("title", issue_info.title); |
| 192 dictionary->SetString("message", issue.message()); | 193 dictionary->SetString("message", issue_info.message); |
| 193 dictionary->SetInteger("defaultActionType", issue.default_action().type()); | 194 dictionary->SetInteger("defaultActionType", |
| 194 if (!issue.secondary_actions().empty()) { | 195 static_cast<int>(issue_info.default_action)); |
| 196 if (!issue_info.secondary_actions.empty()) { |
| 197 DCHECK_EQ(1u, issue_info.secondary_actions.size()); |
| 195 dictionary->SetInteger("secondaryActionType", | 198 dictionary->SetInteger("secondaryActionType", |
| 196 issue.secondary_actions().begin()->type()); | 199 static_cast<int>(issue_info.secondary_actions[0])); |
| 197 } | 200 } |
| 198 if (!issue.route_id().empty()) | 201 if (!issue_info.route_id.empty()) |
| 199 dictionary->SetString("routeId", issue.route_id()); | 202 dictionary->SetString("routeId", issue_info.route_id); |
| 200 dictionary->SetBoolean("isBlocking", issue.is_blocking()); | 203 dictionary->SetBoolean("isBlocking", issue_info.is_blocking); |
| 201 if (issue.help_page_id() > 0) | 204 if (issue_info.help_page_id > 0) |
| 202 dictionary->SetInteger("helpPageId", issue.help_page_id()); | 205 dictionary->SetInteger("helpPageId", issue_info.help_page_id); |
| 203 | 206 |
| 204 return dictionary; | 207 return dictionary; |
| 205 } | 208 } |
| 206 | 209 |
| 207 bool IsValidIssueActionTypeNum(int issue_action_type_num) { | 210 bool IsValidIssueActionTypeNum(int issue_action_type_num) { |
| 208 return issue_action_type_num >= 0 && | 211 return issue_action_type_num >= 0 && |
| 209 issue_action_type_num < IssueAction::TYPE_MAX; | 212 issue_action_type_num <= |
| 213 static_cast<int>(IssueInfo::Action::NUM_VALUES); |
| 210 } | 214 } |
| 211 | 215 |
| 212 // Composes a "learn more" URL. The URL depends on template arguments in |args|. | 216 // Composes a "learn more" URL. The URL depends on template arguments in |args|. |
| 213 // Returns an empty string if |args| is invalid. | 217 // Returns an empty string if |args| is invalid. |
| 214 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { | 218 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { |
| 215 // TODO(imcheng): The template arguments for determining the learn more URL | 219 // TODO(imcheng): The template arguments for determining the learn more URL |
| 216 // should come from the Issue object in the browser, not from WebUI. | 220 // should come from the Issue object in the browser, not from WebUI. |
| 217 int help_page_id = -1; | 221 int help_page_id = -1; |
| 218 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) { | 222 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) { |
| 219 DVLOG(1) << "Invalid help page id."; | 223 DVLOG(1) << "Invalid help page id."; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 292 } |
| 289 } | 293 } |
| 290 | 294 |
| 291 void MediaRouterWebUIMessageHandler::ReturnSearchResult( | 295 void MediaRouterWebUIMessageHandler::ReturnSearchResult( |
| 292 const std::string& sink_id) { | 296 const std::string& sink_id) { |
| 293 DVLOG(2) << "ReturnSearchResult"; | 297 DVLOG(2) << "ReturnSearchResult"; |
| 294 web_ui()->CallJavascriptFunctionUnsafe(kReceiveSearchResult, | 298 web_ui()->CallJavascriptFunctionUnsafe(kReceiveSearchResult, |
| 295 base::StringValue(sink_id)); | 299 base::StringValue(sink_id)); |
| 296 } | 300 } |
| 297 | 301 |
| 298 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 302 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue& issue) { |
| 299 DVLOG(2) << "UpdateIssue"; | 303 DVLOG(2) << "UpdateIssue"; |
| 300 web_ui()->CallJavascriptFunctionUnsafe( | 304 web_ui()->CallJavascriptFunctionUnsafe(kSetIssue, *IssueToValue(issue)); |
| 301 kSetIssue, | 305 } |
| 302 issue ? *IssueToValue(*issue) : *base::Value::CreateNullValue()); | 306 |
| 307 void MediaRouterWebUIMessageHandler::ClearIssue() { |
| 308 DVLOG(2) << "ClearIssue"; |
| 309 web_ui()->CallJavascriptFunctionUnsafe(kSetIssue, |
| 310 *base::Value::CreateNullValue()); |
| 303 } | 311 } |
| 304 | 312 |
| 305 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { | 313 void MediaRouterWebUIMessageHandler::UpdateMaxDialogHeight(int height) { |
| 306 DVLOG(2) << "UpdateMaxDialogHeight"; | 314 DVLOG(2) << "UpdateMaxDialogHeight"; |
| 307 web_ui()->CallJavascriptFunctionUnsafe(kUpdateMaxHeight, | 315 web_ui()->CallJavascriptFunctionUnsafe(kUpdateMaxHeight, |
| 308 base::FundamentalValue(height)); | 316 base::FundamentalValue(height)); |
| 309 } | 317 } |
| 310 | 318 |
| 311 void MediaRouterWebUIMessageHandler::RegisterMessages() { | 319 void MediaRouterWebUIMessageHandler::RegisterMessages() { |
| 312 web_ui()->RegisterMessageCallback( | 320 web_ui()->RegisterMessageCallback( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 if (!IsValidCastModeNum(cast_mode_num)) { | 462 if (!IsValidCastModeNum(cast_mode_num)) { |
| 455 // TODO(imcheng): Record error condition with UMA. | 463 // TODO(imcheng): Record error condition with UMA. |
| 456 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; | 464 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; |
| 457 return; | 465 return; |
| 458 } | 466 } |
| 459 | 467 |
| 460 MediaRouterUI* media_router_ui = | 468 MediaRouterUI* media_router_ui = |
| 461 static_cast<MediaRouterUI*>(web_ui()->GetController()); | 469 static_cast<MediaRouterUI*>(web_ui()->GetController()); |
| 462 if (media_router_ui->HasPendingRouteRequest()) { | 470 if (media_router_ui->HasPendingRouteRequest()) { |
| 463 DVLOG(1) << "UI already has pending route request. Ignoring."; | 471 DVLOG(1) << "UI already has pending route request. Ignoring."; |
| 464 Issue issue( | 472 IssueInfo issue( |
| 465 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), | 473 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), |
| 466 std::string(), IssueAction(IssueAction::TYPE_DISMISS), | 474 IssueInfo::Action::DISMISS, IssueInfo::Severity::NOTIFICATION); |
| 467 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 468 false, -1); | |
| 469 media_router_ui_->AddIssue(issue); | 475 media_router_ui_->AddIssue(issue); |
| 470 return; | 476 return; |
| 471 } | 477 } |
| 472 | 478 |
| 473 DVLOG(2) << __func__ << ": sink id: " << sink_id | 479 DVLOG(2) << __func__ << ": sink id: " << sink_id |
| 474 << ", cast mode: " << cast_mode_num; | 480 << ", cast mode: " << cast_mode_num; |
| 475 | 481 |
| 476 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, | 482 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, |
| 477 // e.g. low-fps-mirror, user-override. (crbug.com/490364) | 483 // e.g. low-fps-mirror, user-override. (crbug.com/490364) |
| 478 if (!media_router_ui->CreateRoute( | 484 if (!media_router_ui->CreateRoute( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 501 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); | 507 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); |
| 502 } | 508 } |
| 503 | 509 |
| 504 void MediaRouterWebUIMessageHandler::OnActOnIssue( | 510 void MediaRouterWebUIMessageHandler::OnActOnIssue( |
| 505 const base::ListValue* args) { | 511 const base::ListValue* args) { |
| 506 DVLOG(1) << "OnActOnIssue"; | 512 DVLOG(1) << "OnActOnIssue"; |
| 507 const base::DictionaryValue* args_dict = nullptr; | 513 const base::DictionaryValue* args_dict = nullptr; |
| 508 Issue::Id issue_id; | 514 Issue::Id issue_id; |
| 509 int action_type_num = -1; | 515 int action_type_num = -1; |
| 510 if (!args->GetDictionary(0, &args_dict) || | 516 if (!args->GetDictionary(0, &args_dict) || |
| 511 !args_dict->GetString("issueId", &issue_id) || | 517 !args_dict->GetInteger("issueId", &issue_id) || |
| 512 !args_dict->GetInteger("actionType", &action_type_num)) { | 518 !args_dict->GetInteger("actionType", &action_type_num)) { |
| 513 DVLOG(1) << "Unable to extract args."; | 519 DVLOG(1) << "Unable to extract args."; |
| 514 return; | 520 return; |
| 515 } | 521 } |
| 516 if (!IsValidIssueActionTypeNum(action_type_num)) { | 522 if (!IsValidIssueActionTypeNum(action_type_num)) { |
| 517 DVLOG(1) << "Invalid action type: " << action_type_num; | 523 DVLOG(1) << "Invalid action type: " << action_type_num; |
| 518 return; | 524 return; |
| 519 } | 525 } |
| 520 IssueAction::Type action_type = | 526 IssueInfo::Action action_type = |
| 521 static_cast<IssueAction::Type>(action_type_num); | 527 static_cast<IssueInfo::Action>(action_type_num); |
| 522 if (ActOnIssueType(action_type, args_dict)) | 528 if (ActOnIssueType(action_type, args_dict)) |
| 523 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; | 529 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; |
| 524 media_router_ui_->ClearIssue(issue_id); | 530 media_router_ui_->ClearIssue(issue_id); |
| 525 } | 531 } |
| 526 | 532 |
| 527 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { | 533 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { |
| 528 DVLOG(1) << "OnJoinRoute"; | 534 DVLOG(1) << "OnJoinRoute"; |
| 529 const base::DictionaryValue* args_dict = nullptr; | 535 const base::DictionaryValue* args_dict = nullptr; |
| 530 std::string route_id; | 536 std::string route_id; |
| 531 std::string sink_id; | 537 std::string sink_id; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 545 if (route_id.empty()) { | 551 if (route_id.empty()) { |
| 546 DVLOG(1) << "Media Route UI did not respond with a " | 552 DVLOG(1) << "Media Route UI did not respond with a " |
| 547 << "valid route ID. Aborting."; | 553 << "valid route ID. Aborting."; |
| 548 return; | 554 return; |
| 549 } | 555 } |
| 550 | 556 |
| 551 MediaRouterUI* media_router_ui = | 557 MediaRouterUI* media_router_ui = |
| 552 static_cast<MediaRouterUI*>(web_ui()->GetController()); | 558 static_cast<MediaRouterUI*>(web_ui()->GetController()); |
| 553 if (media_router_ui->HasPendingRouteRequest()) { | 559 if (media_router_ui->HasPendingRouteRequest()) { |
| 554 DVLOG(1) << "UI already has pending route request. Ignoring."; | 560 DVLOG(1) << "UI already has pending route request. Ignoring."; |
| 555 Issue issue( | 561 IssueInfo issue( |
| 556 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), | 562 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), |
| 557 std::string(), IssueAction(IssueAction::TYPE_DISMISS), | 563 IssueInfo::Action::DISMISS, IssueInfo::Severity::NOTIFICATION); |
| 558 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 559 false, -1); | |
| 560 media_router_ui_->AddIssue(issue); | 564 media_router_ui_->AddIssue(issue); |
| 561 return; | 565 return; |
| 562 } | 566 } |
| 563 | 567 |
| 564 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) { | 568 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) { |
| 565 DVLOG(1) << "Error initiating route join request."; | 569 DVLOG(1) << "Error initiating route join request."; |
| 566 } | 570 } |
| 567 } | 571 } |
| 568 | 572 |
| 569 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { | 573 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 } | 785 } |
| 782 | 786 |
| 783 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( | 787 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( |
| 784 const base::ListValue* args) { | 788 const base::ListValue* args) { |
| 785 DVLOG(1) << "OnInitialDataReceived"; | 789 DVLOG(1) << "OnInitialDataReceived"; |
| 786 media_router_ui_->OnUIInitialDataReceived(); | 790 media_router_ui_->OnUIInitialDataReceived(); |
| 787 MaybeUpdateFirstRunFlowData(); | 791 MaybeUpdateFirstRunFlowData(); |
| 788 } | 792 } |
| 789 | 793 |
| 790 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 794 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 791 const IssueAction::Type& action_type, | 795 IssueInfo::Action action_type, |
| 792 const base::DictionaryValue* args) { | 796 const base::DictionaryValue* args) { |
| 793 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 797 if (action_type == IssueInfo::Action::LEARN_MORE) { |
| 794 std::string learn_more_url = GetLearnMoreUrl(args); | 798 std::string learn_more_url = GetLearnMoreUrl(args); |
| 795 if (learn_more_url.empty()) | 799 if (learn_more_url.empty()) |
| 796 return false; | 800 return false; |
| 797 std::unique_ptr<base::ListValue> open_args(new base::ListValue); | 801 std::unique_ptr<base::ListValue> open_args(new base::ListValue); |
| 798 open_args->AppendString(learn_more_url); | 802 open_args->AppendString(learn_more_url); |
| 799 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); | 803 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); |
| 800 return true; | 804 return true; |
| 801 } else { | 805 } else { |
| 802 // Do nothing; no other issue action types require any other action. | 806 // Do nothing; no other issue action types require any other action. |
| 803 return true; | 807 return true; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 } | 896 } |
| 893 | 897 |
| 894 return value; | 898 return value; |
| 895 } | 899 } |
| 896 | 900 |
| 897 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 901 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 898 set_web_ui(web_ui); | 902 set_web_ui(web_ui); |
| 899 } | 903 } |
| 900 | 904 |
| 901 } // namespace media_router | 905 } // namespace media_router |
| OLD | NEW |