OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/renderer/display_source_custom_bindings.h" | 5 #include "extensions/renderer/display_source_custom_bindings.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/public/child/v8_value_converter.h" | 8 #include "content/public/child/v8_value_converter.h" |
9 #include "extensions/renderer/script_context.h" | 9 #include "extensions/renderer/script_context.h" |
10 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 10 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 GetChildValue(start_info, "authenticationInfo", isolate); | 126 GetChildValue(start_info, "authenticationInfo", isolate); |
127 if (!auth_info_v8_val->IsNull()) { | 127 if (!auth_info_v8_val->IsNull()) { |
128 CHECK(auth_info_v8_val->IsObject()); | 128 CHECK(auth_info_v8_val->IsObject()); |
129 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 129 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
130 scoped_ptr<base::Value> auth_info_val( | 130 scoped_ptr<base::Value> auth_info_val( |
131 converter->FromV8Value(auth_info_v8_val, context()->v8_context())); | 131 converter->FromV8Value(auth_info_v8_val, context()->v8_context())); |
132 CHECK(auth_info_val); | 132 CHECK(auth_info_val); |
133 auth_info = DisplaySourceAuthInfo::FromValue(*auth_info_val); | 133 auth_info = DisplaySourceAuthInfo::FromValue(*auth_info_val); |
134 } | 134 } |
135 | 135 |
| 136 DisplaySourceSessionParams session_params; |
| 137 session_params.sink_id = sink_id; |
| 138 session_params.video_track = video_track; |
| 139 session_params.audio_track = audio_track; |
| 140 session_params.render_frame = context()->GetRenderFrame(); |
| 141 if (auth_info) { |
| 142 session_params.auth_method = auth_info->method; |
| 143 session_params.auth_data = auth_info->data ? *auth_info->data : ""; |
| 144 } |
136 scoped_ptr<DisplaySourceSession> session = | 145 scoped_ptr<DisplaySourceSession> session = |
137 DisplaySourceSessionFactory::CreateSession( | 146 DisplaySourceSessionFactory::CreateSession(session_params); |
138 sink_id, video_track, audio_track, std::move(auth_info)); | |
139 if (!session) { | 147 if (!session) { |
140 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( | 148 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( |
141 isolate, kErrorNotSupported))); | 149 isolate, kErrorNotSupported))); |
142 return; | 150 return; |
143 } | 151 } |
144 | 152 |
145 auto on_started_callback = base::Bind( | 153 auto on_started_callback = base::Bind( |
146 &DisplaySourceCustomBindings::OnSessionStarted, | 154 &DisplaySourceCustomBindings::OnSessionStarted, |
147 weak_factory_.GetWeakPtr()); | 155 weak_factory_.GetWeakPtr()); |
148 auto on_terminated_callback = base::Bind( | 156 auto on_terminated_callback = base::Bind( |
149 &DisplaySourceCustomBindings::OnSessionTerminated, | 157 &DisplaySourceCustomBindings::OnSessionTerminated, |
150 weak_factory_.GetWeakPtr()); | 158 weak_factory_.GetWeakPtr()); |
151 auto on_error_callback = base::Bind( | 159 auto on_error_callback = base::Bind( |
152 &DisplaySourceCustomBindings::OnSessionError, | 160 &DisplaySourceCustomBindings::OnSessionError, |
153 weak_factory_.GetWeakPtr()); | 161 weak_factory_.GetWeakPtr()); |
154 session->SetCallbacks(on_started_callback, | 162 session->SetCallbacks(on_started_callback, |
155 on_terminated_callback, | 163 on_terminated_callback, |
156 on_error_callback); | 164 on_error_callback); |
| 165 session->Start(); |
157 session_map_.insert(std::make_pair(sink_id, std::move(session))); | 166 session_map_.insert(std::make_pair(sink_id, std::move(session))); |
158 session->Start(); | |
159 } | 167 } |
160 | 168 |
161 void DisplaySourceCustomBindings::TerminateSession( | 169 void DisplaySourceCustomBindings::TerminateSession( |
162 const v8::FunctionCallbackInfo<v8::Value>& args) { | 170 const v8::FunctionCallbackInfo<v8::Value>& args) { |
163 CHECK_EQ(1, args.Length()); | 171 CHECK_EQ(1, args.Length()); |
164 CHECK(args[0]->IsInt32()); | 172 CHECK(args[0]->IsInt32()); |
165 | 173 |
166 v8::Isolate* isolate = context()->isolate(); | 174 v8::Isolate* isolate = context()->isolate(); |
167 int sink_id = args[0]->ToInt32(args.GetIsolate())->Value(); | 175 int sink_id = args[0]->ToInt32(args.GetIsolate())->Value(); |
168 DisplaySourceSession* session = GetDisplaySession(sink_id); | 176 DisplaySourceSession* session = GetDisplaySession(sink_id); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 CHECK(session); | 257 CHECK(session); |
250 if (session->state() == DisplaySourceSession::Establishing) { | 258 if (session->state() == DisplaySourceSession::Establishing) { |
251 // Error has occured before the session has actually started. | 259 // Error has occured before the session has actually started. |
252 session_map_.erase(sink_id); | 260 session_map_.erase(sink_id); |
253 } | 261 } |
254 | 262 |
255 DispatchSessionError(sink_id, type, message); | 263 DispatchSessionError(sink_id, type, message); |
256 } | 264 } |
257 | 265 |
258 } // extensions | 266 } // extensions |
OLD | NEW |