Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 cast_mode_val->SetString("host", source_host); 181 cast_mode_val->SetString("host", source_host);
182 value->Append(std::move(cast_mode_val)); 182 value->Append(std::move(cast_mode_val));
183 } 183 }
184 184
185 return value; 185 return value;
186 } 186 }
187 187
188 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 188 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
189 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 189 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
190 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 190 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
191 dictionary->SetString("id", issue.id()); 191 dictionary->SetInteger("id", issue.id());
192 dictionary->SetString("title", issue.title()); 192 dictionary->SetString("title", issue.title());
193 dictionary->SetString("message", issue.message()); 193 dictionary->SetString("message", issue.message());
194 dictionary->SetInteger("defaultActionType", issue.default_action().type()); 194 dictionary->SetInteger("defaultActionType",
195 static_cast<int>(issue.default_action()));
195 if (!issue.secondary_actions().empty()) { 196 if (!issue.secondary_actions().empty()) {
196 dictionary->SetInteger("secondaryActionType", 197 dictionary->SetInteger("secondaryActionType",
197 issue.secondary_actions().begin()->type()); 198 static_cast<int>(issue.secondary_actions()[0]));
198 } 199 }
199 if (!issue.route_id().empty()) 200 if (!issue.route_id().empty())
200 dictionary->SetString("routeId", issue.route_id()); 201 dictionary->SetString("routeId", issue.route_id());
201 dictionary->SetBoolean("isBlocking", issue.is_blocking()); 202 dictionary->SetBoolean("isBlocking", issue.IsBlocking());
202 if (issue.help_page_id() > 0) 203 if (issue.help_page_id() > 0)
203 dictionary->SetInteger("helpPageId", issue.help_page_id()); 204 dictionary->SetInteger("helpPageId", issue.help_page_id());
204 205
205 return dictionary; 206 return dictionary;
206 } 207 }
207 208
208 bool IsValidIssueActionTypeNum(int issue_action_type_num) { 209 bool IsValidIssueActionTypeNum(int issue_action_type_num) {
209 return issue_action_type_num >= 0 && 210 return issue_action_type_num >= 0 &&
210 issue_action_type_num < IssueAction::TYPE_MAX; 211 issue_action_type_num < static_cast<int>(Issue::ActionType::MAX);
211 } 212 }
212 213
213 // Composes a "learn more" URL. The URL depends on template arguments in |args|. 214 // Composes a "learn more" URL. The URL depends on template arguments in |args|.
214 // Returns an empty string if |args| is invalid. 215 // Returns an empty string if |args| is invalid.
215 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { 216 std::string GetLearnMoreUrl(const base::DictionaryValue* args) {
216 // TODO(imcheng): The template arguments for determining the learn more URL 217 // TODO(imcheng): The template arguments for determining the learn more URL
217 // should come from the Issue object in the browser, not from WebUI. 218 // should come from the Issue object in the browser, not from WebUI.
218 int help_page_id = -1; 219 int help_page_id = -1;
219 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) { 220 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) {
220 DVLOG(1) << "Invalid help page id."; 221 DVLOG(1) << "Invalid help page id.";
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (!IsValidCastModeNum(cast_mode_num)) { 448 if (!IsValidCastModeNum(cast_mode_num)) {
448 // TODO(imcheng): Record error condition with UMA. 449 // TODO(imcheng): Record error condition with UMA.
449 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; 450 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting.";
450 return; 451 return;
451 } 452 }
452 453
453 MediaRouterUI* media_router_ui = 454 MediaRouterUI* media_router_ui =
454 static_cast<MediaRouterUI*>(web_ui()->GetController()); 455 static_cast<MediaRouterUI*>(web_ui()->GetController());
455 if (media_router_ui->HasPendingRouteRequest()) { 456 if (media_router_ui->HasPendingRouteRequest()) {
456 DVLOG(1) << "UI already has pending route request. Ignoring."; 457 DVLOG(1) << "UI already has pending route request. Ignoring.";
457 Issue issue( 458 Issue issue(l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
458 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), 459 Issue::ActionType::DISMISS, Issue::Severity::NOTIFICATION);
459 std::string(), IssueAction(IssueAction::TYPE_DISMISS),
460 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
461 false, -1);
462 media_router_ui_->AddIssue(issue); 460 media_router_ui_->AddIssue(issue);
463 return; 461 return;
464 } 462 }
465 463
466 DVLOG(2) << __FUNCTION__ << ": sink id: " << sink_id 464 DVLOG(2) << __FUNCTION__ << ": sink id: " << sink_id
467 << ", cast mode: " << cast_mode_num; 465 << ", cast mode: " << cast_mode_num;
468 466
469 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, 467 // TODO(haibinlu): Pass additional parameters into the CreateRoute request,
470 // e.g. low-fps-mirror, user-override. (crbug.com/490364) 468 // e.g. low-fps-mirror, user-override. (crbug.com/490364)
471 if (!media_router_ui->CreateRoute( 469 if (!media_router_ui->CreateRoute(
(...skipping 24 matching lines...) Expand all
496 #endif // defined(GOOGLE_CHROME_BUILD) 494 #endif // defined(GOOGLE_CHROME_BUILD)
497 } 495 }
498 496
499 void MediaRouterWebUIMessageHandler::OnActOnIssue( 497 void MediaRouterWebUIMessageHandler::OnActOnIssue(
500 const base::ListValue* args) { 498 const base::ListValue* args) {
501 DVLOG(1) << "OnActOnIssue"; 499 DVLOG(1) << "OnActOnIssue";
502 const base::DictionaryValue* args_dict = nullptr; 500 const base::DictionaryValue* args_dict = nullptr;
503 Issue::Id issue_id; 501 Issue::Id issue_id;
504 int action_type_num = -1; 502 int action_type_num = -1;
505 if (!args->GetDictionary(0, &args_dict) || 503 if (!args->GetDictionary(0, &args_dict) ||
506 !args_dict->GetString("issueId", &issue_id) || 504 !args_dict->GetInteger("issueId", &issue_id) ||
507 !args_dict->GetInteger("actionType", &action_type_num)) { 505 !args_dict->GetInteger("actionType", &action_type_num)) {
508 DVLOG(1) << "Unable to extract args."; 506 DVLOG(1) << "Unable to extract args.";
509 return; 507 return;
510 } 508 }
511 if (!IsValidIssueActionTypeNum(action_type_num)) { 509 if (!IsValidIssueActionTypeNum(action_type_num)) {
512 DVLOG(1) << "Invalid action type: " << action_type_num; 510 DVLOG(1) << "Invalid action type: " << action_type_num;
513 return; 511 return;
514 } 512 }
515 IssueAction::Type action_type = 513 Issue::ActionType action_type =
516 static_cast<IssueAction::Type>(action_type_num); 514 static_cast<Issue::ActionType>(action_type_num);
517 if (ActOnIssueType(action_type, args_dict)) 515 if (ActOnIssueType(action_type, args_dict))
518 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; 516 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id;
519 media_router_ui_->ClearIssue(issue_id); 517 media_router_ui_->ClearIssue(issue_id);
520 } 518 }
521 519
522 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { 520 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) {
523 DVLOG(1) << "OnJoinRoute"; 521 DVLOG(1) << "OnJoinRoute";
524 const base::DictionaryValue* args_dict = nullptr; 522 const base::DictionaryValue* args_dict = nullptr;
525 std::string route_id; 523 std::string route_id;
526 std::string sink_id; 524 std::string sink_id;
(...skipping 13 matching lines...) Expand all
540 if (route_id.empty()) { 538 if (route_id.empty()) {
541 DVLOG(1) << "Media Route UI did not respond with a " 539 DVLOG(1) << "Media Route UI did not respond with a "
542 << "valid route ID. Aborting."; 540 << "valid route ID. Aborting.";
543 return; 541 return;
544 } 542 }
545 543
546 MediaRouterUI* media_router_ui = 544 MediaRouterUI* media_router_ui =
547 static_cast<MediaRouterUI*>(web_ui()->GetController()); 545 static_cast<MediaRouterUI*>(web_ui()->GetController());
548 if (media_router_ui->HasPendingRouteRequest()) { 546 if (media_router_ui->HasPendingRouteRequest()) {
549 DVLOG(1) << "UI already has pending route request. Ignoring."; 547 DVLOG(1) << "UI already has pending route request. Ignoring.";
550 Issue issue( 548 Issue issue(l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
551 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), 549 Issue::ActionType::DISMISS, Issue::Severity::NOTIFICATION);
552 std::string(), IssueAction(IssueAction::TYPE_DISMISS),
553 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
554 false, -1);
555 media_router_ui_->AddIssue(issue); 550 media_router_ui_->AddIssue(issue);
556 return; 551 return;
557 } 552 }
558 553
559 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) { 554 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) {
560 DVLOG(1) << "Error initiating route join request."; 555 DVLOG(1) << "Error initiating route join request.";
561 } 556 }
562 } 557 }
563 558
564 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { 559 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 768 }
774 769
775 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( 770 void MediaRouterWebUIMessageHandler::OnInitialDataReceived(
776 const base::ListValue* args) { 771 const base::ListValue* args) {
777 DVLOG(1) << "OnInitialDataReceived"; 772 DVLOG(1) << "OnInitialDataReceived";
778 media_router_ui_->OnUIInitialDataReceived(); 773 media_router_ui_->OnUIInitialDataReceived();
779 MaybeUpdateFirstRunFlowData(); 774 MaybeUpdateFirstRunFlowData();
780 } 775 }
781 776
782 bool MediaRouterWebUIMessageHandler::ActOnIssueType( 777 bool MediaRouterWebUIMessageHandler::ActOnIssueType(
783 const IssueAction::Type& action_type, 778 Issue::ActionType action_type,
784 const base::DictionaryValue* args) { 779 const base::DictionaryValue* args) {
785 if (action_type == IssueAction::TYPE_LEARN_MORE) { 780 if (action_type == Issue::ActionType::LEARN_MORE) {
786 std::string learn_more_url = GetLearnMoreUrl(args); 781 std::string learn_more_url = GetLearnMoreUrl(args);
787 if (learn_more_url.empty()) 782 if (learn_more_url.empty())
788 return false; 783 return false;
789 std::unique_ptr<base::ListValue> open_args(new base::ListValue); 784 std::unique_ptr<base::ListValue> open_args(new base::ListValue);
790 open_args->AppendString(learn_more_url); 785 open_args->AppendString(learn_more_url);
791 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); 786 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args);
792 return true; 787 return true;
793 } else { 788 } else {
794 // Do nothing; no other issue action types require any other action. 789 // Do nothing; no other issue action types require any other action.
795 return true; 790 return true;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } 884 }
890 885
891 return value; 886 return value;
892 } 887 }
893 888
894 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 889 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
895 set_web_ui(web_ui); 890 set_web_ui(web_ui);
896 } 891 }
897 892
898 } // namespace media_router 893 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698