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_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_ |
7 | 7 |
8 #include "base/process.h" | 8 #include "base/process.h" |
9 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 9 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 class FilePath; | 12 class FilePath; |
13 } | 13 } |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
| 17 class NativeMessagingHostManifest; |
| 18 |
17 class NativeProcessLauncher { | 19 class NativeProcessLauncher { |
18 public: | 20 public: |
19 // Callback that's called after the process has been launched. | 21 // Callback that's called after the process has been launched. |
20 // |native_process_handle| is set to base::kNullProcessHandle in case of a | 22 // |native_process_handle| is set to base::kNullProcessHandle in case of a |
21 // failure. | 23 // failure. |
22 typedef base::Callback<void (base::ProcessHandle native_process_handle, | 24 typedef base::Callback<void (base::ProcessHandle native_process_handle, |
23 base::PlatformFile read_file, | 25 base::PlatformFile read_file, |
24 base::PlatformFile write_file)> LaunchedCallback; | 26 base::PlatformFile write_file)> LaunchedCallback; |
25 | 27 |
26 static scoped_ptr<NativeProcessLauncher> CreateDefault(); | 28 static scoped_ptr<NativeProcessLauncher> CreateDefault(); |
27 | 29 |
28 NativeProcessLauncher() {} | 30 NativeProcessLauncher() {} |
29 virtual ~NativeProcessLauncher() {} | 31 virtual ~NativeProcessLauncher() {} |
30 | 32 |
31 // Launches native host with the specified name asynchronously. |callback| is | 33 // Finds native messaging host with the specified name and launches it |
32 // called after the process has been started. If the launcher is destroyed | 34 // asynchronously. Also checks that the specified |origin| is permitted to |
33 // before the callback is called then the call is canceled and the process is | 35 // access the host. |callback| is called after the process has been started. |
34 // killed if it has been started already. | 36 // If the launcher is destroyed before the callback is called then the call is |
35 virtual void Launch(const std::string& native_host_name, | 37 // canceled and the process is killed if it has been started already. |
| 38 virtual void Launch(const std::string& origin, |
| 39 const std::string& native_host_name, |
36 LaunchedCallback callback) const = 0; | 40 LaunchedCallback callback) const = 0; |
37 | 41 |
38 protected: | 42 protected: |
| 43 // The following two methods are platform specific and are implemented in |
| 44 // platform-specific .cc files. |
| 45 |
| 46 // Loads manifest for the native messaging host |name|. |
| 47 static scoped_ptr<NativeMessagingHostManifest> FindAndLoadManifest( |
| 48 const std::string& native_host_name, |
| 49 std::string* error_message); |
| 50 |
| 51 // Launches native messaging process. |
39 static bool LaunchNativeProcess( | 52 static bool LaunchNativeProcess( |
40 const base::FilePath& path, | 53 const base::FilePath& path, |
41 base::ProcessHandle* native_process_handle, | 54 base::ProcessHandle* native_process_handle, |
42 base::PlatformFile* read_file, | 55 base::PlatformFile* read_file, |
43 base::PlatformFile* write_file); | 56 base::PlatformFile* write_file); |
44 | 57 |
45 private: | 58 private: |
46 DISALLOW_COPY_AND_ASSIGN(NativeProcessLauncher); | 59 DISALLOW_COPY_AND_ASSIGN(NativeProcessLauncher); |
47 }; | 60 }; |
48 | 61 |
49 } // namespace extensions | 62 } // namespace extensions |
50 | 63 |
51 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_ | 64 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_ |
OLD | NEW |