| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/android/content_video_view.h" | 5 #include "content/browser/android/content_video_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "content/browser/android/content_view_core_impl.h" | 10 #include "content/browser/android/content_view_core_impl.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { | 43 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { |
| 44 return RegisterNativesImpl(env); | 44 return RegisterNativesImpl(env); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ContentVideoView* ContentVideoView::GetInstance() { | 47 ContentVideoView* ContentVideoView::GetInstance() { |
| 48 return g_content_video_view; | 48 return g_content_video_view; |
| 49 } | 49 } |
| 50 | 50 |
| 51 ContentVideoView::ContentVideoView(Client* client, | 51 ContentVideoView::ContentVideoView(ContentViewCore* content_view_core, |
| 52 ContentViewCore* content_view_core, | 52 const JavaRef<jobject>& video_embedder) |
| 53 const JavaRef<jobject>& video_embedder, | 53 : cvc_(content_view_core), |
| 54 const gfx::Size& video_natural_size) | 54 j_content_video_view_embedder_(video_embedder), |
| 55 : client_(client), weak_factory_(this) { | 55 weak_factory_(this) { |
| 56 DCHECK(!g_content_video_view); | 56 DCHECK(!g_content_video_view); |
| 57 j_content_video_view_ = | |
| 58 CreateJavaObject(content_view_core, video_embedder, video_natural_size); | |
| 59 g_content_video_view = this; | 57 g_content_video_view = this; |
| 60 } | 58 } |
| 61 | 59 |
| 62 ContentVideoView::~ContentVideoView() { | 60 ContentVideoView::~ContentVideoView() { |
| 63 DCHECK(g_content_video_view); | 61 DCHECK(g_content_video_view); |
| 64 JNIEnv* env = AttachCurrentThread(); | 62 JNIEnv* env = AttachCurrentThread(); |
| 65 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 63 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
| 66 if (!content_video_view.is_null()) { | 64 if (!content_video_view.is_null()) { |
| 67 Java_ContentVideoView_destroyContentVideoView(env, content_video_view, | 65 Java_ContentVideoView_destroyContentVideoView(env, content_video_view, |
| 68 true); | 66 true); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 | 88 |
| 91 void ContentVideoView::OnVideoSizeChanged(int width, int height) { | 89 void ContentVideoView::OnVideoSizeChanged(int width, int height) { |
| 92 JNIEnv* env = AttachCurrentThread(); | 90 JNIEnv* env = AttachCurrentThread(); |
| 93 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 91 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
| 94 if (!content_video_view.is_null()) { | 92 if (!content_video_view.is_null()) { |
| 95 Java_ContentVideoView_onVideoSizeChanged(env, content_video_view, width, | 93 Java_ContentVideoView_onVideoSizeChanged(env, content_video_view, width, |
| 96 height); | 94 height); |
| 97 } | 95 } |
| 98 } | 96 } |
| 99 | 97 |
| 98 void ContentVideoView::CreateVideoSurface(VideoSurfaceProvider::Client* client, |
| 99 const gfx::Size& video_natural_size) { |
| 100 client_ = client; |
| 101 j_content_video_view_ = CreateJavaObject(video_natural_size); |
| 102 } |
| 103 |
| 100 void ContentVideoView::ExitFullscreen() { | 104 void ContentVideoView::ExitFullscreen() { |
| 101 JNIEnv* env = AttachCurrentThread(); | 105 JNIEnv* env = AttachCurrentThread(); |
| 102 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 106 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
| 103 bool release_media_player = false; | 107 bool release_media_player = false; |
| 104 if (!content_video_view.is_null()) | 108 if (!content_video_view.is_null()) |
| 105 Java_ContentVideoView_exitFullscreen(env, content_video_view, | 109 Java_ContentVideoView_exitFullscreen(env, content_video_view, |
| 106 release_media_player); | 110 release_media_player); |
| 107 } | 111 } |
| 108 | 112 |
| 109 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { | 113 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } else { | 160 } else { |
| 157 UMA_HISTOGRAM_COUNTS( | 161 UMA_HISTOGRAM_COUNTS( |
| 158 "MobileFullscreenVideo.LandscapeDuration", | 162 "MobileFullscreenVideo.LandscapeDuration", |
| 159 playback_duration_in_milliseconds_before_orientation_change); | 163 playback_duration_in_milliseconds_before_orientation_change); |
| 160 UMA_HISTOGRAM_COUNTS( | 164 UMA_HISTOGRAM_COUNTS( |
| 161 "MobileFullscreenVideo.LandscapeRotation", orientation_changed); | 165 "MobileFullscreenVideo.LandscapeRotation", orientation_changed); |
| 162 } | 166 } |
| 163 } | 167 } |
| 164 | 168 |
| 165 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject( | 169 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject( |
| 166 ContentViewCore* content_view_core, | |
| 167 const JavaRef<jobject>& j_content_video_view_embedder, | |
| 168 const gfx::Size& video_natural_size) { | 170 const gfx::Size& video_natural_size) { |
| 169 JNIEnv* env = AttachCurrentThread(); | 171 JNIEnv* env = AttachCurrentThread(); |
| 170 base::android::ScopedJavaLocalRef<jobject> j_content_view_core = | 172 base::android::ScopedJavaLocalRef<jobject> j_content_view_core = |
| 171 content_view_core->GetJavaObject(); | 173 cvc_->GetJavaObject(); |
| 172 | 174 |
| 173 if (j_content_view_core.is_null()) | 175 if (j_content_view_core.is_null()) |
| 174 return JavaObjectWeakGlobalRef(env, nullptr); | 176 return JavaObjectWeakGlobalRef(env, nullptr); |
| 175 | 177 |
| 176 return JavaObjectWeakGlobalRef( | 178 return JavaObjectWeakGlobalRef( |
| 177 env, Java_ContentVideoView_createContentVideoView( | 179 env, Java_ContentVideoView_createContentVideoView( |
| 178 env, j_content_view_core, j_content_video_view_embedder, | 180 env, j_content_view_core, j_content_video_view_embedder_, |
| 179 reinterpret_cast<intptr_t>(this), | 181 reinterpret_cast<intptr_t>(this), |
| 180 video_natural_size.width(), video_natural_size.height()) | 182 video_natural_size.width(), video_natural_size.height()) |
| 181 .obj()); | 183 .obj()); |
| 182 } | 184 } |
| 183 } // namespace content | 185 } // namespace content |
| OLD | NEW |