| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/media/router/issue.h" | 12 #include "chrome/browser/media/router/issue.h" |
| 13 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 13 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 | 17 |
| 18 namespace media_router { | 18 namespace media_router { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kHelpPageUrlPrefix[] = | 22 const char kHelpPageUrlPrefix[] = |
| 23 "https://support.google.com/chromecast/answer/%d"; | 23 "https://support.google.com/chromecast/answer/%d"; |
| 24 | 24 |
| 25 // Message names. | 25 // Message names. |
| 26 const char kRequestInitialData[] = "requestInitialData"; | 26 const char kRequestInitialData[] = "requestInitialData"; |
| 27 const char kCreateRoute[] = "requestRoute"; | 27 const char kCreateRoute[] = "requestRoute"; |
| 28 const char kActOnIssue[] = "actOnIssue"; | 28 const char kActOnIssue[] = "actOnIssue"; |
| 29 const char kCloseRoute[] = "closeRoute"; | 29 const char kCloseRoute[] = "closeRoute"; |
| 30 const char kJoinRoute[] = "joinRoute"; |
| 30 const char kCloseDialog[] = "closeDialog"; | 31 const char kCloseDialog[] = "closeDialog"; |
| 31 const char kReportSinkCount[] = "reportSinkCount"; | 32 const char kReportSinkCount[] = "reportSinkCount"; |
| 32 | 33 |
| 33 // JS function names. | 34 // JS function names. |
| 34 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 35 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 35 const char kNotifyRouteCreationTimeout[] = | 36 const char kNotifyRouteCreationTimeout[] = |
| 36 "media_router.ui.onNotifyRouteCreationTimeout"; | 37 "media_router.ui.onNotifyRouteCreationTimeout"; |
| 37 const char kOnCreateRouteResponseReceived[] = | 38 const char kOnCreateRouteResponseReceived[] = |
| 38 "media_router.ui.onCreateRouteResponseReceived"; | 39 "media_router.ui.onCreateRouteResponseReceived"; |
| 39 const char kSetIssue[] = "media_router.ui.setIssue"; | 40 const char kSetIssue[] = "media_router.ui.setIssue"; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 base::Unretained(this))); | 243 base::Unretained(this))); |
| 243 web_ui()->RegisterMessageCallback( | 244 web_ui()->RegisterMessageCallback( |
| 244 kActOnIssue, | 245 kActOnIssue, |
| 245 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, | 246 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, |
| 246 base::Unretained(this))); | 247 base::Unretained(this))); |
| 247 web_ui()->RegisterMessageCallback( | 248 web_ui()->RegisterMessageCallback( |
| 248 kCloseRoute, | 249 kCloseRoute, |
| 249 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, | 250 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, |
| 250 base::Unretained(this))); | 251 base::Unretained(this))); |
| 251 web_ui()->RegisterMessageCallback( | 252 web_ui()->RegisterMessageCallback( |
| 253 kJoinRoute, |
| 254 base::Bind(&MediaRouterWebUIMessageHandler::OnJoinRoute, |
| 255 base::Unretained(this))); |
| 256 web_ui()->RegisterMessageCallback( |
| 252 kCloseDialog, | 257 kCloseDialog, |
| 253 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 258 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 254 base::Unretained(this))); | 259 base::Unretained(this))); |
| 255 web_ui()->RegisterMessageCallback( | 260 web_ui()->RegisterMessageCallback( |
| 256 kReportSinkCount, | 261 kReportSinkCount, |
| 257 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, | 262 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, |
| 258 base::Unretained(this))); | 263 base::Unretained(this))); |
| 259 } | 264 } |
| 260 | 265 |
| 261 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 266 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 DVLOG(1) << "Invalid action type: " << action_type_num; | 358 DVLOG(1) << "Invalid action type: " << action_type_num; |
| 354 return; | 359 return; |
| 355 } | 360 } |
| 356 IssueAction::Type action_type = | 361 IssueAction::Type action_type = |
| 357 static_cast<IssueAction::Type>(action_type_num); | 362 static_cast<IssueAction::Type>(action_type_num); |
| 358 if (ActOnIssueType(action_type, args_dict)) | 363 if (ActOnIssueType(action_type, args_dict)) |
| 359 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; | 364 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; |
| 360 media_router_ui_->ClearIssue(issue_id); | 365 media_router_ui_->ClearIssue(issue_id); |
| 361 } | 366 } |
| 362 | 367 |
| 363 void MediaRouterWebUIMessageHandler::OnCloseRoute( | 368 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { |
| 364 const base::ListValue* args) { | 369 DVLOG(0) << "OnJoinRoute"; |
| 370 const base::DictionaryValue* args_dict = nullptr; |
| 371 std::string route_id; |
| 372 std::string sink_id; |
| 373 if (!args->GetDictionary(0, &args_dict) || |
| 374 !args_dict->GetString("sinkId", &sink_id) || |
| 375 !args_dict->GetString("routeId", &route_id)) { |
| 376 DVLOG(1) << "Unable to extract args."; |
| 377 return; |
| 378 } |
| 379 media_router_ui_->JoinRoute(sink_id, route_id); |
| 380 } |
| 381 |
| 382 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { |
| 365 DVLOG(1) << "OnCloseRoute"; | 383 DVLOG(1) << "OnCloseRoute"; |
| 366 const base::DictionaryValue* args_dict = nullptr; | 384 const base::DictionaryValue* args_dict = nullptr; |
| 367 std::string route_id; | 385 std::string route_id; |
| 368 if (!args->GetDictionary(0, &args_dict) || | 386 if (!args->GetDictionary(0, &args_dict) || |
| 369 !args_dict->GetString("routeId", &route_id)) { | 387 !args_dict->GetString("routeId", &route_id)) { |
| 370 DVLOG(1) << "Unable to extract args."; | 388 DVLOG(1) << "Unable to extract args."; |
| 371 return; | 389 return; |
| 372 } | 390 } |
| 373 media_router_ui_->CloseRoute(route_id); | 391 media_router_ui_->CloseRoute(route_id); |
| 374 } | 392 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 405 open_args->AppendString(learn_more_url); | 423 open_args->AppendString(learn_more_url); |
| 406 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 424 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 407 return true; | 425 return true; |
| 408 } else { | 426 } else { |
| 409 // Do nothing; no other issue action types require any other action. | 427 // Do nothing; no other issue action types require any other action. |
| 410 return true; | 428 return true; |
| 411 } | 429 } |
| 412 } | 430 } |
| 413 | 431 |
| 414 } // namespace media_router | 432 } // namespace media_router |
| OLD | NEW |