Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / terminal / terminal_private_api.h
blobf57781471be463b93c72d012bb4a1a03a809b657
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_
8 #include <string>
10 #include "chrome/browser/extensions/chrome_extension_function.h"
12 namespace extensions {
13 // Base class for all terminalPrivate function classes. Main purpose is to run
14 // permission check before calling actual function implementation.
15 class TerminalPrivateFunction : public ChromeAsyncExtensionFunction {
16 public:
17 TerminalPrivateFunction();
19 protected:
20 ~TerminalPrivateFunction() override;
22 // ExtensionFunction:
23 bool RunAsync() override;
25 // Override with actual extension function implementation.
26 virtual bool RunTerminalFunction() = 0;
29 // Opens new terminal process. Returns the new process id.
30 class TerminalPrivateOpenTerminalProcessFunction
31 : public TerminalPrivateFunction {
32 public:
33 DECLARE_EXTENSION_FUNCTION("terminalPrivate.openTerminalProcess",
34 TERMINALPRIVATE_OPENTERMINALPROCESS)
36 TerminalPrivateOpenTerminalProcessFunction();
38 protected:
39 ~TerminalPrivateOpenTerminalProcessFunction() override;
41 // TerminalPrivateFunction:
42 bool RunTerminalFunction() override;
44 private:
45 void OpenOnFileThread();
46 void RespondOnUIThread(pid_t pid);
48 const char* command_;
51 // Send input to the terminal process specified by the pid sent as an argument.
52 class TerminalPrivateSendInputFunction : public TerminalPrivateFunction {
53 public:
54 DECLARE_EXTENSION_FUNCTION("terminalPrivate.sendInput",
55 TERMINALPRIVATE_SENDINPUT)
57 protected:
58 ~TerminalPrivateSendInputFunction() override;
60 // TerminalPrivateFunction:
61 bool RunTerminalFunction() override;
63 private:
64 void SendInputOnFileThread(pid_t pid, const std::string& input);
65 void RespondOnUIThread(bool success);
68 // Closes terminal process with given pid.
69 class TerminalPrivateCloseTerminalProcessFunction
70 : public TerminalPrivateFunction {
71 public:
72 DECLARE_EXTENSION_FUNCTION("terminalPrivate.closeTerminalProcess",
73 TERMINALPRIVATE_CLOSETERMINALPROCESS)
75 protected:
76 ~TerminalPrivateCloseTerminalProcessFunction() override;
78 bool RunTerminalFunction() override;
80 private:
81 void CloseOnFileThread(pid_t pid);
82 void RespondOnUIThread(bool success);
85 // Called by extension when terminal size changes.
86 class TerminalPrivateOnTerminalResizeFunction : public TerminalPrivateFunction {
87 public:
88 DECLARE_EXTENSION_FUNCTION("terminalPrivate.onTerminalResize",
89 TERMINALPRIVATE_ONTERMINALRESIZE)
91 protected:
92 ~TerminalPrivateOnTerminalResizeFunction() override;
94 bool RunTerminalFunction() override;
96 private:
97 void OnResizeOnFileThread(pid_t pid, int width, int height);
98 void RespondOnUIThread(bool success);
101 } // namespace extensions
103 #endif // CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_