| Index: content/browser/media/android/dialog_surface_window_token_provider_impl.cc
|
| diff --git a/content/browser/media/android/dialog_surface_window_token_provider_impl.cc b/content/browser/media/android/dialog_surface_window_token_provider_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..435c59cb0d23eea38eef10e7d6e2b3e74f961920
|
| --- /dev/null
|
| +++ b/content/browser/media/android/dialog_surface_window_token_provider_impl.cc
|
| @@ -0,0 +1,100 @@
|
| +// 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_window_token_provider_impl.h"
|
| +
|
| +#include "base/lazy_instance.h"
|
| +#include "base/threading/thread_task_runner_handle.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/DialogSurfaceWindowTokenProviderImpl_jni.h"
|
| +
|
| +namespace {
|
| +
|
| +static base::android::ScopedJavaGlobalRef<jobject> GetContentViewCore(
|
| + jint renderer_pid,
|
| + jint render_frame_id) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| +
|
| + // 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 nullptr;
|
| + }
|
| +
|
| + // Get the frame from the id.
|
| + content::RenderFrameHostImpl* frame =
|
| + content::RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
|
| + if (!frame) {
|
| + DVLOG(1) << "Cannot find frame for renderer_pid " << renderer_pid
|
| + << " render_frame_id " << render_frame_id;
|
| + return nullptr;
|
| + }
|
| +
|
| + content::WebContents* web_contents =
|
| + content::WebContents::FromRenderFrameHost(frame);
|
| + if (!web_contents) {
|
| + DVLOG(1) << "Cannot find web_contents for renderer_pid " << renderer_pid
|
| + << " render_frame_id " << render_frame_id;
|
| + return nullptr;
|
| + }
|
| +
|
| + content::ContentViewCore* cvc =
|
| + content::ContentViewCoreImpl::FromWebContents(web_contents);
|
| + if (!cvc) {
|
| + DVLOG(1) << "Cannot find cvc for renderer_pid " << renderer_pid
|
| + << " render_frame_id " << render_frame_id;
|
| + return nullptr;
|
| + }
|
| +
|
| + return base::android::ScopedJavaGlobalRef<jobject>(cvc->GetJavaObject());
|
| +}
|
| +
|
| +static void PostContentViewCore(
|
| + jint renderer_pid,
|
| + jint render_frame_id,
|
| + const base::android::ScopedJavaGlobalRef<jobject>& token_provider,
|
| + const base::android::ScopedJavaGlobalRef<jobject>& client) {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + base::android::ScopedJavaGlobalRef<jobject> cvc =
|
| + GetContentViewCore(renderer_pid, render_frame_id);
|
| + content::Java_DialogSurfaceWindowTokenProviderImpl_onContentViewCore(
|
| + env, token_provider.obj(), client.obj(), cvc.obj());
|
| +}
|
| +}
|
| +
|
| +namespace content {
|
| +
|
| +static void CallBackWithContentViewCore(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jclass>& jcaller,
|
| + jint renderer_pid,
|
| + jint render_frame_id,
|
| + const base::android::JavaParamRef<jobject>& token_provider,
|
| + const base::android::JavaParamRef<jobject>& client) {
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(PostContentViewCore, renderer_pid, render_frame_id,
|
| + base::android::ScopedJavaGlobalRef<jobject>(token_provider),
|
| + base::android::ScopedJavaGlobalRef<jobject>(client)));
|
| +}
|
| +
|
| +bool RegisterDialogSurfaceWindowTokenProviderImpl(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +} // namespace content
|
|
|