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_window_token_provider_imp
l.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/DialogSurfaceWindowTokenProviderImpl_jni.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 static base::android::ScopedJavaGlobalRef<jobject> GetContentViewCore( |
| 19 jint renderer_pid, |
| 20 jint render_frame_id) { |
| 21 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 22 |
| 23 // Get the id from the handle. On android, the handle is the pid. |
| 24 content::RenderProcessHost::iterator it = |
| 25 content::RenderProcessHost::AllHostsIterator(); |
| 26 int render_process_id = 0; |
| 27 while (!it.IsAtEnd()) { |
| 28 if (it.GetCurrentValue()->GetHandle() == renderer_pid) { |
| 29 render_process_id = it.GetCurrentValue()->GetID(); |
| 30 break; |
| 31 } |
| 32 it.Advance(); |
| 33 } |
| 34 if (!render_process_id) { |
| 35 DVLOG(1) << "Cannot find render process for renderer_pid " << renderer_pid; |
| 36 return nullptr; |
| 37 } |
| 38 |
| 39 // Get the frame from the id. |
| 40 content::RenderFrameHostImpl* frame = |
| 41 content::RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
| 42 if (!frame) { |
| 43 DVLOG(1) << "Cannot find frame for renderer_pid " << renderer_pid |
| 44 << " render_frame_id " << render_frame_id; |
| 45 return nullptr; |
| 46 } |
| 47 |
| 48 content::WebContents* web_contents = |
| 49 content::WebContents::FromRenderFrameHost(frame); |
| 50 if (!web_contents) { |
| 51 DVLOG(1) << "Cannot find web_contents for renderer_pid " << renderer_pid |
| 52 << " render_frame_id " << render_frame_id; |
| 53 return nullptr; |
| 54 } |
| 55 |
| 56 content::ContentViewCore* cvc = |
| 57 content::ContentViewCoreImpl::FromWebContents(web_contents); |
| 58 if (!cvc) { |
| 59 DVLOG(1) << "Cannot find cvc for renderer_pid " << renderer_pid |
| 60 << " render_frame_id " << render_frame_id; |
| 61 return nullptr; |
| 62 } |
| 63 |
| 64 return base::android::ScopedJavaGlobalRef<jobject>(cvc->GetJavaObject()); |
| 65 } |
| 66 |
| 67 static void PostContentViewCore( |
| 68 jint renderer_pid, |
| 69 jint render_frame_id, |
| 70 const base::android::ScopedJavaGlobalRef<jobject>& token_provider, |
| 71 const base::android::ScopedJavaGlobalRef<jobject>& client) { |
| 72 JNIEnv* env = base::android::AttachCurrentThread(); |
| 73 base::android::ScopedJavaGlobalRef<jobject> cvc = |
| 74 GetContentViewCore(renderer_pid, render_frame_id); |
| 75 content::Java_DialogSurfaceWindowTokenProviderImpl_onContentViewCore( |
| 76 env, token_provider.obj(), client.obj(), cvc.obj()); |
| 77 } |
| 78 } |
| 79 |
| 80 namespace content { |
| 81 |
| 82 static void CallBackWithContentViewCore( |
| 83 JNIEnv* env, |
| 84 const base::android::JavaParamRef<jclass>& jcaller, |
| 85 jint renderer_pid, |
| 86 jint render_frame_id, |
| 87 const base::android::JavaParamRef<jobject>& token_provider, |
| 88 const base::android::JavaParamRef<jobject>& client) { |
| 89 content::BrowserThread::PostTask( |
| 90 content::BrowserThread::UI, FROM_HERE, |
| 91 base::Bind(PostContentViewCore, renderer_pid, render_frame_id, |
| 92 base::android::ScopedJavaGlobalRef<jobject>(token_provider), |
| 93 base::android::ScopedJavaGlobalRef<jobject>(client))); |
| 94 } |
| 95 |
| 96 bool RegisterDialogSurfaceWindowTokenProviderImpl(JNIEnv* env) { |
| 97 return RegisterNativesImpl(env); |
| 98 } |
| 99 |
| 100 } // namespace content |
OLD | NEW |