Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc

Issue 1415103006: Non-Local Join for Media Router and Presentation API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing ChromeOS System Tray Test Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
22 namespace { 22 namespace {
23 23
24 const char kHelpPageUrlPrefix[] = 24 const char kHelpPageUrlPrefix[] =
25 "https://support.google.com/chromecast/answer/%d"; 25 "https://support.google.com/chromecast/answer/%d";
26 26
27 // Message names. 27 // Message names.
28 const char kRequestInitialData[] = "requestInitialData"; 28 const char kRequestInitialData[] = "requestInitialData";
29 const char kCreateRoute[] = "requestRoute"; 29 const char kCreateRoute[] = "requestRoute";
30 const char kActOnIssue[] = "actOnIssue"; 30 const char kActOnIssue[] = "actOnIssue";
31 const char kCloseRoute[] = "closeRoute"; 31 const char kCloseRoute[] = "closeRoute";
32 const char kJoinRoute[] = "joinRoute";
32 const char kCloseDialog[] = "closeDialog"; 33 const char kCloseDialog[] = "closeDialog";
33 const char kReportClickedSinkIndex[] = "reportClickedSinkIndex"; 34 const char kReportClickedSinkIndex[] = "reportClickedSinkIndex";
34 const char kReportNavigateToView[] = "reportNavigateToView"; 35 const char kReportNavigateToView[] = "reportNavigateToView";
35 const char kReportSelectedCastMode[] = "reportSelectedCastMode"; 36 const char kReportSelectedCastMode[] = "reportSelectedCastMode";
36 const char kReportSinkCount[] = "reportSinkCount"; 37 const char kReportSinkCount[] = "reportSinkCount";
37 const char kOnInitialDataReceived[] = "onInitialDataReceived"; 38 const char kOnInitialDataReceived[] = "onInitialDataReceived";
38 39
39 // JS function names. 40 // JS function names.
40 const char kSetInitialData[] = "media_router.ui.setInitialData"; 41 const char kSetInitialData[] = "media_router.ui.setInitialData";
41 const char kNotifyRouteCreationTimeout[] = 42 const char kNotifyRouteCreationTimeout[] =
(...skipping 25 matching lines...) Expand all
67 cast_mode_bits |= cast_mode; 68 cast_mode_bits |= cast_mode;
68 69
69 sink_val->SetInteger("castModes", cast_mode_bits); 70 sink_val->SetInteger("castModes", cast_mode_bits);
70 value->Append(sink_val.release()); 71 value->Append(sink_val.release());
71 } 72 }
72 73
73 return value; 74 return value;
74 } 75 }
75 76
76 scoped_ptr<base::DictionaryValue> RouteToValue( 77 scoped_ptr<base::DictionaryValue> RouteToValue(
77 const MediaRoute& route, const std::string& extension_id) { 78 const MediaRoute& route, bool canJoin, const std::string& extension_id) {
78 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 79 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
79 dictionary->SetString("id", route.media_route_id()); 80 dictionary->SetString("id", route.media_route_id());
80 dictionary->SetString("sinkId", route.media_sink_id()); 81 dictionary->SetString("sinkId", route.media_sink_id());
81 dictionary->SetString("description", route.description()); 82 dictionary->SetString("description", route.description());
82 dictionary->SetBoolean("isLocal", route.is_local()); 83 dictionary->SetBoolean("isLocal", route.is_local());
84 dictionary->SetBoolean("canJoin", canJoin);
83 85
84 const std::string& custom_path = route.custom_controller_path(); 86 const std::string& custom_path = route.custom_controller_path();
85 if (!custom_path.empty()) { 87 if (!custom_path.empty()) {
86 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s", 88 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s",
87 extensions::kExtensionScheme, extension_id.c_str(), 89 extensions::kExtensionScheme, extension_id.c_str(),
88 custom_path.c_str()); 90 custom_path.c_str());
89 DCHECK(GURL(full_custom_controller_path).is_valid()); 91 DCHECK(GURL(full_custom_controller_path).is_valid());
90 dictionary->SetString("customControllerPath", 92 dictionary->SetString("customControllerPath",
91 full_custom_controller_path); 93 full_custom_controller_path);
92 } 94 }
93 95
94 return dictionary; 96 return dictionary;
95 } 97 }
96 98
97 scoped_ptr<base::ListValue> RoutesToValue( 99 scoped_ptr<base::ListValue> RoutesToValue(
98 const std::vector<MediaRoute>& routes, const std::string& extension_id) { 100 const std::vector<MediaRoute>& routes,
101 const std::vector<MediaRoute::Id>& joinable_route_ids,
102 const std::string& extension_id) {
99 scoped_ptr<base::ListValue> value(new base::ListValue); 103 scoped_ptr<base::ListValue> value(new base::ListValue);
100 104
101 for (const MediaRoute& route : routes) { 105 for (const MediaRoute& route : routes) {
106 bool canJoin = ContainsValue(joinable_route_ids, route.media_route_id());
102 scoped_ptr<base::DictionaryValue> route_val(RouteToValue(route, 107 scoped_ptr<base::DictionaryValue> route_val(RouteToValue(route,
103 extension_id)); 108 canJoin, extension_id));
104 value->Append(route_val.release()); 109 value->Append(route_val.release());
105 } 110 }
106 111
107 return value; 112 return value;
108 } 113 }
109 114
110 scoped_ptr<base::ListValue> CastModesToValue(const CastModeSet& cast_modes, 115 scoped_ptr<base::ListValue> CastModesToValue(const CastModeSet& cast_modes,
111 const std::string& source_host) { 116 const std::string& source_host) {
112 scoped_ptr<base::ListValue> value(new base::ListValue); 117 scoped_ptr<base::ListValue> value(new base::ListValue);
113 118
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 183 }
179 184
180 void MediaRouterWebUIMessageHandler::UpdateSinks( 185 void MediaRouterWebUIMessageHandler::UpdateSinks(
181 const std::vector<MediaSinkWithCastModes>& sinks) { 186 const std::vector<MediaSinkWithCastModes>& sinks) {
182 DVLOG(2) << "UpdateSinks"; 187 DVLOG(2) << "UpdateSinks";
183 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); 188 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks));
184 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); 189 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val);
185 } 190 }
186 191
187 void MediaRouterWebUIMessageHandler::UpdateRoutes( 192 void MediaRouterWebUIMessageHandler::UpdateRoutes(
188 const std::vector<MediaRoute>& routes) { 193 const std::vector<MediaRoute>& routes,
189 DVLOG(2) << "UpdateRoutes"; 194 const std::vector<MediaRoute::Id>& joinable_route_ids) {
190 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, 195 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes,
196 joinable_route_ids,
191 media_router_ui_->GetRouteProviderExtensionId())); 197 media_router_ui_->GetRouteProviderExtensionId()));
192 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); 198 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val);
193 } 199 }
194 200
195 void MediaRouterWebUIMessageHandler::UpdateCastModes( 201 void MediaRouterWebUIMessageHandler::UpdateCastModes(
196 const CastModeSet& cast_modes, 202 const CastModeSet& cast_modes,
197 const std::string& source_host) { 203 const std::string& source_host) {
198 DVLOG(2) << "UpdateCastModes"; 204 DVLOG(2) << "UpdateCastModes";
199 scoped_ptr<base::ListValue> cast_modes_val( 205 scoped_ptr<base::ListValue> cast_modes_val(
200 CastModesToValue(cast_modes, source_host)); 206 CastModesToValue(cast_modes, source_host));
201 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); 207 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val);
202 } 208 }
203 209
204 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( 210 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived(
205 const MediaSink::Id& sink_id, 211 const MediaSink::Id& sink_id,
206 const MediaRoute* route) { 212 const MediaRoute* route) {
207 DVLOG(2) << "OnCreateRouteResponseReceived"; 213 DVLOG(2) << "OnCreateRouteResponseReceived";
208 if (route) { 214 if (route) {
209 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, 215 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, false,
210 media_router_ui_->GetRouteProviderExtensionId())); 216 media_router_ui_->GetRouteProviderExtensionId()));
211 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, 217 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived,
212 base::StringValue(sink_id), *route_value); 218 base::StringValue(sink_id), *route_value);
213 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", 219 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful",
214 true); 220 true);
215 } else { 221 } else {
216 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, 222 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived,
217 base::StringValue(sink_id), 223 base::StringValue(sink_id),
218 *base::Value::CreateNullValue()); 224 *base::Value::CreateNullValue());
219 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", 225 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful",
(...skipping 23 matching lines...) Expand all
243 base::Unretained(this))); 249 base::Unretained(this)));
244 web_ui()->RegisterMessageCallback( 250 web_ui()->RegisterMessageCallback(
245 kActOnIssue, 251 kActOnIssue,
246 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, 252 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue,
247 base::Unretained(this))); 253 base::Unretained(this)));
248 web_ui()->RegisterMessageCallback( 254 web_ui()->RegisterMessageCallback(
249 kCloseRoute, 255 kCloseRoute,
250 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, 256 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute,
251 base::Unretained(this))); 257 base::Unretained(this)));
252 web_ui()->RegisterMessageCallback( 258 web_ui()->RegisterMessageCallback(
259 kJoinRoute,
260 base::Bind(&MediaRouterWebUIMessageHandler::OnJoinRoute,
261 base::Unretained(this)));
262 web_ui()->RegisterMessageCallback(
253 kCloseDialog, 263 kCloseDialog,
254 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, 264 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog,
255 base::Unretained(this))); 265 base::Unretained(this)));
256 web_ui()->RegisterMessageCallback( 266 web_ui()->RegisterMessageCallback(
257 kReportClickedSinkIndex, 267 kReportClickedSinkIndex,
258 base::Bind(&MediaRouterWebUIMessageHandler::OnReportClickedSinkIndex, 268 base::Bind(&MediaRouterWebUIMessageHandler::OnReportClickedSinkIndex,
259 base::Unretained(this))); 269 base::Unretained(this)));
260 web_ui()->RegisterMessageCallback( 270 web_ui()->RegisterMessageCallback(
261 kReportSelectedCastMode, 271 kReportSelectedCastMode,
262 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSelectedCastMode, 272 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSelectedCastMode,
(...skipping 19 matching lines...) Expand all
282 base::DictionaryValue initial_data; 292 base::DictionaryValue initial_data;
283 293
284 // "No Cast devices found?" Chromecast help center page. 294 // "No Cast devices found?" Chromecast help center page.
285 initial_data.SetString("deviceMissingUrl", 295 initial_data.SetString("deviceMissingUrl",
286 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); 296 base::StringPrintf(kHelpPageUrlPrefix, 3249268));
287 297
288 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); 298 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks()));
289 initial_data.Set("sinks", sinks.release()); 299 initial_data.Set("sinks", sinks.release());
290 300
291 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), 301 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(),
302 media_router_ui_->joinable_route_ids(),
292 media_router_ui_->GetRouteProviderExtensionId())); 303 media_router_ui_->GetRouteProviderExtensionId()));
293 initial_data.Set("routes", routes.release()); 304 initial_data.Set("routes", routes.release());
294 305
295 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); 306 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes();
296 scoped_ptr<base::ListValue> cast_modes_list( 307 scoped_ptr<base::ListValue> cast_modes_list(
297 CastModesToValue(cast_modes, 308 CastModesToValue(cast_modes,
298 media_router_ui_->GetPresentationRequestSourceName())); 309 media_router_ui_->GetPresentationRequestSourceName()));
299 initial_data.Set("castModes", cast_modes_list.release()); 310 initial_data.Set("castModes", cast_modes_list.release());
300 311
301 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); 312 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 DVLOG(1) << "Invalid action type: " << action_type_num; 380 DVLOG(1) << "Invalid action type: " << action_type_num;
370 return; 381 return;
371 } 382 }
372 IssueAction::Type action_type = 383 IssueAction::Type action_type =
373 static_cast<IssueAction::Type>(action_type_num); 384 static_cast<IssueAction::Type>(action_type_num);
374 if (ActOnIssueType(action_type, args_dict)) 385 if (ActOnIssueType(action_type, args_dict))
375 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; 386 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id;
376 media_router_ui_->ClearIssue(issue_id); 387 media_router_ui_->ClearIssue(issue_id);
377 } 388 }
378 389
379 void MediaRouterWebUIMessageHandler::OnCloseRoute( 390 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) {
380 const base::ListValue* args) { 391 DVLOG(1) << "OnJoinRoute";
392 const base::DictionaryValue* args_dict = nullptr;
393 std::string route_id;
394 std::string sink_id;
395 if (!args->GetDictionary(0, &args_dict) ||
396 !args_dict->GetString("sinkId", &sink_id) ||
397 !args_dict->GetString("routeId", &route_id)) {
398 DVLOG(1) << "Unable to extract args.";
399 return;
400 }
401
402 if (sink_id.empty()) {
403 DVLOG(1) << "Media Route UI did not respond with a "
404 << "valid sink ID. Aborting.";
405 return;
406 }
407
408 if (route_id.empty()) {
409 DVLOG(1) << "Media Route UI did not respond with a "
410 << "valid route ID. Aborting.";
411 return;
412 }
413
414 MediaRouterUI* media_router_ui =
415 static_cast<MediaRouterUI*>(web_ui()->GetController());
416 if (media_router_ui->HasPendingRouteRequest()) {
417 DVLOG(1) << "UI already has pending route request. Ignoring.";
418 Issue issue(
419 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
420 std::string(), IssueAction(IssueAction::TYPE_DISMISS),
421 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
422 false, std::string());
423 media_router_ui_->AddIssue(issue);
424 return;
425 }
426
427 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) {
428 // TODO(boetger): Need to add an issue if failed to initiate a JoinRoute
429 // request.
430 DVLOG(1) << "Error initiating route join request.";
431 }
432 }
433
434 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) {
381 DVLOG(1) << "OnCloseRoute"; 435 DVLOG(1) << "OnCloseRoute";
382 const base::DictionaryValue* args_dict = nullptr; 436 const base::DictionaryValue* args_dict = nullptr;
383 std::string route_id; 437 std::string route_id;
384 bool is_local = false; 438 bool is_local = false;
385 if (!args->GetDictionary(0, &args_dict) || 439 if (!args->GetDictionary(0, &args_dict) ||
386 !args_dict->GetString("routeId", &route_id) || 440 !args_dict->GetString("routeId", &route_id) ||
387 !args_dict->GetBoolean("isLocal", &is_local)) { 441 !args_dict->GetBoolean("isLocal", &is_local)) {
388 DVLOG(1) << "Unable to extract args."; 442 DVLOG(1) << "Unable to extract args.";
389 return; 443 return;
390 } 444 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 open_args->AppendString(learn_more_url); 529 open_args->AppendString(learn_more_url);
476 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); 530 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args);
477 return true; 531 return true;
478 } else { 532 } else {
479 // Do nothing; no other issue action types require any other action. 533 // Do nothing; no other issue action types require any other action.
480 return true; 534 return true;
481 } 535 }
482 } 536 }
483 537
484 } // namespace media_router 538 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698