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/android/unguessable_token_android.h" | |
8 #include "base/lazy_instance.h" | |
9 #include "base/threading/thread_task_runner_handle.h" | |
10 #include "base/unguessable_token.h" | |
11 // TODO(liberato): browser_media_player_manager only does this if !USE_AURA | |
12 #include "content/browser/android/content_view_core_impl.h" | |
13 #include "content/browser/frame_host/render_frame_host_impl.h" | |
14 #include "content/public/browser/render_process_host.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "jni/DialogSurfaceActivityMapper_jni.h" | |
17 | |
18 static base::android::ScopedJavaGlobalRef<jobject> GetContentViewCore( | |
boliu
2016/11/14 16:39:24
anonymous namespace over static
liberato (no reviews please)
2016/12/20 17:16:38
Done.
| |
19 const base::UnguessableToken& frame_token) { | |
20 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
21 | |
22 base::android::ScopedJavaGlobalRef<jobject> nullref; | |
boliu
2016/11/14 16:39:24
nit: return nullptr works I think
liberato (no reviews please)
2016/12/20 17:16:38
didn't know that. thanks!
| |
23 | |
24 // TODO(liberato): use |frame_token| to look up the RenderFrameHostImpl, and | |
25 // use that to get the ContentViewCore. | |
26 // When CVC is removed, we'll get this from the WindowAndroid. | |
27 | |
28 // Get the frame from the id. | |
29 content::RenderFrameHostImpl* frame = nullptr; | |
30 // A separate CL adds content::RenderFrameHostImpl::FromFrameToken. | |
31 if (!frame) { | |
32 DVLOG(1) << "Cannot find frame for token " << frame_token; | |
33 return nullref; | |
34 } | |
35 | |
36 content::WebContents* web_contents = | |
37 content::WebContents::FromRenderFrameHost(frame); | |
38 if (!web_contents) { | |
39 DVLOG(1) << "Cannot find web_contents for token " << frame_token; | |
40 return nullref; | |
41 } | |
42 | |
43 content::ContentViewCore* cvc = | |
44 content::ContentViewCoreImpl::FromWebContents(web_contents); | |
45 if (!cvc) { | |
46 DVLOG(1) << "Cannot find cvc for token " << frame_token; | |
47 return nullref; | |
48 } | |
49 | |
50 return base::android::ScopedJavaGlobalRef<jobject>(cvc->GetJavaObject()); | |
51 } | |
52 | |
53 static void PostContentViewCore( | |
54 const base::android::ScopedJavaGlobalRef<jobject>& frame_token_java, | |
55 const base::android::ScopedJavaGlobalRef<jobject>& mapper, | |
56 const base::android::ScopedJavaGlobalRef<jobject>& holder) { | |
57 JNIEnv* env = base::android::AttachCurrentThread(); | |
58 base::UnguessableToken frame_token = | |
59 base::android::UnguessableTokenAndroid::FromJavaUnguessableToken( | |
60 env, frame_token_java); | |
61 base::android::ScopedJavaGlobalRef<jobject> cvc = | |
62 GetContentViewCore(frame_token); | |
63 content::Java_DialogSurfaceActivityMapper_onContentViewCore( | |
64 env, mapper.obj(), holder.obj(), cvc.obj()); | |
65 } | |
66 | |
67 namespace content { | |
68 | |
69 static void CallBackWithContentViewCore( | |
70 JNIEnv* env, | |
71 const base::android::JavaParamRef<jclass>& jcaller, | |
72 const base::android::JavaParamRef<jobject>& frame_token, | |
73 const base::android::JavaParamRef<jobject>& mapper, | |
74 const base::android::JavaParamRef<jobject>& holder) { | |
75 content::BrowserThread::PostTask( | |
76 content::BrowserThread::UI, FROM_HERE, | |
77 base::Bind(PostContentViewCore, | |
78 base::android::ScopedJavaGlobalRef<jobject>(frame_token), | |
79 base::android::ScopedJavaGlobalRef<jobject>(mapper), | |
80 base::android::ScopedJavaGlobalRef<jobject>(holder))); | |
81 } | |
82 | |
83 bool RegisterDialogSurfaceActivityMapper(JNIEnv* env) { | |
84 return RegisterNativesImpl(env); | |
85 } | |
86 | |
87 } // namespace content | |
OLD | NEW |