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 "base/memory/scoped_ptr.h" |
11 #include "content/browser/android/media_player_manager_android.h" | |
12 #include "content/browser/renderer_host/compositor_impl_android.h" | |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | |
14 #include "content/common/android/scoped_java_surface.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 #include "content/public/browser/render_process_host.h" | |
11 #include "jni/SandboxedProcessLauncher_jni.h" | 17 #include "jni/SandboxedProcessLauncher_jni.h" |
18 #include "media/base/android/media_player_bridge.h" | |
12 | 19 |
13 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
14 using base::android::ToJavaArrayOfStrings; | 21 using base::android::ToJavaArrayOfStrings; |
22 using base::android::ScopedJavaGlobalRef; | |
15 using base::android::ScopedJavaLocalRef; | 23 using base::android::ScopedJavaLocalRef; |
16 using content::StartSandboxedProcessCallback; | 24 using content::StartSandboxedProcessCallback; |
17 | 25 |
18 namespace content { | 26 namespace content { |
19 | 27 |
28 namespace { | |
29 | |
30 // Pass a java surface object to the MediaPlayerBridge object | |
31 // identified by render process handle, render view ID and player ID. | |
32 static void SetSurfacePeer( | |
33 const base::android::JavaRef<jobject>& surface, | |
34 base::ProcessHandle render_process_handle, | |
35 int render_view_id, | |
36 int player_id) { | |
37 int renderer_id = 0; | |
38 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | |
39 while (!it.IsAtEnd()) { | |
40 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | |
41 renderer_id = it.GetCurrentValue()->GetID(); | |
42 break; | |
43 } | |
44 it.Advance(); | |
45 } | |
46 | |
47 if (renderer_id) { | |
48 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | |
49 renderer_id, render_view_id); | |
50 if (host) { | |
51 media::MediaPlayerBridge* player = | |
52 host->media_player_manager()->GetPlayer(player_id); | |
53 if (player && | |
54 player != host->media_player_manager()->GetFullscreenPlayer()) { | |
55 ScopedJavaSurface scoped_surface(surface); | |
56 player->SetVideoSurface(scoped_surface.j_surface().obj()); | |
57 } | |
58 } | |
59 } | |
60 } | |
no sievers
2013/03/05 00:32:33
I guess I should really share this code with Surfa
| |
61 | |
62 } // anonymous namespace | |
bulach
2013/03/05 14:23:58
nit: add a \n
no sievers
2013/03/07 00:51:06
Done.
| |
20 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was | 63 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was |
21 // started. | 64 // started. |
22 // |client_context| is the pointer to StartSandboxedProcessCallback which was | 65 // |client_context| is the pointer to StartSandboxedProcessCallback which was |
23 // passed in from StartSandboxedProcess. | 66 // passed in from StartSandboxedProcess. |
24 // |handle| is the processID of the child process as originated in Java, 0 if | 67 // |handle| is the processID of the child process as originated in Java, 0 if |
25 // the SandboxedProcess could not be created. | 68 // the SandboxedProcess could not be created. |
26 static void OnSandboxedProcessStarted(JNIEnv*, | 69 static void OnSandboxedProcessStarted(JNIEnv*, |
27 jclass, | 70 jclass, |
28 jint client_context, | 71 jint client_context, |
29 jint handle) { | 72 jint handle) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 j_file_auto_close.obj(), | 122 j_file_auto_close.obj(), |
80 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback))); | 123 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback))); |
81 } | 124 } |
82 | 125 |
83 void StopSandboxedProcess(base::ProcessHandle handle) { | 126 void StopSandboxedProcess(base::ProcessHandle handle) { |
84 JNIEnv* env = AttachCurrentThread(); | 127 JNIEnv* env = AttachCurrentThread(); |
85 DCHECK(env); | 128 DCHECK(env); |
86 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle)); | 129 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle)); |
87 } | 130 } |
88 | 131 |
132 void EstablishSurfacePeer( | |
133 JNIEnv* env, jclass clazz, | |
134 jint pid, jobject surface, jint primary_id, jint secondary_id) { | |
135 ScopedJavaGlobalRef<jobject> jsurface; | |
136 jsurface.Reset(env, surface); | |
137 if (jsurface.is_null()) | |
138 return; | |
139 | |
140 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
141 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | |
142 &SetSurfacePeer, jsurface, pid, primary_id, secondary_id)); | |
143 } | |
144 | |
145 jobject GetViewSurface(JNIEnv* env, jclass clazz, jint surface_id) { | |
146 // This is a synchronous call from the GPU process and is expected to be | |
147 // handled on a binder thread. Handling this on the UI thread will lead | |
148 // to deadlocks. | |
149 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
150 return CompositorImpl::GetSurface(surface_id); | |
151 } | |
152 | |
89 bool RegisterSandboxedProcessLauncher(JNIEnv* env) { | 153 bool RegisterSandboxedProcessLauncher(JNIEnv* env) { |
90 return RegisterNativesImpl(env); | 154 return RegisterNativesImpl(env); |
91 } | 155 } |
92 | 156 |
93 } // namespace content | 157 } // namespace content |
OLD | NEW |