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