summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authortbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-14 02:36:31 +0000
committertbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-14 02:36:31 +0000
commit0d2786c4ee50b3e5758e912eb4912ae81639bee8 (patch)
tree05c29b64caf33f2d63412ea92eff9e509493a35f /chrome
parent1382a2756e2d15473479fb87187b3aa9ddbc63c2 (diff)
downloadchromium_src-0d2786c4ee50b3e5758e912eb4912ae81639bee8.zip
chromium_src-0d2786c4ee50b3e5758e912eb4912ae81639bee8.tar.gz
chromium_src-0d2786c4ee50b3e5758e912eb4912ae81639bee8.tar.bz2
[HTerm-Crosh] Add support for terminal window resizing to terminal API
Add method terminalPrivate.onTerminalResize that will be called by hterm when its window gets resized. This is needed by some app we might run in pseudo-terminal that need to know window size to work properly. BUG=chromium-os:25947 TEST=Open some file in crosh using vi, and verify that the file is shown in full terminal screen. Review URL: https://chromiumcodereview.appspot.com/9121035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/process_proxy/process_proxy.cc13
-rw-r--r--chrome/browser/chromeos/process_proxy/process_proxy.h10
-rw-r--r--chrome/browser/chromeos/process_proxy/process_proxy_registry.cc8
-rw-r--r--chrome/browser/chromeos/process_proxy/process_proxy_registry.h11
-rw-r--r--chrome/browser/extensions/api/terminal/terminal_private_api.cc39
-rw-r--r--chrome/browser/extensions/api/terminal/terminal_private_api.h12
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc1
-rw-r--r--chrome/common/extensions/api/terminalPrivate.json34
8 files changed, 121 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/process_proxy/process_proxy.cc b/chrome/browser/chromeos/process_proxy/process_proxy.cc
index 04b2c3f..a5b3ac9 100644
--- a/chrome/browser/chromeos/process_proxy/process_proxy.cc
+++ b/chrome/browser/chromeos/process_proxy/process_proxy.cc
@@ -156,6 +156,19 @@ bool ProcessProxy::Write(const std::string& text) {
return (bytes_written == static_cast<int>(data_size));
}
+bool ProcessProxy::OnTerminalResize(int width, int height) {
+ if (width < 0 || height < 0)
+ return false;
+
+ winsize ws;
+ // Number of rows.
+ ws.ws_row = height;
+ // Number of columns.
+ ws.ws_col = width;
+
+ return (HANDLE_EINTR(ioctl(pt_pair_[PT_MASTER_FD], TIOCSWINSZ, &ws)) != -1);
+}
+
ProcessProxy::~ProcessProxy() {
// In case watcher did not started, we may get deleted without calling Close.
// In that case we have to clean up created pipes. If watcher had been
diff --git a/chrome/browser/chromeos/process_proxy/process_proxy.h b/chrome/browser/chromeos/process_proxy/process_proxy.h
index d3507f0..fb50655 100644
--- a/chrome/browser/chromeos/process_proxy/process_proxy.h
+++ b/chrome/browser/chromeos/process_proxy/process_proxy.h
@@ -26,7 +26,7 @@ class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> {
public:
ProcessProxy();
- // Open a process using command |command|. |pid| is set to new process' pid.
+ // Opens a process using command |command|. |pid| is set to new process' pid.
bool Open(const std::string& command, pid_t* pid);
// Triggers watcher object on |watch_thread|. |watch_thread| gets blocked, so
@@ -35,12 +35,16 @@ class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> {
bool StartWatchingOnThread(base::Thread* watch_thread,
const ProcessOutputCallback& callback);
- // Send some data to the process.
+ // Sends some data to the process.
bool Write(const std::string& text);
- // Close. Must be called if we want this to be eventually deleted.
+ // Closes the process.
+ // Must be called if we want this to be eventually deleted.
void Close();
+ // Notifies underlaying process of terminal size change.
+ bool OnTerminalResize(int width, int height);
+
private:
friend class base::RefCountedThreadSafe<ProcessProxy>;
// We want this be used as ref counted object only.
diff --git a/chrome/browser/chromeos/process_proxy/process_proxy_registry.cc b/chrome/browser/chromeos/process_proxy/process_proxy_registry.cc
index 5c5a09f..22191fc 100644
--- a/chrome/browser/chromeos/process_proxy/process_proxy_registry.cc
+++ b/chrome/browser/chromeos/process_proxy/process_proxy_registry.cc
@@ -115,6 +115,14 @@ bool ProcessProxyRegistry::CloseProcess(pid_t pid) {
return true;
}
+bool ProcessProxyRegistry::OnTerminalResize(pid_t pid, int width, int height) {
+ std::map<pid_t, ProcessProxyInfo>::iterator it = proxy_map_.find(pid);
+ if (it == proxy_map_.end())
+ return false;
+
+ return it->second.proxy->OnTerminalResize(width, height);
+}
+
void ProcessProxyRegistry::OnProcessOutput(pid_t pid,
ProcessOutputType type, const std::string& data) {
const char* type_str = ProcessOutputTypeToString(type);
diff --git a/chrome/browser/chromeos/process_proxy/process_proxy_registry.h b/chrome/browser/chromeos/process_proxy/process_proxy_registry.h
index b6aa71a..776f3a1 100644
--- a/chrome/browser/chromeos/process_proxy/process_proxy_registry.h
+++ b/chrome/browser/chromeos/process_proxy/process_proxy_registry.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -40,12 +40,14 @@ class ProcessProxyRegistry {
// Starts new ProcessProxy (which starts new process).
bool OpenProcess(const std::string& command, pid_t* pid,
const ProcessOutputCallbackWithPid& callback);
- // Send data to the process with id |pid|.
+ // Sends data to the process with id |pid|.
bool SendInput(pid_t pid, const std::string& data);
- // Stop the process with id |pid|.
+ // Stops the process with id |pid|.
bool CloseProcess(pid_t pid);
+ // Reports terminal resize to process proxy.
+ bool OnTerminalResize(pid_t pid, int width, int height);
- // Gets called when output gets detected. Currently used for testing.
+ // Currently used for testing.
void SetOutputCallback(const ProcessOutputCallback& callback);
private:
@@ -54,6 +56,7 @@ class ProcessProxyRegistry {
ProcessProxyRegistry();
~ProcessProxyRegistry();
+ // Gets called when output gets detected.
void OnProcessOutput(pid_t pid,
ProcessOutputType type,
const std::string& data);
diff --git a/chrome/browser/extensions/api/terminal/terminal_private_api.cc b/chrome/browser/extensions/api/terminal/terminal_private_api.cc
index 9176415..7523352 100644
--- a/chrome/browser/extensions/api/terminal/terminal_private_api.cc
+++ b/chrome/browser/extensions/api/terminal/terminal_private_api.cc
@@ -179,3 +179,42 @@ void CloseTerminalProcessFunction::RespondOnUIThread(bool success) {
result_.reset(new base::FundamentalValue(success));
SendResponse(true);
}
+
+bool OnTerminalResizeFunction::RunTerminalFunction() {
+ if (args_->GetSize() != 3)
+ return false;
+
+ pid_t pid;
+ if (!args_->GetInteger(0, &pid))
+ return false;
+
+ int width;
+ if (!args_->GetInteger(1, &width))
+ return false;
+
+ int height;
+ if (!args_->GetInteger(2, &height))
+ return false;
+
+ // Registry lives on the FILE thread.
+ content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&OnTerminalResizeFunction::OnResizeOnFileThread, this, pid,
+ width, height));
+
+ return true;
+}
+
+void OnTerminalResizeFunction::OnResizeOnFileThread(pid_t pid,
+ int width, int height) {
+ bool success = ProcessProxyRegistry::Get()->OnTerminalResize(pid,
+ width, height);
+
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&OnTerminalResizeFunction::RespondOnUIThread, this,
+ success));
+}
+
+void OnTerminalResizeFunction::RespondOnUIThread(bool success) {
+ result_.reset(new base::FundamentalValue(success));
+ SendResponse(true);
+}
diff --git a/chrome/browser/extensions/api/terminal/terminal_private_api.h b/chrome/browser/extensions/api/terminal/terminal_private_api.h
index 771e94b..ad2274a 100644
--- a/chrome/browser/extensions/api/terminal/terminal_private_api.h
+++ b/chrome/browser/extensions/api/terminal/terminal_private_api.h
@@ -65,4 +65,16 @@ class CloseTerminalProcessFunction : public TerminalPrivateFunction {
DECLARE_EXTENSION_FUNCTION_NAME("terminalPrivate.closeTerminalProcess")
};
+// Called by extension when terminal size changes.
+class OnTerminalResizeFunction : public TerminalPrivateFunction {
+ public:
+ virtual bool RunTerminalFunction() OVERRIDE;
+
+ private:
+ void OnResizeOnFileThread(pid_t pid, int width, int height);
+ void RespondOnUIThread(bool success);
+
+ DECLARE_EXTENSION_FUNCTION_NAME("terminalPrivate.onTerminalResize")
+};
+
#endif // CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 5928091..920dc53 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -423,6 +423,7 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<OpenTerminalProcessFunction>();
RegisterFunction<SendInputToTerminalProcessFunction>();
RegisterFunction<CloseTerminalProcessFunction>();
+ RegisterFunction<OnTerminalResizeFunction>();
#if defined(USE_VIRTUAL_KEYBOARD)
// Input
diff --git a/chrome/common/extensions/api/terminalPrivate.json b/chrome/common/extensions/api/terminalPrivate.json
index 42107e7..74d8cb6 100644
--- a/chrome/common/extensions/api/terminalPrivate.json
+++ b/chrome/common/extensions/api/terminalPrivate.json
@@ -82,6 +82,40 @@
]
}
]
+ },
+ {
+ "name": "onTerminalResize",
+ "type": "function",
+ "description": "Notify the process with the id pid that terminal window size has changed.",
+ "parameters": [
+ {
+ "name": "pid",
+ "type": "integer",
+ "description": "The pid of the process."
+ },
+ {
+ "name": "width",
+ "type": "integer",
+ "description": "New window width (as column count)."
+ },
+ {
+ "name": "height",
+ "type": "integer",
+ "description": "New window height (as row count)."
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": true,
+ "description": "Callback that will be called when sendInput method ends. Returns success.",
+ "parameters": [
+ {
+ "name": "success",
+ "type": "boolean"
+ }
+ ]
+ }
+ ]
}
],
"events": [