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 char* tty_rows = getenv("PS_TTY_ROWS"); |
| 242 char* tty_cols = getenv("PS_TTY_COLS"); |
| 243 if (tty_rows && tty_cols) { |
| 244 char* end = tty_rows; |
| 245 int rows = strtol(tty_rows, &end, 10); |
| 246 if (*end != '\0' || rows < 0) { |
| 247 Error("Invalid value for PS_TTY_ROWS: %s", tty_rows); |
| 248 } else { |
| 249 end = tty_cols; |
| 250 int cols = strtol(tty_cols, &end, 10); |
| 251 if (*end != '\0' || cols < 0) |
| 252 Error("Invalid value for PS_TTY_COLS: %s", tty_cols); |
| 253 else |
| 254 HandleResize(cols, rows); |
| 255 } |
| 256 } |
| 257 else if (tty_rows || tty_cols) { |
| 258 Error("PS_TTY_ROWS and PS_TTY_COLS must be set together"); |
| 259 } |
| 260 |
241 tioc_nacl_output handler; | 261 tioc_nacl_output handler; |
242 handler.handler = TtyOutputHandlerStatic; | 262 handler.handler = TtyOutputHandlerStatic; |
243 handler.user_data = this; | 263 handler.user_data = this; |
244 ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler)); | 264 ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler)); |
245 } else { | 265 } else { |
246 Error("Failed to open /dev/tty.\n"); | 266 Error("Failed to open /dev/tty.\n"); |
247 } | 267 } |
248 } | 268 } |
249 | 269 |
250 const char* exit_message = getenv("PS_EXIT_MESSAGE"); | 270 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; | 385 struct tioc_nacl_input_string ioctl_message; |
366 ioctl_message.length = buffer.size(); | 386 ioctl_message.length = buffer.size(); |
367 ioctl_message.buffer = buffer.c_str(); | 387 ioctl_message.buffer = buffer.c_str(); |
368 int ret = | 388 int ret = |
369 ioctl(tty_fd_, TIOCNACLINPUT, reinterpret_cast<char*>(&ioctl_message)); | 389 ioctl(tty_fd_, TIOCNACLINPUT, reinterpret_cast<char*>(&ioctl_message)); |
370 if (ret != 0 && errno != ENOTTY) { | 390 if (ret != 0 && errno != ENOTTY) { |
371 Error("ioctl returned unexpected error: %d.\n", ret); | 391 Error("ioctl returned unexpected error: %d.\n", ret); |
372 } | 392 } |
373 } | 393 } |
374 | 394 |
| 395 void PSInstance::HandleResize(int width, int height){ |
| 396 struct winsize size; |
| 397 memset(&size, 0, sizeof(size)); |
| 398 size.ws_col = width; |
| 399 size.ws_row = height; |
| 400 ioctl(tty_fd_, TIOCSWINSZ, reinterpret_cast<char*>(&size)); |
| 401 } |
| 402 |
375 void PSInstance::MessageHandlerResize(const pp::Var& message) { | 403 void PSInstance::MessageHandlerResize(const pp::Var& message) { |
376 assert(message.is_array()); | 404 assert(message.is_array()); |
377 pp::VarArray array(message); | 405 pp::VarArray array(message); |
378 assert(array.GetLength() == 2); | 406 assert(array.GetLength() == 2); |
379 | 407 |
380 struct winsize size; | 408 int width = array.Get(0).AsInt(); |
381 memset(&size, 0, sizeof(size)); | 409 int height = array.Get(1).AsInt(); |
382 size.ws_col = array.Get(0).AsInt(); | 410 HandleResize(width, height); |
383 size.ws_row = array.Get(1).AsInt(); | |
384 ioctl(tty_fd_, TIOCSWINSZ, reinterpret_cast<char*>(&size)); | |
385 } | 411 } |
386 | 412 |
387 ssize_t PSInstance::TtyOutputHandlerStatic(const char* buf, | 413 ssize_t PSInstance::TtyOutputHandlerStatic(const char* buf, |
388 size_t count, | 414 size_t count, |
389 void* user_data) { | 415 void* user_data) { |
390 PSInstance* instance = reinterpret_cast<PSInstance*>(user_data); | 416 PSInstance* instance = reinterpret_cast<PSInstance*>(user_data); |
391 return instance->TtyOutputHandler(buf, count); | 417 return instance->TtyOutputHandler(buf, count); |
392 } | 418 } |
393 | 419 |
394 void PSInstance::MessageHandlerInputStatic(const pp::Var& key, | 420 void PSInstance::MessageHandlerInputStatic(const pp::Var& key, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 556 |
531 void PSInstance::Graphics3DContextLost() { | 557 void PSInstance::Graphics3DContextLost() { |
532 Log("Graphics3DContextLost\n"); | 558 Log("Graphics3DContextLost\n"); |
533 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); | 559 PostEvent(PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST); |
534 } | 560 } |
535 | 561 |
536 void PSInstance::MouseLockLost() { | 562 void PSInstance::MouseLockLost() { |
537 Log("MouseLockLost\n"); | 563 Log("MouseLockLost\n"); |
538 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); | 564 PostEvent(PSE_MOUSELOCK_MOUSELOCKLOST); |
539 } | 565 } |
OLD | NEW |