| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
| 13 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 #if !defined(OS_ANDROID) |
| 21 base::FilePath FindManifestInDir(int dir_key, const std::string& host_name) { | 22 base::FilePath FindManifestInDir(int dir_key, const std::string& host_name) { |
| 22 base::FilePath base_path; | 23 base::FilePath base_path; |
| 23 if (PathService::Get(dir_key, &base_path)) { | 24 if (PathService::Get(dir_key, &base_path)) { |
| 24 base::FilePath path = base_path.Append(host_name + ".json"); | 25 base::FilePath path = base_path.Append(host_name + ".json"); |
| 25 if (base::PathExists(path)) | 26 if (base::PathExists(path)) |
| 26 return path; | 27 return path; |
| 27 } | 28 } |
| 28 return base::FilePath(); | 29 return base::FilePath(); |
| 29 } | 30 } |
| 31 #endif |
| 30 | 32 |
| 31 } // namespace | 33 } // namespace |
| 32 | 34 |
| 33 // static | 35 // static |
| 34 base::FilePath NativeProcessLauncher::FindManifest( | 36 base::FilePath NativeProcessLauncher::FindManifest( |
| 35 const std::string& host_name, | 37 const std::string& host_name, |
| 36 bool allow_user_level_hosts, | 38 bool allow_user_level_hosts, |
| 37 std::string* error_message) { | 39 std::string* error_message) { |
| 38 base::FilePath result; | 40 base::FilePath result; |
| 41 #if !defined(OS_ANDROID) |
| 39 if (allow_user_level_hosts) | 42 if (allow_user_level_hosts) |
| 40 result = FindManifestInDir(chrome::DIR_USER_NATIVE_MESSAGING, host_name); | 43 result = FindManifestInDir(chrome::DIR_USER_NATIVE_MESSAGING, host_name); |
| 41 if (result.empty()) | 44 if (result.empty()) |
| 42 result = FindManifestInDir(chrome::DIR_NATIVE_MESSAGING, host_name); | 45 result = FindManifestInDir(chrome::DIR_NATIVE_MESSAGING, host_name); |
| 43 | 46 |
| 44 if (result.empty()) | 47 if (result.empty()) |
| 45 *error_message = "Can't find native messaging host " + host_name; | 48 *error_message = "Can't find native messaging host " + host_name; |
| 46 | 49 #endif |
| 47 return result; | 50 return result; |
| 48 } | 51 } |
| 49 | 52 |
| 50 // static | 53 // static |
| 51 bool NativeProcessLauncher::LaunchNativeProcess( | 54 bool NativeProcessLauncher::LaunchNativeProcess( |
| 52 const base::CommandLine& command_line, | 55 const base::CommandLine& command_line, |
| 53 base::Process* process, | 56 base::Process* process, |
| 54 base::File* read_file, | 57 base::File* read_file, |
| 55 base::File* write_file) { | 58 base::File* write_file) { |
| 56 base::FileHandleMappingVector fd_map; | 59 base::FileHandleMappingVector fd_map; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 read_pipe_write_fd.reset(); | 95 read_pipe_write_fd.reset(); |
| 93 | 96 |
| 94 *process = local_process.Pass(); | 97 *process = local_process.Pass(); |
| 95 *read_file = base::File(read_pipe_read_fd.release()); | 98 *read_file = base::File(read_pipe_read_fd.release()); |
| 96 *write_file = base::File(write_pipe_write_fd.release()); | 99 *write_file = base::File(write_pipe_write_fd.release()); |
| 97 | 100 |
| 98 return true; | 101 return true; |
| 99 } | 102 } |
| 100 | 103 |
| 101 } // namespace extensions | 104 } // namespace extensions |
| OLD | NEW |