| 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"; |
| 31 const char kCanJoinRoute[] = "canJoin"; |
| 30 const char kCloseDialog[] = "closeDialog"; | 32 const char kCloseDialog[] = "closeDialog"; |
| 31 const char kReportSinkCount[] = "reportSinkCount"; | 33 const char kReportSinkCount[] = "reportSinkCount"; |
| 32 | 34 |
| 33 // JS function names. | 35 // JS function names. |
| 34 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 36 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 35 const char kNotifyRouteCreationTimeout[] = | 37 const char kNotifyRouteCreationTimeout[] = |
| 36 "media_router.ui.onNotifyRouteCreationTimeout"; | 38 "media_router.ui.onNotifyRouteCreationTimeout"; |
| 37 const char kOnCreateRouteResponseReceived[] = | 39 const char kOnCreateRouteResponseReceived[] = |
| 38 "media_router.ui.onCreateRouteResponseReceived"; | 40 "media_router.ui.onCreateRouteResponseReceived"; |
| 39 const char kSetIssue[] = "media_router.ui.setIssue"; | 41 const char kSetIssue[] = "media_router.ui.setIssue"; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 59 cast_modes_val->AppendInteger(cast_mode); | 61 cast_modes_val->AppendInteger(cast_mode); |
| 60 sink_val->Set("castModes", cast_modes_val.Pass()); | 62 sink_val->Set("castModes", cast_modes_val.Pass()); |
| 61 | 63 |
| 62 value->Append(sink_val.release()); | 64 value->Append(sink_val.release()); |
| 63 } | 65 } |
| 64 | 66 |
| 65 return value.Pass(); | 67 return value.Pass(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 scoped_ptr<base::DictionaryValue> RouteToValue( | 70 scoped_ptr<base::DictionaryValue> RouteToValue( |
| 69 const MediaRoute& route, const std::string& extension_id) { | 71 const MediaRoute& route, |
| 72 const std::string& extension_id) { |
| 70 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 73 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 71 | 74 |
| 72 dictionary->SetString("id", route.media_route_id()); | 75 dictionary->SetString("id", route.media_route_id()); |
| 73 dictionary->SetString("sinkId", route.media_sink_id()); | 76 dictionary->SetString("sinkId", route.media_sink_id()); |
| 74 dictionary->SetString("description", route.description()); | 77 dictionary->SetString("description", route.description()); |
| 75 dictionary->SetBoolean("isLocal", route.is_local()); | 78 dictionary->SetBoolean("isLocal", route.is_local()); |
| 76 | 79 |
| 77 const std::string& custom_path = route.custom_controller_path(); | 80 const std::string& custom_path = route.custom_controller_path(); |
| 78 | 81 |
| 79 if (!custom_path.empty()) { | 82 if (!custom_path.empty()) { |
| 80 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s", | 83 std::string full_custom_controller_path = |
| 81 extensions::kExtensionScheme, extension_id.c_str(), | 84 base::StringPrintf("%s://%s/%s", extensions::kExtensionScheme, |
| 82 custom_path.c_str()); | 85 extension_id.c_str(), custom_path.c_str()); |
| 83 DCHECK(GURL(full_custom_controller_path).is_valid()); | 86 DCHECK(GURL(full_custom_controller_path).is_valid()); |
| 84 dictionary->SetString("customControllerPath", | 87 dictionary->SetString("customControllerPath", full_custom_controller_path); |
| 85 full_custom_controller_path); | |
| 86 } | 88 } |
| 87 | 89 |
| 88 return dictionary.Pass(); | 90 return dictionary.Pass(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 scoped_ptr<base::ListValue> RoutesToValue( | 93 scoped_ptr<base::ListValue> RoutesToValue(const std::vector<MediaRoute>& routes, |
| 92 const std::vector<MediaRoute>& routes, const std::string& extension_id) { | 94 const std::string& extension_id) { |
| 93 scoped_ptr<base::ListValue> value(new base::ListValue); | 95 scoped_ptr<base::ListValue> value(new base::ListValue); |
| 94 | 96 |
| 95 for (const MediaRoute& route : routes) { | 97 for (const MediaRoute& route : routes) { |
| 96 scoped_ptr<base::DictionaryValue> route_val(RouteToValue(route, | 98 scoped_ptr<base::DictionaryValue> route_val( |
| 97 extension_id)); | 99 RouteToValue(route, extension_id)); |
| 98 value->Append(route_val.release()); | 100 value->Append(route_val.release()); |
| 99 } | 101 } |
| 100 | 102 |
| 101 return value.Pass(); | 103 return value.Pass(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 scoped_ptr<base::ListValue> CastModesToValue(const CastModeSet& cast_modes, | 106 scoped_ptr<base::ListValue> CastModesToValue(const CastModeSet& cast_modes, |
| 105 const std::string& source_host) { | 107 const std::string& source_host) { |
| 106 scoped_ptr<base::ListValue> value(new base::ListValue); | 108 scoped_ptr<base::ListValue> value(new base::ListValue); |
| 107 | 109 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 DVLOG(1) << "Error: URL is invalid and cannot be opened."; | 158 DVLOG(1) << "Error: URL is invalid and cannot be opened."; |
| 157 return std::string(); | 159 return std::string(); |
| 158 } | 160 } |
| 159 return help_url; | 161 return help_url; |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace | 164 } // namespace |
| 163 | 165 |
| 164 MediaRouterWebUIMessageHandler::MediaRouterWebUIMessageHandler( | 166 MediaRouterWebUIMessageHandler::MediaRouterWebUIMessageHandler( |
| 165 MediaRouterUI* media_router_ui) | 167 MediaRouterUI* media_router_ui) |
| 166 : dialog_closing_(false), | 168 : dialog_closing_(false), media_router_ui_(media_router_ui) { |
| 167 media_router_ui_(media_router_ui) { | |
| 168 DCHECK(media_router_ui_); | 169 DCHECK(media_router_ui_); |
| 169 } | 170 } |
| 170 | 171 |
| 171 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { | 172 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() {} |
| 172 } | |
| 173 | 173 |
| 174 void MediaRouterWebUIMessageHandler::UpdateSinks( | 174 void MediaRouterWebUIMessageHandler::UpdateSinks( |
| 175 const std::vector<MediaSinkWithCastModes>& sinks) { | 175 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 176 DVLOG(2) << "UpdateSinks"; | 176 DVLOG(2) << "UpdateSinks"; |
| 177 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); | 177 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); |
| 178 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); | 178 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 181 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 182 const std::vector<MediaRoute>& routes) { | 182 const std::vector<MediaRoute>& routes) { |
| 183 DVLOG(2) << "UpdateRoutes"; | 183 DVLOG(2) << "UpdateRoutes"; |
| 184 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, | 184 scoped_ptr<base::ListValue> routes_val( |
| 185 media_router_ui_->GetRouteProviderExtensionId())); | 185 RoutesToValue(routes, media_router_ui_->GetRouteProviderExtensionId())); |
| 186 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 186 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void MediaRouterWebUIMessageHandler::UpdateCastModes( | 189 void MediaRouterWebUIMessageHandler::UpdateCastModes( |
| 190 const CastModeSet& cast_modes, | 190 const CastModeSet& cast_modes, |
| 191 const std::string& source_host) { | 191 const std::string& source_host) { |
| 192 DVLOG(2) << "UpdateCastModes"; | 192 DVLOG(2) << "UpdateCastModes"; |
| 193 scoped_ptr<base::ListValue> cast_modes_val( | 193 scoped_ptr<base::ListValue> cast_modes_val( |
| 194 CastModesToValue(cast_modes, source_host)); | 194 CastModesToValue(cast_modes, source_host)); |
| 195 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); | 195 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( | 198 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 199 const MediaSink::Id& sink_id, | 199 const MediaSink::Id& sink_id, |
| 200 const MediaRoute* route) { | 200 const MediaRoute* route) { |
| 201 DVLOG(2) << "OnCreateRouteResponseReceived"; | 201 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 202 if (route) { | 202 if (route) { |
| 203 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, | 203 scoped_ptr<base::DictionaryValue> route_value( |
| 204 media_router_ui_->GetRouteProviderExtensionId())); | 204 RouteToValue(*route, media_router_ui_->GetRouteProviderExtensionId())); |
| 205 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 205 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 206 base::StringValue(sink_id), *route_value); | 206 base::StringValue(sink_id), *route_value); |
| 207 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", | 207 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", |
| 208 true); | 208 true); |
| 209 } else { | 209 } else { |
| 210 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 210 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 211 base::StringValue(sink_id), | 211 base::StringValue(sink_id), |
| 212 *base::Value::CreateNullValue()); | 212 *base::Value::CreateNullValue()); |
| 213 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", | 213 UMA_HISTOGRAM_BOOLEAN("MediaRouter.Ui.Action.StartLocalSessionSuccessful", |
| 214 false); | 214 false); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 230 DVLOG(2) << "NotifyRouteCreationTimeout"; | 230 DVLOG(2) << "NotifyRouteCreationTimeout"; |
| 231 web_ui()->CallJavascriptFunction(kNotifyRouteCreationTimeout); | 231 web_ui()->CallJavascriptFunction(kNotifyRouteCreationTimeout); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void MediaRouterWebUIMessageHandler::RegisterMessages() { | 234 void MediaRouterWebUIMessageHandler::RegisterMessages() { |
| 235 web_ui()->RegisterMessageCallback( | 235 web_ui()->RegisterMessageCallback( |
| 236 kRequestInitialData, | 236 kRequestInitialData, |
| 237 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, | 237 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, |
| 238 base::Unretained(this))); | 238 base::Unretained(this))); |
| 239 web_ui()->RegisterMessageCallback( | 239 web_ui()->RegisterMessageCallback( |
| 240 kCreateRoute, | 240 kCreateRoute, base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, |
| 241 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, | 241 base::Unretained(this))); |
| 242 base::Unretained(this))); | |
| 243 web_ui()->RegisterMessageCallback( | 242 web_ui()->RegisterMessageCallback( |
| 244 kActOnIssue, | 243 kActOnIssue, base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, |
| 245 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, | 244 base::Unretained(this))); |
| 246 base::Unretained(this))); | |
| 247 web_ui()->RegisterMessageCallback( | 245 web_ui()->RegisterMessageCallback( |
| 248 kCloseRoute, | 246 kCloseRoute, base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, |
| 249 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, | 247 base::Unretained(this))); |
| 250 base::Unretained(this))); | |
| 251 web_ui()->RegisterMessageCallback( | 248 web_ui()->RegisterMessageCallback( |
| 252 kCloseDialog, | 249 kJoinRoute, base::Bind(&MediaRouterWebUIMessageHandler::OnJoinRoute, |
| 253 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 250 base::Unretained(this))); |
| 254 base::Unretained(this))); | 251 web_ui()->RegisterMessageCallback( |
| 252 kCanJoinRoute, base::Bind(&MediaRouterWebUIMessageHandler::OnCanJoinRoute, |
| 253 base::Unretained(this))); |
| 254 web_ui()->RegisterMessageCallback( |
| 255 kCloseDialog, base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 256 base::Unretained(this))); |
| 255 web_ui()->RegisterMessageCallback( | 257 web_ui()->RegisterMessageCallback( |
| 256 kReportSinkCount, | 258 kReportSinkCount, |
| 257 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, | 259 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, |
| 258 base::Unretained(this))); | 260 base::Unretained(this))); |
| 259 } | 261 } |
| 260 | 262 |
| 261 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 263 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 262 const base::ListValue* args) { | 264 const base::ListValue* args) { |
| 263 DVLOG(1) << "OnRequestInitialData"; | 265 DVLOG(1) << "OnRequestInitialData"; |
| 264 base::DictionaryValue initial_data; | 266 base::DictionaryValue initial_data; |
| 265 | 267 |
| 266 // "No Cast devices found?" Chromecast help center page. | 268 // "No Cast devices found?" Chromecast help center page. |
| 267 initial_data.SetString("deviceMissingUrl", | 269 initial_data.SetString("deviceMissingUrl", |
| 268 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 270 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 269 | 271 |
| 270 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); | 272 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); |
| 271 initial_data.Set("sinks", sinks.release()); | 273 initial_data.Set("sinks", sinks.release()); |
| 272 | 274 |
| 273 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), | 275 scoped_ptr<base::ListValue> routes( |
| 274 media_router_ui_->GetRouteProviderExtensionId())); | 276 RoutesToValue(media_router_ui_->routes(), |
| 277 media_router_ui_->GetRouteProviderExtensionId())); |
| 275 initial_data.Set("routes", routes.release()); | 278 initial_data.Set("routes", routes.release()); |
| 276 | 279 |
| 277 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 280 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 278 scoped_ptr<base::ListValue> cast_modes_list( | 281 scoped_ptr<base::ListValue> cast_modes_list( |
| 279 CastModesToValue(cast_modes, media_router_ui_->GetFrameURLHost())); | 282 CastModesToValue(cast_modes, media_router_ui_->GetFrameURLHost())); |
| 280 initial_data.Set("castModes", cast_modes_list.release()); | 283 initial_data.Set("castModes", cast_modes_list.release()); |
| 281 if (!cast_modes.empty()) { | 284 if (!cast_modes.empty()) { |
| 282 initial_data.SetInteger("initialCastModeType", | 285 initial_data.SetInteger("initialCastModeType", |
| 283 GetPreferredCastMode(cast_modes)); | 286 GetPreferredCastMode(cast_modes)); |
| 284 } | 287 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 308 | 311 |
| 309 if (!IsValidCastModeNum(cast_mode_num)) { | 312 if (!IsValidCastModeNum(cast_mode_num)) { |
| 310 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; | 313 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; |
| 311 return; | 314 return; |
| 312 } | 315 } |
| 313 | 316 |
| 314 MediaRouterUI* media_router_ui = | 317 MediaRouterUI* media_router_ui = |
| 315 static_cast<MediaRouterUI*>(web_ui()->GetController()); | 318 static_cast<MediaRouterUI*>(web_ui()->GetController()); |
| 316 if (media_router_ui->HasPendingRouteRequest()) { | 319 if (media_router_ui->HasPendingRouteRequest()) { |
| 317 DVLOG(1) << "UI already has pending route request. Ignoring."; | 320 DVLOG(1) << "UI already has pending route request. Ignoring."; |
| 318 Issue issue( | 321 Issue issue(l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), |
| 319 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), | 322 std::string(), IssueAction(IssueAction::TYPE_DISMISS), |
| 320 std::string(), IssueAction(IssueAction::TYPE_DISMISS), | 323 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, |
| 321 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | 324 false, std::string()); |
| 322 false, std::string()); | |
| 323 media_router_ui_->AddIssue(issue); | 325 media_router_ui_->AddIssue(issue); |
| 324 return; | 326 return; |
| 325 } | 327 } |
| 326 | 328 |
| 327 DVLOG(2) << __FUNCTION__ << ": sink id: " << sink_id | 329 DVLOG(2) << __FUNCTION__ << ": sink id: " << sink_id |
| 328 << ", cast mode: " << cast_mode_num; | 330 << ", cast mode: " << cast_mode_num; |
| 329 | 331 |
| 330 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, | 332 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, |
| 331 // e.g. low-fps-mirror, user-override. (crbug.com/490364) | 333 // e.g. low-fps-mirror, user-override. (crbug.com/490364) |
| 332 if (!media_router_ui->CreateRoute( | 334 if (!media_router_ui->CreateRoute( |
| 333 sink_id, static_cast<MediaCastMode>(cast_mode_num))) { | 335 sink_id, static_cast<MediaCastMode>(cast_mode_num))) { |
| 334 // TODO(imcheng): Need to add an issue if failed to initiate a CreateRoute | 336 // TODO(imcheng): Need to add an issue if failed to initiate a CreateRoute |
| 335 // request. | 337 // request. |
| 336 DVLOG(1) << "Error initiating route request."; | 338 DVLOG(1) << "Error initiating route request."; |
| 337 } | 339 } |
| 338 } | 340 } |
| 339 | 341 |
| 340 void MediaRouterWebUIMessageHandler::OnActOnIssue( | 342 void MediaRouterWebUIMessageHandler::OnActOnIssue(const base::ListValue* args) { |
| 341 const base::ListValue* args) { | |
| 342 DVLOG(1) << "OnActOnIssue"; | 343 DVLOG(1) << "OnActOnIssue"; |
| 343 const base::DictionaryValue* args_dict = nullptr; | 344 const base::DictionaryValue* args_dict = nullptr; |
| 344 Issue::Id issue_id; | 345 Issue::Id issue_id; |
| 345 int action_type_num = -1; | 346 int action_type_num = -1; |
| 346 if (!args->GetDictionary(0, &args_dict) || | 347 if (!args->GetDictionary(0, &args_dict) || |
| 347 !args_dict->GetString("issueId", &issue_id) || | 348 !args_dict->GetString("issueId", &issue_id) || |
| 348 !args_dict->GetInteger("actionType", &action_type_num)) { | 349 !args_dict->GetInteger("actionType", &action_type_num)) { |
| 349 DVLOG(1) << "Unable to extract args."; | 350 DVLOG(1) << "Unable to extract args."; |
| 350 return; | 351 return; |
| 351 } | 352 } |
| 352 if (!IsValidIssueActionTypeNum(action_type_num)) { | 353 if (!IsValidIssueActionTypeNum(action_type_num)) { |
| 353 DVLOG(1) << "Invalid action type: " << action_type_num; | 354 DVLOG(1) << "Invalid action type: " << action_type_num; |
| 354 return; | 355 return; |
| 355 } | 356 } |
| 356 IssueAction::Type action_type = | 357 IssueAction::Type action_type = |
| 357 static_cast<IssueAction::Type>(action_type_num); | 358 static_cast<IssueAction::Type>(action_type_num); |
| 358 if (ActOnIssueType(action_type, args_dict)) | 359 if (ActOnIssueType(action_type, args_dict)) |
| 359 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; | 360 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; |
| 360 media_router_ui_->ClearIssue(issue_id); | 361 media_router_ui_->ClearIssue(issue_id); |
| 361 } | 362 } |
| 362 | 363 |
| 363 void MediaRouterWebUIMessageHandler::OnCloseRoute( | 364 void MediaRouterWebUIMessageHandler::OnCanJoinRoute( |
| 364 const base::ListValue* args) { | 365 const base::ListValue* args) { |
| 366 DVLOG(0) << "OnCanJoinRoute"; |
| 367 const base::DictionaryValue* args_dict = nullptr; |
| 368 std::string route_id; |
| 369 if (!args->GetDictionary(0, &args_dict) || |
| 370 !args_dict->GetString("routeId", &route_id)) { |
| 371 DVLOG(1) << "Unable to extract args."; |
| 372 return; |
| 373 } |
| 374 media_router_ui_->CanJoinRoute(route_id); |
| 375 } |
| 376 |
| 377 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { |
| 378 DVLOG(0) << "OnJoinRoute"; |
| 379 const base::DictionaryValue* args_dict = nullptr; |
| 380 std::string route_id; |
| 381 std::string sink_id; |
| 382 if (!args->GetDictionary(0, &args_dict) || |
| 383 !args_dict->GetString("sinkId", &sink_id) || |
| 384 !args_dict->GetString("routeId", &route_id)) { |
| 385 DVLOG(1) << "Unable to extract args."; |
| 386 return; |
| 387 } |
| 388 media_router_ui_->JoinRoute(sink_id, route_id); |
| 389 } |
| 390 |
| 391 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { |
| 365 DVLOG(1) << "OnCloseRoute"; | 392 DVLOG(1) << "OnCloseRoute"; |
| 366 const base::DictionaryValue* args_dict = nullptr; | 393 const base::DictionaryValue* args_dict = nullptr; |
| 367 std::string route_id; | 394 std::string route_id; |
| 368 if (!args->GetDictionary(0, &args_dict) || | 395 if (!args->GetDictionary(0, &args_dict) || |
| 369 !args_dict->GetString("routeId", &route_id)) { | 396 !args_dict->GetString("routeId", &route_id)) { |
| 370 DVLOG(1) << "Unable to extract args."; | 397 DVLOG(1) << "Unable to extract args."; |
| 371 return; | 398 return; |
| 372 } | 399 } |
| 373 media_router_ui_->CloseRoute(route_id); | 400 media_router_ui_->CloseRoute(route_id); |
| 374 } | 401 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 405 open_args->AppendString(learn_more_url); | 432 open_args->AppendString(learn_more_url); |
| 406 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 433 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 407 return true; | 434 return true; |
| 408 } else { | 435 } else { |
| 409 // Do nothing; no other issue action types require any other action. | 436 // Do nothing; no other issue action types require any other action. |
| 410 return true; | 437 return true; |
| 411 } | 438 } |
| 412 } | 439 } |
| 413 | 440 |
| 414 } // namespace media_router | 441 } // namespace media_router |
| OLD | NEW |