| 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 "content/browser/android/sandboxed_process_launcher.h" | 5 #include "content/browser/android/sandboxed_process_launcher.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "jni/sandboxed_process_launcher_jni.h" | 11 #include "jni/sandboxed_process_launcher_jni.h" |
| 11 | 12 |
| 12 using base::android::AttachCurrentThread; | 13 using base::android::AttachCurrentThread; |
| 13 using base::android::ToJavaArrayOfStrings; | 14 using base::android::ToJavaArrayOfStrings; |
| 14 using base::android::ScopedJavaLocalRef; | 15 using base::android::ScopedJavaLocalRef; |
| 16 using base::GlobalDescriptors; |
| 15 using content::StartSandboxedProcessCallback; | 17 using content::StartSandboxedProcessCallback; |
| 16 | 18 |
| 17 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was | 19 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was |
| 18 // started. | 20 // started. |
| 19 // |client_context| is the pointer to StartSandboxedProcessCallback which was | 21 // |client_context| is the pointer to StartSandboxedProcessCallback which was |
| 20 // passed in from StartSandboxedProcess. | 22 // passed in from StartSandboxedProcess. |
| 21 // |handle| is the processID of the child process as originated in Java. | 23 // |handle| is the processID of the child process as originated in Java. |
| 22 static void OnSandboxedProcessStarted(JNIEnv*, | 24 static void OnSandboxedProcessStarted(JNIEnv*, |
| 23 jclass, | 25 jclass, |
| 24 jint client_context, | 26 jint client_context, |
| 25 jint handle) { | 27 jint handle) { |
| 26 StartSandboxedProcessCallback* callback = | 28 StartSandboxedProcessCallback* callback = |
| 27 reinterpret_cast<StartSandboxedProcessCallback*>(client_context); | 29 reinterpret_cast<StartSandboxedProcessCallback*>(client_context); |
| 28 callback->Run(static_cast<base::ProcessHandle>(handle)); | 30 callback->Run(static_cast<base::ProcessHandle>(handle)); |
| 29 delete callback; | 31 delete callback; |
| 30 } | 32 } |
| 31 | 33 |
| 32 namespace content { | 34 namespace content { |
| 33 | 35 |
| 34 ScopedJavaLocalRef<jobject> StartSandboxedProcess( | 36 void StartSandboxedProcess( |
| 35 const CommandLine::StringVector& argv, | 37 const CommandLine::StringVector& argv, |
| 36 int ipc_fd, | 38 int ipc_fd, |
| 37 int crash_fd, | 39 const GlobalDescriptors::Mapping& files_to_register, |
| 38 const StartSandboxedProcessCallback& callback) { | 40 const StartSandboxedProcessCallback& callback) { |
| 39 JNIEnv* env = AttachCurrentThread(); | 41 JNIEnv* env = AttachCurrentThread(); |
| 40 DCHECK(env); | 42 DCHECK(env); |
| 41 | 43 |
| 42 // Create the Command line String[] | 44 // Create the Command line String[] |
| 43 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); | 45 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); |
| 44 | 46 |
| 45 return Java_SandboxedProcessLauncher_start(env, | 47 ScopedJavaLocalRef<jintArray> j_file_to_register_id_files(env, |
| 48 env->NewIntArray(files_to_register.size() * 2)); |
| 49 scoped_array<jint> file_to_register_id_files( |
| 50 new jint[files_to_register.size() * 2]); |
| 51 for (size_t i = 0; i < files_to_register.size(); ++i) { |
| 52 const GlobalDescriptors::KeyFDPair& id_file = files_to_register[i]; |
| 53 file_to_register_id_files[2 * i] = id_file.first; |
| 54 file_to_register_id_files[(2 * i) + 1] = id_file.second; |
| 55 } |
| 56 env->SetIntArrayRegion(j_file_to_register_id_files.obj(), |
| 57 0, files_to_register.size() * 2, |
| 58 file_to_register_id_files.get()); |
| 59 Java_SandboxedProcessLauncher_start(env, |
| 46 base::android::GetApplicationContext(), | 60 base::android::GetApplicationContext(), |
| 47 static_cast<jobjectArray>(j_argv.obj()), | 61 static_cast<jobjectArray>(j_argv.obj()), |
| 48 static_cast<jint>(ipc_fd), | 62 static_cast<jint>(ipc_fd), |
| 49 static_cast<jint>(crash_fd), | 63 j_file_to_register_id_files.obj(), |
| 50 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback))); | 64 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback))); |
| 51 } | 65 } |
| 52 | 66 |
| 53 void CancelStartSandboxedProcess( | |
| 54 const base::android::JavaRef<jobject>& connection) { | |
| 55 Java_SandboxedProcessLauncher_cancelStart(AttachCurrentThread(), | |
| 56 connection.obj()); | |
| 57 } | |
| 58 | |
| 59 void StopSandboxedProcess(base::ProcessHandle handle) { | 67 void StopSandboxedProcess(base::ProcessHandle handle) { |
| 60 JNIEnv* env = AttachCurrentThread(); | 68 JNIEnv* env = AttachCurrentThread(); |
| 61 DCHECK(env); | 69 DCHECK(env); |
| 62 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle)); | 70 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle)); |
| 63 } | 71 } |
| 64 | 72 |
| 65 bool RegisterSandboxedProcessLauncher(JNIEnv* env) { | 73 bool RegisterSandboxedProcessLauncher(JNIEnv* env) { |
| 66 return RegisterNativesImpl(env); | 74 return RegisterNativesImpl(env); |
| 67 } | 75 } |
| 68 | 76 |
| 69 } // namespace content | 77 } // namespace content |
| OLD | NEW |