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

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

Issue 2770403002: [Extensions Bindings] Remove ScriptContext::DispatchEvent (Closed)
Patch Set: Created 3 years, 9 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 15 matching lines...) Expand all
26 #include "chrome/common/extensions/api/cast_streaming_receiver_session.h" 26 #include "chrome/common/extensions/api/cast_streaming_receiver_session.h"
27 #include "chrome/common/extensions/api/cast_streaming_rtp_stream.h" 27 #include "chrome/common/extensions/api/cast_streaming_rtp_stream.h"
28 #include "chrome/common/extensions/api/cast_streaming_udp_transport.h" 28 #include "chrome/common/extensions/api/cast_streaming_udp_transport.h"
29 #include "chrome/renderer/media/cast_receiver_session.h" 29 #include "chrome/renderer/media/cast_receiver_session.h"
30 #include "chrome/renderer/media/cast_rtp_stream.h" 30 #include "chrome/renderer/media/cast_rtp_stream.h"
31 #include "chrome/renderer/media/cast_session.h" 31 #include "chrome/renderer/media/cast_session.h"
32 #include "chrome/renderer/media/cast_udp_transport.h" 32 #include "chrome/renderer/media/cast_udp_transport.h"
33 #include "content/public/child/v8_value_converter.h" 33 #include "content/public/child/v8_value_converter.h"
34 #include "content/public/renderer/media_stream_utils.h" 34 #include "content/public/renderer/media_stream_utils.h"
35 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 #include "extensions/renderer/extension_bindings_system.h"
36 #include "extensions/renderer/script_context.h" 37 #include "extensions/renderer/script_context.h"
37 #include "media/base/audio_parameters.h" 38 #include "media/base/audio_parameters.h"
38 #include "media/base/limits.h" 39 #include "media/base/limits.h"
39 #include "net/base/host_port_pair.h" 40 #include "net/base/host_port_pair.h"
40 #include "net/base/ip_address.h" 41 #include "net/base/ip_address.h"
41 #include "third_party/WebKit/public/platform/WebMediaStream.h" 42 #include "third_party/WebKit/public/platform/WebMediaStream.h"
42 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 43 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
43 #include "third_party/WebKit/public/platform/WebURL.h" 44 #include "third_party/WebKit/public/platform/WebURL.h"
44 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" 45 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h"
45 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" 46 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 288
288 } // namespace 289 } // namespace
289 290
290 // |last_transport_id_| is the identifier for the next created RTP stream. To 291 // |last_transport_id_| is the identifier for the next created RTP stream. To
291 // create globally unique IDs used for referring to RTP stream objects in 292 // create globally unique IDs used for referring to RTP stream objects in
292 // browser process, we set its higher 16 bits as HASH(extension_id)&0x7fff, and 293 // browser process, we set its higher 16 bits as HASH(extension_id)&0x7fff, and
293 // lower 16 bits as the sequence number of the RTP stream created in the same 294 // lower 16 bits as the sequence number of the RTP stream created in the same
294 // extension. Collision will happen when the first RTP stream keeps alive after 295 // extension. Collision will happen when the first RTP stream keeps alive after
295 // creating another 64k-1 RTP streams in the same extension, which is very 296 // creating another 64k-1 RTP streams in the same extension, which is very
296 // unlikely to happen in normal use cases. 297 // unlikely to happen in normal use cases.
297 CastStreamingNativeHandler::CastStreamingNativeHandler(ScriptContext* context) 298 CastStreamingNativeHandler::CastStreamingNativeHandler(
299 ScriptContext* context,
300 ExtensionBindingsSystem* bindings_system)
298 : ObjectBackedNativeHandler(context), 301 : ObjectBackedNativeHandler(context),
299 last_transport_id_( 302 last_transport_id_(
300 context->extension() 303 context->extension()
301 ? (((base::Hash(context->extension()->id()) & 0x7fff) << 16) + 1) 304 ? (((base::Hash(context->extension()->id()) & 0x7fff) << 16) + 1)
302 : 1), 305 : 1),
306 bindings_system_(bindings_system),
303 weak_factory_(this) { 307 weak_factory_(this) {
304 RouteFunction("CreateSession", "cast.streaming.session", 308 RouteFunction("CreateSession", "cast.streaming.session",
305 base::Bind(&CastStreamingNativeHandler::CreateCastSession, 309 base::Bind(&CastStreamingNativeHandler::CreateCastSession,
306 weak_factory_.GetWeakPtr())); 310 weak_factory_.GetWeakPtr()));
307 RouteFunction("DestroyCastRtpStream", "cast.streaming.rtpStream", 311 RouteFunction("DestroyCastRtpStream", "cast.streaming.rtpStream",
308 base::Bind(&CastStreamingNativeHandler::DestroyCastRtpStream, 312 base::Bind(&CastStreamingNativeHandler::DestroyCastRtpStream,
309 weak_factory_.GetWeakPtr())); 313 weak_factory_.GetWeakPtr()));
310 RouteFunction( 314 RouteFunction(
311 "GetSupportedParamsCastRtpStream", "cast.streaming.rtpStream", 315 "GetSupportedParamsCastRtpStream", "cast.streaming.rtpStream",
312 base::Bind(&CastStreamingNativeHandler::GetSupportedParamsCastRtpStream, 316 base::Bind(&CastStreamingNativeHandler::GetSupportedParamsCastRtpStream,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 const int udp_id = last_transport_id_++; 444 const int udp_id = last_transport_id_++;
441 udp_transport_map_[udp_id] = std::move(udp_transport); 445 udp_transport_map_[udp_id] = std::move(udp_transport);
442 callback_args[2] = v8::Integer::New(isolate, udp_id); 446 callback_args[2] = v8::Integer::New(isolate, udp_id);
443 context()->SafeCallFunction( 447 context()->SafeCallFunction(
444 v8::Local<v8::Function>::New(isolate, create_callback_), 3, 448 v8::Local<v8::Function>::New(isolate, create_callback_), 3,
445 callback_args); 449 callback_args);
446 create_callback_.Reset(); 450 create_callback_.Reset();
447 } 451 }
448 452
449 void CastStreamingNativeHandler::CallStartCallback(int stream_id) const { 453 void CastStreamingNativeHandler::CallStartCallback(int stream_id) const {
450 v8::Isolate* isolate = context()->isolate(); 454 base::ListValue event_args;
451 v8::HandleScope handle_scope(isolate); 455 event_args.AppendInteger(stream_id);
452 v8::Context::Scope context_scope(context()->v8_context()); 456 bindings_system_->DispatchEventInContext("cast.streaming.rtpStream.onStarted",
453 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 1); 457 &event_args, nullptr, context());
454 event_args->Set(0, v8::Integer::New(isolate, stream_id));
455 context()->DispatchEvent("cast.streaming.rtpStream.onStarted", event_args);
456 } 458 }
457 459
458 void CastStreamingNativeHandler::CallStopCallback(int stream_id) const { 460 void CastStreamingNativeHandler::CallStopCallback(int stream_id) const {
459 v8::Isolate* isolate = context()->isolate(); 461 base::ListValue event_args;
460 v8::HandleScope handle_scope(isolate); 462 event_args.AppendInteger(stream_id);
461 v8::Context::Scope context_scope(context()->v8_context()); 463 bindings_system_->DispatchEventInContext("cast.streaming.rtpStream.onStopped",
462 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 1); 464 &event_args, nullptr, context());
463 event_args->Set(0, v8::Integer::New(isolate, stream_id));
464 context()->DispatchEvent("cast.streaming.rtpStream.onStopped", event_args);
465 } 465 }
466 466
467 void CastStreamingNativeHandler::CallErrorCallback( 467 void CastStreamingNativeHandler::CallErrorCallback(
468 int stream_id, 468 int stream_id,
469 const std::string& message) const { 469 const std::string& message) const {
470 v8::Isolate* isolate = context()->isolate(); 470 base::ListValue event_args;
471 v8::HandleScope handle_scope(isolate); 471 event_args.AppendInteger(stream_id);
472 v8::Context::Scope context_scope(context()->v8_context()); 472 event_args.AppendString(message);
473 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 2); 473 bindings_system_->DispatchEventInContext("cast.streaming.rtpStream.onError",
474 event_args->Set(0, v8::Integer::New(isolate, stream_id)); 474 &event_args, nullptr, context());
475 event_args->Set(
476 1,
477 v8::String::NewFromUtf8(
478 isolate, message.data(), v8::String::kNormalString, message.size()));
479 context()->DispatchEvent("cast.streaming.rtpStream.onError", event_args);
480 } 475 }
481 476
482 void CastStreamingNativeHandler::DestroyCastRtpStream( 477 void CastStreamingNativeHandler::DestroyCastRtpStream(
483 const v8::FunctionCallbackInfo<v8::Value>& args) { 478 const v8::FunctionCallbackInfo<v8::Value>& args) {
484 CHECK_EQ(1, args.Length()); 479 CHECK_EQ(1, args.Length());
485 CHECK(args[0]->IsInt32()); 480 CHECK(args[0]->IsInt32());
486 481
487 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value(); 482 const int transport_id = args[0]->ToInt32(args.GetIsolate())->Value();
488 if (!GetRtpStreamOrThrow(transport_id)) 483 if (!GetRtpStreamOrThrow(transport_id))
489 return; 484 return;
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 LOG(ERROR) << "Failed to add Cast audio track to media stream."; 989 LOG(ERROR) << "Failed to add Cast audio track to media stream.";
995 } 990 }
996 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote 991 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote
997 true, // is_readonly 992 true, // is_readonly
998 &web_stream)) { 993 &web_stream)) {
999 LOG(ERROR) << "Failed to add Cast video track to media stream."; 994 LOG(ERROR) << "Failed to add Cast video track to media stream.";
1000 } 995 }
1001 } 996 }
1002 997
1003 } // namespace extensions 998 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698