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