| 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 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include "base/android/jni_weak_ref.h" | 10 #include "base/android/jni_weak_ref.h" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/public/browser/android/content_view_core.h" | 14 #include "content/public/browser/android/content_view_core.h" |
| 15 #include "content/public/browser/android/video_surface_provider.h" |
| 16 #include "ui/gfx/geometry/size.h" |
| 15 #include "ui/gl/android/scoped_java_surface.h" | 17 #include "ui/gl/android/scoped_java_surface.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 | 20 |
| 19 // Native mirror of ContentVideoView.java. This class is responsible for | 21 // Native mirror of ContentVideoView.java. This class is responsible for |
| 20 // creating the Java video view and passing changes in player status to it. | 22 // creating the Java video view and passing changes in player status to it. |
| 21 // This class must be used on the UI thread. | 23 // This class must be used on the UI thread. |
| 22 class ContentVideoView { | 24 class ContentVideoView : public content::VideoSurfaceProvider { |
| 23 public: | 25 public: |
| 24 static bool RegisterContentVideoView(JNIEnv* env); | 26 static bool RegisterContentVideoView(JNIEnv* env); |
| 25 | 27 |
| 26 // Returns the singleton object or NULL. | 28 // Returns the singleton object or NULL. |
| 27 static ContentVideoView* GetInstance(); | 29 static ContentVideoView* GetInstance(); |
| 28 | 30 |
| 29 class Client { | 31 explicit ContentVideoView(ContentViewCore* content_view_core, |
| 30 public: | 32 const base::android::JavaRef<jobject>& embedder); |
| 31 Client() {} | |
| 32 // For receiving notififcations when the SurfaceView surface is created and | |
| 33 // destroyed. When |surface.IsEmpty()| the surface was destroyed and | |
| 34 // the client should not hold any references to it once this returns. | |
| 35 virtual void SetVideoSurface(gl::ScopedJavaSurface surface) = 0; | |
| 36 | |
| 37 // Called after the ContentVideoView has been hidden because we're exiting | |
| 38 // fullscreen. | |
| 39 virtual void DidExitFullscreen(bool release_media_player) = 0; | |
| 40 | |
| 41 protected: | |
| 42 ~Client() {} | |
| 43 | |
| 44 DISALLOW_COPY_AND_ASSIGN(Client); | |
| 45 }; | |
| 46 | |
| 47 explicit ContentVideoView(Client* client, | |
| 48 ContentViewCore* content_view_core, | |
| 49 const base::android::JavaRef<jobject>& embedder, | |
| 50 const gfx::Size& video_natural_size); | |
| 51 ~ContentVideoView(); | 33 ~ContentVideoView(); |
| 52 | 34 |
| 53 // To open another video on existing ContentVideoView. | 35 // To open another video on existing ContentVideoView. |
| 54 void OpenVideo(); | 36 void OpenVideo(); |
| 55 | 37 |
| 56 // Display an error dialog to the user. | 38 // Display an error dialog to the user. |
| 57 void OnMediaPlayerError(int error_type); | 39 void OnMediaPlayerError(int error_type); |
| 58 | 40 |
| 59 // Update the video size. | 41 // Update the video size. |
| 60 void OnVideoSizeChanged(int width, int height); | 42 void OnVideoSizeChanged(int width, int height) override; |
| 43 |
| 44 // Instantiates the Java object and creates the video surface. |
| 45 void CreateVideoSurface(VideoSurfaceProvider::Client* client, |
| 46 const gfx::Size& video_natural_size) override; |
| 47 |
| 61 | 48 |
| 62 // Exit fullscreen and notify |client_| with |DidExitFullscreen|. | 49 // Exit fullscreen and notify |client_| with |DidExitFullscreen|. |
| 63 void ExitFullscreen(); | 50 void ExitFullscreen(); |
| 64 | 51 |
| 65 // Returns the corresponding ContentVideoView Java object if any. | 52 // Returns the corresponding ContentVideoView Java object if any. |
| 66 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); | 53 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); |
| 67 | 54 |
| 68 // Called by the Java class when the surface changes. | 55 // Called by the Java class when the surface changes. |
| 69 void SetSurface(JNIEnv* env, | 56 void SetSurface(JNIEnv* env, |
| 70 const base::android::JavaParamRef<jobject>& obj, | 57 const base::android::JavaParamRef<jobject>& obj, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 bool is_orientation_portrait); | 71 bool is_orientation_portrait); |
| 85 void RecordExitFullscreenPlayback( | 72 void RecordExitFullscreenPlayback( |
| 86 JNIEnv*, | 73 JNIEnv*, |
| 87 const base::android::JavaParamRef<jobject>&, | 74 const base::android::JavaParamRef<jobject>&, |
| 88 bool is_portrait_video, | 75 bool is_portrait_video, |
| 89 long playback_duration_in_milliseconds_before_orientation_change, | 76 long playback_duration_in_milliseconds_before_orientation_change, |
| 90 long playback_duration_in_milliseconds_after_orientation_change); | 77 long playback_duration_in_milliseconds_after_orientation_change); |
| 91 | 78 |
| 92 private: | 79 private: |
| 93 // Creates the corresponding ContentVideoView Java object. | 80 // Creates the corresponding ContentVideoView Java object. |
| 94 JavaObjectWeakGlobalRef CreateJavaObject( | 81 JavaObjectWeakGlobalRef CreateJavaObject(const gfx::Size& video_natural_size); |
| 95 ContentViewCore* content_view_core, | |
| 96 const base::android::JavaRef<jobject>& j_content_video_view_embedder, | |
| 97 const gfx::Size& video_natural_size); | |
| 98 | 82 |
| 99 Client* client_; | 83 VideoSurfaceProvider::Client* client_; |
| 84 ContentViewCore* cvc_; |
| 85 const base::android::JavaRef<jobject>& j_content_video_view_embedder_; |
| 100 | 86 |
| 101 // Weak reference to corresponding Java object. | 87 // Weak reference to corresponding Java object. |
| 102 JavaObjectWeakGlobalRef j_content_video_view_; | 88 JavaObjectWeakGlobalRef j_content_video_view_; |
| 103 | 89 |
| 104 // Weak pointer for posting tasks. | 90 // Weak pointer for posting tasks. |
| 105 base::WeakPtrFactory<ContentVideoView> weak_factory_; | 91 base::WeakPtrFactory<ContentVideoView> weak_factory_; |
| 106 | 92 |
| 107 DISALLOW_COPY_AND_ASSIGN(ContentVideoView); | 93 DISALLOW_COPY_AND_ASSIGN(ContentVideoView); |
| 108 }; | 94 }; |
| 109 | 95 |
| 110 } // namespace content | 96 } // namespace content |
| 111 | 97 |
| 112 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 98 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
| OLD | NEW |