Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/media/android/dialog_surface_activity_mapper.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/threading/thread_task_runner_handle.h" | |
| 9 // TODO(liberato): browser_media_player_manager only does this if !USE_AURA | |
| 10 #include "content/browser/android/content_view_core_impl.h" | |
| 11 #include "content/browser/frame_host/render_frame_host_impl.h" | |
| 12 #include "content/public/browser/render_process_host.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "jni/DialogSurfaceActivityMapper_jni.h" | |
| 15 | |
| 16 static base::android::ScopedJavaGlobalRef<jobject> | |
| 17 GetContentViewCore(JNIEnv* env, jint renderer_pid, jint render_frame_id) { | |
|
boliu
2016/11/04 00:07:19
we'd like to remove ContentViewCore, and then foll
liberato (no reviews please)
2016/11/11 21:52:35
CVC: once CVC goes away, i'm assuming that a Rende
| |
| 18 base::android::ScopedJavaGlobalRef<jobject> nullref; | |
| 19 | |
| 20 // Get the id from the handle. On android, the handle is the pid. | |
| 21 content::RenderProcessHost::iterator it = | |
| 22 content::RenderProcessHost::AllHostsIterator(); | |
|
boliu
2016/11/04 00:07:19
DCHECK this is on UI thread?
liberato (no reviews please)
2016/11/11 21:52:35
Done.
| |
| 23 int render_process_id = 0; | |
| 24 while (!it.IsAtEnd()) { | |
| 25 if (it.GetCurrentValue()->GetHandle() == renderer_pid) { | |
| 26 render_process_id = it.GetCurrentValue()->GetID(); | |
| 27 break; | |
| 28 } | |
| 29 it.Advance(); | |
| 30 } | |
| 31 if (!render_process_id) { | |
| 32 DVLOG(1) << "Cannot find render process for renderer_pid " << renderer_pid; | |
| 33 return nullref; | |
| 34 } | |
| 35 | |
| 36 // Get the frame from the id. | |
| 37 content::RenderFrameHostImpl* frame = | |
| 38 content::RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | |
| 39 if (!frame) { | |
| 40 DVLOG(1) << "Cannot find frame for renderer_pid " << renderer_pid | |
| 41 << " render_frame_id " << render_frame_id; | |
| 42 return nullref; | |
| 43 } | |
| 44 | |
| 45 content::WebContents* web_contents = | |
| 46 content::WebContents::FromRenderFrameHost(frame); | |
| 47 if (!web_contents) { | |
| 48 DVLOG(1) << "Cannot find web_contents for renderer_pid " << renderer_pid | |
| 49 << " render_frame_id " << render_frame_id; | |
| 50 return nullref; | |
| 51 } | |
| 52 | |
| 53 content::ContentViewCore* cvc = | |
| 54 content::ContentViewCoreImpl::FromWebContents(web_contents); | |
| 55 if (!cvc) { | |
| 56 DVLOG(1) << "Cannot find cvc for renderer_pid " << renderer_pid | |
| 57 << " render_frame_id " << render_frame_id; | |
| 58 return nullref; | |
| 59 } | |
| 60 | |
| 61 return base::android::ScopedJavaGlobalRef<jobject>(cvc->GetJavaObject()); | |
| 62 } | |
| 63 | |
| 64 static void PostContentViewCore( | |
| 65 jint renderer_pid, | |
| 66 jint render_frame_id, | |
| 67 const base::android::ScopedJavaGlobalRef<jobject>& mapper, | |
| 68 const base::android::ScopedJavaGlobalRef<jobject>& holder) { | |
| 69 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 70 base::android::ScopedJavaGlobalRef<jobject> cvc = | |
| 71 GetContentViewCore(env, renderer_pid, render_frame_id); | |
| 72 Java_DialogSurfaceActivityMapper_onContentViewCore(env, mapper.obj(), | |
| 73 holder.obj(), cvc.obj()); | |
| 74 } | |
| 75 | |
| 76 static void CallBackWithContentViewCore( | |
| 77 JNIEnv* env, | |
| 78 const base::android::JavaParamRef<jclass>& jcaller, | |
| 79 jint renderer_pid, | |
| 80 jint render_frame_id, | |
| 81 const base::android::JavaParamRef<jobject>& mapper, | |
| 82 const base::android::JavaParamRef<jobject>& holder) { | |
| 83 content::BrowserThread::PostTask( | |
| 84 content::BrowserThread::UI, FROM_HERE, | |
| 85 base::Bind(PostContentViewCore, renderer_pid, render_frame_id, | |
| 86 base::android::ScopedJavaGlobalRef<jobject>(mapper), | |
| 87 base::android::ScopedJavaGlobalRef<jobject>(holder))); | |
| 88 } | |
| 89 | |
| 90 namespace content { | |
| 91 | |
| 92 bool RegisterDialogSurfaceActivityMapper(JNIEnv* env) { | |
| 93 return RegisterNativesImpl(env); | |
| 94 } | |
| 95 | |
| 96 } // namespace content | |
| OLD | NEW |