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 11 matching lines...) Expand all Loading... | |
| 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 kCloseDialog[] = "closeDialog"; | 30 const char kCloseDialog[] = "closeDialog"; |
| 31 const char kReportSinkCount[] = "reportSinkCount"; | 31 const char kReportSinkCount[] = "reportSinkCount"; |
| 32 const char kOnInitialDataReceived[] = "onInitialDataReceived"; | |
| 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"; |
| 40 const char kSetSinkList[] = "media_router.ui.setSinkList"; | 41 const char kSetSinkList[] = "media_router.ui.setSinkList"; |
| 41 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 42 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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( |
| 252 kCloseDialog, | 253 kCloseDialog, |
| 253 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 254 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 254 base::Unretained(this))); | 255 base::Unretained(this))); |
| 255 web_ui()->RegisterMessageCallback( | 256 web_ui()->RegisterMessageCallback( |
| 256 kReportSinkCount, | 257 kReportSinkCount, |
| 257 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, | 258 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, |
| 258 base::Unretained(this))); | 259 base::Unretained(this))); |
| 260 web_ui()->RegisterMessageCallback( | |
| 261 kOnInitialDataReceived, | |
| 262 base::Bind(&MediaRouterWebUIMessageHandler::OnInitialDataReceived, | |
| 263 base::Unretained(this))); | |
| 259 } | 264 } |
| 260 | 265 |
| 261 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 266 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 262 const base::ListValue* args) { | 267 const base::ListValue* args) { |
| 263 DVLOG(1) << "OnRequestInitialData"; | 268 DVLOG(1) << "OnRequestInitialData"; |
| 269 media_router_ui_->OnUIInitiallyLoaded(); | |
|
mark a. foltz
2015/12/09 22:20:13
When is this called in the initialization flow? I
apacible
2015/12/09 23:19:55
This is called ASAP when the WebUI finishes loadin
| |
| 264 base::DictionaryValue initial_data; | 270 base::DictionaryValue initial_data; |
| 265 | 271 |
| 266 // "No Cast devices found?" Chromecast help center page. | 272 // "No Cast devices found?" Chromecast help center page. |
| 267 initial_data.SetString("deviceMissingUrl", | 273 initial_data.SetString("deviceMissingUrl", |
| 268 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 274 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 269 | 275 |
| 270 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); | 276 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); |
| 271 initial_data.Set("sinks", sinks.release()); | 277 initial_data.Set("sinks", sinks.release()); |
| 272 | 278 |
| 273 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), | 279 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 const base::ListValue* args) { | 394 const base::ListValue* args) { |
| 389 DVLOG(1) << "OnReportSinkCount"; | 395 DVLOG(1) << "OnReportSinkCount"; |
| 390 int sink_count; | 396 int sink_count; |
| 391 if (!args->GetInteger(0, &sink_count)) { | 397 if (!args->GetInteger(0, &sink_count)) { |
| 392 DVLOG(1) << "Unable to extract args."; | 398 DVLOG(1) << "Unable to extract args."; |
| 393 return; | 399 return; |
| 394 } | 400 } |
| 395 UMA_HISTOGRAM_COUNTS_100("MediaRouter.Ui.Device.Count", sink_count); | 401 UMA_HISTOGRAM_COUNTS_100("MediaRouter.Ui.Device.Count", sink_count); |
| 396 } | 402 } |
| 397 | 403 |
| 404 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( | |
| 405 const base::ListValue* args) { | |
| 406 DVLOG(1) << "OnInitialDataReceived"; | |
| 407 media_router_ui_->OnUIInitialDataReceived(); | |
| 408 } | |
| 409 | |
| 398 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 410 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 399 const IssueAction::Type& action_type, | 411 const IssueAction::Type& action_type, |
| 400 const base::DictionaryValue* args) { | 412 const base::DictionaryValue* args) { |
| 401 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 413 if (action_type == IssueAction::TYPE_LEARN_MORE) { |
| 402 std::string learn_more_url = GetLearnMoreUrl(args); | 414 std::string learn_more_url = GetLearnMoreUrl(args); |
| 403 if (learn_more_url.empty()) | 415 if (learn_more_url.empty()) |
| 404 return false; | 416 return false; |
| 405 scoped_ptr<base::ListValue> open_args(new base::ListValue); | 417 scoped_ptr<base::ListValue> open_args(new base::ListValue); |
| 406 open_args->AppendString(learn_more_url); | 418 open_args->AppendString(learn_more_url); |
| 407 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 419 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 408 return true; | 420 return true; |
| 409 } else { | 421 } else { |
| 410 // Do nothing; no other issue action types require any other action. | 422 // Do nothing; no other issue action types require any other action. |
| 411 return true; | 423 return true; |
| 412 } | 424 } |
| 413 } | 425 } |
| 414 | 426 |
| 415 } // namespace media_router | 427 } // namespace media_router |
| OLD | NEW |