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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/media/router/issue.h" | 12 #include "chrome/browser/media/router/issue.h" |
| 12 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 13 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 | 17 |
| 17 namespace media_router { | 18 namespace media_router { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const char kHelpPageUrlPrefix[] = | 22 const char kHelpPageUrlPrefix[] = |
| 22 "https://support.google.com/chromecast/answer/%d"; | 23 "https://support.google.com/chromecast/answer/%d"; |
| 23 | 24 |
| 24 // Message names. | 25 // Message names. |
| 25 const char kRequestInitialData[] = "requestInitialData"; | 26 const char kRequestInitialData[] = "requestInitialData"; |
| 26 const char kCreateRoute[] = "requestRoute"; | 27 const char kCreateRoute[] = "requestRoute"; |
| 27 const char kActOnIssue[] = "actOnIssue"; | 28 const char kActOnIssue[] = "actOnIssue"; |
| 28 const char kCloseRoute[] = "closeRoute"; | 29 const char kCloseRoute[] = "closeRoute"; |
| 29 const char kCloseDialog[] = "closeDialog"; | 30 const char kCloseDialog[] = "closeDialog"; |
| 31 const char kReportSinkCount[] = "reportSinkCount"; | |
| 30 | 32 |
| 31 // JS function names. | 33 // JS function names. |
| 32 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 34 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 33 const char kNotifyRouteCreationTimeout[] = | 35 const char kNotifyRouteCreationTimeout[] = |
| 34 "media_router.ui.onNotifyRouteCreationTimeout"; | 36 "media_router.ui.onNotifyRouteCreationTimeout"; |
| 35 const char kOnCreateRouteResponseReceived[] = | 37 const char kOnCreateRouteResponseReceived[] = |
| 36 "media_router.ui.onCreateRouteResponseReceived"; | 38 "media_router.ui.onCreateRouteResponseReceived"; |
| 37 const char kSetIssue[] = "media_router.ui.setIssue"; | 39 const char kSetIssue[] = "media_router.ui.setIssue"; |
| 38 const char kSetSinkList[] = "media_router.ui.setSinkList"; | 40 const char kSetSinkList[] = "media_router.ui.setSinkList"; |
| 39 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 41 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 if (route) { | 202 if (route) { |
| 201 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, | 203 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, |
| 202 media_router_ui_->GetRouteProviderExtensionId())); | 204 media_router_ui_->GetRouteProviderExtensionId())); |
| 203 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 205 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 204 base::StringValue(sink_id), *route_value); | 206 base::StringValue(sink_id), *route_value); |
| 205 } else { | 207 } else { |
| 206 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 208 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 207 base::StringValue(sink_id), | 209 base::StringValue(sink_id), |
| 208 *base::Value::CreateNullValue()); | 210 *base::Value::CreateNullValue()); |
| 209 } | 211 } |
| 212 | |
| 213 UMA_HISTOGRAM_BOOLEAN( | |
| 214 "MediaRouter.Ui.Action.StartLocalSessionSuccessful", route); | |
| 210 } | 215 } |
| 211 | 216 |
| 212 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 217 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 213 DVLOG(2) << "UpdateIssue"; | 218 DVLOG(2) << "UpdateIssue"; |
| 214 if (issue) { | 219 if (issue) { |
| 215 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); | 220 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); |
| 216 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); | 221 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); |
| 217 } else { | 222 } else { |
| 218 // Clears the issue in the WebUI. | 223 // Clears the issue in the WebUI. |
| 219 web_ui()->CallJavascriptFunction(kSetIssue); | 224 web_ui()->CallJavascriptFunction(kSetIssue); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 239 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, | 244 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, |
| 240 base::Unretained(this))); | 245 base::Unretained(this))); |
| 241 web_ui()->RegisterMessageCallback( | 246 web_ui()->RegisterMessageCallback( |
| 242 kCloseRoute, | 247 kCloseRoute, |
| 243 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, | 248 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, |
| 244 base::Unretained(this))); | 249 base::Unretained(this))); |
| 245 web_ui()->RegisterMessageCallback( | 250 web_ui()->RegisterMessageCallback( |
| 246 kCloseDialog, | 251 kCloseDialog, |
| 247 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 252 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 248 base::Unretained(this))); | 253 base::Unretained(this))); |
| 254 web_ui()->RegisterMessageCallback( | |
| 255 kReportSinkCount, | |
| 256 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, | |
| 257 base::Unretained(this))); | |
| 249 } | 258 } |
| 250 | 259 |
| 251 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 260 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 252 const base::ListValue* args) { | 261 const base::ListValue* args) { |
| 253 DVLOG(1) << "OnRequestInitialData"; | 262 DVLOG(1) << "OnRequestInitialData"; |
| 254 base::DictionaryValue initial_data; | 263 base::DictionaryValue initial_data; |
| 255 | 264 |
| 256 // "No Cast devices found?" Chromecast help center page. | 265 // "No Cast devices found?" Chromecast help center page. |
| 257 initial_data.SetString("deviceMissingUrl", | 266 initial_data.SetString("deviceMissingUrl", |
| 258 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 267 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 void MediaRouterWebUIMessageHandler::OnCloseDialog( | 375 void MediaRouterWebUIMessageHandler::OnCloseDialog( |
| 367 const base::ListValue* args) { | 376 const base::ListValue* args) { |
| 368 DVLOG(1) << "OnCloseDialog"; | 377 DVLOG(1) << "OnCloseDialog"; |
| 369 if (dialog_closing_) | 378 if (dialog_closing_) |
| 370 return; | 379 return; |
| 371 | 380 |
| 372 dialog_closing_ = true; | 381 dialog_closing_ = true; |
| 373 media_router_ui_->Close(); | 382 media_router_ui_->Close(); |
| 374 } | 383 } |
| 375 | 384 |
| 385 void MediaRouterWebUIMessageHandler::OnReportSinkCount( | |
| 386 const base::ListValue* args) { | |
| 387 DVLOG(1) << "OnReportSinkCount"; | |
|
Peter Kasting
2015/10/23 23:48:51
Do you need these? We try hard to avoid logging a
apacible
2015/10/24 22:06:28
+imcheng: Do you remember our plans with the per-f
imcheng
2015/10/26 17:18:14
It helps with our debugging. Since it is only a DV
| |
| 388 const base::DictionaryValue* args_dict = nullptr; | |
| 389 int sink_count = -1; | |
|
Peter Kasting
2015/10/23 23:48:51
Do you get a warning if you omit the initializers
apacible
2015/10/24 22:06:28
Done.
| |
| 390 if (!args->GetDictionary(0, &args_dict) || | |
| 391 !args_dict->GetInteger("sinkCount", &sink_count)) { | |
| 392 DVLOG(1) << "Unable to extract args."; | |
| 393 return; | |
| 394 } | |
| 395 UMA_HISTOGRAM_COUNTS_100("MediaRouter.Ui.Device.Count", sink_count); | |
| 396 } | |
| 397 | |
| 376 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 398 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 377 const IssueAction::Type& action_type, | 399 const IssueAction::Type& action_type, |
| 378 const base::DictionaryValue* args) { | 400 const base::DictionaryValue* args) { |
| 379 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 401 if (action_type == IssueAction::TYPE_LEARN_MORE) { |
| 380 std::string learn_more_url = GetLearnMoreUrl(args); | 402 std::string learn_more_url = GetLearnMoreUrl(args); |
| 381 if (learn_more_url.empty()) | 403 if (learn_more_url.empty()) |
| 382 return false; | 404 return false; |
| 383 scoped_ptr<base::ListValue> open_args(new base::ListValue); | 405 scoped_ptr<base::ListValue> open_args(new base::ListValue); |
| 384 open_args->AppendString(learn_more_url); | 406 open_args->AppendString(learn_more_url); |
| 385 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 407 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 386 return true; | 408 return true; |
| 387 } else { | 409 } else { |
| 388 // Do nothing; no other issue action types require any other action. | 410 // Do nothing; no other issue action types require any other action. |
| 389 return true; | 411 return true; |
| 390 } | 412 } |
| 391 } | 413 } |
| 392 | 414 |
| 393 } // namespace media_router | 415 } // namespace media_router |
| OLD | NEW |