summaryrefslogtreecommitdiffstats
path: root/chromium/content/browser/android/content_video_view.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/browser/android/content_video_view.cc')
-rw-r--r--chromium/content/browser/android/content_video_view.cc83
1 files changed, 53 insertions, 30 deletions
diff --git a/chromium/content/browser/android/content_video_view.cc b/chromium/content/browser/android/content_video_view.cc
index 9ee541aab0d..5407032441b 100644
--- a/chromium/content/browser/android/content_video_view.cc
+++ b/chromium/content/browser/android/content_video_view.cc
@@ -6,6 +6,8 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "content/browser/android/content_view_core_impl.h"
#include "content/browser/media/android/browser_media_player_manager.h"
#include "content/browser/power_save_blocker_impl.h"
#include "content/common/android/surface_texture_peer.h"
@@ -36,27 +38,29 @@ bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) {
return RegisterNativesImpl(env);
}
-bool ContentVideoView::HasContentVideoView() {
+ContentVideoView* ContentVideoView::GetInstance() {
return g_content_video_view;
}
ContentVideoView::ContentVideoView(
- const ScopedJavaLocalRef<jobject>& context,
- const ScopedJavaLocalRef<jobject>& client,
BrowserMediaPlayerManager* manager)
- : manager_(manager) {
+ : manager_(manager),
+ weak_factory_(this) {
DCHECK(!g_content_video_view);
- JNIEnv *env = AttachCurrentThread();
- j_content_video_view_ = JavaObjectWeakGlobalRef(env,
- Java_ContentVideoView_createContentVideoView(env, context.obj(),
- reinterpret_cast<intptr_t>(this), client.obj()).obj());
+ j_content_video_view_ = CreateJavaObject();
g_content_video_view = this;
CreatePowerSaveBlocker();
}
ContentVideoView::~ContentVideoView() {
DCHECK(g_content_video_view);
- DestroyContentVideoView(true);
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
+ if (!content_video_view.is_null()) {
+ Java_ContentVideoView_destroyContentVideoView(env,
+ content_video_view.obj(), true);
+ j_content_video_view_.reset();
+ }
g_content_video_view = NULL;
}
@@ -107,14 +111,26 @@ void ContentVideoView::OnPlaybackComplete() {
}
void ContentVideoView::OnExitFullscreen() {
- DestroyContentVideoView(false);
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
+ if (!content_video_view.is_null())
+ Java_ContentVideoView_onExitFullscreen(env, content_video_view.obj());
}
void ContentVideoView::UpdateMediaMetadata() {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
- if (!content_video_view.is_null())
- UpdateMediaMetadata(env, content_video_view.obj());
+ if (content_video_view.is_null())
+ return;
+
+ media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer();
+ if (player && player->IsPlayerReady()) {
+ Java_ContentVideoView_onUpdateMediaMetadata(
+ env, content_video_view.obj(), player->GetVideoWidth(),
+ player->GetVideoHeight(),
+ static_cast<int>(player->GetDuration().InMilliseconds()),
+ player->CanPause(),player->CanSeekForward(), player->CanSeekBackward());
+ }
}
int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const {
@@ -169,13 +185,11 @@ void ContentVideoView::SetSurface(JNIEnv* env, jobject obj,
gfx::ScopedJavaSurface::AcquireExternalSurface(surface));
}
-void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) {
- media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer();
- if (player && player->IsPlayerReady())
- Java_ContentVideoView_onUpdateMediaMetadata(
- env, obj, player->GetVideoWidth(), player->GetVideoHeight(),
- player->GetDuration().InMilliseconds(), player->CanPause(),
- player->CanSeekForward(), player->CanSeekBackward());
+void ContentVideoView::RequestMediaMetadata(JNIEnv* env, jobject obj) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ContentVideoView::UpdateMediaMetadata,
+ weak_factory_.GetWeakPtr()));
}
ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) {
@@ -194,7 +208,27 @@ gfx::NativeView ContentVideoView::GetNativeView() {
}
+JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject() {
+ ContentViewCoreImpl* content_view_core = manager_->GetContentViewCore();
+ JNIEnv* env = AttachCurrentThread();
+ bool legacyMode = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableOverlayFullscreenVideoSubtitle);
+ return JavaObjectWeakGlobalRef(
+ env,
+ Java_ContentVideoView_createContentVideoView(
+ env,
+ content_view_core->GetContext().obj(),
+ reinterpret_cast<intptr_t>(this),
+ content_view_core->GetContentVideoViewClient().obj(),
+ legacyMode).obj());
+}
+
void ContentVideoView::CreatePowerSaveBlocker() {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableOverlayFullscreenVideoSubtitle)) {
+ return;
+ }
+
if (power_save_blocker_) return;
power_save_blocker_ = PowerSaveBlocker::Create(
@@ -203,15 +237,4 @@ void ContentVideoView::CreatePowerSaveBlocker() {
static_cast<PowerSaveBlockerImpl*>(power_save_blocker_.get())->
InitDisplaySleepBlocker(GetNativeView());
}
-
-void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
- if (!content_video_view.is_null()) {
- j_content_video_view_.reset();
- Java_ContentVideoView_destroyContentVideoView(env,
- content_video_view.obj(), native_view_destroyed);
- j_content_video_view_.reset();
- }
-}
} // namespace content