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