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/app/android/dialog_surface_activity_mapper.h" |
| 6 |
| 7 // TODO(liberato): browser_media_player_manager only does this if !USE_AURA |
| 8 #include "content/browser/android/content_view_core_impl.h" |
| 9 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 10 #include "content/public/browser/render_process_host.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "jni/DialogSurfaceActivityMapper_jni.h" |
| 13 |
| 14 using namespace content; |
| 15 |
| 16 static ScopedJavaLocalRef<jobject> GetContentViewCore( |
| 17 JNIEnv* env, |
| 18 const JavaParamRef<jclass>& jcaller, |
| 19 jint renderHandle, |
| 20 jint renderFrameId) { |
| 21 base::android::ScopedJavaLocalRef<jobject> nullref; |
| 22 |
| 23 // Get the id from the handle. |
| 24 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 25 int render_process_id = 0; |
| 26 while (!it.IsAtEnd()) { |
| 27 if (it.GetCurrentValue()->GetHandle() == renderHandle) { |
| 28 render_process_id = it.GetCurrentValue()->GetID(); |
| 29 break; |
| 30 } |
| 31 it.Advance(); |
| 32 } |
| 33 if (!render_process_id) { |
| 34 DVLOG(1) << "Cannot find render process for render_process_handle " |
| 35 << renderHandle; |
| 36 return nullref; |
| 37 } |
| 38 |
| 39 // Get the frame from the id. |
| 40 RenderFrameHostImpl* frame = |
| 41 RenderFrameHostImpl::FromID(render_process_id, renderFrameId); |
| 42 if (!frame) |
| 43 return nullref; |
| 44 |
| 45 WebContents* web_contents = WebContents::FromRenderFrameHost(frame); |
| 46 if (!web_contents) |
| 47 return nullref; |
| 48 |
| 49 ContentViewCore* cvc = ContentViewCoreImpl::FromWebContents(web_contents); |
| 50 if (!cvc) |
| 51 return nullref; |
| 52 |
| 53 return base::android::ScopedJavaLocalRef<jobject>(cvc->GetJavaObject()); |
| 54 } |
| 55 |
| 56 namespace content { |
| 57 |
| 58 bool RegisterDialogSurfaceActivityMapper(JNIEnv* env) { |
| 59 return RegisterNativesImpl(env); |
| 60 } |
| 61 } |
OLD | NEW |