Chromium Code Reviews| 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 | |
| 11 #include "base/bind.h" | 16 #include "base/bind.h" |
| 12 #include "base/callback.h" | 17 #include "base/callback.h" |
| 13 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 19 #include "base/json/json_writer.h" |
| 15 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 21 #include "base/logging.h" |
| 17 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 18 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 19 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 20 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 21 #include "base/values.h" | 26 #include "base/values.h" |
| 22 #include "crypto/random.h" | 27 #include "crypto/random.h" |
| 23 #include "jingle/glue/thread_wrapper.h" | 28 #include "jingle/glue/thread_wrapper.h" |
| 24 #include "media/base/media.h" | 29 #include "media/base/yuv_convert.h" |
| 25 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
| 26 #include "ppapi/cpp/completion_callback.h" | 31 #include "ppapi/cpp/completion_callback.h" |
| 27 #include "ppapi/cpp/dev/url_util_dev.h" | 32 #include "ppapi/cpp/dev/url_util_dev.h" |
| 28 #include "ppapi/cpp/image_data.h" | 33 #include "ppapi/cpp/image_data.h" |
| 29 #include "ppapi/cpp/input_event.h" | 34 #include "ppapi/cpp/input_event.h" |
| 30 #include "ppapi/cpp/rect.h" | 35 #include "ppapi/cpp/rect.h" |
| 31 #include "remoting/base/constants.h" | 36 #include "remoting/base/constants.h" |
| 32 #include "remoting/base/util.h" | 37 #include "remoting/base/util.h" |
| 33 #include "remoting/client/chromoting_client.h" | 38 #include "remoting/client/chromoting_client.h" |
| 34 #include "remoting/client/client_config.h" | 39 #include "remoting/client/client_config.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 initialized_(false), | 206 initialized_(false), |
| 202 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), | 207 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), |
| 203 context_(plugin_task_runner_.get()), | 208 context_(plugin_task_runner_.get()), |
| 204 input_tracker_(&mouse_input_filter_), | 209 input_tracker_(&mouse_input_filter_), |
| 205 key_mapper_(&input_tracker_), | 210 key_mapper_(&input_tracker_), |
| 206 normalizing_input_filter_(CreateNormalizingInputFilter(&key_mapper_)), | 211 normalizing_input_filter_(CreateNormalizingInputFilter(&key_mapper_)), |
| 207 input_handler_(this, normalizing_input_filter_.get()), | 212 input_handler_(this, normalizing_input_filter_.get()), |
| 208 use_async_pin_dialog_(false), | 213 use_async_pin_dialog_(false), |
| 209 use_media_source_rendering_(false), | 214 use_media_source_rendering_(false), |
| 210 weak_factory_(this) { | 215 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(); | |
|
Jamie
2014/04/14 22:23:42
Is this run on the same thread as it would have be
Sergey Ulanov
2014/04/14 23:16:51
Yes. All code in this file is executed on the main
| |
| 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 | |
| 211 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); | 234 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); |
| 212 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 235 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| 213 | 236 |
| 214 // Resister this instance to handle debug log messsages. | 237 // Resister this instance to handle debug log messsages. |
| 215 RegisterLoggingInstance(); | 238 RegisterLoggingInstance(); |
| 216 | 239 |
| 217 #if defined(USE_OPENSSL) | 240 #if defined(USE_OPENSSL) |
| 218 // Initialize random seed for libjingle. It's necessary only with OpenSSL. | 241 // Initialize random seed for libjingle. It's necessary only with OpenSSL. |
| 219 char random_seed[kRandomSeedSize]; | 242 char random_seed[kRandomSeedSize]; |
| 220 crypto::RandBytes(random_seed, sizeof(random_seed)); | 243 crypto::RandBytes(random_seed, sizeof(random_seed)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 } | 278 } |
| 256 | 279 |
| 257 bool ChromotingInstance::Init(uint32_t argc, | 280 bool ChromotingInstance::Init(uint32_t argc, |
| 258 const char* argn[], | 281 const char* argn[], |
| 259 const char* argv[]) { | 282 const char* argv[]) { |
| 260 CHECK(!initialized_); | 283 CHECK(!initialized_); |
| 261 initialized_ = true; | 284 initialized_ = true; |
| 262 | 285 |
| 263 VLOG(1) << "Started ChromotingInstance::Init"; | 286 VLOG(1) << "Started ChromotingInstance::Init"; |
| 264 | 287 |
| 265 // Check to make sure the media library is initialized. | 288 // Check that the calling content is part of an app or extension. This is only |
| 266 // http://crbug.com/91521. | 289 // necessary for non-PNaCl version of the plugin. Also PPB_URLUtil_Dev doesn't |
| 267 if (!media::IsMediaLibraryInitialized()) { | 290 // work in NaCl at the moment so the check fails in NaCl builds. |
|
Jamie
2014/04/14 22:23:42
Do we want this to work for non-extensions, or is
Sergey Ulanov
2014/04/14 23:16:51
We don't need this check for NaCl plugin. Pepper p
| |
| 268 LOG(ERROR) << "Media library not initialized."; | 291 #if !defined(OS_NACL) |
| 269 return false; | |
| 270 } | |
| 271 | |
| 272 // Check that the calling content is part of an app or extension. | |
| 273 if (!IsCallerAppOrExtension()) { | 292 if (!IsCallerAppOrExtension()) { |
| 274 LOG(ERROR) << "Not an app or extension"; | 293 LOG(ERROR) << "Not an app or extension"; |
| 275 return false; | 294 return false; |
| 276 } | 295 } |
| 277 | 296 #endif |
| 278 // Enable support for SSL server sockets, which must be done as early as | |
| 279 // possible, preferably before any NSS SSL sockets (client or server) have | |
| 280 // been created. | |
| 281 // It's possible that the hosting process has already made use of SSL, in | |
| 282 // which case, there may be a slight race. | |
| 283 net::EnableSSLServerSockets(); | |
|
Jamie
2014/04/14 22:23:42
Did you intend to remove this? If so, please add s
Sergey Ulanov
2014/04/14 23:16:51
Yes, this is intentional. There is no reason to in
| |
| 284 | 297 |
| 285 // Start all the threads. | 298 // Start all the threads. |
| 286 context_.Start(); | 299 context_.Start(); |
| 287 | 300 |
| 288 return true; | 301 return true; |
| 289 } | 302 } |
| 290 | 303 |
| 291 void ChromotingInstance::HandleMessage(const pp::Var& message) { | 304 void ChromotingInstance::HandleMessage(const pp::Var& message) { |
| 292 if (!message.is_string()) { | 305 if (!message.is_string()) { |
| 293 LOG(ERROR) << "Received a message that is not a string."; | 306 LOG(ERROR) << "Received a message that is not a string."; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 } else if (method == "allowMouseLock") { | 356 } else if (method == "allowMouseLock") { |
| 344 HandleAllowMouseLockMessage(); | 357 HandleAllowMouseLockMessage(); |
| 345 } else if (method == "enableMediaSourceRendering") { | 358 } else if (method == "enableMediaSourceRendering") { |
| 346 HandleEnableMediaSourceRendering(); | 359 HandleEnableMediaSourceRendering(); |
| 347 } | 360 } |
| 348 } | 361 } |
| 349 | 362 |
| 350 void ChromotingInstance::DidChangeFocus(bool has_focus) { | 363 void ChromotingInstance::DidChangeFocus(bool has_focus) { |
| 351 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 364 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 352 | 365 |
| 366 if (!IsConnected()) | |
| 367 return; | |
|
Jamie
2014/04/14 22:23:42
Is this required for this CL, or an unrelated bug-
Sergey Ulanov
2014/04/14 23:16:51
It fixes a bug that affects only NaCl build (I did
| |
| 368 | |
| 353 input_handler_.DidChangeFocus(has_focus); | 369 input_handler_.DidChangeFocus(has_focus); |
| 354 } | 370 } |
| 355 | 371 |
| 356 void ChromotingInstance::DidChangeView(const pp::View& view) { | 372 void ChromotingInstance::DidChangeView(const pp::View& view) { |
| 357 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 373 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 358 | 374 |
| 359 plugin_view_ = view; | 375 plugin_view_ = view; |
| 360 mouse_input_filter_.set_input_size( | 376 mouse_input_filter_.set_input_size( |
| 361 webrtc::DesktopSize(view.GetRect().width(), view.GetRect().height())); | 377 webrtc::DesktopSize(view.GetRect().width(), view.GetRect().height())); |
| 362 | 378 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 } | 641 } |
| 626 } | 642 } |
| 627 | 643 |
| 628 ConnectWithConfig(config, local_jid); | 644 ConnectWithConfig(config, local_jid); |
| 629 } | 645 } |
| 630 | 646 |
| 631 void ChromotingInstance::ConnectWithConfig(const ClientConfig& config, | 647 void ChromotingInstance::ConnectWithConfig(const ClientConfig& config, |
| 632 const std::string& local_jid) { | 648 const std::string& local_jid) { |
| 633 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 649 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 634 | 650 |
| 635 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | |
| 636 | |
| 637 if (use_media_source_rendering_) { | 651 if (use_media_source_rendering_) { |
| 638 video_renderer_.reset(new MediaSourceVideoRenderer(this)); | 652 video_renderer_.reset(new MediaSourceVideoRenderer(this)); |
| 639 } else { | 653 } else { |
| 640 view_.reset(new PepperView(this, &context_)); | 654 view_.reset(new PepperView(this, &context_)); |
| 641 view_weak_factory_.reset( | 655 view_weak_factory_.reset( |
| 642 new base::WeakPtrFactory<FrameConsumer>(view_.get())); | 656 new base::WeakPtrFactory<FrameConsumer>(view_.get())); |
| 643 | 657 |
| 644 // SoftwareVideoRenderer runs on a separate thread so for now we wrap | 658 // SoftwareVideoRenderer runs on a separate thread so for now we wrap |
| 645 // PepperView with a ref-counted proxy object. | 659 // PepperView with a ref-counted proxy object. |
| 646 scoped_refptr<FrameConsumerProxy> consumer_proxy = | 660 scoped_refptr<FrameConsumerProxy> consumer_proxy = |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 pp::VarArrayBuffer array_buffer(buffer_size); | 1142 pp::VarArrayBuffer array_buffer(buffer_size); |
| 1129 void* data_ptr = array_buffer.Map(); | 1143 void* data_ptr = array_buffer.Map(); |
| 1130 memcpy(data_ptr, buffer, buffer_size); | 1144 memcpy(data_ptr, buffer, buffer_size); |
| 1131 array_buffer.Unmap(); | 1145 array_buffer.Unmap(); |
| 1132 pp::VarDictionary data_dictionary; | 1146 pp::VarDictionary data_dictionary; |
| 1133 data_dictionary.Set(pp::Var("buffer"), array_buffer); | 1147 data_dictionary.Set(pp::Var("buffer"), array_buffer); |
| 1134 PostChromotingMessage("mediaSourceData", data_dictionary); | 1148 PostChromotingMessage("mediaSourceData", data_dictionary); |
| 1135 } | 1149 } |
| 1136 | 1150 |
| 1137 } // namespace remoting | 1151 } // namespace remoting |
| OLD | NEW |