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 <errno.h> | 5 #include <errno.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <pthread.h> | 7 #include <pthread.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <sys/ioctl.h> | 10 #include <sys/ioctl.h> |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 assert(message.is_string()); | 402 assert(message.is_string()); |
403 pthread_mutex_lock(&exit_lock_); | 403 pthread_mutex_lock(&exit_lock_); |
404 pthread_cond_signal(&exit_cond_); | 404 pthread_cond_signal(&exit_cond_); |
405 pthread_mutex_unlock(&exit_lock_); | 405 pthread_mutex_unlock(&exit_lock_); |
406 } | 406 } |
407 | 407 |
408 void PSInstance::MessageHandlerInput(const pp::Var& key, | 408 void PSInstance::MessageHandlerInput(const pp::Var& key, |
409 const pp::Var& message) { | 409 const pp::Var& message) { |
410 std::string key_string = key.AsString(); | 410 std::string key_string = key.AsString(); |
411 | 411 |
412 // Legacy support for passing TTY data as a string, rather than a array | |
413 // buffer. TODO(sbc): remove this in a future release. | |
414 if (message.is_string() && key_string == tty_prefix_) { | 412 if (message.is_string() && key_string == tty_prefix_) { |
415 std::string buffer = message.AsString(); | 413 std::string buffer = message.AsString(); |
416 Warn("Passing TTY input as a string is deprected. Please use a " | |
417 "JavaScript ArrayBuffer instead"); | |
418 | 414 |
419 // Since our message may contain null characters, we can't send it as a | 415 // Since our message may contain null characters, we can't send it as a |
420 // naked C string, so we package it up in this struct before sending it | 416 // naked C string, so we package it up in this struct before sending it |
421 // to the ioctl. | 417 // to the ioctl. |
422 struct tioc_nacl_input_string ioctl_message; | 418 struct tioc_nacl_input_string ioctl_message; |
423 ioctl_message.length = buffer.size(); | 419 ioctl_message.length = buffer.size(); |
424 ioctl_message.buffer = buffer.c_str(); | 420 ioctl_message.buffer = buffer.c_str(); |
425 int ret = | 421 int ret = ioctl(tty_fd_, TIOCNACLINPUT, &ioctl_message); |
426 ioctl(tty_fd_, TIOCNACLINPUT, &ioctl_message); | |
427 if (ret != 0 && errno != ENOTTY) { | 422 if (ret != 0 && errno != ENOTTY) { |
428 Error("ioctl returned unexpected error: %d.\n", ret); | 423 Error("ioctl returned unexpected error: %d.\n", ret); |
429 } | 424 } |
| 425 return; |
430 } | 426 } |
431 | 427 |
432 if (!message.is_array_buffer()) { | 428 if (!message.is_array_buffer()) { |
433 Error("Expected ArrayBuffer object but got: %d", message.pp_var().type); | 429 Error("Expected ArrayBuffer object but got: %d", message.pp_var().type); |
434 return; | 430 return; |
435 } | 431 } |
436 | 432 |
437 const char* filename = NULL; | 433 const char* filename = NULL; |
438 if (key_string == tty_prefix_) { | 434 if (key_string == tty_prefix_) { |
439 filename = "/dev/tty"; | 435 filename = "/dev/tty"; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 message_handlers_[message_name] = message_handler; | 521 message_handlers_[message_name] = message_handler; |
526 } | 522 } |
527 | 523 |
528 void PSInstance::PostEvent(PSEventType type, const PP_Var& var) { | 524 void PSInstance::PostEvent(PSEventType type, const PP_Var& var) { |
529 assert(PSE_INSTANCE_HANDLEMESSAGE == type); | 525 assert(PSE_INSTANCE_HANDLEMESSAGE == type); |
530 | 526 |
531 pp::Var event(var); | 527 pp::Var event(var); |
532 // Legacy support for passing TTY input as a string <prefix>:<payload> | 528 // Legacy support for passing TTY input as a string <prefix>:<payload> |
533 // TODO(sbc): remove this in a future release. | 529 // TODO(sbc): remove this in a future release. |
534 if (tty_fd_ >= 0 && event.is_string()) { | 530 if (tty_fd_ >= 0 && event.is_string()) { |
535 Warn("passing TTY data using a string prefix is deprected." | |
536 " Use a JavaScript dictionary instead."); | |
537 std::string message = event.AsString(); | 531 std::string message = event.AsString(); |
538 size_t prefix_len = strlen(tty_prefix_); | 532 size_t prefix_len = strlen(tty_prefix_); |
539 if (message.size() > prefix_len) { | 533 if (message.size() > prefix_len) { |
540 if (!strncmp(message.c_str(), tty_prefix_, prefix_len)) { | 534 if (!strncmp(message.c_str(), tty_prefix_, prefix_len)) { |
| 535 LOG_WARN("Passing TTY data using a string prefix is deprecated. " |
| 536 "Use a JavaScript dictionary instead."); |
541 MessageHandlerInput(pp::Var(message.substr(0, prefix_len)), | 537 MessageHandlerInput(pp::Var(message.substr(0, prefix_len)), |
542 pp::Var(message.substr(prefix_len))); | 538 pp::Var(message.substr(prefix_len))); |
543 return; | 539 return; |
544 } | 540 } |
545 } | 541 } |
546 } | 542 } |
547 | 543 |
548 // If the message is a dictionary then see if it matches one | 544 // If the message is a dictionary then see if it matches one |
549 // of the specific handlers, then call that handler rather than | 545 // of the specific handlers, then call that handler rather than |
550 // queuing an event. | 546 // queuing an event. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 637 |
642 void PSInstance::Graphics3DContextLost() { | 638 void PSInstance::Graphics3DContextLost() { |
643 Log("Graphics3DContextLost\n"); | 639 Log("Graphics3DContextLost\n"); |
644 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); | 640 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); |
645 } | 641 } |
646 | 642 |
647 void PSInstance::MouseLockLost() { | 643 void PSInstance::MouseLockLost() { |
648 Log("MouseLockLost\n"); | 644 Log("MouseLockLost\n"); |
649 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); | 645 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); |
650 } | 646 } |
OLD | NEW |