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/child_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 "base/memory/scoped_ptr.h" |
11 #include "content/browser/android/media_player_manager_android.h" | 11 #include "content/browser/android/media_player_manager_android.h" |
12 #include "content/browser/renderer_host/compositor_impl_android.h" | 12 #include "content/browser/renderer_host/compositor_impl_android.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/common/android/scoped_java_surface.h" | 14 #include "content/common/android/scoped_java_surface.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
17 #include "jni/SandboxedProcessLauncher_jni.h" | 17 #include "jni/ChildProcessLauncher_jni.h" |
18 #include "media/base/android/media_player_bridge.h" | 18 #include "media/base/android/media_player_bridge.h" |
19 | 19 |
20 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
21 using base::android::ToJavaArrayOfStrings; | 21 using base::android::ToJavaArrayOfStrings; |
22 using base::android::ScopedJavaGlobalRef; | 22 using base::android::ScopedJavaGlobalRef; |
23 using base::android::ScopedJavaLocalRef; | 23 using base::android::ScopedJavaLocalRef; |
24 using content::StartSandboxedProcessCallback; | 24 using content::StartChildProcessCallback; |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // Pass a java surface object to the MediaPlayerBridge object | 30 // Pass a java surface object to the MediaPlayerBridge object |
31 // identified by render process handle, render view ID and player ID. | 31 // identified by render process handle, render view ID and player ID. |
32 static void SetSurfacePeer( | 32 static void SetSurfacePeer( |
33 const base::android::JavaRef<jobject>& surface, | 33 const base::android::JavaRef<jobject>& surface, |
34 base::ProcessHandle render_process_handle, | 34 base::ProcessHandle render_process_handle, |
(...skipping 19 matching lines...) Expand all Loading... |
54 player != host->media_player_manager()->GetFullscreenPlayer()) { | 54 player != host->media_player_manager()->GetFullscreenPlayer()) { |
55 ScopedJavaSurface scoped_surface(surface); | 55 ScopedJavaSurface scoped_surface(surface); |
56 player->SetVideoSurface(scoped_surface.j_surface().obj()); | 56 player->SetVideoSurface(scoped_surface.j_surface().obj()); |
57 } | 57 } |
58 } | 58 } |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 } // anonymous namespace | 62 } // anonymous namespace |
63 | 63 |
64 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was | 64 // Called from ChildProcessLauncher.java when the ChildProcess was |
65 // started. | 65 // started. |
66 // |client_context| is the pointer to StartSandboxedProcessCallback which was | 66 // |client_context| is the pointer to StartChildProcessCallback which was |
67 // passed in from StartSandboxedProcess. | 67 // passed in from StartChildProcess. |
68 // |handle| is the processID of the child process as originated in Java, 0 if | 68 // |handle| is the processID of the child process as originated in Java, 0 if |
69 // the SandboxedProcess could not be created. | 69 // the ChildProcess could not be created. |
70 static void OnSandboxedProcessStarted(JNIEnv*, | 70 static void OnChildProcessStarted(JNIEnv*, |
71 jclass, | 71 jclass, |
72 jint client_context, | 72 jint client_context, |
73 jint handle) { | 73 jint handle) { |
74 StartSandboxedProcessCallback* callback = | 74 StartChildProcessCallback* callback = |
75 reinterpret_cast<StartSandboxedProcessCallback*>(client_context); | 75 reinterpret_cast<StartChildProcessCallback*>(client_context); |
76 if (handle) | 76 if (handle) |
77 callback->Run(static_cast<base::ProcessHandle>(handle)); | 77 callback->Run(static_cast<base::ProcessHandle>(handle)); |
78 delete callback; | 78 delete callback; |
79 } | 79 } |
80 | 80 |
81 void StartSandboxedProcess( | 81 void StartChildProcess( |
82 const CommandLine::StringVector& argv, | 82 const CommandLine::StringVector& argv, |
83 const std::vector<content::FileDescriptorInfo>& files_to_register, | 83 const std::vector<content::FileDescriptorInfo>& files_to_register, |
84 const StartSandboxedProcessCallback& callback) { | 84 const StartChildProcessCallback& callback) { |
85 JNIEnv* env = AttachCurrentThread(); | 85 JNIEnv* env = AttachCurrentThread(); |
86 DCHECK(env); | 86 DCHECK(env); |
87 | 87 |
88 // Create the Command line String[] | 88 // Create the Command line String[] |
89 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); | 89 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); |
90 | 90 |
91 size_t file_count = files_to_register.size(); | 91 size_t file_count = files_to_register.size(); |
92 DCHECK(file_count > 0); | 92 DCHECK(file_count > 0); |
93 | 93 |
94 ScopedJavaLocalRef<jintArray> j_file_ids(env, env->NewIntArray(file_count)); | 94 ScopedJavaLocalRef<jintArray> j_file_ids(env, env->NewIntArray(file_count)); |
(...skipping 13 matching lines...) Expand all Loading... |
108 for (size_t i = 0; i < file_count; ++i) { | 108 for (size_t i = 0; i < file_count; ++i) { |
109 const content::FileDescriptorInfo& fd_info = files_to_register[i]; | 109 const content::FileDescriptorInfo& fd_info = files_to_register[i]; |
110 file_ids[i] = fd_info.id; | 110 file_ids[i] = fd_info.id; |
111 file_fds[i] = fd_info.fd.fd; | 111 file_fds[i] = fd_info.fd.fd; |
112 file_auto_close[i] = fd_info.fd.auto_close; | 112 file_auto_close[i] = fd_info.fd.auto_close; |
113 } | 113 } |
114 env->ReleaseIntArrayElements(j_file_ids.obj(), file_ids, 0); | 114 env->ReleaseIntArrayElements(j_file_ids.obj(), file_ids, 0); |
115 env->ReleaseIntArrayElements(j_file_fds.obj(), file_fds, 0); | 115 env->ReleaseIntArrayElements(j_file_fds.obj(), file_fds, 0); |
116 env->ReleaseBooleanArrayElements(j_file_auto_close.obj(), file_auto_close, 0); | 116 env->ReleaseBooleanArrayElements(j_file_auto_close.obj(), file_auto_close, 0); |
117 | 117 |
118 Java_SandboxedProcessLauncher_start(env, | 118 Java_ChildProcessLauncher_start(env, |
119 base::android::GetApplicationContext(), | 119 base::android::GetApplicationContext(), |
120 j_argv.obj(), | 120 j_argv.obj(), |
121 j_file_ids.obj(), | 121 j_file_ids.obj(), |
122 j_file_fds.obj(), | 122 j_file_fds.obj(), |
123 j_file_auto_close.obj(), | 123 j_file_auto_close.obj(), |
124 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback))); | 124 reinterpret_cast<jint>(new StartChildProcessCallback(callback))); |
125 } | 125 } |
126 | 126 |
127 void StopSandboxedProcess(base::ProcessHandle handle) { | 127 void StopChildProcess(base::ProcessHandle handle) { |
128 JNIEnv* env = AttachCurrentThread(); | 128 JNIEnv* env = AttachCurrentThread(); |
129 DCHECK(env); | 129 DCHECK(env); |
130 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle)); | 130 Java_ChildProcessLauncher_stop(env, static_cast<jint>(handle)); |
131 } | 131 } |
132 | 132 |
133 void EstablishSurfacePeer( | 133 void EstablishSurfacePeer( |
134 JNIEnv* env, jclass clazz, | 134 JNIEnv* env, jclass clazz, |
135 jint pid, jobject surface, jint primary_id, jint secondary_id) { | 135 jint pid, jobject surface, jint primary_id, jint secondary_id) { |
136 ScopedJavaGlobalRef<jobject> jsurface; | 136 ScopedJavaGlobalRef<jobject> jsurface; |
137 jsurface.Reset(env, surface); | 137 jsurface.Reset(env, surface); |
138 if (jsurface.is_null()) | 138 if (jsurface.is_null()) |
139 return; | 139 return; |
140 | 140 |
141 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
142 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 142 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
143 &SetSurfacePeer, jsurface, pid, primary_id, secondary_id)); | 143 &SetSurfacePeer, jsurface, pid, primary_id, secondary_id)); |
144 } | 144 } |
145 | 145 |
146 jobject GetViewSurface(JNIEnv* env, jclass clazz, jint surface_id) { | 146 jobject GetViewSurface(JNIEnv* env, jclass clazz, jint surface_id) { |
147 // This is a synchronous call from the GPU process and is expected to be | 147 // This is a synchronous call from the GPU process and is expected to be |
148 // handled on a binder thread. Handling this on the UI thread will lead | 148 // handled on a binder thread. Handling this on the UI thread will lead |
149 // to deadlocks. | 149 // to deadlocks. |
150 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 150 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
151 return CompositorImpl::GetSurface(surface_id); | 151 return CompositorImpl::GetSurface(surface_id); |
152 } | 152 } |
153 | 153 |
154 bool RegisterSandboxedProcessLauncher(JNIEnv* env) { | 154 bool RegisterChildProcessLauncher(JNIEnv* env) { |
155 return RegisterNativesImpl(env); | 155 return RegisterNativesImpl(env); |
156 } | 156 } |
157 | 157 |
158 } // namespace content | 158 } // namespace content |
OLD | NEW |