| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 197 |
| 196 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( | 198 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 197 const MediaSink::Id& sink_id, | 199 const MediaSink::Id& sink_id, |
| 198 const MediaRoute* route) { | 200 const MediaRoute* route) { |
| 199 DVLOG(2) << "OnCreateRouteResponseReceived"; | 201 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 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); |
| 207 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", |
| 208 true); |
| 205 } else { | 209 } else { |
| 206 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 210 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 207 base::StringValue(sink_id), | 211 base::StringValue(sink_id), |
| 208 *base::Value::CreateNullValue()); | 212 *base::Value::CreateNullValue()); |
| 213 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", |
| 214 false); |
| 209 } | 215 } |
| 210 } | 216 } |
| 211 | 217 |
| 212 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 218 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 213 DVLOG(2) << "UpdateIssue"; | 219 DVLOG(2) << "UpdateIssue"; |
| 214 if (issue) { | 220 if (issue) { |
| 215 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); | 221 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); |
| 216 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); | 222 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); |
| 217 } else { | 223 } else { |
| 218 // Clears the issue in the WebUI. | 224 // Clears the issue in the WebUI. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 239 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, | 245 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, |
| 240 base::Unretained(this))); | 246 base::Unretained(this))); |
| 241 web_ui()->RegisterMessageCallback( | 247 web_ui()->RegisterMessageCallback( |
| 242 kCloseRoute, | 248 kCloseRoute, |
| 243 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, | 249 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, |
| 244 base::Unretained(this))); | 250 base::Unretained(this))); |
| 245 web_ui()->RegisterMessageCallback( | 251 web_ui()->RegisterMessageCallback( |
| 246 kCloseDialog, | 252 kCloseDialog, |
| 247 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 253 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 248 base::Unretained(this))); | 254 base::Unretained(this))); |
| 255 web_ui()->RegisterMessageCallback( |
| 256 kReportSinkCount, |
| 257 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, |
| 258 base::Unretained(this))); |
| 249 } | 259 } |
| 250 | 260 |
| 251 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 261 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 252 const base::ListValue* args) { | 262 const base::ListValue* args) { |
| 253 DVLOG(1) << "OnRequestInitialData"; | 263 DVLOG(1) << "OnRequestInitialData"; |
| 254 base::DictionaryValue initial_data; | 264 base::DictionaryValue initial_data; |
| 255 | 265 |
| 256 // "No Cast devices found?" Chromecast help center page. | 266 // "No Cast devices found?" Chromecast help center page. |
| 257 initial_data.SetString("deviceMissingUrl", | 267 initial_data.SetString("deviceMissingUrl", |
| 258 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 268 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 void MediaRouterWebUIMessageHandler::OnCloseDialog( | 376 void MediaRouterWebUIMessageHandler::OnCloseDialog( |
| 367 const base::ListValue* args) { | 377 const base::ListValue* args) { |
| 368 DVLOG(1) << "OnCloseDialog"; | 378 DVLOG(1) << "OnCloseDialog"; |
| 369 if (dialog_closing_) | 379 if (dialog_closing_) |
| 370 return; | 380 return; |
| 371 | 381 |
| 372 dialog_closing_ = true; | 382 dialog_closing_ = true; |
| 373 media_router_ui_->Close(); | 383 media_router_ui_->Close(); |
| 374 } | 384 } |
| 375 | 385 |
| 386 void MediaRouterWebUIMessageHandler::OnReportSinkCount( |
| 387 const base::ListValue* args) { |
| 388 DVLOG(1) << "OnReportSinkCount"; |
| 389 int sink_count; |
| 390 if (!args->GetInteger(0, &sink_count)) { |
| 391 DVLOG(1) << "Unable to extract args."; |
| 392 return; |
| 393 } |
| 394 UMA_HISTOGRAM_COUNTS_100("MediaRouter.Ui.Device.Count", sink_count); |
| 395 } |
| 396 |
| 376 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 397 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 377 const IssueAction::Type& action_type, | 398 const IssueAction::Type& action_type, |
| 378 const base::DictionaryValue* args) { | 399 const base::DictionaryValue* args) { |
| 379 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 400 if (action_type == IssueAction::TYPE_LEARN_MORE) { |
| 380 std::string learn_more_url = GetLearnMoreUrl(args); | 401 std::string learn_more_url = GetLearnMoreUrl(args); |
| 381 if (learn_more_url.empty()) | 402 if (learn_more_url.empty()) |
| 382 return false; | 403 return false; |
| 383 scoped_ptr<base::ListValue> open_args(new base::ListValue); | 404 scoped_ptr<base::ListValue> open_args(new base::ListValue); |
| 384 open_args->AppendString(learn_more_url); | 405 open_args->AppendString(learn_more_url); |
| 385 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 406 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 386 return true; | 407 return true; |
| 387 } else { | 408 } else { |
| 388 // Do nothing; no other issue action types require any other action. | 409 // Do nothing; no other issue action types require any other action. |
| 389 return true; | 410 return true; |
| 390 } | 411 } |
| 391 } | 412 } |
| 392 | 413 |
| 393 } // namespace media_router | 414 } // namespace media_router |
| OLD | NEW |