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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 | 231 |
232 tty_prefix_ = getenv("PS_TTY_PREFIX"); | 232 tty_prefix_ = getenv("PS_TTY_PREFIX"); |
233 if (tty_prefix_) { | 233 if (tty_prefix_) { |
234 tty_fd_ = open("/dev/tty", O_WRONLY); | 234 tty_fd_ = open("/dev/tty", O_WRONLY); |
235 if (tty_fd_ >= 0) { | 235 if (tty_fd_ >= 0) { |
236 RegisterMessageHandler(tty_prefix_, MessageHandlerInputStatic, this); | 236 RegisterMessageHandler(tty_prefix_, MessageHandlerInputStatic, this); |
237 const char* tty_resize = getenv("PS_TTY_RESIZE"); | 237 const char* tty_resize = getenv("PS_TTY_RESIZE"); |
238 if (tty_resize) | 238 if (tty_resize) |
239 RegisterMessageHandler(tty_resize, MessageHandlerResizeStatic, this); | 239 RegisterMessageHandler(tty_resize, MessageHandlerResizeStatic, this); |
240 | 240 |
241 const char* tty_rows = getenv("PS_TTY_ROWS"); | |
242 const char* tty_cols = getenv("PS_TTY_COLS"); | |
243 if (tty_rows && tty_cols) | |
244 HandleResize(atoi(tty_cols), atoi(tty_rows)); | |
binji
2013/11/09 00:55:08
better error messaging here? What if only one is s
Sam Clegg
2013/11/09 01:12:58
Done.
| |
245 | |
241 tioc_nacl_output handler; | 246 tioc_nacl_output handler; |
242 handler.handler = TtyOutputHandlerStatic; | 247 handler.handler = TtyOutputHandlerStatic; |
243 handler.user_data = this; | 248 handler.user_data = this; |
244 ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler)); | 249 ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler)); |
245 } else { | 250 } else { |
246 Error("Failed to open /dev/tty.\n"); | 251 Error("Failed to open /dev/tty.\n"); |
247 } | 252 } |
248 } | 253 } |
249 | 254 |
250 const char* exit_message = getenv("PS_EXIT_MESSAGE"); | 255 const char* exit_message = getenv("PS_EXIT_MESSAGE"); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 struct tioc_nacl_input_string ioctl_message; | 370 struct tioc_nacl_input_string ioctl_message; |
366 ioctl_message.length = buffer.size(); | 371 ioctl_message.length = buffer.size(); |
367 ioctl_message.buffer = buffer.c_str(); | 372 ioctl_message.buffer = buffer.c_str(); |
368 int ret = | 373 int ret = |
369 ioctl(tty_fd_, TIOCNACLINPUT, reinterpret_cast<char*>(&ioctl_message)); | 374 ioctl(tty_fd_, TIOCNACLINPUT, reinterpret_cast<char*>(&ioctl_message)); |
370 if (ret != 0 && errno != ENOTTY) { | 375 if (ret != 0 && errno != ENOTTY) { |
371 Error("ioctl returned unexpected error: %d.\n", ret); | 376 Error("ioctl returned unexpected error: %d.\n", ret); |
372 } | 377 } |
373 } | 378 } |
374 | 379 |
380 void PSInstance::HandleResize(int width, int height){ | |
381 struct winsize size; | |
382 memset(&size, 0, sizeof(size)); | |
383 size.ws_col = width; | |
384 size.ws_row = height; | |
385 ioctl(tty_fd_, TIOCSWINSZ, reinterpret_cast<char*>(&size)); | |
386 } | |
387 | |
375 void PSInstance::MessageHandlerResize(const pp::Var& message) { | 388 void PSInstance::MessageHandlerResize(const pp::Var& message) { |
376 assert(message.is_array()); | 389 assert(message.is_array()); |
377 pp::VarArray array(message); | 390 pp::VarArray array(message); |
378 assert(array.GetLength() == 2); | 391 assert(array.GetLength() == 2); |
379 | 392 |
380 struct winsize size; | 393 int width = array.Get(0).AsInt(); |
381 memset(&size, 0, sizeof(size)); | 394 int height = array.Get(1).AsInt(); |
382 size.ws_col = array.Get(0).AsInt(); | 395 HandleResize(width, height); |
383 size.ws_row = array.Get(1).AsInt(); | |
384 ioctl(tty_fd_, TIOCSWINSZ, reinterpret_cast<char*>(&size)); | |
385 } | 396 } |
386 | 397 |
387 ssize_t PSInstance::TtyOutputHandlerStatic(const char* buf, | 398 ssize_t PSInstance::TtyOutputHandlerStatic(const char* buf, |
388 size_t count, | 399 size_t count, |
389 void* user_data) { | 400 void* user_data) { |
390 PSInstance* instance = reinterpret_cast<PSInstance*>(user_data); | 401 PSInstance* instance = reinterpret_cast<PSInstance*>(user_data); |
391 return instance->TtyOutputHandler(buf, count); | 402 return instance->TtyOutputHandler(buf, count); |
392 } | 403 } |
393 | 404 |
394 void PSInstance::MessageHandlerInputStatic(const pp::Var& key, | 405 void PSInstance::MessageHandlerInputStatic(const pp::Var& key, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 | 541 |
531 void PSInstance::Graphics3DContextLost() { | 542 void PSInstance::Graphics3DContextLost() { |
532 Log("Graphics3DContextLost\n"); | 543 Log("Graphics3DContextLost\n"); |
533 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); | 544 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); |
534 } | 545 } |
535 | 546 |
536 void PSInstance::MouseLockLost() { | 547 void PSInstance::MouseLockLost() { |
537 Log("MouseLockLost\n"); | 548 Log("MouseLockLost\n"); |
538 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); | 549 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); |
539 } | 550 } |
OLD | NEW |