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

Side by Side Diff: chrome/renderer/extensions/cast_streaming_native_handler.cc

Issue 753523002: remove some calls to to-be-deprecated v8::Value::To* functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | chrome/renderer/extensions/tabs_custom_bindings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 v8::String::NewFromUtf8( 320 v8::String::NewFromUtf8(
321 isolate, message.data(), v8::String::kNormalString, message.size())); 321 isolate, message.data(), v8::String::kNormalString, message.size()));
322 context()->DispatchEvent("cast.streaming.rtpStream.onError", event_args); 322 context()->DispatchEvent("cast.streaming.rtpStream.onError", event_args);
323 } 323 }
324 324
325 void CastStreamingNativeHandler::DestroyCastRtpStream( 325 void CastStreamingNativeHandler::DestroyCastRtpStream(
326 const v8::FunctionCallbackInfo<v8::Value>& args) { 326 const v8::FunctionCallbackInfo<v8::Value>& args) {
327 CHECK_EQ(1, args.Length()); 327 CHECK_EQ(1, args.Length());
328 CHECK(args[0]->IsInt32()); 328 CHECK(args[0]->IsInt32());
329 329
330 const int transport_id = args[0]->ToInt32()->Value(); 330 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
331 if (!GetRtpStreamOrThrow(transport_id)) 331 if (!GetRtpStreamOrThrow(transport_id))
332 return; 332 return;
333 rtp_stream_map_.erase(transport_id); 333 rtp_stream_map_.erase(transport_id);
334 } 334 }
335 335
336 void CastStreamingNativeHandler::GetSupportedParamsCastRtpStream( 336 void CastStreamingNativeHandler::GetSupportedParamsCastRtpStream(
337 const v8::FunctionCallbackInfo<v8::Value>& args) { 337 const v8::FunctionCallbackInfo<v8::Value>& args) {
338 CHECK_EQ(1, args.Length()); 338 CHECK_EQ(1, args.Length());
339 CHECK(args[0]->IsInt32()); 339 CHECK(args[0]->IsInt32());
340 340
341 const int transport_id = args[0]->ToInt32()->Value(); 341 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
342 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 342 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
343 if (!transport) 343 if (!transport)
344 return; 344 return;
345 345
346 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 346 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
347 std::vector<CastRtpParams> cast_params = transport->GetSupportedParams(); 347 std::vector<CastRtpParams> cast_params = transport->GetSupportedParams();
348 v8::Handle<v8::Array> result = 348 v8::Handle<v8::Array> result =
349 v8::Array::New(args.GetIsolate(), 349 v8::Array::New(args.GetIsolate(),
350 static_cast<int>(cast_params.size())); 350 static_cast<int>(cast_params.size()));
351 for (size_t i = 0; i < cast_params.size(); ++i) { 351 for (size_t i = 0; i < cast_params.size(); ++i) {
352 RtpParams params; 352 RtpParams params;
353 FromCastRtpParams(cast_params[i], &params); 353 FromCastRtpParams(cast_params[i], &params);
354 scoped_ptr<base::DictionaryValue> params_value = params.ToValue(); 354 scoped_ptr<base::DictionaryValue> params_value = params.ToValue();
355 result->Set( 355 result->Set(
356 static_cast<int>(i), 356 static_cast<int>(i),
357 converter->ToV8Value(params_value.get(), context()->v8_context())); 357 converter->ToV8Value(params_value.get(), context()->v8_context()));
358 } 358 }
359 args.GetReturnValue().Set(result); 359 args.GetReturnValue().Set(result);
360 } 360 }
361 361
362 void CastStreamingNativeHandler::StartCastRtpStream( 362 void CastStreamingNativeHandler::StartCastRtpStream(
363 const v8::FunctionCallbackInfo<v8::Value>& args) { 363 const v8::FunctionCallbackInfo<v8::Value>& args) {
364 CHECK_EQ(2, args.Length()); 364 CHECK_EQ(2, args.Length());
365 CHECK(args[0]->IsInt32()); 365 CHECK(args[0]->IsInt32());
366 CHECK(args[1]->IsObject()); 366 CHECK(args[1]->IsObject());
367 367
368 const int transport_id = args[0]->ToInt32()->Value(); 368 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
369 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 369 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
370 if (!transport) 370 if (!transport)
371 return; 371 return;
372 372
373 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 373 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
374 scoped_ptr<base::Value> params_value( 374 scoped_ptr<base::Value> params_value(
375 converter->FromV8Value(args[1], context()->v8_context())); 375 converter->FromV8Value(args[1], context()->v8_context()));
376 if (!params_value) { 376 if (!params_value) {
377 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 377 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
378 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertParams))); 378 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertParams)));
(...skipping 24 matching lines...) Expand all
403 weak_factory_.GetWeakPtr(), 403 weak_factory_.GetWeakPtr(),
404 transport_id); 404 transport_id);
405 transport->Start(cast_params, start_callback, stop_callback, error_callback); 405 transport->Start(cast_params, start_callback, stop_callback, error_callback);
406 } 406 }
407 407
408 void CastStreamingNativeHandler::StopCastRtpStream( 408 void CastStreamingNativeHandler::StopCastRtpStream(
409 const v8::FunctionCallbackInfo<v8::Value>& args) { 409 const v8::FunctionCallbackInfo<v8::Value>& args) {
410 CHECK_EQ(1, args.Length()); 410 CHECK_EQ(1, args.Length());
411 CHECK(args[0]->IsInt32()); 411 CHECK(args[0]->IsInt32());
412 412
413 const int transport_id = args[0]->ToInt32()->Value(); 413 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
414 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 414 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
415 if (!transport) 415 if (!transport)
416 return; 416 return;
417 transport->Stop(); 417 transport->Stop();
418 } 418 }
419 419
420 void CastStreamingNativeHandler::DestroyCastUdpTransport( 420 void CastStreamingNativeHandler::DestroyCastUdpTransport(
421 const v8::FunctionCallbackInfo<v8::Value>& args) { 421 const v8::FunctionCallbackInfo<v8::Value>& args) {
422 CHECK_EQ(1, args.Length()); 422 CHECK_EQ(1, args.Length());
423 CHECK(args[0]->IsInt32()); 423 CHECK(args[0]->IsInt32());
424 424
425 const int transport_id = args[0]->ToInt32()->Value(); 425 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
426 if (!GetUdpTransportOrThrow(transport_id)) 426 if (!GetUdpTransportOrThrow(transport_id))
427 return; 427 return;
428 udp_transport_map_.erase(transport_id); 428 udp_transport_map_.erase(transport_id);
429 } 429 }
430 430
431 void CastStreamingNativeHandler::SetDestinationCastUdpTransport( 431 void CastStreamingNativeHandler::SetDestinationCastUdpTransport(
432 const v8::FunctionCallbackInfo<v8::Value>& args) { 432 const v8::FunctionCallbackInfo<v8::Value>& args) {
433 CHECK_EQ(2, args.Length()); 433 CHECK_EQ(2, args.Length());
434 CHECK(args[0]->IsInt32()); 434 CHECK(args[0]->IsInt32());
435 CHECK(args[1]->IsObject()); 435 CHECK(args[1]->IsObject());
436 436
437 const int transport_id = args[0]->ToInt32()->Value(); 437 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
438 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id); 438 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id);
439 if (!transport) 439 if (!transport)
440 return; 440 return;
441 441
442 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 442 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
443 scoped_ptr<base::Value> destination_value( 443 scoped_ptr<base::Value> destination_value(
444 converter->FromV8Value(args[1], context()->v8_context())); 444 converter->FromV8Value(args[1], context()->v8_context()));
445 if (!destination_value) { 445 if (!destination_value) {
446 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 446 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
447 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs))); 447 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs)));
(...skipping 14 matching lines...) Expand all
462 } 462 }
463 transport->SetDestination(net::IPEndPoint(ip, destination->port)); 463 transport->SetDestination(net::IPEndPoint(ip, destination->port));
464 } 464 }
465 465
466 void CastStreamingNativeHandler::SetOptionsCastUdpTransport( 466 void CastStreamingNativeHandler::SetOptionsCastUdpTransport(
467 const v8::FunctionCallbackInfo<v8::Value>& args) { 467 const v8::FunctionCallbackInfo<v8::Value>& args) {
468 CHECK_EQ(2, args.Length()); 468 CHECK_EQ(2, args.Length());
469 CHECK(args[0]->IsInt32()); 469 CHECK(args[0]->IsInt32());
470 CHECK(args[1]->IsObject()); 470 CHECK(args[1]->IsObject());
471 471
472 const int transport_id = args[0]->ToInt32()->Value(); 472 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
473 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id); 473 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id);
474 if (!transport) 474 if (!transport)
475 return; 475 return;
476 476
477 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 477 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
478 base::Value* options_value = 478 base::Value* options_value =
479 converter->FromV8Value(args[1], context()->v8_context()); 479 converter->FromV8Value(args[1], context()->v8_context());
480 base::DictionaryValue* options; 480 base::DictionaryValue* options;
481 if (!options_value || !options_value->GetAsDictionary(&options)) { 481 if (!options_value || !options_value->GetAsDictionary(&options)) {
482 delete options_value; 482 delete options_value;
483 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 483 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
484 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs))); 484 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs)));
485 return; 485 return;
486 } 486 }
487 transport->SetOptions(make_scoped_ptr(options)); 487 transport->SetOptions(make_scoped_ptr(options));
488 } 488 }
489 489
490 void CastStreamingNativeHandler::ToggleLogging( 490 void CastStreamingNativeHandler::ToggleLogging(
491 const v8::FunctionCallbackInfo<v8::Value>& args) { 491 const v8::FunctionCallbackInfo<v8::Value>& args) {
492 CHECK_EQ(2, args.Length()); 492 CHECK_EQ(2, args.Length());
493 CHECK(args[0]->IsInt32()); 493 CHECK(args[0]->IsInt32());
494 CHECK(args[1]->IsBoolean()); 494 CHECK(args[1]->IsBoolean());
495 495
496 const int stream_id = args[0]->ToInt32()->Value(); 496 const int stream_id = args[0]->ToInt32(args.GetIsolate())->Value();
497 CastRtpStream* stream = GetRtpStreamOrThrow(stream_id); 497 CastRtpStream* stream = GetRtpStreamOrThrow(stream_id);
498 if (!stream) 498 if (!stream)
499 return; 499 return;
500 500
501 const bool enable = args[1]->ToBoolean()->Value(); 501 const bool enable = args[1]->ToBoolean(args.GetIsolate())->Value();
502 stream->ToggleLogging(enable); 502 stream->ToggleLogging(enable);
503 } 503 }
504 504
505 void CastStreamingNativeHandler::GetRawEvents( 505 void CastStreamingNativeHandler::GetRawEvents(
506 const v8::FunctionCallbackInfo<v8::Value>& args) { 506 const v8::FunctionCallbackInfo<v8::Value>& args) {
507 CHECK_EQ(3, args.Length()); 507 CHECK_EQ(3, args.Length());
508 CHECK(args[0]->IsInt32()); 508 CHECK(args[0]->IsInt32());
509 CHECK(args[1]->IsNull() || args[1]->IsString()); 509 CHECK(args[1]->IsNull() || args[1]->IsString());
510 CHECK(args[2]->IsFunction()); 510 CHECK(args[2]->IsFunction());
511 511
512 const int transport_id = args[0]->ToInt32()->Value(); 512 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
513 // TODO(imcheng): Use a weak reference to ensure we don't call into an 513 // TODO(imcheng): Use a weak reference to ensure we don't call into an
514 // invalid context when the callback is invoked. 514 // invalid context when the callback is invoked.
515 linked_ptr<ScopedPersistent<v8::Function> > callback( 515 linked_ptr<ScopedPersistent<v8::Function> > callback(
516 new ScopedPersistent<v8::Function>(args[2].As<v8::Function>())); 516 new ScopedPersistent<v8::Function>(args[2].As<v8::Function>()));
517 std::string extra_data; 517 std::string extra_data;
518 if (!args[1]->IsNull()) { 518 if (!args[1]->IsNull()) {
519 extra_data = *v8::String::Utf8Value(args[1]); 519 extra_data = *v8::String::Utf8Value(args[1]);
520 } 520 }
521 521
522 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 522 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
523 if (!transport) 523 if (!transport)
524 return; 524 return;
525 525
526 get_raw_events_callbacks_.insert(std::make_pair(transport_id, callback)); 526 get_raw_events_callbacks_.insert(std::make_pair(transport_id, callback));
527 527
528 transport->GetRawEvents( 528 transport->GetRawEvents(
529 base::Bind(&CastStreamingNativeHandler::CallGetRawEventsCallback, 529 base::Bind(&CastStreamingNativeHandler::CallGetRawEventsCallback,
530 weak_factory_.GetWeakPtr(), 530 weak_factory_.GetWeakPtr(),
531 transport_id), 531 transport_id),
532 extra_data); 532 extra_data);
533 } 533 }
534 534
535 void CastStreamingNativeHandler::GetStats( 535 void CastStreamingNativeHandler::GetStats(
536 const v8::FunctionCallbackInfo<v8::Value>& args) { 536 const v8::FunctionCallbackInfo<v8::Value>& args) {
537 CHECK_EQ(2, args.Length()); 537 CHECK_EQ(2, args.Length());
538 CHECK(args[0]->IsInt32()); 538 CHECK(args[0]->IsInt32());
539 CHECK(args[1]->IsFunction()); 539 CHECK(args[1]->IsFunction());
540 const int transport_id = args[0]->ToInt32()->Value(); 540 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
541 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 541 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
542 if (!transport) 542 if (!transport)
543 return; 543 return;
544 544
545 // TODO(imcheng): Use a weak reference to ensure we don't call into an 545 // TODO(imcheng): Use a weak reference to ensure we don't call into an
546 // invalid context when the callback is invoked. 546 // invalid context when the callback is invoked.
547 linked_ptr<ScopedPersistent<v8::Function> > callback( 547 linked_ptr<ScopedPersistent<v8::Function> > callback(
548 new ScopedPersistent<v8::Function>(args[1].As<v8::Function>())); 548 new ScopedPersistent<v8::Function>(args[1].As<v8::Function>()));
549 get_stats_callbacks_.insert(std::make_pair(transport_id, callback)); 549 get_stats_callbacks_.insert(std::make_pair(transport_id, callback));
550 550
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 transport_id); 609 transport_id);
610 if (iter != udp_transport_map_.end()) 610 if (iter != udp_transport_map_.end())
611 return iter->second.get(); 611 return iter->second.get();
612 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 612 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
613 isolate->ThrowException(v8::Exception::RangeError( 613 isolate->ThrowException(v8::Exception::RangeError(
614 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); 614 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound)));
615 return NULL; 615 return NULL;
616 } 616 }
617 617
618 } // namespace extensions 618 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/extensions/tabs_custom_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698