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/child_process_launcher_android.h" | 5 #include "content/browser/android/child_process_launcher_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 19 matching lines...) Expand all Loading... |
30 using base::android::AttachCurrentThread; | 30 using base::android::AttachCurrentThread; |
31 using base::android::JavaParamRef; | 31 using base::android::JavaParamRef; |
32 using base::android::JavaRef; | 32 using base::android::JavaRef; |
33 using base::android::ToJavaArrayOfStrings; | 33 using base::android::ToJavaArrayOfStrings; |
34 using base::android::ScopedJavaGlobalRef; | 34 using base::android::ScopedJavaGlobalRef; |
35 using base::android::ScopedJavaLocalRef; | 35 using base::android::ScopedJavaLocalRef; |
36 using content::StartChildProcessCallback; | 36 using content::StartChildProcessCallback; |
37 | 37 |
38 namespace content { | 38 namespace content { |
39 | 39 |
40 namespace { | |
41 | |
42 // Pass a java surface object to the MediaPlayerAndroid object | |
43 // identified by render process handle, render frame ID and player ID. | |
44 static void SetSurfacePeer( | |
45 const base::android::JavaRef<jobject>& surface, | |
46 base::ProcessHandle render_process_handle, | |
47 int render_frame_id, | |
48 int player_id) { | |
49 int render_process_id = 0; | |
50 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | |
51 while (!it.IsAtEnd()) { | |
52 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | |
53 render_process_id = it.GetCurrentValue()->GetID(); | |
54 break; | |
55 } | |
56 it.Advance(); | |
57 } | |
58 if (!render_process_id) { | |
59 DVLOG(1) << "Cannot find render process for render_process_handle " | |
60 << render_process_handle; | |
61 return; | |
62 } | |
63 | |
64 RenderFrameHostImpl* frame = | |
65 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | |
66 if (!frame) { | |
67 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id; | |
68 return; | |
69 } | |
70 | |
71 BrowserMediaPlayerManager* player_manager = | |
72 MediaWebContentsObserverAndroid::FromWebContents( | |
73 WebContents::FromRenderFrameHost(frame)) | |
74 ->GetMediaPlayerManager(frame); | |
75 if (!player_manager) { | |
76 DVLOG(1) << "Cannot find the media player manager for frame " << frame; | |
77 return; | |
78 } | |
79 | |
80 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); | |
81 if (!player) { | |
82 DVLOG(1) << "Cannot find media player for player_id " << player_id; | |
83 return; | |
84 } | |
85 | |
86 if (player != player_manager->GetFullscreenPlayer()) { | |
87 gl::ScopedJavaSurface scoped_surface(surface); | |
88 player->SetVideoSurface(std::move(scoped_surface)); | |
89 } | |
90 } | |
91 | |
92 } // anonymous namespace | |
93 | |
94 // Called from ChildProcessLauncher.java when the ChildProcess was | 40 // Called from ChildProcessLauncher.java when the ChildProcess was |
95 // started. | 41 // started. |
96 // |client_context| is the pointer to StartChildProcessCallback which was | 42 // |client_context| is the pointer to StartChildProcessCallback which was |
97 // passed in from StartChildProcess. | 43 // passed in from StartChildProcess. |
98 // |handle| is the processID of the child process as originated in Java, 0 if | 44 // |handle| is the processID of the child process as originated in Java, 0 if |
99 // the ChildProcess could not be created. | 45 // the ChildProcess could not be created. |
100 static void OnChildProcessStarted(JNIEnv*, | 46 static void OnChildProcessStarted(JNIEnv*, |
101 const JavaParamRef<jclass>&, | 47 const JavaParamRef<jclass>&, |
102 jlong client_context, | 48 jlong client_context, |
103 jint handle) { | 49 jint handle) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 112 } |
167 | 113 |
168 void SetChildProcessInForeground(base::ProcessHandle handle, | 114 void SetChildProcessInForeground(base::ProcessHandle handle, |
169 bool in_foreground) { | 115 bool in_foreground) { |
170 JNIEnv* env = AttachCurrentThread(); | 116 JNIEnv* env = AttachCurrentThread(); |
171 DCHECK(env); | 117 DCHECK(env); |
172 return Java_ChildProcessLauncher_setInForeground(env, | 118 return Java_ChildProcessLauncher_setInForeground(env, |
173 static_cast<jint>(handle), static_cast<jboolean>(in_foreground)); | 119 static_cast<jint>(handle), static_cast<jboolean>(in_foreground)); |
174 } | 120 } |
175 | 121 |
176 void EstablishSurfacePeer(JNIEnv* env, | |
177 const JavaParamRef<jclass>& clazz, | |
178 jint pid, | |
179 const JavaParamRef<jobject>& surface, | |
180 jint primary_id, | |
181 jint secondary_id) { | |
182 ScopedJavaGlobalRef<jobject> jsurface; | |
183 jsurface.Reset(env, surface); | |
184 if (jsurface.is_null()) | |
185 return; | |
186 | |
187 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
188 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | |
189 &SetSurfacePeer, jsurface, pid, primary_id, secondary_id)); | |
190 } | |
191 | |
192 void CompleteScopedSurfaceRequest(JNIEnv* env, | 122 void CompleteScopedSurfaceRequest(JNIEnv* env, |
193 const JavaParamRef<jclass>& clazz, | 123 const JavaParamRef<jclass>& clazz, |
194 const JavaParamRef<jobject>& token, | 124 const JavaParamRef<jobject>& token, |
195 const JavaParamRef<jobject>& surface) { | 125 const JavaParamRef<jobject>& surface) { |
196 base::UnguessableToken requestToken = | 126 base::UnguessableToken requestToken = |
197 base::android::UnguessableTokenAndroid::FromJavaUnguessableToken(env, | 127 base::android::UnguessableTokenAndroid::FromJavaUnguessableToken(env, |
198 token); | 128 token); |
199 if (!requestToken) { | 129 if (!requestToken) { |
200 DLOG(ERROR) << "Received invalid surface request token."; | 130 DLOG(ERROR) << "Received invalid surface request token."; |
201 return; | 131 return; |
(...skipping 18 matching lines...) Expand all Loading... |
220 gl::ScopedJavaSurface surface_view = | 150 gl::ScopedJavaSurface surface_view = |
221 gpu::GpuSurfaceTracker::GetInstance()->AcquireJavaSurface(surface_id); | 151 gpu::GpuSurfaceTracker::GetInstance()->AcquireJavaSurface(surface_id); |
222 return base::android::ScopedJavaLocalRef<jobject>(surface_view.j_surface()); | 152 return base::android::ScopedJavaLocalRef<jobject>(surface_view.j_surface()); |
223 } | 153 } |
224 | 154 |
225 bool RegisterChildProcessLauncher(JNIEnv* env) { | 155 bool RegisterChildProcessLauncher(JNIEnv* env) { |
226 return RegisterNativesImpl(env); | 156 return RegisterNativesImpl(env); |
227 } | 157 } |
228 | 158 |
229 } // namespace content | 159 } // namespace content |
OLD | NEW |