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 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" | 5 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/string16.h" | |
13 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
16 #include "base/win/registry.h" | |
17 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
18 #include "crypto/random.h" | 16 #include "crypto/random.h" |
19 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" | |
20 | 17 |
21 namespace extensions { | 18 namespace extensions { |
22 | 19 |
23 const wchar_t kNativeMessagingRegistryKey[] = | |
24 L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts"; | |
25 | |
26 // static | |
27 scoped_ptr<NativeMessagingHostManifest> | |
28 NativeProcessLauncher::FindAndLoadManifest( | |
29 const std::string& native_host_name, | |
30 std::string* error_message) { | |
31 base::win::RegKey key; | |
32 | |
33 string16 manifest_path; | |
34 string16 native_host_name_wide = UTF8ToUTF16(native_host_name); | |
35 | |
36 bool found = false; | |
37 | |
38 // First check 32-bit registry and then try 64-bit. | |
39 if (key.Open(HKEY_LOCAL_MACHINE, kNativeMessagingRegistryKey, | |
40 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
41 if (key.ReadValue(native_host_name_wide.c_str(), &manifest_path) == | |
42 ERROR_SUCCESS) { | |
43 found = true; | |
44 } | |
45 } | |
46 | |
47 if (!found && key.Open(HKEY_LOCAL_MACHINE, kNativeMessagingRegistryKey, | |
48 KEY_QUERY_VALUE | KEY_WOW64_64KEY) == ERROR_SUCCESS) { | |
49 if (key.ReadValue(native_host_name_wide.c_str(), &manifest_path) == | |
50 ERROR_SUCCESS) { | |
51 found = true; | |
52 } | |
53 } | |
54 | |
55 if (!found) { | |
56 *error_message = "Native messaging host " + native_host_name + | |
57 " is not registered"; | |
58 return scoped_ptr<NativeMessagingHostManifest>(); | |
59 } | |
60 | |
61 return NativeMessagingHostManifest::Load( | |
62 base::FilePath(manifest_path), error_message); | |
63 } | |
64 | |
65 // static | 20 // static |
66 bool NativeProcessLauncher::LaunchNativeProcess( | 21 bool NativeProcessLauncher::LaunchNativeProcess( |
67 const base::FilePath& path, | 22 const base::FilePath& path, |
68 base::PlatformFile* read_file, | 23 base::PlatformFile* read_file, |
69 base::PlatformFile* write_file) { | 24 base::PlatformFile* write_file) { |
70 // Timeout for the IO pipes. | 25 // Timeout for the IO pipes. |
71 const DWORD kTimeoutMs = 5000; | 26 const DWORD kTimeoutMs = 5000; |
72 | 27 |
73 // Windows will use default buffer size when 0 is passed to | 28 // Windows will use default buffer size when 0 is passed to |
74 // CreateNamedPipeW(). | 29 // CreateNamedPipeW(). |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 116 |
162 base::CloseProcessHandle(cmd_handle); | 117 base::CloseProcessHandle(cmd_handle); |
163 | 118 |
164 *read_file = stdout_pipe.Take(); | 119 *read_file = stdout_pipe.Take(); |
165 *write_file = stdin_pipe.Take(); | 120 *write_file = stdin_pipe.Take(); |
166 | 121 |
167 return true; | 122 return true; |
168 } | 123 } |
169 | 124 |
170 } // namespace extensions | 125 } // namespace extensions |
OLD | NEW |