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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 audio_track = | 122 audio_track = |
123 blink::WebDOMMediaStreamTrack::fromV8Value( | 123 blink::WebDOMMediaStreamTrack::fromV8Value( |
124 audio_stream_val).component(); | 124 audio_stream_val).component(); |
125 if (audio_track.isNull()) { | 125 if (audio_track.isNull()) { |
126 isolate->ThrowException(v8::Exception::Error( | 126 isolate->ThrowException(v8::Exception::Error( |
127 v8::String::NewFromUtf8(isolate, kInvalidStreamArgs))); | 127 v8::String::NewFromUtf8(isolate, kInvalidStreamArgs))); |
128 return; | 128 return; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 scoped_ptr<DisplaySourceAuthInfo> auth_info; | 132 std::unique_ptr<DisplaySourceAuthInfo> auth_info; |
133 v8::Local<v8::Value> auth_info_v8_val = | 133 v8::Local<v8::Value> auth_info_v8_val = |
134 GetChildValue(start_info, "authenticationInfo", isolate); | 134 GetChildValue(start_info, "authenticationInfo", isolate); |
135 if (!auth_info_v8_val->IsNull()) { | 135 if (!auth_info_v8_val->IsNull()) { |
136 CHECK(auth_info_v8_val->IsObject()); | 136 CHECK(auth_info_v8_val->IsObject()); |
137 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 137 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
138 scoped_ptr<base::Value> auth_info_val( | 138 std::unique_ptr<base::Value> auth_info_val( |
139 converter->FromV8Value(auth_info_v8_val, context()->v8_context())); | 139 converter->FromV8Value(auth_info_v8_val, context()->v8_context())); |
140 CHECK(auth_info_val); | 140 CHECK(auth_info_val); |
141 auth_info = DisplaySourceAuthInfo::FromValue(*auth_info_val); | 141 auth_info = DisplaySourceAuthInfo::FromValue(*auth_info_val); |
142 } | 142 } |
143 | 143 |
144 DisplaySourceSessionParams session_params; | 144 DisplaySourceSessionParams session_params; |
145 session_params.sink_id = sink_id; | 145 session_params.sink_id = sink_id; |
146 session_params.video_track = video_track; | 146 session_params.video_track = video_track; |
147 session_params.audio_track = audio_track; | 147 session_params.audio_track = audio_track; |
148 session_params.render_frame = context()->GetRenderFrame(); | 148 session_params.render_frame = context()->GetRenderFrame(); |
149 if (auth_info) { | 149 if (auth_info) { |
150 session_params.auth_method = auth_info->method; | 150 session_params.auth_method = auth_info->method; |
151 session_params.auth_data = auth_info->data ? *auth_info->data : ""; | 151 session_params.auth_data = auth_info->data ? *auth_info->data : ""; |
152 } | 152 } |
153 scoped_ptr<DisplaySourceSession> session = | 153 std::unique_ptr<DisplaySourceSession> session = |
154 DisplaySourceSessionFactory::CreateSession(session_params); | 154 DisplaySourceSessionFactory::CreateSession(session_params); |
155 if (!session) { | 155 if (!session) { |
156 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( | 156 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( |
157 isolate, kErrorNotSupported))); | 157 isolate, kErrorNotSupported))); |
158 return; | 158 return; |
159 } | 159 } |
160 | 160 |
161 auto on_terminated_callback = | 161 auto on_terminated_callback = |
162 base::Bind(&DisplaySourceCustomBindings::OnSessionTerminated, | 162 base::Bind(&DisplaySourceCustomBindings::OnSessionTerminated, |
163 weak_factory_.GetWeakPtr(), sink_id); | 163 weak_factory_.GetWeakPtr(), sink_id); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 const std::string& message) const { | 264 const std::string& message) const { |
265 v8::Isolate* isolate = context()->isolate(); | 265 v8::Isolate* isolate = context()->isolate(); |
266 v8::HandleScope handle_scope(isolate); | 266 v8::HandleScope handle_scope(isolate); |
267 v8::Context::Scope context_scope(context()->v8_context()); | 267 v8::Context::Scope context_scope(context()->v8_context()); |
268 | 268 |
269 api::display_source::ErrorInfo error_info; | 269 api::display_source::ErrorInfo error_info; |
270 error_info.type = type; | 270 error_info.type = type; |
271 if (!message.empty()) | 271 if (!message.empty()) |
272 error_info.description.reset(new std::string(message)); | 272 error_info.description.reset(new std::string(message)); |
273 | 273 |
274 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 274 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
275 v8::Local<v8::Value> info_arg = | 275 v8::Local<v8::Value> info_arg = |
276 converter->ToV8Value(error_info.ToValue().get(), | 276 converter->ToV8Value(error_info.ToValue().get(), |
277 context()->v8_context()); | 277 context()->v8_context()); |
278 | 278 |
279 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 2); | 279 v8::Local<v8::Array> event_args = v8::Array::New(isolate, 2); |
280 event_args->Set(0, v8::Integer::New(isolate, sink_id)); | 280 event_args->Set(0, v8::Integer::New(isolate, sink_id)); |
281 event_args->Set(1, info_arg); | 281 event_args->Set(1, info_arg); |
282 context()->DispatchEvent("displaySource.onSessionErrorOccured", event_args); | 282 context()->DispatchEvent("displaySource.onSessionErrorOccured", event_args); |
283 } | 283 } |
284 | 284 |
(...skipping 12 matching lines...) Expand all Loading... |
297 } | 297 } |
298 | 298 |
299 void DisplaySourceCustomBindings::OnSessionError(int sink_id, | 299 void DisplaySourceCustomBindings::OnSessionError(int sink_id, |
300 DisplaySourceErrorType type, | 300 DisplaySourceErrorType type, |
301 const std::string& message) { | 301 const std::string& message) { |
302 CHECK(GetDisplaySession(sink_id)); | 302 CHECK(GetDisplaySession(sink_id)); |
303 DispatchSessionError(sink_id, type, message); | 303 DispatchSessionError(sink_id, type, message); |
304 } | 304 } |
305 | 305 |
306 } // extensions | 306 } // extensions |
OLD | NEW |