OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/client/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #if defined(OS_NACL) | |
12 #include <sys/mount.h> | |
13 #include <nacl_io/nacl_io.h> | |
14 #endif | |
15 | |
16 #include "base/bind.h" | 11 #include "base/bind.h" |
17 #include "base/callback.h" | 12 #include "base/callback.h" |
18 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
19 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
20 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
21 #include "base/logging.h" | 16 #include "base/logging.h" |
22 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
23 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
24 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
25 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
26 #include "base/values.h" | 21 #include "base/values.h" |
27 #include "crypto/random.h" | 22 #include "crypto/random.h" |
28 #include "jingle/glue/thread_wrapper.h" | 23 #include "jingle/glue/thread_wrapper.h" |
29 #include "media/base/yuv_convert.h" | 24 #include "media/base/media.h" |
30 #include "net/socket/ssl_server_socket.h" | 25 #include "net/socket/ssl_server_socket.h" |
31 #include "ppapi/cpp/completion_callback.h" | 26 #include "ppapi/cpp/completion_callback.h" |
32 #include "ppapi/cpp/dev/url_util_dev.h" | 27 #include "ppapi/cpp/dev/url_util_dev.h" |
33 #include "ppapi/cpp/image_data.h" | 28 #include "ppapi/cpp/image_data.h" |
34 #include "ppapi/cpp/input_event.h" | 29 #include "ppapi/cpp/input_event.h" |
35 #include "ppapi/cpp/rect.h" | 30 #include "ppapi/cpp/rect.h" |
36 #include "remoting/base/constants.h" | 31 #include "remoting/base/constants.h" |
37 #include "remoting/base/util.h" | 32 #include "remoting/base/util.h" |
38 #include "remoting/client/chromoting_client.h" | 33 #include "remoting/client/chromoting_client.h" |
39 #include "remoting/client/client_config.h" | 34 #include "remoting/client/client_config.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 initialized_(false), | 201 initialized_(false), |
207 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), | 202 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), |
208 context_(plugin_task_runner_.get()), | 203 context_(plugin_task_runner_.get()), |
209 input_tracker_(&mouse_input_filter_), | 204 input_tracker_(&mouse_input_filter_), |
210 key_mapper_(&input_tracker_), | 205 key_mapper_(&input_tracker_), |
211 normalizing_input_filter_(CreateNormalizingInputFilter(&key_mapper_)), | 206 normalizing_input_filter_(CreateNormalizingInputFilter(&key_mapper_)), |
212 input_handler_(this, normalizing_input_filter_.get()), | 207 input_handler_(this, normalizing_input_filter_.get()), |
213 use_async_pin_dialog_(false), | 208 use_async_pin_dialog_(false), |
214 use_media_source_rendering_(false), | 209 use_media_source_rendering_(false), |
215 weak_factory_(this) { | 210 weak_factory_(this) { |
216 #if defined(OS_NACL) | |
217 // In NaCl global resources need to be initialized differently because they | |
218 // are not shared with Chrome. | |
219 thread_task_runner_handle_.reset( | |
220 new base::ThreadTaskRunnerHandle(plugin_task_runner_)); | |
221 thread_wrapper_.reset( | |
222 new jingle_glue::JingleThreadWrapper(plugin_task_runner_)); | |
223 media::InitializeCPUSpecificYUVConversions(); | |
224 #else | |
225 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | |
226 #endif | |
227 | |
228 #if defined(OS_NACL) | |
229 nacl_io_init_ppapi(pp_instance, pp::Module::Get()->get_browser_interface()); | |
230 mount("", "/etc", "memfs", 0, ""); | |
231 mount("", "/usr", "memfs", 0, ""); | |
232 #endif | |
233 | |
234 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); | 211 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); |
235 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 212 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
236 | 213 |
237 // Resister this instance to handle debug log messsages. | 214 // Resister this instance to handle debug log messsages. |
238 RegisterLoggingInstance(); | 215 RegisterLoggingInstance(); |
239 | 216 |
240 #if defined(USE_OPENSSL) | 217 #if defined(USE_OPENSSL) |
241 // Initialize random seed for libjingle. It's necessary only with OpenSSL. | 218 // Initialize random seed for libjingle. It's necessary only with OpenSSL. |
242 char random_seed[kRandomSeedSize]; | 219 char random_seed[kRandomSeedSize]; |
243 crypto::RandBytes(random_seed, sizeof(random_seed)); | 220 crypto::RandBytes(random_seed, sizeof(random_seed)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 255 } |
279 | 256 |
280 bool ChromotingInstance::Init(uint32_t argc, | 257 bool ChromotingInstance::Init(uint32_t argc, |
281 const char* argn[], | 258 const char* argn[], |
282 const char* argv[]) { | 259 const char* argv[]) { |
283 CHECK(!initialized_); | 260 CHECK(!initialized_); |
284 initialized_ = true; | 261 initialized_ = true; |
285 | 262 |
286 VLOG(1) << "Started ChromotingInstance::Init"; | 263 VLOG(1) << "Started ChromotingInstance::Init"; |
287 | 264 |
288 // Check that the calling content is part of an app or extension. This is only | 265 // Check to make sure the media library is initialized. |
289 // necessary for non-PNaCl version of the plugin. Also PPB_URLUtil_Dev doesn't | 266 // http://crbug.com/91521. |
290 // work in NaCl at the moment so the check fails in NaCl builds. | 267 if (!media::IsMediaLibraryInitialized()) { |
291 #if !defined(OS_NACL) | 268 LOG(ERROR) << "Media library not initialized."; |
| 269 return false; |
| 270 } |
| 271 |
| 272 // Check that the calling content is part of an app or extension. |
292 if (!IsCallerAppOrExtension()) { | 273 if (!IsCallerAppOrExtension()) { |
293 LOG(ERROR) << "Not an app or extension"; | 274 LOG(ERROR) << "Not an app or extension"; |
294 return false; | 275 return false; |
295 } | 276 } |
296 #endif | |
297 | 277 |
298 // Start all the threads. | 278 // Start all the threads. |
299 context_.Start(); | 279 context_.Start(); |
300 | 280 |
301 return true; | 281 return true; |
302 } | 282 } |
303 | 283 |
304 void ChromotingInstance::HandleMessage(const pp::Var& message) { | 284 void ChromotingInstance::HandleMessage(const pp::Var& message) { |
305 if (!message.is_string()) { | 285 if (!message.is_string()) { |
306 LOG(ERROR) << "Received a message that is not a string."; | 286 LOG(ERROR) << "Received a message that is not a string."; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } else if (method == "allowMouseLock") { | 336 } else if (method == "allowMouseLock") { |
357 HandleAllowMouseLockMessage(); | 337 HandleAllowMouseLockMessage(); |
358 } else if (method == "enableMediaSourceRendering") { | 338 } else if (method == "enableMediaSourceRendering") { |
359 HandleEnableMediaSourceRendering(); | 339 HandleEnableMediaSourceRendering(); |
360 } | 340 } |
361 } | 341 } |
362 | 342 |
363 void ChromotingInstance::DidChangeFocus(bool has_focus) { | 343 void ChromotingInstance::DidChangeFocus(bool has_focus) { |
364 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 344 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
365 | 345 |
366 if (!IsConnected()) | |
367 return; | |
368 | |
369 input_handler_.DidChangeFocus(has_focus); | 346 input_handler_.DidChangeFocus(has_focus); |
370 } | 347 } |
371 | 348 |
372 void ChromotingInstance::DidChangeView(const pp::View& view) { | 349 void ChromotingInstance::DidChangeView(const pp::View& view) { |
373 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 350 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
374 | 351 |
375 plugin_view_ = view; | 352 plugin_view_ = view; |
376 mouse_input_filter_.set_input_size( | 353 mouse_input_filter_.set_input_size( |
377 webrtc::DesktopSize(view.GetRect().width(), view.GetRect().height())); | 354 webrtc::DesktopSize(view.GetRect().width(), view.GetRect().height())); |
378 | 355 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 } | 618 } |
642 } | 619 } |
643 | 620 |
644 ConnectWithConfig(config, local_jid); | 621 ConnectWithConfig(config, local_jid); |
645 } | 622 } |
646 | 623 |
647 void ChromotingInstance::ConnectWithConfig(const ClientConfig& config, | 624 void ChromotingInstance::ConnectWithConfig(const ClientConfig& config, |
648 const std::string& local_jid) { | 625 const std::string& local_jid) { |
649 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 626 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
650 | 627 |
| 628 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 629 |
651 if (use_media_source_rendering_) { | 630 if (use_media_source_rendering_) { |
652 video_renderer_.reset(new MediaSourceVideoRenderer(this)); | 631 video_renderer_.reset(new MediaSourceVideoRenderer(this)); |
653 } else { | 632 } else { |
654 view_.reset(new PepperView(this, &context_)); | 633 view_.reset(new PepperView(this, &context_)); |
655 view_weak_factory_.reset( | 634 view_weak_factory_.reset( |
656 new base::WeakPtrFactory<FrameConsumer>(view_.get())); | 635 new base::WeakPtrFactory<FrameConsumer>(view_.get())); |
657 | 636 |
658 // SoftwareVideoRenderer runs on a separate thread so for now we wrap | 637 // SoftwareVideoRenderer runs on a separate thread so for now we wrap |
659 // PepperView with a ref-counted proxy object. | 638 // PepperView with a ref-counted proxy object. |
660 scoped_refptr<FrameConsumerProxy> consumer_proxy = | 639 scoped_refptr<FrameConsumerProxy> consumer_proxy = |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 pp::VarArrayBuffer array_buffer(buffer_size); | 1121 pp::VarArrayBuffer array_buffer(buffer_size); |
1143 void* data_ptr = array_buffer.Map(); | 1122 void* data_ptr = array_buffer.Map(); |
1144 memcpy(data_ptr, buffer, buffer_size); | 1123 memcpy(data_ptr, buffer, buffer_size); |
1145 array_buffer.Unmap(); | 1124 array_buffer.Unmap(); |
1146 pp::VarDictionary data_dictionary; | 1125 pp::VarDictionary data_dictionary; |
1147 data_dictionary.Set(pp::Var("buffer"), array_buffer); | 1126 data_dictionary.Set(pp::Var("buffer"), array_buffer); |
1148 PostChromotingMessage("mediaSourceData", data_dictionary); | 1127 PostChromotingMessage("mediaSourceData", data_dictionary); |
1149 } | 1128 } |
1150 | 1129 |
1151 } // namespace remoting | 1130 } // namespace remoting |
OLD | NEW |