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/media/android/browser_media_player_manager.h" | 12 #include "content/browser/media/android/browser_media_player_manager.h" |
| 13 #include "content/browser/media/android/media_web_contents_observer.h" |
12 #include "content/browser/renderer_host/compositor_impl_android.h" | 14 #include "content/browser/renderer_host/compositor_impl_android.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
17 #include "jni/ChildProcessLauncher_jni.h" | 19 #include "jni/ChildProcessLauncher_jni.h" |
18 #include "media/base/android/media_player_android.h" | 20 #include "media/base/android/media_player_android.h" |
19 #include "ui/gl/android/scoped_java_surface.h" | 21 #include "ui/gl/android/scoped_java_surface.h" |
20 | 22 |
21 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
22 using base::android::ToJavaArrayOfStrings; | 24 using base::android::ToJavaArrayOfStrings; |
23 using base::android::ScopedJavaGlobalRef; | 25 using base::android::ScopedJavaGlobalRef; |
24 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
25 using content::StartChildProcessCallback; | 27 using content::StartChildProcessCallback; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 // Pass a java surface object to the MediaPlayerAndroid object | 33 // Pass a java surface object to the MediaPlayerAndroid object |
32 // identified by render process handle, render view ID and player ID. | 34 // identified by render process handle, render frame ID and player ID. |
33 static void SetSurfacePeer( | 35 static void SetSurfacePeer( |
34 const base::android::JavaRef<jobject>& surface, | 36 const base::android::JavaRef<jobject>& surface, |
35 base::ProcessHandle render_process_handle, | 37 base::ProcessHandle render_process_handle, |
36 int render_view_id, | 38 int render_frame_id, |
37 int player_id) { | 39 int player_id) { |
38 int renderer_id = 0; | 40 int render_process_id = 0; |
39 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 41 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
40 while (!it.IsAtEnd()) { | 42 while (!it.IsAtEnd()) { |
41 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | 43 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { |
42 renderer_id = it.GetCurrentValue()->GetID(); | 44 render_process_id = it.GetCurrentValue()->GetID(); |
43 break; | 45 break; |
44 } | 46 } |
45 it.Advance(); | 47 it.Advance(); |
46 } | 48 } |
| 49 if (!render_process_id) { |
| 50 DVLOG(1) << "Cannot find render process for render_process_handle " |
| 51 << render_process_handle; |
| 52 return; |
| 53 } |
47 | 54 |
48 if (renderer_id) { | 55 RenderFrameHostImpl* frame = |
49 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | 56 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
50 renderer_id, render_view_id); | 57 if (!frame) { |
51 if (host) { | 58 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id; |
52 media::MediaPlayerAndroid* player = | 59 return; |
53 host->media_player_manager()->GetPlayer(player_id); | 60 } |
54 if (player && | 61 |
55 player != host->media_player_manager()->GetFullscreenPlayer()) { | 62 RenderViewHostImpl* view = |
56 gfx::ScopedJavaSurface scoped_surface(surface); | 63 static_cast<RenderViewHostImpl*>(frame->GetRenderViewHost()); |
57 player->SetVideoSurface(scoped_surface.Pass()); | 64 BrowserMediaPlayerManager* player_manager = |
58 } | 65 view->media_web_contents_observer()->GetMediaPlayerManager(frame); |
59 } | 66 if (!player_manager) { |
| 67 DVLOG(1) << "Cannot find the media player manager for frame " << frame; |
| 68 return; |
| 69 } |
| 70 |
| 71 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); |
| 72 if (!player) { |
| 73 DVLOG(1) << "Cannot find media player for player_id " << player_id; |
| 74 return; |
| 75 } |
| 76 |
| 77 if (player != player_manager->GetFullscreenPlayer()) { |
| 78 gfx::ScopedJavaSurface scoped_surface(surface); |
| 79 player->SetVideoSurface(scoped_surface.Pass()); |
60 } | 80 } |
61 } | 81 } |
62 | 82 |
63 } // anonymous namespace | 83 } // anonymous namespace |
64 | 84 |
65 // Called from ChildProcessLauncher.java when the ChildProcess was | 85 // Called from ChildProcessLauncher.java when the ChildProcess was |
66 // started. | 86 // started. |
67 // |client_context| is the pointer to StartChildProcessCallback which was | 87 // |client_context| is the pointer to StartChildProcessCallback which was |
68 // passed in from StartChildProcess. | 88 // passed in from StartChildProcess. |
69 // |handle| is the processID of the child process as originated in Java, 0 if | 89 // |handle| is the processID of the child process as originated in Java, 0 if |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 212 |
193 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { | 213 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { |
194 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 214 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
195 } | 215 } |
196 | 216 |
197 bool RegisterChildProcessLauncher(JNIEnv* env) { | 217 bool RegisterChildProcessLauncher(JNIEnv* env) { |
198 return RegisterNativesImpl(env); | 218 return RegisterNativesImpl(env); |
199 } | 219 } |
200 | 220 |
201 } // namespace content | 221 } // namespace content |
OLD | NEW |