| 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" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/win/registry.h" |
| 15 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
| 16 #include "crypto/random.h" | 18 #include "crypto/random.h" |
| 19 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
| 17 | 20 |
| 18 namespace extensions { | 21 namespace extensions { |
| 19 | 22 |
| 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 |
| 20 // static | 65 // static |
| 21 bool NativeProcessLauncher::LaunchNativeProcess( | 66 bool NativeProcessLauncher::LaunchNativeProcess( |
| 22 const base::FilePath& path, | 67 const base::FilePath& path, |
| 23 base::PlatformFile* read_file, | 68 base::PlatformFile* read_file, |
| 24 base::PlatformFile* write_file) { | 69 base::PlatformFile* write_file) { |
| 25 // Timeout for the IO pipes. | 70 // Timeout for the IO pipes. |
| 26 const DWORD kTimeoutMs = 5000; | 71 const DWORD kTimeoutMs = 5000; |
| 27 | 72 |
| 28 // Windows will use default buffer size when 0 is passed to | 73 // Windows will use default buffer size when 0 is passed to |
| 29 // CreateNamedPipeW(). | 74 // CreateNamedPipeW(). |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 161 |
| 117 base::CloseProcessHandle(cmd_handle); | 162 base::CloseProcessHandle(cmd_handle); |
| 118 | 163 |
| 119 *read_file = stdout_pipe.Take(); | 164 *read_file = stdout_pipe.Take(); |
| 120 *write_file = stdin_pipe.Take(); | 165 *write_file = stdin_pipe.Take(); |
| 121 | 166 |
| 122 return true; | 167 return true; |
| 123 } | 168 } |
| 124 | 169 |
| 125 } // namespace extensions | 170 } // namespace extensions |
| OLD | NEW |