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" |
| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } | 173 } |
| 173 | 174 |
| 174 void MediaRouterWebUIMessageHandler::UpdateSinks( | 175 void MediaRouterWebUIMessageHandler::UpdateSinks( |
| 175 const std::vector<MediaSinkWithCastModes>& sinks) { | 176 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 176 DVLOG(2) << "UpdateSinks"; | 177 DVLOG(2) << "UpdateSinks"; |
| 177 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); | 178 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); |
| 178 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); | 179 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 182 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 182 const std::vector<MediaRoute>& routes) { | 183 const std::vector<MediaRoute>& routes, |
| 183 DVLOG(2) << "UpdateRoutes"; | 184 const std::vector<MediaRoute>& joinable_routes) { |
| 184 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, | 185 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, |
| 185 media_router_ui_->GetRouteProviderExtensionId())); | 186 media_router_ui_->GetRouteProviderExtensionId())); |
| 186 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 187 scoped_ptr<base::ListValue> joinable_routes_val( |
| 188 RoutesToValue(joinable_routes, | |
| 189 media_router_ui_->GetRouteProviderExtensionId())); | |
| 190 web_ui()->CallJavascriptFunction( | |
| 191 kSetRouteList, *routes_val, *joinable_routes_val); | |
| 187 } | 192 } |
| 188 | 193 |
| 189 void MediaRouterWebUIMessageHandler::UpdateCastModes( | 194 void MediaRouterWebUIMessageHandler::UpdateCastModes( |
| 190 const CastModeSet& cast_modes, | 195 const CastModeSet& cast_modes, |
| 191 const std::string& source_host) { | 196 const std::string& source_host) { |
| 192 DVLOG(2) << "UpdateCastModes"; | 197 DVLOG(2) << "UpdateCastModes"; |
| 193 scoped_ptr<base::ListValue> cast_modes_val( | 198 scoped_ptr<base::ListValue> cast_modes_val( |
| 194 CastModesToValue(cast_modes, source_host)); | 199 CastModesToValue(cast_modes, source_host)); |
| 195 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); | 200 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); |
| 196 } | 201 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 base::Unretained(this))); | 247 base::Unretained(this))); |
| 243 web_ui()->RegisterMessageCallback( | 248 web_ui()->RegisterMessageCallback( |
| 244 kActOnIssue, | 249 kActOnIssue, |
| 245 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, | 250 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, |
| 246 base::Unretained(this))); | 251 base::Unretained(this))); |
| 247 web_ui()->RegisterMessageCallback( | 252 web_ui()->RegisterMessageCallback( |
| 248 kCloseRoute, | 253 kCloseRoute, |
| 249 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, | 254 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, |
| 250 base::Unretained(this))); | 255 base::Unretained(this))); |
| 251 web_ui()->RegisterMessageCallback( | 256 web_ui()->RegisterMessageCallback( |
| 257 kJoinRoute, | |
| 258 base::Bind(&MediaRouterWebUIMessageHandler::OnJoinRoute, | |
| 259 base::Unretained(this))); | |
| 260 web_ui()->RegisterMessageCallback( | |
| 252 kCloseDialog, | 261 kCloseDialog, |
| 253 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 262 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 254 base::Unretained(this))); | 263 base::Unretained(this))); |
| 255 web_ui()->RegisterMessageCallback( | 264 web_ui()->RegisterMessageCallback( |
| 256 kReportSinkCount, | 265 kReportSinkCount, |
| 257 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, | 266 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, |
| 258 base::Unretained(this))); | 267 base::Unretained(this))); |
| 259 } | 268 } |
| 260 | 269 |
| 261 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 270 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 262 const base::ListValue* args) { | 271 const base::ListValue* args) { |
| 263 DVLOG(1) << "OnRequestInitialData"; | 272 DVLOG(1) << "OnRequestInitialData"; |
| 264 base::DictionaryValue initial_data; | 273 base::DictionaryValue initial_data; |
| 265 | 274 |
| 266 // "No Cast devices found?" Chromecast help center page. | 275 // "No Cast devices found?" Chromecast help center page. |
| 267 initial_data.SetString("deviceMissingUrl", | 276 initial_data.SetString("deviceMissingUrl", |
| 268 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 277 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 269 | 278 |
| 270 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); | 279 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); |
| 271 initial_data.Set("sinks", sinks.release()); | 280 initial_data.Set("sinks", sinks.release()); |
| 272 | 281 |
| 273 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), | 282 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), |
| 274 media_router_ui_->GetRouteProviderExtensionId())); | 283 media_router_ui_->GetRouteProviderExtensionId())); |
| 275 initial_data.Set("routes", routes.release()); | 284 initial_data.Set("routes", routes.release()); |
| 276 | 285 |
| 286 | |
| 287 scoped_ptr<base::ListValue> joinable_routes( | |
| 288 RoutesToValue(media_router_ui_->joinable_routes(), | |
| 289 media_router_ui_->GetRouteProviderExtensionId())); | |
| 290 initial_data.Set("joinableRoutes", joinable_routes.release()); | |
| 291 | |
| 277 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 292 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 278 scoped_ptr<base::ListValue> cast_modes_list( | 293 scoped_ptr<base::ListValue> cast_modes_list( |
| 279 CastModesToValue(cast_modes, media_router_ui_->GetFrameURLHost())); | 294 CastModesToValue(cast_modes, media_router_ui_->GetFrameURLHost())); |
| 280 initial_data.Set("castModes", cast_modes_list.release()); | 295 initial_data.Set("castModes", cast_modes_list.release()); |
| 281 if (!cast_modes.empty()) { | 296 if (!cast_modes.empty()) { |
| 282 initial_data.SetInteger("initialCastModeType", | 297 initial_data.SetInteger("initialCastModeType", |
| 283 GetPreferredCastMode(cast_modes)); | 298 GetPreferredCastMode(cast_modes)); |
| 284 } | 299 } |
| 285 | 300 |
| 286 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); | 301 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 DVLOG(1) << "Invalid action type: " << action_type_num; | 368 DVLOG(1) << "Invalid action type: " << action_type_num; |
| 354 return; | 369 return; |
| 355 } | 370 } |
| 356 IssueAction::Type action_type = | 371 IssueAction::Type action_type = |
| 357 static_cast<IssueAction::Type>(action_type_num); | 372 static_cast<IssueAction::Type>(action_type_num); |
| 358 if (ActOnIssueType(action_type, args_dict)) | 373 if (ActOnIssueType(action_type, args_dict)) |
| 359 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; | 374 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; |
| 360 media_router_ui_->ClearIssue(issue_id); | 375 media_router_ui_->ClearIssue(issue_id); |
| 361 } | 376 } |
| 362 | 377 |
| 363 void MediaRouterWebUIMessageHandler::OnCloseRoute( | 378 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { |
| 364 const base::ListValue* args) { | 379 DVLOG(1) << "OnJoinRoute"; |
| 380 const base::DictionaryValue* args_dict = nullptr; | |
| 381 std::string route_id; | |
| 382 std::string sink_id; | |
| 383 if (!args->GetDictionary(0, &args_dict) || | |
| 384 !args_dict->GetString("sinkId", &sink_id) || | |
| 385 !args_dict->GetString("routeId", &route_id)) { | |
| 386 DVLOG(1) << "Unable to extract args."; | |
| 387 return; | |
| 388 } | |
| 389 media_router_ui_->JoinRoute(sink_id, route_id); | |
|
imcheng
2015/11/19 18:55:08
Do we need to check HasPendingRouteRequest() simil
matt.boetger
2015/11/24 19:45:24
Done.
| |
| 390 } | |
| 391 | |
| 392 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { | |
| 365 DVLOG(1) << "OnCloseRoute"; | 393 DVLOG(1) << "OnCloseRoute"; |
| 366 const base::DictionaryValue* args_dict = nullptr; | 394 const base::DictionaryValue* args_dict = nullptr; |
| 367 std::string route_id; | 395 std::string route_id; |
| 368 if (!args->GetDictionary(0, &args_dict) || | 396 if (!args->GetDictionary(0, &args_dict) || |
| 369 !args_dict->GetString("routeId", &route_id)) { | 397 !args_dict->GetString("routeId", &route_id)) { |
| 370 DVLOG(1) << "Unable to extract args."; | 398 DVLOG(1) << "Unable to extract args."; |
| 371 return; | 399 return; |
| 372 } | 400 } |
| 373 media_router_ui_->CloseRoute(route_id); | 401 media_router_ui_->CloseRoute(route_id); |
| 374 } | 402 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 405 open_args->AppendString(learn_more_url); | 433 open_args->AppendString(learn_more_url); |
| 406 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 434 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 407 return true; | 435 return true; |
| 408 } else { | 436 } else { |
| 409 // Do nothing; no other issue action types require any other action. | 437 // Do nothing; no other issue action types require any other action. |
| 410 return true; | 438 return true; |
| 411 } | 439 } |
| 412 } | 440 } |
| 413 | 441 |
| 414 } // namespace media_router | 442 } // namespace media_router |
| OLD | NEW |