When enabling new profile management programmatically, make sure to set the
[chromium-blink-merge.git] / content / browser / android / content_video_view.h
blobfaea292b5f0f9757730dcf4a385b6d044959e263
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_
6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_
8 #include <jni.h>
10 #include "base/android/jni_weak_ref.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/timer/timer.h"
17 #include "ui/gfx/native_widget_types.h"
19 namespace content {
21 class BrowserMediaPlayerManager;
22 class PowerSaveBlocker;
24 // Native mirror of ContentVideoView.java. This class is responsible for
25 // creating the Java video view and pass all the player status change to
26 // it. It accepts media control from Java class, and forwards it to
27 // MediaPlayerManagerImpl.
28 class ContentVideoView {
29 public:
30 // Construct a ContentVideoView object. The |manager| will handle all the
31 // playback controls from the Java class.
32 explicit ContentVideoView(BrowserMediaPlayerManager* manager);
34 ~ContentVideoView();
36 // To open another video on existing ContentVideoView.
37 void OpenVideo();
39 static bool RegisterContentVideoView(JNIEnv* env);
40 static void KeepScreenOn(bool screen_on);
42 // Return the singleton object or NULL.
43 static ContentVideoView* GetInstance();
45 // Getter method called by the Java class to get the media information.
46 int GetVideoWidth(JNIEnv*, jobject obj) const;
47 int GetVideoHeight(JNIEnv*, jobject obj) const;
48 int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const;
49 int GetCurrentPosition(JNIEnv*, jobject obj) const;
50 bool IsPlaying(JNIEnv*, jobject obj);
51 void RequestMediaMetadata(JNIEnv*, jobject obj);
53 // Called when the Java fullscreen view is destroyed. If
54 // |release_media_player| is true, |manager_| needs to release the player
55 // as we are quitting the app.
56 void ExitFullscreen(JNIEnv*, jobject, jboolean release_media_player);
58 // Media control method called by the Java class.
59 void SeekTo(JNIEnv*, jobject obj, jint msec);
60 void Play(JNIEnv*, jobject obj);
61 void Pause(JNIEnv*, jobject obj);
63 // Called by the Java class to pass the surface object to the player.
64 void SetSurface(JNIEnv*, jobject obj, jobject surface);
66 // Method called by |manager_| to inform the Java class about player status
67 // change.
68 void UpdateMediaMetadata();
69 void OnMediaPlayerError(int errorType);
70 void OnVideoSizeChanged(int width, int height);
71 void OnBufferingUpdate(int percent);
72 void OnPlaybackComplete();
73 void OnExitFullscreen();
75 // Return the corresponing ContentVideoView Java object if any.
76 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env);
78 private:
79 // Creates the corresponding ContentVideoView Java object.
80 JavaObjectWeakGlobalRef CreateJavaObject();
82 // Returns the associated NativeView
83 gfx::NativeView GetNativeView();
85 void CreatePowerSaveBlocker();
87 // Object that manages the fullscreen media player. It is responsible for
88 // handling all the playback controls.
89 BrowserMediaPlayerManager* manager_;
91 // PowerSaveBlock to keep screen on for fullscreen video.
92 // There is already blocker when inline video started, and it requires the
93 // ContentView's container displayed to take effect; but in WebView, apps
94 // could use another container to hold ContentVideoView, and the blocker in
95 // ContentView's container can not keep screen on; so we need another blocker
96 // here, it is no harm, just an additonal blocker.
97 scoped_ptr<PowerSaveBlocker> power_save_blocker_;
99 // Weak reference of corresponding Java object.
100 JavaObjectWeakGlobalRef j_content_video_view_;
102 // Weak pointer for posting tasks.
103 base::WeakPtrFactory<ContentVideoView> weak_factory_;
105 DISALLOW_COPY_AND_ASSIGN(ContentVideoView);
108 } // namespace content
110 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_