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 "base/message_loop/message_loop.h" |
10 #include "content/browser/android/content_view_core_impl.h" | 10 #include "content/browser/android/content_view_core_impl.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 return RegisterNativesImpl(env); | 37 return RegisterNativesImpl(env); |
38 } | 38 } |
39 | 39 |
40 ContentVideoView* ContentVideoView::GetInstance() { | 40 ContentVideoView* ContentVideoView::GetInstance() { |
41 return g_content_video_view; | 41 return g_content_video_view; |
42 } | 42 } |
43 | 43 |
44 ContentVideoView::ContentVideoView( | 44 ContentVideoView::ContentVideoView( |
45 BrowserMediaPlayerManager* manager) | 45 BrowserMediaPlayerManager* manager) |
46 : manager_(manager), | 46 : manager_(manager), |
47 fullscreen_state_(ENTERED), | |
48 weak_factory_(this) { | 47 weak_factory_(this) { |
49 DCHECK(!g_content_video_view); | 48 DCHECK(!g_content_video_view); |
50 j_content_video_view_ = CreateJavaObject(); | 49 j_content_video_view_ = CreateJavaObject(); |
51 g_content_video_view = this; | 50 g_content_video_view = this; |
52 } | 51 } |
53 | 52 |
54 ContentVideoView::~ContentVideoView() { | 53 ContentVideoView::~ContentVideoView() { |
55 DCHECK(g_content_video_view); | 54 DCHECK(g_content_video_view); |
56 DestroyContentVideoView(true); | 55 DestroyContentVideoView(true); |
57 g_content_video_view = NULL; | 56 g_content_video_view = NULL; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void ContentVideoView::Play(JNIEnv*, jobject obj) { | 153 void ContentVideoView::Play(JNIEnv*, jobject obj) { |
155 manager_->FullscreenPlayerPlay(); | 154 manager_->FullscreenPlayerPlay(); |
156 } | 155 } |
157 | 156 |
158 void ContentVideoView::Pause(JNIEnv*, jobject obj) { | 157 void ContentVideoView::Pause(JNIEnv*, jobject obj) { |
159 manager_->FullscreenPlayerPause(); | 158 manager_->FullscreenPlayerPause(); |
160 } | 159 } |
161 | 160 |
162 void ContentVideoView::ExitFullscreen( | 161 void ContentVideoView::ExitFullscreen( |
163 JNIEnv*, jobject, jboolean release_media_player) { | 162 JNIEnv*, jobject, jboolean release_media_player) { |
164 if (fullscreen_state_ == SUSPENDED) | |
165 return; | |
166 j_content_video_view_.reset(); | 163 j_content_video_view_.reset(); |
167 manager_->ExitFullscreen(release_media_player); | 164 manager_->ExitFullscreen(release_media_player); |
168 } | 165 } |
169 | 166 |
170 void ContentVideoView::SuspendFullscreen() { | |
171 if (fullscreen_state_ != ENTERED) | |
172 return; | |
173 fullscreen_state_ = SUSPENDED; | |
174 DestroyContentVideoView(false); | |
175 manager_->SuspendFullscreen(); | |
176 } | |
177 | |
178 void ContentVideoView::ResumeFullscreenIfSuspended() { | |
179 if (fullscreen_state_ != SUSPENDED) | |
180 return; | |
181 JNIEnv* env = AttachCurrentThread(); | |
182 DCHECK(!GetJavaObject(env).obj()); | |
183 fullscreen_state_ = RESUME; | |
184 j_content_video_view_ = CreateJavaObject(); | |
185 } | |
186 | |
187 void ContentVideoView::SetSurface(JNIEnv* env, jobject obj, | 167 void ContentVideoView::SetSurface(JNIEnv* env, jobject obj, |
188 jobject surface) { | 168 jobject surface) { |
189 gfx::ScopedJavaSurface scoped_surface = | 169 manager_->SetVideoSurface( |
190 gfx::ScopedJavaSurface::AcquireExternalSurface(surface); | 170 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); |
191 if (fullscreen_state_ == RESUME) { | |
192 DCHECK(surface); | |
193 manager_->ResumeFullscreen(scoped_surface.Pass()); | |
194 fullscreen_state_ = ENTERED; | |
195 } else { | |
196 manager_->SetVideoSurface(scoped_surface.Pass()); | |
197 } | |
198 } | 171 } |
199 | 172 |
200 void ContentVideoView::RequestMediaMetadata(JNIEnv* env, jobject obj) { | 173 void ContentVideoView::RequestMediaMetadata(JNIEnv* env, jobject obj) { |
201 base::MessageLoop::current()->PostTask( | 174 base::MessageLoop::current()->PostTask( |
202 FROM_HERE, | 175 FROM_HERE, |
203 base::Bind(&ContentVideoView::UpdateMediaMetadata, | 176 base::Bind(&ContentVideoView::UpdateMediaMetadata, |
204 weak_factory_.GetWeakPtr())); | 177 weak_factory_.GetWeakPtr())); |
205 } | 178 } |
206 | 179 |
207 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { | 180 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { |
(...skipping 18 matching lines...) Expand all Loading... |
226 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) { | 199 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) { |
227 JNIEnv *env = AttachCurrentThread(); | 200 JNIEnv *env = AttachCurrentThread(); |
228 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); | 201 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); |
229 if (!content_video_view.is_null()) { | 202 if (!content_video_view.is_null()) { |
230 Java_ContentVideoView_destroyContentVideoView(env, | 203 Java_ContentVideoView_destroyContentVideoView(env, |
231 content_video_view.obj(), native_view_destroyed); | 204 content_video_view.obj(), native_view_destroyed); |
232 j_content_video_view_.reset(); | 205 j_content_video_view_.reset(); |
233 } | 206 } |
234 } | 207 } |
235 } // namespace content | 208 } // namespace content |
OLD | NEW |