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 #ifndef CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
11 | 11 |
12 // Base class for all terminalPrivate function classes. Main purpose is to run | 12 // Base class for all terminalPrivate function classes. Main purpose is to run |
13 // permission check before calling actual function implementation. | 13 // permission check before calling actual function implementation. |
14 class TerminalPrivateFunction : public AsyncExtensionFunction { | 14 class TerminalPrivateFunction : public AsyncExtensionFunction { |
15 public: | 15 public: |
16 TerminalPrivateFunction(); | 16 TerminalPrivateFunction(); |
17 | 17 |
18 protected: | 18 protected: |
19 virtual ~TerminalPrivateFunction(); | 19 virtual ~TerminalPrivateFunction(); |
20 | 20 |
21 // ExtensionFunction: | 21 // ExtensionFunction: |
22 virtual bool RunImpl() OVERRIDE; | 22 virtual bool RunImpl() OVERRIDE; |
23 | 23 |
24 // Override with actual extension function implementation. | 24 // Override with actual extension function implementation. |
25 virtual bool RunTerminalFunction() = 0; | 25 virtual bool RunTerminalFunction() = 0; |
26 | 26 |
27 }; | 27 }; |
28 | 28 |
29 // Opens new terminal process. Returns the new process id. | 29 // Opens new terminal process. Returns the new process id. |
30 class OpenTerminalProcessFunction : public TerminalPrivateFunction { | 30 class TerminalPrivateOpenTerminalProcessFunction |
| 31 : public TerminalPrivateFunction { |
31 public: | 32 public: |
32 DECLARE_EXTENSION_FUNCTION("terminalPrivate.openTerminalProcess", | 33 DECLARE_EXTENSION_FUNCTION("terminalPrivate.openTerminalProcess", |
33 TERMINALPRIVATE_OPENTERMINALPROCESS) | 34 TERMINALPRIVATE_OPENTERMINALPROCESS) |
34 | 35 |
35 OpenTerminalProcessFunction(); | 36 TerminalPrivateOpenTerminalProcessFunction(); |
36 | 37 |
37 protected: | 38 protected: |
38 virtual ~OpenTerminalProcessFunction(); | 39 virtual ~TerminalPrivateOpenTerminalProcessFunction(); |
39 | 40 |
40 // TerminalPrivateFunction: | 41 // TerminalPrivateFunction: |
41 virtual bool RunTerminalFunction() OVERRIDE; | 42 virtual bool RunTerminalFunction() OVERRIDE; |
42 | 43 |
43 private: | 44 private: |
44 void OpenOnFileThread(); | 45 void OpenOnFileThread(); |
45 void RespondOnUIThread(pid_t pid); | 46 void RespondOnUIThread(pid_t pid); |
46 | 47 |
47 const char* command_; | 48 const char* command_; |
48 }; | 49 }; |
49 | 50 |
50 // Send input to the terminal process specified by the pid sent as an argument. | 51 // Send input to the terminal process specified by the pid sent as an argument. |
51 class SendInputToTerminalProcessFunction : public TerminalPrivateFunction { | 52 class TerminalPrivateSendInputFunction : public TerminalPrivateFunction { |
52 public: | 53 public: |
53 DECLARE_EXTENSION_FUNCTION("terminalPrivate.sendInput", | 54 DECLARE_EXTENSION_FUNCTION("terminalPrivate.sendInput", |
54 TERMINALPRIVATE_SENDINPUT) | 55 TERMINALPRIVATE_SENDINPUT) |
55 | 56 |
56 protected: | 57 protected: |
57 virtual ~SendInputToTerminalProcessFunction(); | 58 virtual ~TerminalPrivateSendInputFunction(); |
58 | 59 |
59 // TerminalPrivateFunction: | 60 // TerminalPrivateFunction: |
60 virtual bool RunTerminalFunction() OVERRIDE; | 61 virtual bool RunTerminalFunction() OVERRIDE; |
61 | 62 |
62 private: | 63 private: |
63 void SendInputOnFileThread(pid_t pid, const std::string& input); | 64 void SendInputOnFileThread(pid_t pid, const std::string& input); |
64 void RespondOnUIThread(bool success); | 65 void RespondOnUIThread(bool success); |
65 }; | 66 }; |
66 | 67 |
67 // Closes terminal process with given pid. | 68 // Closes terminal process with given pid. |
68 class CloseTerminalProcessFunction : public TerminalPrivateFunction { | 69 class TerminalPrivateCloseTerminalProcessFunction |
| 70 : public TerminalPrivateFunction { |
69 public: | 71 public: |
70 DECLARE_EXTENSION_FUNCTION("terminalPrivate.closeTerminalProcess", | 72 DECLARE_EXTENSION_FUNCTION("terminalPrivate.closeTerminalProcess", |
71 TERMINALPRIVATE_CLOSETERMINALPROCESS) | 73 TERMINALPRIVATE_CLOSETERMINALPROCESS) |
72 | 74 |
73 protected: | 75 protected: |
74 virtual ~CloseTerminalProcessFunction(); | 76 virtual ~TerminalPrivateCloseTerminalProcessFunction(); |
75 | 77 |
76 virtual bool RunTerminalFunction() OVERRIDE; | 78 virtual bool RunTerminalFunction() OVERRIDE; |
77 | 79 |
78 private: | 80 private: |
79 void CloseOnFileThread(pid_t pid); | 81 void CloseOnFileThread(pid_t pid); |
80 void RespondOnUIThread(bool success); | 82 void RespondOnUIThread(bool success); |
81 }; | 83 }; |
82 | 84 |
83 // Called by extension when terminal size changes. | 85 // Called by extension when terminal size changes. |
84 class OnTerminalResizeFunction : public TerminalPrivateFunction { | 86 class TerminalPrivateOnTerminalResizeFunction : public TerminalPrivateFunction { |
85 public: | 87 public: |
86 DECLARE_EXTENSION_FUNCTION("terminalPrivate.onTerminalResize", | 88 DECLARE_EXTENSION_FUNCTION("terminalPrivate.onTerminalResize", |
87 TERMINALPRIVATE_ONTERMINALRESIZE) | 89 TERMINALPRIVATE_ONTERMINALRESIZE) |
88 | 90 |
89 protected: | 91 protected: |
90 virtual ~OnTerminalResizeFunction(); | 92 virtual ~TerminalPrivateOnTerminalResizeFunction(); |
91 | 93 |
92 virtual bool RunTerminalFunction() OVERRIDE; | 94 virtual bool RunTerminalFunction() OVERRIDE; |
93 | 95 |
94 private: | 96 private: |
95 void OnResizeOnFileThread(pid_t pid, int width, int height); | 97 void OnResizeOnFileThread(pid_t pid, int width, int height); |
96 void RespondOnUIThread(bool success); | 98 void RespondOnUIThread(bool success); |
97 }; | 99 }; |
98 | 100 |
99 #endif // CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_ | 101 #endif // CHROME_BROWSER_EXTENSIONS_API_TERMINAL_TERMINAL_PRIVATE_API_H_ |
OLD | NEW |