Chromium Code Reviews| Index: content/browser/media/android/dialog_surface_activity_mapper.cc | 
| diff --git a/content/browser/media/android/dialog_surface_activity_mapper.cc b/content/browser/media/android/dialog_surface_activity_mapper.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..76426e0a4c0851cd4980cd7c79a7dea42fc9c0ef | 
| --- /dev/null | 
| +++ b/content/browser/media/android/dialog_surface_activity_mapper.cc | 
| @@ -0,0 +1,60 @@ | 
| +// Copyright 2016 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "content/browser/media/android/dialog_surface_activity_mapper.h" | 
| + | 
| +// TODO(liberato): browser_media_player_manager only does this if !USE_AURA | 
| +#include "content/browser/android/content_view_core_impl.h" | 
| +#include "content/browser/frame_host/render_frame_host_impl.h" | 
| +#include "content/public/browser/render_process_host.h" | 
| +#include "content/public/browser/web_contents.h" | 
| +#include "jni/DialogSurfaceActivityMapper_jni.h" | 
| + | 
| +static ScopedJavaLocalRef<jobject> GetContentViewCore( | 
| + JNIEnv* env, | 
| + const JavaParamRef<jclass>& jcaller, | 
| + jint renderer_pid, | 
| + jint render_frame_id) { | 
| + base::android::ScopedJavaLocalRef<jobject> nullref; | 
| + | 
| + // Get the id from the handle. On android, the handle is the pid. | 
| + content::RenderProcessHost::iterator it = | 
| + content::RenderProcessHost::AllHostsIterator(); | 
| + int render_process_id = 0; | 
| + while (!it.IsAtEnd()) { | 
| + if (it.GetCurrentValue()->GetHandle() == renderer_pid) { | 
| + render_process_id = it.GetCurrentValue()->GetID(); | 
| + break; | 
| + } | 
| + it.Advance(); | 
| + } | 
| + if (!render_process_id) { | 
| + DVLOG(1) << "Cannot find render process for renderer_pid " << renderer_pid; | 
| + return nullref; | 
| + } | 
| + | 
| + // Get the frame from the id. | 
| + content::RenderFrameHostImpl* frame = | 
| + content::RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 
| + if (!frame) | 
| 
 
Tima Vaisburd
2016/08/03 18:05:13
Similar DVLOG(1) as l.33 (and below)? Or not havin
 
liberato (no reviews please)
2016/08/03 23:11:54
Done.
 
 | 
| + return nullref; | 
| + | 
| + content::WebContents* web_contents = | 
| + content::WebContents::FromRenderFrameHost(frame); | 
| + if (!web_contents) | 
| + return nullref; | 
| + | 
| + content::ContentViewCore* cvc = | 
| + content::ContentViewCoreImpl::FromWebContents(web_contents); | 
| + if (!cvc) | 
| + return nullref; | 
| + | 
| + return base::android::ScopedJavaLocalRef<jobject>(cvc->GetJavaObject()); | 
| +} | 
| + | 
| +namespace content { | 
| +bool RegisterDialogSurfaceActivityMapper(JNIEnv* env) { | 
| + return RegisterNativesImpl(env); | 
| +} | 
| +} |