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

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

Powered by Google App Engine
This is Rietveld 408576698