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

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

Issue 2931393003: [Content] Update V8ValueConverter::create to return a std::unique_ptr (Closed)
Patch Set: rebase Created 3 years, 6 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 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void CastStreamingNativeHandler::GetSupportedParamsCastRtpStream( 489 void CastStreamingNativeHandler::GetSupportedParamsCastRtpStream(
490 const v8::FunctionCallbackInfo<v8::Value>& args) const { 490 const v8::FunctionCallbackInfo<v8::Value>& args) const {
491 CHECK_EQ(1, args.Length()); 491 CHECK_EQ(1, args.Length());
492 CHECK(args[0]->IsInt32()); 492 CHECK(args[0]->IsInt32());
493 493
494 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value(); 494 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
495 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 495 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
496 if (!transport) 496 if (!transport)
497 return; 497 return;
498 498
499 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 499 std::unique_ptr<V8ValueConverter> converter = V8ValueConverter::Create();
500 std::vector<FrameSenderConfig> configs = transport->GetSupportedConfigs(); 500 std::vector<FrameSenderConfig> configs = transport->GetSupportedConfigs();
501 v8::Local<v8::Array> result = 501 v8::Local<v8::Array> result =
502 v8::Array::New(args.GetIsolate(), static_cast<int>(configs.size())); 502 v8::Array::New(args.GetIsolate(), static_cast<int>(configs.size()));
503 for (size_t i = 0; i < configs.size(); ++i) { 503 for (size_t i = 0; i < configs.size(); ++i) {
504 RtpParams params; 504 RtpParams params;
505 FromFrameSenderConfig(configs[i], &params.payload); 505 FromFrameSenderConfig(configs[i], &params.payload);
506 std::unique_ptr<base::DictionaryValue> params_value = params.ToValue(); 506 std::unique_ptr<base::DictionaryValue> params_value = params.ToValue();
507 result->Set( 507 result->Set(
508 static_cast<int>(i), 508 static_cast<int>(i),
509 converter->ToV8Value(params_value.get(), context()->v8_context())); 509 converter->ToV8Value(params_value.get(), context()->v8_context()));
510 } 510 }
511 args.GetReturnValue().Set(result); 511 args.GetReturnValue().Set(result);
512 } 512 }
513 513
514 void CastStreamingNativeHandler::StartCastRtpStream( 514 void CastStreamingNativeHandler::StartCastRtpStream(
515 const v8::FunctionCallbackInfo<v8::Value>& args) { 515 const v8::FunctionCallbackInfo<v8::Value>& args) {
516 CHECK_EQ(2, args.Length()); 516 CHECK_EQ(2, args.Length());
517 CHECK(args[0]->IsInt32()); 517 CHECK(args[0]->IsInt32());
518 CHECK(args[1]->IsObject()); 518 CHECK(args[1]->IsObject());
519 519
520 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value(); 520 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
521 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 521 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
522 if (!transport) 522 if (!transport)
523 return; 523 return;
524 524
525 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 525 std::unique_ptr<base::Value> params_value =
526 std::unique_ptr<base::Value> params_value( 526 V8ValueConverter::Create()->FromV8Value(args[1], context()->v8_context());
527 converter->FromV8Value(args[1], context()->v8_context()));
528 if (!params_value) { 527 if (!params_value) {
529 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 528 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
530 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertParams))); 529 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertParams)));
531 return; 530 return;
532 } 531 }
533 std::unique_ptr<RtpParams> params = RtpParams::FromValue(*params_value); 532 std::unique_ptr<RtpParams> params = RtpParams::FromValue(*params_value);
534 if (!params) { 533 if (!params) {
535 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 534 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
536 v8::String::NewFromUtf8(args.GetIsolate(), kInvalidRtpParams))); 535 v8::String::NewFromUtf8(args.GetIsolate(), kInvalidRtpParams)));
537 return; 536 return;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 const v8::FunctionCallbackInfo<v8::Value>& args) { 610 const v8::FunctionCallbackInfo<v8::Value>& args) {
612 CHECK_EQ(2, args.Length()); 611 CHECK_EQ(2, args.Length());
613 CHECK(args[0]->IsInt32()); 612 CHECK(args[0]->IsInt32());
614 CHECK(args[1]->IsObject()); 613 CHECK(args[1]->IsObject());
615 614
616 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value(); 615 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
617 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id); 616 CastUdpTransport* transport = GetUdpTransportOrThrow(transport_id);
618 if (!transport) 617 if (!transport)
619 return; 618 return;
620 619
621 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 620 std::unique_ptr<base::DictionaryValue> options =
622 std::unique_ptr<base::DictionaryValue> options = base::DictionaryValue::From( 621 base::DictionaryValue::From(V8ValueConverter::Create()->FromV8Value(
623 converter->FromV8Value(args[1], context()->v8_context())); 622 args[1], context()->v8_context()));
624 if (!options) { 623 if (!options) {
625 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 624 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
626 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs))); 625 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs)));
627 return; 626 return;
628 } 627 }
629 transport->SetOptions(std::move(options)); 628 transport->SetOptions(std::move(options));
630 } 629 }
631 630
632 void CastStreamingNativeHandler::ToggleLogging( 631 void CastStreamingNativeHandler::ToggleLogging(
633 const v8::FunctionCallbackInfo<v8::Value>& args) { 632 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 int transport_id, 697 int transport_id,
699 std::unique_ptr<base::Value> raw_events) { 698 std::unique_ptr<base::Value> raw_events) {
700 v8::Isolate* isolate = context()->isolate(); 699 v8::Isolate* isolate = context()->isolate();
701 v8::HandleScope handle_scope(isolate); 700 v8::HandleScope handle_scope(isolate);
702 v8::Context::Scope context_scope(context()->v8_context()); 701 v8::Context::Scope context_scope(context()->v8_context());
703 702
704 RtpStreamCallbackMap::iterator it = 703 RtpStreamCallbackMap::iterator it =
705 get_raw_events_callbacks_.find(transport_id); 704 get_raw_events_callbacks_.find(transport_id);
706 if (it == get_raw_events_callbacks_.end()) 705 if (it == get_raw_events_callbacks_.end())
707 return; 706 return;
708 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 707 v8::Local<v8::Value> callback_args[] = {V8ValueConverter::Create()->ToV8Value(
709 v8::Local<v8::Value> callback_args[] = { 708 raw_events.get(), context()->v8_context())};
710 converter->ToV8Value(raw_events.get(), context()->v8_context())};
711 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, it->second), 709 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, it->second),
712 arraysize(callback_args), callback_args); 710 arraysize(callback_args), callback_args);
713 get_raw_events_callbacks_.erase(it); 711 get_raw_events_callbacks_.erase(it);
714 } 712 }
715 713
716 void CastStreamingNativeHandler::CallGetStatsCallback( 714 void CastStreamingNativeHandler::CallGetStatsCallback(
717 int transport_id, 715 int transport_id,
718 std::unique_ptr<base::DictionaryValue> stats) { 716 std::unique_ptr<base::DictionaryValue> stats) {
719 v8::Isolate* isolate = context()->isolate(); 717 v8::Isolate* isolate = context()->isolate();
720 v8::HandleScope handle_scope(isolate); 718 v8::HandleScope handle_scope(isolate);
721 v8::Context::Scope context_scope(context()->v8_context()); 719 v8::Context::Scope context_scope(context()->v8_context());
722 720
723 RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id); 721 RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id);
724 if (it == get_stats_callbacks_.end()) 722 if (it == get_stats_callbacks_.end())
725 return; 723 return;
726 724
727 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 725 v8::Local<v8::Value> callback_args[] = {V8ValueConverter::Create()->ToV8Value(
728 v8::Local<v8::Value> callback_args[] = { 726 stats.get(), context()->v8_context())};
729 converter->ToV8Value(stats.get(), context()->v8_context())};
730 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, it->second), 727 context()->SafeCallFunction(v8::Local<v8::Function>::New(isolate, it->second),
731 arraysize(callback_args), callback_args); 728 arraysize(callback_args), callback_args);
732 get_stats_callbacks_.erase(it); 729 get_stats_callbacks_.erase(it);
733 } 730 }
734 731
735 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow( 732 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow(
736 int transport_id) const { 733 int transport_id) const {
737 RtpStreamMap::const_iterator iter = rtp_stream_map_.find( 734 RtpStreamMap::const_iterator iter = rtp_stream_map_.find(
738 transport_id); 735 transport_id);
739 if (iter != rtp_stream_map_.end()) 736 if (iter != rtp_stream_map_.end())
(...skipping 13 matching lines...) Expand all
753 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 750 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
754 isolate->ThrowException(v8::Exception::RangeError( 751 isolate->ThrowException(v8::Exception::RangeError(
755 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); 752 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound)));
756 return NULL; 753 return NULL;
757 } 754 }
758 755
759 bool CastStreamingNativeHandler::FrameReceiverConfigFromArg( 756 bool CastStreamingNativeHandler::FrameReceiverConfigFromArg(
760 v8::Isolate* isolate, 757 v8::Isolate* isolate,
761 const v8::Local<v8::Value>& arg, 758 const v8::Local<v8::Value>& arg,
762 media::cast::FrameReceiverConfig* config) const { 759 media::cast::FrameReceiverConfig* config) const {
763 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 760 std::unique_ptr<base::Value> params_value =
764 std::unique_ptr<base::Value> params_value( 761 V8ValueConverter::Create()->FromV8Value(arg, context()->v8_context());
765 converter->FromV8Value(arg, context()->v8_context()));
766 if (!params_value) { 762 if (!params_value) {
767 isolate->ThrowException(v8::Exception::TypeError( 763 isolate->ThrowException(v8::Exception::TypeError(
768 v8::String::NewFromUtf8(isolate, kUnableToConvertParams))); 764 v8::String::NewFromUtf8(isolate, kUnableToConvertParams)));
769 return false; 765 return false;
770 } 766 }
771 std::unique_ptr<RtpReceiverParams> params = 767 std::unique_ptr<RtpReceiverParams> params =
772 RtpReceiverParams::FromValue(*params_value); 768 RtpReceiverParams::FromValue(*params_value);
773 if (!params) { 769 if (!params) {
774 isolate->ThrowException(v8::Exception::TypeError( 770 isolate->ThrowException(v8::Exception::TypeError(
775 v8::String::NewFromUtf8(isolate, kInvalidRtpParams))); 771 v8::String::NewFromUtf8(isolate, kInvalidRtpParams)));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask))); 822 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask)));
827 return false; 823 return false;
828 } 824 }
829 return true; 825 return true;
830 } 826 }
831 827
832 bool CastStreamingNativeHandler::IPEndPointFromArg( 828 bool CastStreamingNativeHandler::IPEndPointFromArg(
833 v8::Isolate* isolate, 829 v8::Isolate* isolate,
834 const v8::Local<v8::Value>& arg, 830 const v8::Local<v8::Value>& arg,
835 net::IPEndPoint* ip_endpoint) const { 831 net::IPEndPoint* ip_endpoint) const {
836 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 832 std::unique_ptr<base::Value> destination_value =
837 std::unique_ptr<base::Value> destination_value( 833 V8ValueConverter::Create()->FromV8Value(arg, context()->v8_context());
838 converter->FromV8Value(arg, context()->v8_context()));
839 if (!destination_value) { 834 if (!destination_value) {
840 isolate->ThrowException(v8::Exception::TypeError( 835 isolate->ThrowException(v8::Exception::TypeError(
841 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask))); 836 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask)));
842 return false; 837 return false;
843 } 838 }
844 std::unique_ptr<IPEndPoint> destination = 839 std::unique_ptr<IPEndPoint> destination =
845 IPEndPoint::FromValue(*destination_value); 840 IPEndPoint::FromValue(*destination_value);
846 if (!destination) { 841 if (!destination) {
847 isolate->ThrowException(v8::Exception::TypeError( 842 isolate->ThrowException(v8::Exception::TypeError(
848 v8::String::NewFromUtf8(isolate, kInvalidDestination))); 843 v8::String::NewFromUtf8(isolate, kInvalidDestination)));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 audio_config.target_frame_rate)); 917 audio_config.target_frame_rate));
923 918
924 if (!params.IsValid()) { 919 if (!params.IsValid()) {
925 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 920 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
926 v8::String::NewFromUtf8(args.GetIsolate(), kInvalidAudioParams))); 921 v8::String::NewFromUtf8(args.GetIsolate(), kInvalidAudioParams)));
927 return; 922 return;
928 } 923 }
929 924
930 std::unique_ptr<base::DictionaryValue> options; 925 std::unique_ptr<base::DictionaryValue> options;
931 if (args.Length() >= 9) { 926 if (args.Length() >= 9) {
932 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 927 std::unique_ptr<base::Value> options_value =
933 std::unique_ptr<base::Value> options_value( 928 V8ValueConverter::Create()->FromV8Value(args[8],
934 converter->FromV8Value(args[8], context()->v8_context())); 929 context()->v8_context());
935 if (!options_value->IsType(base::Value::Type::NONE)) { 930 if (!options_value->IsType(base::Value::Type::NONE)) {
936 options = base::DictionaryValue::From(std::move(options_value)); 931 options = base::DictionaryValue::From(std::move(options_value));
937 if (!options) { 932 if (!options) {
938 args.GetIsolate()->ThrowException(v8::Exception::TypeError( 933 args.GetIsolate()->ThrowException(v8::Exception::TypeError(
939 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs))); 934 v8::String::NewFromUtf8(args.GetIsolate(), kUnableToConvertArgs)));
940 return; 935 return;
941 } 936 }
942 } 937 }
943 } 938 }
944 939
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 &web_stream)) { 983 &web_stream)) {
989 LOG(ERROR) << "Failed to add Cast audio track to media stream."; 984 LOG(ERROR) << "Failed to add Cast audio track to media stream.";
990 } 985 }
991 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote 986 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote
992 &web_stream)) { 987 &web_stream)) {
993 LOG(ERROR) << "Failed to add Cast video track to media stream."; 988 LOG(ERROR) << "Failed to add Cast video track to media stream.";
994 } 989 }
995 } 990 }
996 991
997 } // namespace extensions 992 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/app_bindings_core.cc ('k') | chrome/renderer/extensions/platform_keys_natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698