Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: content/browser/android/content_video_view.cc

Issue 103583005: Restart fullscreen video playback when switching back from background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed comment without whitespace noise Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/android/content_view_core_impl.h"
9 #include "content/browser/media/android/browser_media_player_manager.h" 10 #include "content/browser/media/android/browser_media_player_manager.h"
10 #include "content/common/android/surface_texture_peer.h" 11 #include "content/common/android/surface_texture_peer.h"
11 #include "content/public/common/content_switches.h" 12 #include "content/public/common/content_switches.h"
12 #include "jni/ContentVideoView_jni.h" 13 #include "jni/ContentVideoView_jni.h"
13 14
14 using base::android::AttachCurrentThread; 15 using base::android::AttachCurrentThread;
15 using base::android::CheckException; 16 using base::android::CheckException;
16 using base::android::ScopedJavaGlobalRef; 17 using base::android::ScopedJavaGlobalRef;
17 18
18 namespace content { 19 namespace content {
19 20
20 namespace { 21 namespace {
21 // There can only be one content video view at a time, this holds onto that 22 // There can only be one content video view at a time, this holds onto that
22 // singleton instance. 23 // singleton instance.
23 ContentVideoView* g_content_video_view = NULL; 24 ContentVideoView* g_content_video_view = NULL;
24 25
25 } // namespace 26 } // namespace
26 27
27 static jobject GetSingletonJavaContentVideoView(JNIEnv*env, jclass) { 28 static jobject GetSingletonJavaContentVideoView(JNIEnv*env, jclass) {
28 if (g_content_video_view) 29 if (g_content_video_view)
29 return g_content_video_view->GetJavaObject(env).Release(); 30 return g_content_video_view->GetJavaObject(env).Release();
30 else 31 else
31 return NULL; 32 return NULL;
32 } 33 }
33 34
34 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { 35 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) {
35 return RegisterNativesImpl(env); 36 return RegisterNativesImpl(env);
36 } 37 }
37 38
38 bool ContentVideoView::HasContentVideoView() { 39 ContentVideoView* ContentVideoView::GetInstance() {
39 return g_content_video_view; 40 return g_content_video_view;
40 } 41 }
41 42
42 ContentVideoView::ContentVideoView( 43 ContentVideoView::ContentVideoView(
43 const ScopedJavaLocalRef<jobject>& context,
44 const ScopedJavaLocalRef<jobject>& client,
45 BrowserMediaPlayerManager* manager) 44 BrowserMediaPlayerManager* manager)
46 : manager_(manager) { 45 : manager_(manager),
46 fullscreen_state_(ENTERED) {
47 DCHECK(!g_content_video_view); 47 DCHECK(!g_content_video_view);
48 JNIEnv *env = AttachCurrentThread(); 48 j_content_video_view_ = CreateJavaObject();
49 j_content_video_view_ = JavaObjectWeakGlobalRef(env,
50 Java_ContentVideoView_createContentVideoView(env, context.obj(),
51 reinterpret_cast<intptr_t>(this), client.obj()).obj());
52 g_content_video_view = this; 49 g_content_video_view = this;
53 } 50 }
54 51
55 ContentVideoView::~ContentVideoView() { 52 ContentVideoView::~ContentVideoView() {
56 DCHECK(g_content_video_view); 53 DCHECK(g_content_video_view);
57 DestroyContentVideoView(true); 54 DestroyContentVideoView(true);
58 g_content_video_view = NULL; 55 g_content_video_view = NULL;
59 } 56 }
60 57
61 void ContentVideoView::OpenVideo() { 58 void ContentVideoView::OpenVideo() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 138
142 void ContentVideoView::Play(JNIEnv*, jobject obj) { 139 void ContentVideoView::Play(JNIEnv*, jobject obj) {
143 manager_->FullscreenPlayerPlay(); 140 manager_->FullscreenPlayerPlay();
144 } 141 }
145 142
146 void ContentVideoView::Pause(JNIEnv*, jobject obj) { 143 void ContentVideoView::Pause(JNIEnv*, jobject obj) {
147 manager_->FullscreenPlayerPause(); 144 manager_->FullscreenPlayerPause();
148 } 145 }
149 146
150 void ContentVideoView::ExitFullscreen( 147 void ContentVideoView::ExitFullscreen(
151 JNIEnv*, jobject, jboolean release_media_player) { 148 JNIEnv* env, jobject, jboolean release_media_player) {
149 if (fullscreen_state_ == SUSPENDED)
150 return;
152 j_content_video_view_.reset(); 151 j_content_video_view_.reset();
153 manager_->ExitFullscreen(release_media_player); 152 manager_->ExitFullscreen(release_media_player);
154 } 153 }
155 154
155 void ContentVideoView::SuspendFullscreen() {
156 if (fullscreen_state_ != ENTERED)
157 return;
158 fullscreen_state_ = SUSPENDED;
159 DestroyContentVideoView(false);
160 manager_->SuspendFullscreen();
161 }
162
163 void ContentVideoView::ResumeFullscreenIfSuspended() {
164 if (fullscreen_state_ != SUSPENDED)
165 return;
166 JNIEnv* env = AttachCurrentThread();
167 DCHECK(!GetJavaObject(env).obj());
168 fullscreen_state_ = RESUME;
169 j_content_video_view_ = CreateJavaObject();
170 }
171
156 void ContentVideoView::SetSurface(JNIEnv* env, jobject obj, 172 void ContentVideoView::SetSurface(JNIEnv* env, jobject obj,
157 jobject surface) { 173 jobject surface) {
158 manager_->SetVideoSurface( 174 gfx::ScopedJavaSurface scoped_surface =
159 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); 175 gfx::ScopedJavaSurface::AcquireExternalSurface(surface);
176 if (fullscreen_state_ == RESUME) {
177 DCHECK(surface);
178 manager_->ResumeFullscreen(scoped_surface.Pass());
179 fullscreen_state_ = ENTERED;
180 } else {
181 manager_->SetVideoSurface(scoped_surface.Pass());
182 }
160 } 183 }
161 184
162 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { 185 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) {
163 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); 186 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer();
164 if (player && player->IsPlayerReady()) 187 if (player && player->IsPlayerReady())
165 Java_ContentVideoView_onUpdateMediaMetadata( 188 Java_ContentVideoView_onUpdateMediaMetadata(
166 env, obj, player->GetVideoWidth(), player->GetVideoHeight(), 189 env, obj, player->GetVideoWidth(), player->GetVideoHeight(),
167 player->GetDuration().InMilliseconds(), player->CanPause(), 190 player->GetDuration().InMilliseconds(), player->CanPause(),
168 player->CanSeekForward(), player->CanSeekBackward()); 191 player->CanSeekForward(), player->CanSeekBackward());
169 } 192 }
170 193
171 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { 194 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) {
172 return j_content_video_view_.get(env); 195 return j_content_video_view_.get(env);
173 } 196 }
174 197
198 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject() {
199 ContentViewCoreImpl* content_view_core = manager_->GetContentViewCore();
200 JNIEnv *env = AttachCurrentThread();
201 return JavaObjectWeakGlobalRef(
202 env,
bulach 2014/01/06 15:44:03 nit: indent should be just +4 from the beginning o
203 Java_ContentVideoView_createContentVideoView(
204 env,
205 content_view_core->GetContext().obj(),
206 reinterpret_cast<intptr_t>(this),
207 content_view_core->GetContentVideoViewClient().obj()).obj());
208 }
209
175 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) { 210 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) {
176 JNIEnv *env = AttachCurrentThread(); 211 JNIEnv *env = AttachCurrentThread();
177 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); 212 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
178 if (!content_video_view.is_null()) { 213 if (!content_video_view.is_null()) {
179 Java_ContentVideoView_destroyContentVideoView(env, 214 Java_ContentVideoView_destroyContentVideoView(env,
180 content_video_view.obj(), native_view_destroyed); 215 content_video_view.obj(), native_view_destroyed);
181 j_content_video_view_.reset(); 216 j_content_video_view_.reset();
182 } 217 }
183 } 218 }
184 } // namespace content 219 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698