OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/native/external_video_surface_container_impl.h" | 5 #include "android_webview/native/external_video_surface_container_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "content/public/browser/android/content_view_core.h" | 8 #include "content/public/browser/android/content_view_core.h" |
9 #include "jni/ExternalVideoSurfaceContainer_jni.h" | 9 #include "jni/ExternalVideoSurfaceContainer_jni.h" |
10 #include "ui/gfx/geometry/rect_f.h" | 10 #include "ui/gfx/geometry/rect_f.h" |
11 | 11 |
12 using base::android::AttachCurrentThread; | 12 using base::android::AttachCurrentThread; |
13 using content::ContentViewCore; | 13 using content::ContentViewCore; |
14 | 14 |
15 namespace android_webview { | 15 namespace android_webview { |
16 | 16 |
17 ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl( | 17 // static |
| 18 ExternalVideoSurfaceContainerImpl* ExternalVideoSurfaceContainerImpl::Create( |
18 content::WebContents* web_contents) { | 19 content::WebContents* web_contents) { |
19 ContentViewCore* cvc = ContentViewCore::FromWebContents(web_contents); | 20 ContentViewCore* cvc = ContentViewCore::FromWebContents(web_contents); |
20 if (cvc) { | 21 if (!cvc) |
21 JNIEnv* env = AttachCurrentThread(); | 22 return nullptr; |
22 jobject_.Reset( | 23 base::android::ScopedJavaLocalRef<jobject> jcvc = cvc->GetJavaObject(); |
23 Java_ExternalVideoSurfaceContainer_create( | 24 if (jcvc.is_null()) |
24 env, reinterpret_cast<intptr_t>(this), cvc->GetJavaObject().obj())); | 25 return nullptr; |
25 } | 26 return new ExternalVideoSurfaceContainerImpl(jcvc); |
| 27 } |
| 28 |
| 29 ExternalVideoSurfaceContainerImpl::ExternalVideoSurfaceContainerImpl( |
| 30 base::android::ScopedJavaLocalRef<jobject> java_content_view_core) { |
| 31 JNIEnv* env = AttachCurrentThread(); |
| 32 jobject_.Reset(Java_ExternalVideoSurfaceContainer_create( |
| 33 env, reinterpret_cast<intptr_t>(this), java_content_view_core.obj())); |
26 } | 34 } |
27 | 35 |
28 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() { | 36 ExternalVideoSurfaceContainerImpl::~ExternalVideoSurfaceContainerImpl() { |
29 JNIEnv* env = AttachCurrentThread(); | 37 JNIEnv* env = AttachCurrentThread(); |
30 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj()); | 38 Java_ExternalVideoSurfaceContainer_destroy(env, jobject_.obj()); |
31 jobject_.Reset(); | 39 jobject_.Reset(); |
32 } | 40 } |
33 | 41 |
34 void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface( | 42 void ExternalVideoSurfaceContainerImpl::RequestExternalVideoSurface( |
35 int player_id, | 43 int player_id, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 JNIEnv* env, jobject obj, jint player_id) { | 103 JNIEnv* env, jobject obj, jint player_id) { |
96 if (!surface_destroyed_cb_.is_null()) | 104 if (!surface_destroyed_cb_.is_null()) |
97 surface_destroyed_cb_.Run(static_cast<int>(player_id)); | 105 surface_destroyed_cb_.Run(static_cast<int>(player_id)); |
98 } | 106 } |
99 | 107 |
100 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) { | 108 bool RegisterExternalVideoSurfaceContainer(JNIEnv* env) { |
101 return RegisterNativesImpl(env); | 109 return RegisterNativesImpl(env); |
102 } | 110 } |
103 | 111 |
104 } // namespace android_webview | 112 } // namespace android_webview |
OLD | NEW |