Chromium Code Reviews| Index: chrome/renderer/extensions/cast_streaming_native_handler.cc |
| diff --git a/chrome/renderer/extensions/cast_streaming_native_handler.cc b/chrome/renderer/extensions/cast_streaming_native_handler.cc |
| index 284ad774ef33df6d214d3ada1426fcd2d5184ca9..38a957d5bf3e6bee6e29f908ac47c1a0c9296901 100644 |
| --- a/chrome/renderer/extensions/cast_streaming_native_handler.cc |
| +++ b/chrome/renderer/extensions/cast_streaming_native_handler.cc |
| @@ -38,8 +38,10 @@ const char kInvalidDestination[] = "Invalid destination"; |
| const char kInvalidRtpParams[] = "Invalid value for RTP params"; |
| const char kInvalidAesKey[] = "Invalid value for AES key"; |
| const char kInvalidAesIvMask[] = "Invalid value for AES IV mask"; |
| +const char kInvalidStreamArgs[] = "Invalid stream arguments"; |
| const char kUnableToConvertArgs[] = "Unable to convert arguments"; |
| const char kUnableToConvertParams[] = "Unable to convert params"; |
| +const int kInvalidId = 0; |
| // These helper methods are used to convert between Extension API |
| // types and Cast types. |
| @@ -196,24 +198,29 @@ CastStreamingNativeHandler::~CastStreamingNativeHandler() { |
| void CastStreamingNativeHandler::CreateCastSession( |
| const v8::FunctionCallbackInfo<v8::Value>& args) { |
| CHECK_EQ(3, args.Length()); |
| - CHECK(args[0]->IsObject()); |
| - CHECK(args[1]->IsObject()); |
| CHECK(args[2]->IsFunction()); |
| - blink::WebDOMMediaStreamTrack track1 = |
| - blink::WebDOMMediaStreamTrack::fromV8Value(args[0]); |
| - if (track1.isNull()) |
| - return; |
| - blink::WebDOMMediaStreamTrack track2 = |
| - blink::WebDOMMediaStreamTrack::fromV8Value(args[1]); |
| - if (track2.isNull()) |
| + if (args[0]->IsNull() && args[1]->IsNull()) { |
| + v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
| + isolate->ThrowException(v8::Exception::Error( |
| + v8::String::NewFromUtf8(isolate, kInvalidStreamArgs))); |
| return; |
| + } |
| scoped_refptr<CastSession> session(new CastSession()); |
| - scoped_ptr<CastRtpStream> stream1( |
| - new CastRtpStream(track1.component(), session)); |
| - scoped_ptr<CastRtpStream> stream2( |
| - new CastRtpStream(track2.component(), session)); |
| + scoped_ptr<CastRtpStream> stream1, stream2; |
| + if (!args[0]->IsNull()) { |
| + CHECK(args[0]->IsObject()); |
| + blink::WebDOMMediaStreamTrack track = |
| + blink::WebDOMMediaStreamTrack::fromV8Value(args[0]); |
| + stream1.reset(new CastRtpStream(track.component(), session)); |
| + } |
| + if (!args[1]->IsNull()) { |
| + CHECK(args[1]->IsObject()); |
| + blink::WebDOMMediaStreamTrack track = |
| + blink::WebDOMMediaStreamTrack::fromV8Value(args[1]); |
| + stream2.reset(new CastRtpStream(track.component(), session)); |
| + } |
| scoped_ptr<CastUdpTransport> udp_transport( |
| new CastUdpTransport(session)); |
| @@ -239,19 +246,30 @@ void CastStreamingNativeHandler::CallCreateCallback( |
| v8::HandleScope handle_scope(isolate); |
| v8::Context::Scope context_scope(context()->v8_context()); |
| - const int stream1_id = last_transport_id_++; |
| - rtp_stream_map_[stream1_id] = |
| - linked_ptr<CastRtpStream>(stream1.release()); |
| - const int stream2_id = last_transport_id_++; |
| - rtp_stream_map_[stream2_id] = |
| - linked_ptr<CastRtpStream>(stream2.release()); |
| + int stream1_id = kInvalidId; |
| + int stream2_id = kInvalidId; |
| + |
| + if (stream1) { |
| + stream1_id = last_transport_id_++; |
| + rtp_stream_map_[stream1_id] = |
| + linked_ptr<CastRtpStream>(stream1.release()); |
| + } |
| + if (stream2) { |
| + stream2_id = last_transport_id_++; |
| + rtp_stream_map_[stream2_id] = |
| + linked_ptr<CastRtpStream>(stream2.release()); |
| + } |
| const int udp_id = last_transport_id_++; |
| udp_transport_map_[udp_id] = |
| linked_ptr<CastUdpTransport>(udp_transport.release()); |
| v8::Handle<v8::Value> callback_args[3]; |
| - callback_args[0] = v8::Integer::New(isolate, stream1_id); |
| - callback_args[1] = v8::Integer::New(isolate, stream2_id); |
| + callback_args[0] = v8::Null(isolate); |
| + callback_args[1] = v8::Null(isolate); |
| + if (stream1_id != kInvalidId) |
| + callback_args[0] = v8::Integer::New(isolate, stream1_id); |
|
not at google - send to devlin
2014/07/15 23:32:18
can you put this up where it's guarded by the if (
Alpha Left Google
2014/07/15 23:48:42
Done.
|
| + if (stream2_id != kInvalidId) |
| + callback_args[1] = v8::Integer::New(isolate, stream2_id); |
| callback_args[2] = v8::Integer::New(isolate, udp_id); |
| context()->CallFunction(create_callback_.NewHandle(isolate), |
| 3, callback_args); |
| @@ -537,11 +555,11 @@ void CastStreamingNativeHandler::CallGetStatsCallback( |
| CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow( |
| int transport_id) const { |
| + v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
|
not at google - send to devlin
2014/07/15 23:32:18
this change doesn't seem necessary
Alpha Left Google
2014/07/15 23:48:42
Done.
|
| RtpStreamMap::const_iterator iter = rtp_stream_map_.find( |
| transport_id); |
| if (iter != rtp_stream_map_.end()) |
| return iter->second.get(); |
| - v8::Isolate* isolate = context()->v8_context()->GetIsolate(); |
| isolate->ThrowException(v8::Exception::RangeError(v8::String::NewFromUtf8( |
| isolate, kRtpStreamNotFound))); |
| return NULL; |