| 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 "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/frame_host/render_frame_host_impl.h" | 11 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 12 #include "content/browser/media/android/browser_media_player_manager.h" | |
| 13 #include "content/browser/media/media_web_contents_observer.h" | |
| 14 #include "content/browser/renderer_host/compositor_impl_android.h" | |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 19 #include "jni/ChildProcessLauncher_jni.h" | 16 #include "jni/ChildProcessLauncher_jni.h" |
| 17 #include "ui/gl/android/surface_texture.h" |
| 18 |
| 19 |
| 20 #if !defined(USE_AURA) |
| 21 #include "content/browser/media/android/browser_media_player_manager.h" |
| 22 #include "content/browser/media/media_web_contents_observer.h" |
| 23 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 20 #include "media/base/android/media_player_android.h" | 24 #include "media/base/android/media_player_android.h" |
| 21 #include "ui/gl/android/surface_texture.h" | 25 #endif |
| 22 | 26 |
| 23 using base::android::AttachCurrentThread; | 27 using base::android::AttachCurrentThread; |
| 24 using base::android::ToJavaArrayOfStrings; | 28 using base::android::ToJavaArrayOfStrings; |
| 25 using base::android::ScopedJavaGlobalRef; | 29 using base::android::ScopedJavaGlobalRef; |
| 26 using base::android::ScopedJavaLocalRef; | 30 using base::android::ScopedJavaLocalRef; |
| 27 using content::StartChildProcessCallback; | 31 using content::StartChildProcessCallback; |
| 28 | 32 |
| 29 namespace content { | 33 namespace content { |
| 30 | 34 |
| 35 |
| 31 namespace { | 36 namespace { |
| 32 | 37 |
| 33 // Pass a java surface object to the MediaPlayerAndroid object | 38 // Pass a java surface object to the MediaPlayerAndroid object |
| 34 // identified by render process handle, render frame ID and player ID. | 39 // identified by render process handle, render frame ID and player ID. |
| 35 static void SetSurfacePeer( | 40 static void SetSurfacePeer( |
| 36 const base::android::JavaRef<jobject>& surface, | 41 const base::android::JavaRef<jobject>& surface, |
| 37 base::ProcessHandle render_process_handle, | 42 base::ProcessHandle render_process_handle, |
| 38 int render_frame_id, | 43 int render_frame_id, |
| 39 int player_id) { | 44 int player_id) { |
| 40 int render_process_id = 0; | 45 int render_process_id = 0; |
| 41 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 46 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 42 while (!it.IsAtEnd()) { | 47 while (!it.IsAtEnd()) { |
| 43 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | 48 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { |
| 44 render_process_id = it.GetCurrentValue()->GetID(); | 49 render_process_id = it.GetCurrentValue()->GetID(); |
| 45 break; | 50 break; |
| 46 } | 51 } |
| 47 it.Advance(); | 52 it.Advance(); |
| 48 } | 53 } |
| 49 if (!render_process_id) { | 54 if (!render_process_id) { |
| 50 DVLOG(1) << "Cannot find render process for render_process_handle " | 55 DVLOG(1) << "Cannot find render process for render_process_handle " |
| 51 << render_process_handle; | 56 << render_process_handle; |
| 52 return; | 57 return; |
| 53 } | 58 } |
| 54 | 59 |
| 60 #if !defined(USE_AURA) |
| 55 RenderFrameHostImpl* frame = | 61 RenderFrameHostImpl* frame = |
| 56 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 62 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
| 57 if (!frame) { | 63 if (!frame) { |
| 58 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id; | 64 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id; |
| 59 return; | 65 return; |
| 60 } | 66 } |
| 61 | 67 |
| 62 WebContentsImpl* web_contents = | 68 WebContentsImpl* web_contents = |
| 63 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(frame)); | 69 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(frame)); |
| 64 BrowserMediaPlayerManager* player_manager = | 70 BrowserMediaPlayerManager* player_manager = |
| 65 web_contents->media_web_contents_observer()->GetMediaPlayerManager(frame); | 71 web_contents->media_web_contents_observer()->GetMediaPlayerManager(frame); |
| 66 if (!player_manager) { | 72 if (!player_manager) { |
| 67 DVLOG(1) << "Cannot find the media player manager for frame " << frame; | 73 DVLOG(1) << "Cannot find the media player manager for frame " << frame; |
| 68 return; | 74 return; |
| 69 } | 75 } |
| 70 | 76 |
| 71 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); | 77 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); |
| 72 if (!player) { | 78 if (!player) { |
| 73 DVLOG(1) << "Cannot find media player for player_id " << player_id; | 79 DVLOG(1) << "Cannot find media player for player_id " << player_id; |
| 74 return; | 80 return; |
| 75 } | 81 } |
| 76 | 82 |
| 77 if (player != player_manager->GetFullscreenPlayer()) { | 83 if (player != player_manager->GetFullscreenPlayer()) { |
| 78 gfx::ScopedJavaSurface scoped_surface(surface); | 84 gfx::ScopedJavaSurface scoped_surface(surface); |
| 79 player->SetVideoSurface(scoped_surface.Pass()); | 85 player->SetVideoSurface(scoped_surface.Pass()); |
| 80 } | 86 } |
| 87 #endif |
| 81 } | 88 } |
| 82 | 89 |
| 83 } // anonymous namespace | 90 } // anonymous namespace |
| 84 | 91 |
| 85 // Called from ChildProcessLauncher.java when the ChildProcess was | 92 // Called from ChildProcessLauncher.java when the ChildProcess was |
| 86 // started. | 93 // started. |
| 87 // |client_context| is the pointer to StartChildProcessCallback which was | 94 // |client_context| is the pointer to StartChildProcessCallback which was |
| 88 // passed in from StartChildProcess. | 95 // passed in from StartChildProcess. |
| 89 // |handle| is the processID of the child process as originated in Java, 0 if | 96 // |handle| is the processID of the child process as originated in Java, 0 if |
| 90 // the ChildProcess could not be created. | 97 // the ChildProcess could not be created. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 169 } |
| 163 | 170 |
| 164 void SetChildProcessInForeground(base::ProcessHandle handle, | 171 void SetChildProcessInForeground(base::ProcessHandle handle, |
| 165 bool in_foreground) { | 172 bool in_foreground) { |
| 166 JNIEnv* env = AttachCurrentThread(); | 173 JNIEnv* env = AttachCurrentThread(); |
| 167 DCHECK(env); | 174 DCHECK(env); |
| 168 return Java_ChildProcessLauncher_setInForeground(env, | 175 return Java_ChildProcessLauncher_setInForeground(env, |
| 169 static_cast<jint>(handle), static_cast<jboolean>(in_foreground)); | 176 static_cast<jint>(handle), static_cast<jboolean>(in_foreground)); |
| 170 } | 177 } |
| 171 | 178 |
| 179 //#if !defined(USE_AURA) |
| 172 void EstablishSurfacePeer( | 180 void EstablishSurfacePeer( |
| 173 JNIEnv* env, jclass clazz, | 181 JNIEnv* env, jclass clazz, |
| 174 jint pid, jobject surface, jint primary_id, jint secondary_id) { | 182 jint pid, jobject surface, jint primary_id, jint secondary_id) { |
| 175 ScopedJavaGlobalRef<jobject> jsurface; | 183 ScopedJavaGlobalRef<jobject> jsurface; |
| 176 jsurface.Reset(env, surface); | 184 jsurface.Reset(env, surface); |
| 177 if (jsurface.is_null()) | 185 if (jsurface.is_null()) |
| 178 return; | 186 return; |
| 179 | 187 |
| 180 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 188 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 181 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 189 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 222 } |
| 215 | 223 |
| 216 gfx::ScopedJavaSurface GetSurfaceTextureSurface(int surface_texture_id, | 224 gfx::ScopedJavaSurface GetSurfaceTextureSurface(int surface_texture_id, |
| 217 int client_id) { | 225 int client_id) { |
| 218 JNIEnv* env = AttachCurrentThread(); | 226 JNIEnv* env = AttachCurrentThread(); |
| 219 DCHECK(env); | 227 DCHECK(env); |
| 220 return gfx::ScopedJavaSurface::AcquireExternalSurface( | 228 return gfx::ScopedJavaSurface::AcquireExternalSurface( |
| 221 Java_ChildProcessLauncher_getSurfaceTextureSurface( | 229 Java_ChildProcessLauncher_getSurfaceTextureSurface( |
| 222 env, surface_texture_id, client_id).obj()); | 230 env, surface_texture_id, client_id).obj()); |
| 223 } | 231 } |
| 232 //#endif |
| 224 | 233 |
| 225 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { | 234 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { |
| 226 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 235 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 227 switches::kSingleProcess); | 236 switches::kSingleProcess); |
| 228 } | 237 } |
| 229 | 238 |
| 230 bool RegisterChildProcessLauncher(JNIEnv* env) { | 239 bool RegisterChildProcessLauncher(JNIEnv* env) { |
| 231 return RegisterNativesImpl(env); | 240 return RegisterNativesImpl(env); |
| 232 } | 241 } |
| 233 | 242 |
| 234 } // namespace content | 243 } // namespace content |
| OLD | NEW |