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

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

Issue 1103273009: Use v8::Local inplace of v8::Handle in src/chrome/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 <functional> 7 #include <functional>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 void CastStreamingNativeHandler::CallCreateCallback( 272 void CastStreamingNativeHandler::CallCreateCallback(
273 scoped_ptr<CastRtpStream> stream1, 273 scoped_ptr<CastRtpStream> stream1,
274 scoped_ptr<CastRtpStream> stream2, 274 scoped_ptr<CastRtpStream> stream2,
275 scoped_ptr<CastUdpTransport> udp_transport) { 275 scoped_ptr<CastUdpTransport> udp_transport) {
276 v8::Isolate* isolate = context()->isolate(); 276 v8::Isolate* isolate = context()->isolate();
277 v8::HandleScope handle_scope(isolate); 277 v8::HandleScope handle_scope(isolate);
278 v8::Context::Scope context_scope(context()->v8_context()); 278 v8::Context::Scope context_scope(context()->v8_context());
279 279
280 v8::Handle<v8::Value> callback_args[3]; 280 v8::Local<v8::Value> callback_args[3];
281 callback_args[0] = v8::Null(isolate); 281 callback_args[0] = v8::Null(isolate);
282 callback_args[1] = v8::Null(isolate); 282 callback_args[1] = v8::Null(isolate);
283 283
284 if (stream1) { 284 if (stream1) {
285 const int stream1_id = last_transport_id_++; 285 const int stream1_id = last_transport_id_++;
286 callback_args[0] = v8::Integer::New(isolate, stream1_id); 286 callback_args[0] = v8::Integer::New(isolate, stream1_id);
287 rtp_stream_map_[stream1_id] = 287 rtp_stream_map_[stream1_id] =
288 linked_ptr<CastRtpStream>(stream1.release()); 288 linked_ptr<CastRtpStream>(stream1.release());
289 } 289 }
290 if (stream2) { 290 if (stream2) {
291 const int stream2_id = last_transport_id_++; 291 const int stream2_id = last_transport_id_++;
292 callback_args[1] = v8::Integer::New(isolate, stream2_id); 292 callback_args[1] = v8::Integer::New(isolate, stream2_id);
293 rtp_stream_map_[stream2_id] = 293 rtp_stream_map_[stream2_id] =
294 linked_ptr<CastRtpStream>(stream2.release()); 294 linked_ptr<CastRtpStream>(stream2.release());
295 } 295 }
296 const int udp_id = last_transport_id_++; 296 const int udp_id = last_transport_id_++;
297 udp_transport_map_[udp_id] = 297 udp_transport_map_[udp_id] =
298 linked_ptr<CastUdpTransport>(udp_transport.release()); 298 linked_ptr<CastUdpTransport>(udp_transport.release());
299 callback_args[2] = v8::Integer::New(isolate, udp_id); 299 callback_args[2] = v8::Integer::New(isolate, udp_id);
300 context()->CallFunction( 300 context()->CallFunction(
301 v8::Local<v8::Function>::New(isolate, create_callback_), 3, 301 v8::Local<v8::Function>::New(isolate, create_callback_), 3,
302 callback_args); 302 callback_args);
303 create_callback_.Reset(); 303 create_callback_.Reset();
304 } 304 }
305 305
306 void CastStreamingNativeHandler::CallStartCallback(int stream_id) { 306 void CastStreamingNativeHandler::CallStartCallback(int stream_id) {
307 v8::Isolate* isolate = context()->isolate(); 307 v8::Isolate* isolate = context()->isolate();
308 v8::HandleScope handle_scope(isolate); 308 v8::HandleScope handle_scope(isolate);
309 v8::Context::Scope context_scope(context()->v8_context()); 309 v8::Context::Scope context_scope(context()->v8_context());
310 v8::Handle<v8::Array> event_args = v8::Array::New(isolate, 1); 310 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 1);
311 event_args->Set(0, v8::Integer::New(isolate, stream_id)); 311 event_args->Set(0, v8::Integer::New(isolate, stream_id));
312 context()->DispatchEvent("cast.streaming.rtpStream.onStarted", event_args); 312 context()->DispatchEvent("cast.streaming.rtpStream.onStarted", event_args);
313 } 313 }
314 314
315 void CastStreamingNativeHandler::CallStopCallback(int stream_id) { 315 void CastStreamingNativeHandler::CallStopCallback(int stream_id) {
316 v8::Isolate* isolate = context()->isolate(); 316 v8::Isolate* isolate = context()->isolate();
317 v8::HandleScope handle_scope(isolate); 317 v8::HandleScope handle_scope(isolate);
318 v8::Context::Scope context_scope(context()->v8_context()); 318 v8::Context::Scope context_scope(context()->v8_context());
319 v8::Handle<v8::Array> event_args = v8::Array::New(isolate, 1); 319 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 1);
320 event_args->Set(0, v8::Integer::New(isolate, stream_id)); 320 event_args->Set(0, v8::Integer::New(isolate, stream_id));
321 context()->DispatchEvent("cast.streaming.rtpStream.onStopped", event_args); 321 context()->DispatchEvent("cast.streaming.rtpStream.onStopped", event_args);
322 } 322 }
323 323
324 void CastStreamingNativeHandler::CallErrorCallback(int stream_id, 324 void CastStreamingNativeHandler::CallErrorCallback(int stream_id,
325 const std::string& message) { 325 const std::string& message) {
326 v8::Isolate* isolate = context()->isolate(); 326 v8::Isolate* isolate = context()->isolate();
327 v8::HandleScope handle_scope(isolate); 327 v8::HandleScope handle_scope(isolate);
328 v8::Context::Scope context_scope(context()->v8_context()); 328 v8::Context::Scope context_scope(context()->v8_context());
329 v8::Handle<v8::Array> event_args = v8::Array::New(isolate, 2); 329 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 2);
330 event_args->Set(0, v8::Integer::New(isolate, stream_id)); 330 event_args->Set(0, v8::Integer::New(isolate, stream_id));
331 event_args->Set( 331 event_args->Set(
332 1, 332 1,
333 v8::String::NewFromUtf8( 333 v8::String::NewFromUtf8(
334 isolate, message.data(), v8::String::kNormalString, message.size())); 334 isolate, message.data(), v8::String::kNormalString, message.size()));
335 context()->DispatchEvent("cast.streaming.rtpStream.onError", event_args); 335 context()->DispatchEvent("cast.streaming.rtpStream.onError", event_args);
336 } 336 }
337 337
338 void CastStreamingNativeHandler::DestroyCastRtpStream( 338 void CastStreamingNativeHandler::DestroyCastRtpStream(
339 const v8::FunctionCallbackInfo<v8::Value>& args) { 339 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 11 matching lines...) Expand all
351 CHECK_EQ(1, args.Length()); 351 CHECK_EQ(1, args.Length());
352 CHECK(args[0]->IsInt32()); 352 CHECK(args[0]->IsInt32());
353 353
354 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value(); 354 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
355 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id); 355 CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
356 if (!transport) 356 if (!transport)
357 return; 357 return;
358 358
359 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 359 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
360 std::vector<CastRtpParams> cast_params = transport->GetSupportedParams(); 360 std::vector<CastRtpParams> cast_params = transport->GetSupportedParams();
361 v8::Handle<v8::Array> result = 361 v8::Local<v8::Array> result =
362 v8::Array::New(args.GetIsolate(), 362 v8::Array::New(args.GetIsolate(),
363 static_cast<int>(cast_params.size())); 363 static_cast<int>(cast_params.size()));
364 for (size_t i = 0; i < cast_params.size(); ++i) { 364 for (size_t i = 0; i < cast_params.size(); ++i) {
365 RtpParams params; 365 RtpParams params;
366 FromCastRtpParams(cast_params[i], &params); 366 FromCastRtpParams(cast_params[i], &params);
367 scoped_ptr<base::DictionaryValue> params_value = params.ToValue(); 367 scoped_ptr<base::DictionaryValue> params_value = params.ToValue();
368 result->Set( 368 result->Set(
369 static_cast<int>(i), 369 static_cast<int>(i),
370 converter->ToV8Value(params_value.get(), context()->v8_context())); 370 converter->ToV8Value(params_value.get(), context()->v8_context()));
371 } 371 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 scoped_ptr<base::BinaryValue> raw_events) { 561 scoped_ptr<base::BinaryValue> raw_events) {
562 v8::Isolate* isolate = context()->isolate(); 562 v8::Isolate* isolate = context()->isolate();
563 v8::HandleScope handle_scope(isolate); 563 v8::HandleScope handle_scope(isolate);
564 v8::Context::Scope context_scope(context()->v8_context()); 564 v8::Context::Scope context_scope(context()->v8_context());
565 565
566 RtpStreamCallbackMap::iterator it = 566 RtpStreamCallbackMap::iterator it =
567 get_raw_events_callbacks_.find(transport_id); 567 get_raw_events_callbacks_.find(transport_id);
568 if (it == get_raw_events_callbacks_.end()) 568 if (it == get_raw_events_callbacks_.end())
569 return; 569 return;
570 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 570 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
571 v8::Handle<v8::Value> callback_args[] = { 571 v8::Local<v8::Value> callback_args[] = {
572 converter->ToV8Value(raw_events.get(), context()->v8_context())}; 572 converter->ToV8Value(raw_events.get(), context()->v8_context())};
573 context()->CallFunction(v8::Local<v8::Function>::New(isolate, *it->second), 573 context()->CallFunction(v8::Local<v8::Function>::New(isolate, *it->second),
574 arraysize(callback_args), callback_args); 574 arraysize(callback_args), callback_args);
575 get_raw_events_callbacks_.erase(it); 575 get_raw_events_callbacks_.erase(it);
576 } 576 }
577 577
578 void CastStreamingNativeHandler::CallGetStatsCallback( 578 void CastStreamingNativeHandler::CallGetStatsCallback(
579 int transport_id, 579 int transport_id,
580 scoped_ptr<base::DictionaryValue> stats) { 580 scoped_ptr<base::DictionaryValue> stats) {
581 v8::Isolate* isolate = context()->isolate(); 581 v8::Isolate* isolate = context()->isolate();
582 v8::HandleScope handle_scope(isolate); 582 v8::HandleScope handle_scope(isolate);
583 v8::Context::Scope context_scope(context()->v8_context()); 583 v8::Context::Scope context_scope(context()->v8_context());
584 584
585 RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id); 585 RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id);
586 if (it == get_stats_callbacks_.end()) 586 if (it == get_stats_callbacks_.end())
587 return; 587 return;
588 588
589 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 589 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
590 v8::Handle<v8::Value> callback_args[] = { 590 v8::Local<v8::Value> callback_args[] = {
591 converter->ToV8Value(stats.get(), context()->v8_context())}; 591 converter->ToV8Value(stats.get(), context()->v8_context())};
592 context()->CallFunction(v8::Local<v8::Function>::New(isolate, *it->second), 592 context()->CallFunction(v8::Local<v8::Function>::New(isolate, *it->second),
593 arraysize(callback_args), callback_args); 593 arraysize(callback_args), callback_args);
594 get_stats_callbacks_.erase(it); 594 get_stats_callbacks_.erase(it);
595 } 595 }
596 596
597 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow( 597 CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow(
598 int transport_id) const { 598 int transport_id) const {
599 RtpStreamMap::const_iterator iter = rtp_stream_map_.find( 599 RtpStreamMap::const_iterator iter = rtp_stream_map_.find(
600 transport_id); 600 transport_id);
(...skipping 12 matching lines...) Expand all
613 if (iter != udp_transport_map_.end()) 613 if (iter != udp_transport_map_.end())
614 return iter->second.get(); 614 return iter->second.get();
615 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 615 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
616 isolate->ThrowException(v8::Exception::RangeError( 616 isolate->ThrowException(v8::Exception::RangeError(
617 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound))); 617 v8::String::NewFromUtf8(isolate, kUdpTransportNotFound)));
618 return NULL; 618 return NULL;
619 } 619 }
620 620
621 bool CastStreamingNativeHandler::FrameReceiverConfigFromArg( 621 bool CastStreamingNativeHandler::FrameReceiverConfigFromArg(
622 v8::Isolate* isolate, 622 v8::Isolate* isolate,
623 const v8::Handle<v8::Value>& arg, 623 const v8::Local<v8::Value>& arg,
624 media::cast::FrameReceiverConfig* config) { 624 media::cast::FrameReceiverConfig* config) {
625 625
626 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 626 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
627 scoped_ptr<base::Value> params_value( 627 scoped_ptr<base::Value> params_value(
628 converter->FromV8Value(arg, context()->v8_context())); 628 converter->FromV8Value(arg, context()->v8_context()));
629 if (!params_value) { 629 if (!params_value) {
630 isolate->ThrowException(v8::Exception::TypeError( 630 isolate->ThrowException(v8::Exception::TypeError(
631 v8::String::NewFromUtf8(isolate, kUnableToConvertParams))); 631 v8::String::NewFromUtf8(isolate, kUnableToConvertParams)));
632 return false; 632 return false;
633 } 633 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 !HexDecode(*params->aes_iv_mask, &config->aes_iv_mask)) { 687 !HexDecode(*params->aes_iv_mask, &config->aes_iv_mask)) {
688 isolate->ThrowException(v8::Exception::Error( 688 isolate->ThrowException(v8::Exception::Error(
689 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask))); 689 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask)));
690 return false; 690 return false;
691 } 691 }
692 return true; 692 return true;
693 } 693 }
694 694
695 bool CastStreamingNativeHandler::IPEndPointFromArg( 695 bool CastStreamingNativeHandler::IPEndPointFromArg(
696 v8::Isolate* isolate, 696 v8::Isolate* isolate,
697 const v8::Handle<v8::Value>& arg, 697 const v8::Local<v8::Value>& arg,
698 net::IPEndPoint* ip_endpoint) { 698 net::IPEndPoint* ip_endpoint) {
699 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 699 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
700 scoped_ptr<base::Value> destination_value( 700 scoped_ptr<base::Value> destination_value(
701 converter->FromV8Value(arg, context()->v8_context())); 701 converter->FromV8Value(arg, context()->v8_context()));
702 if (!destination_value) { 702 if (!destination_value) {
703 isolate->ThrowException(v8::Exception::TypeError( 703 isolate->ThrowException(v8::Exception::TypeError(
704 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask))); 704 v8::String::NewFromUtf8(isolate, kInvalidAesIvMask)));
705 return false; 705 return false;
706 } 706 }
707 scoped_ptr<IPEndPoint> destination = 707 scoped_ptr<IPEndPoint> destination =
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 806 }
807 } 807 }
808 } 808 }
809 809
810 if (!options) { 810 if (!options) {
811 options = new base::DictionaryValue(); 811 options = new base::DictionaryValue();
812 } 812 }
813 813
814 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent error_callback; 814 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent error_callback;
815 error_callback.Reset(args.GetIsolate(), 815 error_callback.Reset(args.GetIsolate(),
816 v8::Handle<v8::Function>(args[7].As<v8::Function>())); 816 v8::Local<v8::Function>(args[7].As<v8::Function>()));
817 817
818 session->Start( 818 session->Start(
819 audio_config, 819 audio_config,
820 video_config, 820 video_config,
821 local_endpoint, 821 local_endpoint,
822 remote_endpoint, 822 remote_endpoint,
823 make_scoped_ptr(options), 823 make_scoped_ptr(options),
824 capture_format, 824 capture_format,
825 base::Bind(&CastStreamingNativeHandler::AddTracksToMediaStream, 825 base::Bind(&CastStreamingNativeHandler::AddTracksToMediaStream,
826 weak_factory_.GetWeakPtr(), 826 weak_factory_.GetWeakPtr(),
827 url, 827 url,
828 params), 828 params),
829 base::Bind(&CastStreamingNativeHandler::CallReceiverErrorCallback, 829 base::Bind(&CastStreamingNativeHandler::CallReceiverErrorCallback,
830 weak_factory_.GetWeakPtr(), 830 weak_factory_.GetWeakPtr(),
831 error_callback)); 831 error_callback));
832 } 832 }
833 833
834 void CastStreamingNativeHandler::CallReceiverErrorCallback( 834 void CastStreamingNativeHandler::CallReceiverErrorCallback(
835 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent function, 835 v8::CopyablePersistentTraits<v8::Function>::CopyablePersistent function,
836 const std::string& error_message) { 836 const std::string& error_message) {
837 v8::Isolate* isolate = context()->v8_context()->GetIsolate(); 837 v8::Isolate* isolate = context()->v8_context()->GetIsolate();
838 v8::Handle<v8::Value> arg = v8::String::NewFromUtf8(isolate, 838 v8::Local<v8::Value> arg = v8::String::NewFromUtf8(isolate,
839 error_message.data(), 839 error_message.data(),
840 v8::String::kNormalString, 840 v8::String::kNormalString,
841 error_message.size()); 841 error_message.size());
842 context()->CallFunction( 842 context()->CallFunction(
843 v8::Local<v8::Function>::New(isolate, function), 1, &arg); 843 v8::Local<v8::Function>::New(isolate, function), 1, &arg);
844 } 844 }
845 845
846 846
847 void CastStreamingNativeHandler::AddTracksToMediaStream( 847 void CastStreamingNativeHandler::AddTracksToMediaStream(
848 const std::string& url, 848 const std::string& url,
849 const media::AudioParameters& params, 849 const media::AudioParameters& params,
850 scoped_refptr<media::AudioCapturerSource> audio, 850 scoped_refptr<media::AudioCapturerSource> audio,
851 scoped_ptr<media::VideoCapturerSource> video) { 851 scoped_ptr<media::VideoCapturerSource> video) {
852 content::AddAudioTrackToMediaStream(audio, params, true, true, url); 852 content::AddAudioTrackToMediaStream(audio, params, true, true, url);
853 content::AddVideoTrackToMediaStream(video.Pass(), true, true, url); 853 content::AddVideoTrackToMediaStream(video.Pass(), true, true, url);
854 } 854 }
855 855
856 } // namespace extensions 856 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/cast_streaming_native_handler.h ('k') | chrome/renderer/extensions/webstore_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698