OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/extensions/cast_streaming_native_handler.h" | 5 #include "chrome/renderer/extensions/cast_streaming_native_handler.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 base::Unretained(this))); | 177 base::Unretained(this))); |
178 RouteFunction("StopCastRtpStream", | 178 RouteFunction("StopCastRtpStream", |
179 base::Bind(&CastStreamingNativeHandler::StopCastRtpStream, | 179 base::Bind(&CastStreamingNativeHandler::StopCastRtpStream, |
180 base::Unretained(this))); | 180 base::Unretained(this))); |
181 RouteFunction("DestroyCastUdpTransport", | 181 RouteFunction("DestroyCastUdpTransport", |
182 base::Bind(&CastStreamingNativeHandler::DestroyCastUdpTransport, | 182 base::Bind(&CastStreamingNativeHandler::DestroyCastUdpTransport, |
183 base::Unretained(this))); | 183 base::Unretained(this))); |
184 RouteFunction("SetDestinationCastUdpTransport", | 184 RouteFunction("SetDestinationCastUdpTransport", |
185 base::Bind(&CastStreamingNativeHandler::SetDestinationCastUdpTransport, | 185 base::Bind(&CastStreamingNativeHandler::SetDestinationCastUdpTransport, |
186 base::Unretained(this))); | 186 base::Unretained(this))); |
| 187 RouteFunction("SetOptionsCastUdpTransport", |
| 188 base::Bind(&CastStreamingNativeHandler::SetOptionsCastUdpTransport, |
| 189 base::Unretained(this))); |
187 RouteFunction("ToggleLogging", | 190 RouteFunction("ToggleLogging", |
188 base::Bind(&CastStreamingNativeHandler::ToggleLogging, | 191 base::Bind(&CastStreamingNativeHandler::ToggleLogging, |
189 base::Unretained(this))); | 192 base::Unretained(this))); |
190 RouteFunction("GetRawEvents", | 193 RouteFunction("GetRawEvents", |
191 base::Bind(&CastStreamingNativeHandler::GetRawEvents, | 194 base::Bind(&CastStreamingNativeHandler::GetRawEvents, |
192 base::Unretained(this))); | 195 base::Unretained(this))); |
193 RouteFunction("GetStats", | 196 RouteFunction("GetStats", |
194 base::Bind(&CastStreamingNativeHandler::GetStats, | 197 base::Bind(&CastStreamingNativeHandler::GetStats, |
195 base::Unretained(this))); | 198 base::Unretained(this))); |
196 } | 199 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 } | 454 } |
452 net::IPAddressNumber ip; | 455 net::IPAddressNumber ip; |
453 if (!net::ParseIPLiteralToNumber(destination->address, &ip)) { | 456 if (!net::ParseIPLiteralToNumber(destination->address, &ip)) { |
454 args.GetIsolate()->ThrowException(v8::Exception::TypeError( | 457 args.GetIsolate()->ThrowException(v8::Exception::TypeError( |
455 v8::String::NewFromUtf8(args.GetIsolate(), kInvalidDestination))); | 458 v8::String::NewFromUtf8(args.GetIsolate(), kInvalidDestination))); |
456 return; | 459 return; |
457 } | 460 } |
458 transport->SetDestination(net::IPEndPoint(ip, destination->port)); | 461 transport->SetDestination(net::IPEndPoint(ip, destination->port)); |
459 } | 462 } |
460 | 463 |
| 464 void CastStreamingNativeHandler::SetOptionsCastUdpTransport( |
| 465 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 466 CHECK_EQ(2, args.Length()); |
| 467 CHECK(args[0]->IsInt32()); |
| 468 CHECK(args[1]->IsObject()); |
| 469 |
| 470 const int transport_id = args[0]->ToInt32()->Value(); |
| 471 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id); |
| 472 if (!transport) |
| 473 return; |
| 474 |
| 475 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 476 base::Value* options_value = |
| 477 converter->FromV8Value(args[1], context()->v8_context()); |
| 478 base::DictionaryValue* options; |
| 479 if (!options_value || !options_value->GetAsDictionary(&options)) { |
| 480 delete options_value; |
| 481 args.GetIsolate()->ThrowException(v8::Exception::TypeError( |
| 482 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs))); |
| 483 return; |
| 484 } |
| 485 transport->SetOptions(make_scoped_ptr(options)); |
| 486 } |
| 487 |
461 void CastStreamingNativeHandler::ToggleLogging( | 488 void CastStreamingNativeHandler::ToggleLogging( |
462 const v8::FunctionCallbackInfo<v8::Value>& args) { | 489 const v8::FunctionCallbackInfo<v8::Value>& args) { |
463 CHECK_EQ(2, args.Length()); | 490 CHECK_EQ(2, args.Length()); |
464 CHECK(args[0]->IsInt32()); | 491 CHECK(args[0]->IsInt32()); |
465 CHECK(args[1]->IsBoolean()); | 492 CHECK(args[1]->IsBoolean()); |
466 | 493 |
467 const int stream_id = args[0]->ToInt32()->Value(); | 494 const int stream_id = args[0]->ToInt32()->Value(); |
468 CastRtpStream* stream = GetRtpStreamOrThrow(stream_id); | 495 CastRtpStream* stream = GetRtpStreamOrThrow(stream_id); |
469 if (!stream) | 496 if (!stream) |
470 return; | 497 return; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 transport_id); | 607 transport_id); |
581 if (iter != udp_transport_map_.end()) | 608 if (iter != udp_transport_map_.end()) |
582 return iter->second.get(); | 609 return iter->second.get(); |
583 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); | 610 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
584 isolate->ThrowException(v8::Exception::RangeError( | 611 isolate->ThrowException(v8::Exception::RangeError( |
585 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); | 612 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); |
586 return NULL; | 613 return NULL; |
587 } | 614 } |
588 | 615 |
589 } // namespace extensions | 616 } // namespace extensions |
OLD | NEW |