summaryrefslogtreecommitdiffstats
path: root/content/browser/android
diff options
context:
space:
mode:
authormichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-11 00:25:27 +0000
committermichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-11 00:25:27 +0000
commitba3b5e6447e6e47e054a307855e1c465c14a4645 (patch)
tree9095e708df725dfa10cf4f1fd9aa3bbe1cbba36f /content/browser/android
parent9f6e921145950792bbec25dec809276ed323ac8a (diff)
downloadchromium_src-ba3b5e6447e6e47e054a307855e1c465c14a4645.zip
chromium_src-ba3b5e6447e6e47e054a307855e1c465c14a4645.tar.gz
chromium_src-ba3b5e6447e6e47e054a307855e1c465c14a4645.tar.bz2
Merge 249327 "Add PowerSaveBlocker in ContentVideoView"
> Add PowerSaveBlocker in ContentVideoView > > This patch add additonal PowerSaveBlocker in ContentVideoView, and will block > screen sleep when ContentView's container isn't visiable. > > BUG=338873 > > Review URL: https://codereview.chromium.org/141553010 TBR=michaelbai@chromium.org Review URL: https://codereview.chromium.org/136443012 git-svn-id: svn://svn.chromium.org/chrome/branches/1750/src@250245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/android')
-rw-r--r--content/browser/android/content_video_view.cc56
-rw-r--r--content/browser/android/content_video_view.h15
2 files changed, 62 insertions, 9 deletions
diff --git a/content/browser/android/content_video_view.cc b/content/browser/android/content_video_view.cc
index 116e7b4..6f3f2b1 100644
--- a/content/browser/android/content_video_view.cc
+++ b/content/browser/android/content_video_view.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/logging.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"
#include "content/public/common/content_switches.h"
#include "jni/ContentVideoView_jni.h"
@@ -50,6 +51,7 @@ ContentVideoView::ContentVideoView(
Java_ContentVideoView_createContentVideoView(env, context.obj(),
reinterpret_cast<intptr_t>(this), client.obj()).obj());
g_content_video_view = this;
+ CreatePowerSaveBlocker();
}
ContentVideoView::~ContentVideoView() {
@@ -59,23 +61,26 @@ ContentVideoView::~ContentVideoView() {
}
void ContentVideoView::OpenVideo() {
- JNIEnv *env = AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
- if (!content_video_view.is_null())
+ if (!content_video_view.is_null()) {
+ CreatePowerSaveBlocker();
Java_ContentVideoView_openVideo(env, content_video_view.obj());
+ }
}
void ContentVideoView::OnMediaPlayerError(int error_type) {
- JNIEnv *env = AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
if (!content_video_view.is_null()) {
+ power_save_blocker_.reset();
Java_ContentVideoView_onMediaPlayerError(env, content_video_view.obj(),
error_type);
}
}
void ContentVideoView::OnVideoSizeChanged(int width, int height) {
- JNIEnv *env = AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
if (!content_video_view.is_null()) {
Java_ContentVideoView_onVideoSizeChanged(env, content_video_view.obj(),
@@ -84,7 +89,7 @@ void ContentVideoView::OnVideoSizeChanged(int width, int height) {
}
void ContentVideoView::OnBufferingUpdate(int percent) {
- JNIEnv *env = AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
if (!content_video_view.is_null()) {
Java_ContentVideoView_onBufferingUpdate(env, content_video_view.obj(),
@@ -93,18 +98,25 @@ void ContentVideoView::OnBufferingUpdate(int percent) {
}
void ContentVideoView::OnPlaybackComplete() {
- JNIEnv *env = AttachCurrentThread();
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
- if (!content_video_view.is_null())
+ if (!content_video_view.is_null()) {
+ power_save_blocker_.reset();
Java_ContentVideoView_onPlaybackComplete(env, content_video_view.obj());
+ }
}
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();
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
if (!content_video_view.is_null())
UpdateMediaMetadata(env, content_video_view.obj());
@@ -140,15 +152,18 @@ void ContentVideoView::SeekTo(JNIEnv*, jobject obj, jint msec) {
}
void ContentVideoView::Play(JNIEnv*, jobject obj) {
+ CreatePowerSaveBlocker();
manager_->FullscreenPlayerPlay();
}
void ContentVideoView::Pause(JNIEnv*, jobject obj) {
+ power_save_blocker_.reset();
manager_->FullscreenPlayerPause();
}
void ContentVideoView::ExitFullscreen(
JNIEnv*, jobject, jboolean release_media_player) {
+ power_save_blocker_.reset();
j_content_video_view_.reset();
manager_->ExitFullscreen(release_media_player);
}
@@ -172,10 +187,33 @@ ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) {
return j_content_video_view_.get(env);
}
+gfx::NativeView ContentVideoView::GetNativeView() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
+ if (content_video_view.is_null())
+ return NULL;
+
+ return reinterpret_cast<gfx::NativeView>(
+ Java_ContentVideoView_getNativeViewAndroid(env,
+ content_video_view.obj()));
+
+}
+
+void ContentVideoView::CreatePowerSaveBlocker() {
+ if (power_save_blocker_) return;
+
+ power_save_blocker_ = PowerSaveBlocker::Create(
+ PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
+ "Playing video").Pass();
+ static_cast<PowerSaveBlockerImpl*>(power_save_blocker_.get())->
+ InitDisplaySleepBlocker(GetNativeView());
+}
+
void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) {
- JNIEnv *env = AttachCurrentThread();
+ 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();
diff --git a/content/browser/android/content_video_view.h b/content/browser/android/content_video_view.h
index 2a86830..633b903 100644
--- a/content/browser/android/content_video_view.h
+++ b/content/browser/android/content_video_view.h
@@ -13,10 +13,12 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
+#include "ui/gfx/native_widget_types.h"
namespace content {
class BrowserMediaPlayerManager;
+class PowerSaveBlocker;
// Native mirror of ContentVideoView.java. This class is responsible for
// creating the Java video view and pass all the player status change to
@@ -80,10 +82,23 @@ class ContentVideoView {
// no further calls to the native object is allowed.
void DestroyContentVideoView(bool native_view_destroyed);
+ // Returns the associated NativeView
+ gfx::NativeView GetNativeView();
+
+ void CreatePowerSaveBlocker();
+
// Object that manages the fullscreen media player. It is responsible for
// handling all the playback controls.
BrowserMediaPlayerManager* manager_;
+ // PowerSaveBlock to keep screen on for fullscreen video.
+ // There is already blocker when inline video started, and it requires the
+ // ContentView's container displayed to take effect; but in WebView, apps
+ // could use another container to hold ContentVideoView, and the blocker in
+ // ContentView's container can not keep screen on; so we need another blocker
+ // here, it is no harm, just an additonal blocker.
+ scoped_ptr<PowerSaveBlocker> power_save_blocker_;
+
// Weak reference of corresponding Java object.
JavaObjectWeakGlobalRef j_content_video_view_;