Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: content/browser/android/child_process_launcher_android.cc

Issue 278353003: Make RendererMediaPlayerManager a RenderFrameObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/media/android/browser_media_player_manager.h" 11 #include "content/browser/media/android/browser_media_player_manager.h"
12 #include "content/browser/media/android/media_web_contents_observer.h"
12 #include "content/browser/renderer_host/compositor_impl_android.h" 13 #include "content/browser/renderer_host/compositor_impl_android.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 14 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
16 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
17 #include "jni/ChildProcessLauncher_jni.h" 18 #include "jni/ChildProcessLauncher_jni.h"
18 #include "media/base/android/media_player_android.h" 19 #include "media/base/android/media_player_android.h"
19 #include "ui/gl/android/scoped_java_surface.h" 20 #include "ui/gl/android/scoped_java_surface.h"
20 21
21 using base::android::AttachCurrentThread; 22 using base::android::AttachCurrentThread;
22 using base::android::ToJavaArrayOfStrings; 23 using base::android::ToJavaArrayOfStrings;
23 using base::android::ScopedJavaGlobalRef; 24 using base::android::ScopedJavaGlobalRef;
24 using base::android::ScopedJavaLocalRef; 25 using base::android::ScopedJavaLocalRef;
25 using content::StartChildProcessCallback; 26 using content::StartChildProcessCallback;
26 27
27 namespace content { 28 namespace content {
28 29
29 namespace { 30 namespace {
30 31
31 // Pass a java surface object to the MediaPlayerAndroid object 32 // Pass a java surface object to the MediaPlayerAndroid object
32 // identified by render process handle, render view ID and player ID. 33 // identified by render process handle, render view ID and player ID.
jam 2014/05/20 00:34:49 nit: update to render frame ID
xhwang 2014/05/22 19:06:00 Done.
33 static void SetSurfacePeer( 34 static void SetSurfacePeer(
34 const base::android::JavaRef<jobject>& surface, 35 const base::android::JavaRef<jobject>& surface,
35 base::ProcessHandle render_process_handle, 36 base::ProcessHandle render_process_handle,
36 int render_view_id, 37 int render_view_id,
37 int player_id) { 38 int player_id) {
38 int renderer_id = 0; 39 int renderer_id = 0;
39 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); 40 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
40 while (!it.IsAtEnd()) { 41 while (!it.IsAtEnd()) {
41 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { 42 if (it.GetCurrentValue()->GetHandle() == render_process_handle) {
42 renderer_id = it.GetCurrentValue()->GetID(); 43 renderer_id = it.GetCurrentValue()->GetID();
43 break; 44 break;
44 } 45 }
45 it.Advance(); 46 it.Advance();
46 } 47 }
47 48
48 if (renderer_id) { 49 if (!renderer_id) {
49 RenderViewHostImpl* host = RenderViewHostImpl::FromID( 50 DVLOG(1) << "Cannot find renderer for " << render_process_handle;
50 renderer_id, render_view_id); 51 return;
51 if (host) { 52 }
52 media::MediaPlayerAndroid* player = 53
53 host->media_player_manager()->GetPlayer(player_id); 54 RenderViewHostImpl* host =
54 if (player && 55 RenderViewHostImpl::FromID(renderer_id, render_view_id);
55 player != host->media_player_manager()->GetFullscreenPlayer()) { 56
56 gfx::ScopedJavaSurface scoped_surface(surface); 57 if (!host) {
57 player->SetVideoSurface(scoped_surface.Pass()); 58 DVLOG(1) << "Cannot find host for render_view" << render_view_id;
58 } 59 return;
59 } 60 }
61
62 // TODO(xhwang): This assumes all media elements are in the main frame which
63 // is not true. Update the SetSurfacePeer() stack to use |render_frame_id|
64 // instead of |render_view_id|.
xhwang 2014/05/12 17:01:58 qinmin: let me know if this TODO makes sense ;)
jam 2014/05/20 00:34:49 hmm, this is going to be broken in the meantime. w
xhwang 2014/05/22 19:06:00 Done.
65 RenderFrameHost* frame = host->GetMainFrame();
66 if (!frame) {
67 DVLOG(1) << "Cannot find the main frame.";
68 return;
69 }
70
71 BrowserMediaPlayerManager* player_manager =
72 host->media_web_contents_observer()->GetMediaPlayerManager(frame);
73 if (!player_manager) {
74 DVLOG(1) << "Cannot find the media player manager for frame " << frame;
75 return;
76 }
77
78 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id);
79 if (!player) {
80 DVLOG(1) << "Cannot find the media player player_id " << player_id;
81 return;
82 }
83
84 if (player != player_manager->GetFullscreenPlayer()) {
85 gfx::ScopedJavaSurface scoped_surface(surface);
86 player->SetVideoSurface(scoped_surface.Pass());
60 } 87 }
61 } 88 }
62 89
63 } // anonymous namespace 90 } // anonymous namespace
64 91
65 // Called from ChildProcessLauncher.java when the ChildProcess was 92 // Called from ChildProcessLauncher.java when the ChildProcess was
66 // started. 93 // started.
67 // |client_context| is the pointer to StartChildProcessCallback which was 94 // |client_context| is the pointer to StartChildProcessCallback which was
68 // passed in from StartChildProcess. 95 // passed in from StartChildProcess.
69 // |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
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 219
193 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { 220 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) {
194 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); 221 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess);
195 } 222 }
196 223
197 bool RegisterChildProcessLauncher(JNIEnv* env) { 224 bool RegisterChildProcessLauncher(JNIEnv* env) {
198 return RegisterNativesImpl(env); 225 return RegisterNativesImpl(env);
199 } 226 }
200 227
201 } // namespace content 228 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698