Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / messaging / native_process_launcher.h
blob7558fa3369ce904d8e96ea1e57ecceb76cc535c8
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_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_
8 #include "base/callback_forward.h"
9 #include "base/files/file.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/process/process.h"
12 #include "ui/gfx/native_widget_types.h"
14 class GURL;
16 namespace base {
17 class CommandLine;
18 class FilePath;
21 namespace extensions {
23 class NativeProcessLauncher {
24 public:
25 enum LaunchResult {
26 RESULT_SUCCESS,
27 RESULT_INVALID_NAME,
28 RESULT_NOT_FOUND,
29 RESULT_FORBIDDEN,
30 RESULT_FAILED_TO_START,
33 // Callback that's called after the process has been launched. |result| is set
34 // to false in case of a failure. Handler must take ownership of the IO
35 // handles.
36 typedef base::Callback<void(LaunchResult result,
37 base::Process process,
38 base::File read_file,
39 base::File write_file)> LaunchedCallback;
41 // Creates default launcher for the current OS. |native_view| refers to the
42 // window that contains calling page. Can be nullptr, e.g. for background
43 // pages.
44 static scoped_ptr<NativeProcessLauncher> CreateDefault(
45 bool allow_user_level_hosts,
46 gfx::NativeView native_view);
48 NativeProcessLauncher() {}
49 virtual ~NativeProcessLauncher() {}
51 // Finds native messaging host with the specified name and launches it
52 // asynchronously. Also checks that the specified |origin| is permitted to
53 // access the host. |callback| is called after the process has been started.
54 // If the launcher is destroyed before the callback is called then the call is
55 // canceled and the process is stopped if it has been started already (by
56 // closing IO pipes).
57 virtual void Launch(const GURL& origin,
58 const std::string& native_host_name,
59 const LaunchedCallback& callback) const = 0;
61 protected:
62 // The following two methods are platform specific and are implemented in
63 // platform-specific .cc files.
65 // Finds manifest file for the native messaging host |native_host_name|.
66 // |user_level| is set to true if the manifest is installed on user level.
67 // Returns an empty path if the host with the specified name cannot be found.
68 static base::FilePath FindManifest(const std::string& native_host_name,
69 bool allow_user_level_hosts,
70 std::string* error_message);
72 // Launches native messaging process.
73 static bool LaunchNativeProcess(const base::CommandLine& command_line,
74 base::Process* process,
75 base::File* read_file,
76 base::File* write_file);
78 private:
79 DISALLOW_COPY_AND_ASSIGN(NativeProcessLauncher);
82 } // namespace extensions
84 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_PROCESS_LAUNCHER_H_