| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 9 #include "content/browser/android/content_view_core_impl.h" | 10 #include "content/browser/android/content_view_core_impl.h" |
| 10 #include "content/browser/media/android/browser_media_player_manager.h" | 11 #include "content/browser/media/android/browser_media_player_manager.h" |
| 11 #include "content/common/android/surface_texture_peer.h" | 12 #include "content/common/android/surface_texture_peer.h" |
| 12 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 13 #include "jni/ContentVideoView_jni.h" | 14 #include "jni/ContentVideoView_jni.h" |
| 14 | 15 |
| 15 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
| 16 using base::android::CheckException; | 17 using base::android::CheckException; |
| 17 using base::android::ScopedJavaGlobalRef; | 18 using base::android::ScopedJavaGlobalRef; |
| 18 | 19 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 36 return RegisterNativesImpl(env); | 37 return RegisterNativesImpl(env); |
| 37 } | 38 } |
| 38 | 39 |
| 39 ContentVideoView* ContentVideoView::GetInstance() { | 40 ContentVideoView* ContentVideoView::GetInstance() { |
| 40 return g_content_video_view; | 41 return g_content_video_view; |
| 41 } | 42 } |
| 42 | 43 |
| 43 ContentVideoView::ContentVideoView( | 44 ContentVideoView::ContentVideoView( |
| 44 BrowserMediaPlayerManager* manager) | 45 BrowserMediaPlayerManager* manager) |
| 45 : manager_(manager), | 46 : manager_(manager), |
| 46 fullscreen_state_(ENTERED) { | 47 fullscreen_state_(ENTERED), |
| 48 weak_this_(this) { |
| 47 DCHECK(!g_content_video_view); | 49 DCHECK(!g_content_video_view); |
| 48 j_content_video_view_ = CreateJavaObject(); | 50 j_content_video_view_ = CreateJavaObject(); |
| 49 g_content_video_view = this; | 51 g_content_video_view = this; |
| 50 } | 52 } |
| 51 | 53 |
| 52 ContentVideoView::~ContentVideoView() { | 54 ContentVideoView::~ContentVideoView() { |
| 53 DCHECK(g_content_video_view); | 55 DCHECK(g_content_video_view); |
| 54 DestroyContentVideoView(true); | 56 DestroyContentVideoView(true); |
| 55 g_content_video_view = NULL; | 57 g_content_video_view = NULL; |
| 56 } | 58 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 103 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
| 102 if (!content_video_view.is_null()) { | 104 if (!content_video_view.is_null()) { |
| 103 Java_ContentVideoView_onExitFullscreen(env, content_video_view.obj()); | 105 Java_ContentVideoView_onExitFullscreen(env, content_video_view.obj()); |
| 104 j_content_video_view_.reset(); | 106 j_content_video_view_.reset(); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 void ContentVideoView::UpdateMediaMetadata() { | 110 void ContentVideoView::UpdateMediaMetadata() { |
| 109 JNIEnv *env = AttachCurrentThread(); | 111 JNIEnv *env = AttachCurrentThread(); |
| 110 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 112 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
| 111 if (!content_video_view.is_null()) | 113 if (content_video_view.is_null()) |
| 112 UpdateMediaMetadata(env, content_video_view.obj()); | 114 return; |
| 115 |
| 116 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); |
| 117 if (player && player->IsPlayerReady()) { |
| 118 Java_ContentVideoView_onUpdateMediaMetadata( |
| 119 env, content_video_view.obj(), player->GetVideoWidth(), |
| 120 player->GetVideoHeight(), player->GetDuration().InMilliseconds(), |
| 121 player->CanPause(),player->CanSeekForward(), player->CanSeekBackward()); |
| 122 } |
| 113 } | 123 } |
| 114 | 124 |
| 115 int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const { | 125 int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const { |
| 116 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); | 126 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); |
| 117 return player ? player->GetVideoWidth() : 0; | 127 return player ? player->GetVideoWidth() : 0; |
| 118 } | 128 } |
| 119 | 129 |
| 120 int ContentVideoView::GetVideoHeight(JNIEnv*, jobject obj) const { | 130 int ContentVideoView::GetVideoHeight(JNIEnv*, jobject obj) const { |
| 121 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); | 131 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); |
| 122 return player ? player->GetVideoHeight() : 0; | 132 return player ? player->GetVideoHeight() : 0; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 gfx::ScopedJavaSurface::AcquireExternalSurface(surface); | 190 gfx::ScopedJavaSurface::AcquireExternalSurface(surface); |
| 181 if (fullscreen_state_ == RESUME) { | 191 if (fullscreen_state_ == RESUME) { |
| 182 DCHECK(surface); | 192 DCHECK(surface); |
| 183 manager_->ResumeFullscreen(scoped_surface.Pass()); | 193 manager_->ResumeFullscreen(scoped_surface.Pass()); |
| 184 fullscreen_state_ = ENTERED; | 194 fullscreen_state_ = ENTERED; |
| 185 } else { | 195 } else { |
| 186 manager_->SetVideoSurface(scoped_surface.Pass()); | 196 manager_->SetVideoSurface(scoped_surface.Pass()); |
| 187 } | 197 } |
| 188 } | 198 } |
| 189 | 199 |
| 190 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { | 200 void ContentVideoView::RequestMediaMetadata(JNIEnv* env, jobject obj) { |
| 191 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); | 201 base::MessageLoop::current()->PostTask( |
| 192 if (player && player->IsPlayerReady()) | 202 FROM_HERE, |
| 193 Java_ContentVideoView_onUpdateMediaMetadata( | 203 base::Bind(&ContentVideoView::UpdateMediaMetadata, |
| 194 env, obj, player->GetVideoWidth(), player->GetVideoHeight(), | 204 weak_this_.GetWeakPtr())); |
| 195 player->GetDuration().InMilliseconds(), player->CanPause(), | |
| 196 player->CanSeekForward(), player->CanSeekBackward()); | |
| 197 } | 205 } |
| 198 | 206 |
| 199 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { | 207 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { |
| 200 return j_content_video_view_.get(env); | 208 return j_content_video_view_.get(env); |
| 201 } | 209 } |
| 202 | 210 |
| 203 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject() { | 211 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject() { |
| 204 ContentViewCoreImpl* content_view_core = manager_->GetContentViewCore(); | 212 ContentViewCoreImpl* content_view_core = manager_->GetContentViewCore(); |
| 205 JNIEnv *env = AttachCurrentThread(); | 213 JNIEnv *env = AttachCurrentThread(); |
| 206 bool legacyMode = !CommandLine::ForCurrentProcess()->HasSwitch( | 214 bool legacyMode = !CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 218 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) { | 226 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) { |
| 219 JNIEnv *env = AttachCurrentThread(); | 227 JNIEnv *env = AttachCurrentThread(); |
| 220 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 228 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
| 221 if (!content_video_view.is_null()) { | 229 if (!content_video_view.is_null()) { |
| 222 Java_ContentVideoView_destroyContentVideoView(env, | 230 Java_ContentVideoView_destroyContentVideoView(env, |
| 223 content_video_view.obj(), native_view_destroyed); | 231 content_video_view.obj(), native_view_destroyed); |
| 224 j_content_video_view_.reset(); | 232 j_content_video_view_.reset(); |
| 225 } | 233 } |
| 226 } | 234 } |
| 227 } // namespace content | 235 } // namespace content |
| OLD | NEW |