| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 #include "base/files/file_path.h" |
| 6 #include "base/metrics/field_trial.h" |
| 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/win/scoped_handle.h" |
| 9 #include "base/win/win_util.h" |
| 10 #include "content/browser/child_process_launcher_helper.h" |
| 11 #include "content/common/sandbox_win.h" |
| 12 #include "content/public/common/result_codes.h" |
| 13 #include "content/public/common/sandbox_init.h" |
| 14 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 15 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 17 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 18 #include "sandbox/win/src/sandbox_types.h" |
| 19 |
| 20 namespace content { |
| 21 namespace internal { |
| 22 |
| 23 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { |
| 24 DCHECK_CURRENTLY_ON(client_thread_id_); |
| 25 } |
| 26 |
| 27 mojo::edk::ScopedPlatformHandle |
| 28 ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() { |
| 29 DCHECK_CURRENTLY_ON(client_thread_id_); |
| 30 |
| 31 if (!delegate_->ShouldLaunchElevated()) |
| 32 return mojo::edk::ScopedPlatformHandle(); |
| 33 |
| 34 mojo::edk::NamedPlatformChannelPair named_pair; |
| 35 named_pair.PrepareToPassClientHandleToChildProcess(command_line()); |
| 36 return named_pair.PassServerHandle(); |
| 37 } |
| 38 |
| 39 std::unique_ptr<FileMappedForLaunch> |
| 40 ChildProcessLauncherHelper::GetFilesToMap() { |
| 41 return std::unique_ptr<FileMappedForLaunch>(); |
| 42 } |
| 43 |
| 44 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( |
| 45 const FileMappedForLaunch& files_to_register, |
| 46 base::LaunchOptions* options) { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 48 } |
| 49 |
| 50 ChildProcessLauncherHelper::Process |
| 51 ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( |
| 52 const base::LaunchOptions& options, |
| 53 std::unique_ptr<FileMappedForLaunch> files_to_register, |
| 54 bool* is_synchronous_launch, |
| 55 int* launch_result) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 57 *is_synchronous_launch = true; |
| 58 if (delegate_->ShouldLaunchElevated()) { |
| 59 // When establishing a Mojo connection, the pipe path has already been added |
| 60 // to the command line. |
| 61 base::LaunchOptions win_options; |
| 62 win_options.start_hidden = true; |
| 63 ChildProcessLauncherHelper::Process process; |
| 64 process.process = base::LaunchElevatedProcess(*command_line(), win_options); |
| 65 return process; |
| 66 } |
| 67 base::HandlesToInheritVector handles; |
| 68 handles.push_back(mojo_client_handle().handle); |
| 69 base::FieldTrialList::AppendFieldTrialHandleIfNeeded(&handles); |
| 70 command_line()->AppendSwitchASCII( |
| 71 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, |
| 72 base::UintToString(base::win::HandleToUint32(handles[0]))); |
| 73 ChildProcessLauncherHelper::Process process; |
| 74 *launch_result = StartSandboxedProcess( |
| 75 delegate_.get(), |
| 76 command_line(), |
| 77 handles, |
| 78 &process.process); |
| 79 return process; |
| 80 } |
| 81 |
| 82 void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread( |
| 83 const ChildProcessLauncherHelper::Process& process, |
| 84 const base::LaunchOptions& options) { |
| 85 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 86 } |
| 87 |
| 88 // static |
| 89 base::TerminationStatus ChildProcessLauncherHelper::GetTerminationStatus( |
| 90 const ChildProcessLauncherHelper::Process& process, |
| 91 bool known_dead, |
| 92 int* exit_code) { |
| 93 return base::GetTerminationStatus(process.process.Handle(), exit_code); |
| 94 } |
| 95 |
| 96 // static |
| 97 bool ChildProcessLauncherHelper::TerminateProcess( |
| 98 const base::Process& process, int exit_code, bool wait) { |
| 99 return process.Terminate(exit_code, wait); |
| 100 } |
| 101 |
| 102 void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync( |
| 103 ChildProcessLauncherHelper::Process process) { |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 105 // Client has gone away, so just kill the process. Using exit code 0 means |
| 106 // that UMA won't treat this as a crash. |
| 107 process.process.Terminate(RESULT_CODE_NORMAL_EXIT, false); |
| 108 } |
| 109 |
| 110 // static |
| 111 void ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread( |
| 112 base::Process process, bool background) { |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 114 if (process.CanBackgroundProcesses()) |
| 115 process.SetProcessBackgrounded(background); |
| 116 } |
| 117 |
| 118 } // namespace internal |
| 119 } // namespace content |
| OLD | NEW |