Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / content / browser / media / android / browser_media_player_manager.h
index 50eef7f..fe78b8e 100644 (file)
@@ -5,57 +5,57 @@
 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_
 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_
 
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
 #include "base/basictypes.h"
 #include "base/callback.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/scoped_vector.h"
 #include "base/time/time.h"
 #include "content/browser/android/content_video_view.h"
+#include "content/common/content_export.h"
 #include "content/common/media/media_player_messages_enums_android.h"
-#include "content/public/browser/web_contents_observer.h"
+#include "ipc/ipc_message.h"
 #include "media/base/android/media_player_android.h"
 #include "media/base/android/media_player_manager.h"
+#include "media/base/android/media_url_interceptor.h"
 #include "ui/gfx/rect_f.h"
 #include "url/gurl.h"
 
 namespace media {
 class DemuxerAndroid;
-class MediaDrmBridge;
 }
 
+struct MediaPlayerHostMsg_Initialize_Params;
+
 namespace content {
 class BrowserDemuxerAndroid;
 class ContentViewCoreImpl;
+class ExternalVideoSurfaceContainer;
+class RenderFrameHost;
 class WebContents;
 
-// This class manages all the MediaPlayerAndroid objects. It receives
-// control operations from the the render process, and forwards
+// This class manages all the MediaPlayerAndroid objects.
+// It receives control operations from the the render process, and forwards
 // them to corresponding MediaPlayerAndroid object. Callbacks from
-// MediaPlayerAndroid objects are converted to IPCs and then sent to the
-// render process.
+// MediaPlayerAndroid objects are converted to IPCs and then sent to the render
+// process.
 class CONTENT_EXPORT BrowserMediaPlayerManager
-    : public WebContentsObserver,
-      public media::MediaPlayerManager {
+    : public media::MediaPlayerManager {
  public:
   // Permits embedders to provide an extended version of the class.
-  typedef BrowserMediaPlayerManager* (*Factory)(RenderViewHost*);
+  typedef BrowserMediaPlayerManager* (*Factory)(RenderFrameHost*);
   static void RegisterFactory(Factory factory);
 
+  // Permits embedders to handle custom urls.
+  static void RegisterMediaUrlInterceptor(
+      media::MediaUrlInterceptor* media_url_interceptor);
+
   // Returns a new instance using the registered factory if available.
-  static BrowserMediaPlayerManager* Create(RenderViewHost* rvh);
+  static BrowserMediaPlayerManager* Create(RenderFrameHost* rfh);
 
   ContentViewCoreImpl* GetContentViewCore() const;
 
   virtual ~BrowserMediaPlayerManager();
 
-  // WebContentsObserver overrides.
-  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
-
   // Fullscreen video playback controls.
   virtual void FullscreenPlayerPlay();
   virtual void FullscreenPlayerPause();
@@ -67,6 +67,12 @@ class CONTENT_EXPORT BrowserMediaPlayerManager
   // Any actual seek started by renderer will be handled by browser in OnSeek().
   void OnSeekRequest(int player_id, const base::TimeDelta& time_to_seek);
 
+  // Pauses all video players manages by this class.
+  void PauseVideo();
+
+  // Stops and releases every media managed by this class.
+  void ReleaseAllMediaPlayers();
+
   // media::MediaPlayerManager overrides.
   virtual void OnTimeUpdate(
       int player_id, base::TimeDelta current_time) OVERRIDE;
@@ -85,50 +91,24 @@ class CONTENT_EXPORT BrowserMediaPlayerManager
   virtual void OnError(int player_id, int error) OVERRIDE;
   virtual void OnVideoSizeChanged(
       int player_id, int width, int height) OVERRIDE;
-  virtual void RequestMediaResources(int player_id) OVERRIDE;
-  virtual void ReleaseMediaResources(int player_id) OVERRIDE;
   virtual media::MediaResourceGetter* GetMediaResourceGetter() OVERRIDE;
+  virtual media::MediaUrlInterceptor* GetMediaUrlInterceptor() OVERRIDE;
   virtual media::MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE;
   virtual media::MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE;
-  virtual media::MediaDrmBridge* GetDrmBridge(int media_keys_id) OVERRIDE;
-  virtual void DestroyAllMediaPlayers() OVERRIDE;
-  virtual void OnProtectedSurfaceRequested(int player_id) OVERRIDE;
-  virtual void OnSessionCreated(int media_keys_id,
-                                uint32 session_id,
-                                const std::string& web_session_id) OVERRIDE;
-  virtual void OnSessionMessage(int media_keys_id,
-                                uint32 session_id,
-                                const std::vector<uint8>& message,
-                                const GURL& destination_url) OVERRIDE;
-  virtual void OnSessionReady(int media_keys_id, uint32 session_id) OVERRIDE;
-  virtual void OnSessionClosed(int media_keys_id, uint32 session_id) OVERRIDE;
-  virtual void OnSessionError(int media_keys_id,
-                              uint32 session_id,
-                              media::MediaKeys::KeyError error_code,
-                              int system_code) OVERRIDE;
-
+  virtual void RequestFullScreen(int player_id) OVERRIDE;
 #if defined(VIDEO_HOLE)
+  virtual bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo() OVERRIDE;
+
   void AttachExternalVideoSurface(int player_id, jobject surface);
   void DetachExternalVideoSurface(int player_id);
+  void OnFrameInfoUpdated();
 #endif  // defined(VIDEO_HOLE)
 
-  // Called to disble the current fullscreen playback if the video is encrypted.
-  // TODO(qinmin): remove this once we have the new fullscreen mode.
-  void DisableFullscreenEncryptedMediaPlayback();
-
- protected:
-  // Clients must use Create() or subclass constructor.
-  explicit BrowserMediaPlayerManager(RenderViewHost* render_view_host);
-
   // Message handlers.
   virtual void OnEnterFullscreen(int player_id);
   virtual void OnExitFullscreen(int player_id);
   virtual void OnInitialize(
-      MediaPlayerHostMsg_Initialize_Type type,
-      int player_id,
-      const GURL& url,
-      const GURL& first_party_for_cookies,
-      int demuxer_client_id);
+      const MediaPlayerHostMsg_Initialize_Params& media_player_params);
   virtual void OnStart(int player_id);
   virtual void OnSeek(int player_id, const base::TimeDelta& time);
   virtual void OnPause(int player_id, bool is_media_related_action);
@@ -137,28 +117,17 @@ class CONTENT_EXPORT BrowserMediaPlayerManager
   virtual void OnReleaseResources(int player_id);
   virtual void OnDestroyPlayer(int player_id);
   virtual void ReleaseFullscreenPlayer(media::MediaPlayerAndroid* player);
-  void OnInitializeCDM(int media_keys_id,
-                       const std::vector<uint8>& uuid,
-                       const GURL& frame_url);
-  void OnCreateSession(int media_keys_id,
-                       uint32 session_id,
-                       MediaKeysHostMsg_CreateSession_Type content_type,
-                       const std::vector<uint8>& init_data);
-  void OnUpdateSession(int media_keys_id,
-                       uint32 session_id,
-                       const std::vector<uint8>& response);
-  void OnReleaseSession(int media_keys_id, uint32 session_id);
-  void OnSetMediaKeys(int player_id, int media_keys_id);
-  void OnDestroyCdm(int media_keys_id);
-
-  // Cancels all pending session creations associated with |media_keys_id|.
-  void CancelAllPendingSessionCreations(int media_keys_id);
-
 #if defined(VIDEO_HOLE)
-  virtual void OnNotifyExternalSurface(
+  void OnNotifyExternalSurface(
       int player_id, bool is_request, const gfx::RectF& rect);
 #endif  // defined(VIDEO_HOLE)
 
+ protected:
+  // Clients must use Create() or subclass constructor.
+  explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host);
+
+  WebContents* web_contents() const { return web_contents_; }
+
   // Adds a given player to the list.
   void AddPlayer(media::MediaPlayerAndroid* player);
 
@@ -172,75 +141,59 @@ class CONTENT_EXPORT BrowserMediaPlayerManager
       int player_id,
       media::MediaPlayerAndroid* player);
 
-  // Adds a new MediaDrmBridge for the given |uuid|, |media_keys_id|, and
-  // |frame_url|.
-  void AddDrmBridge(int media_keys_id,
-                    const std::vector<uint8>& uuid,
-                    const GURL& frame_url);
+  int RoutingID();
 
-  // Removes the DRM bridge with the specified id.
-  void RemoveDrmBridge(int media_keys_id);
+  // Helper function to send messages to RenderFrameObserver.
+  bool Send(IPC::Message* msg);
 
  private:
-  // If |permitted| is false, it does nothing but send
-  // |MediaKeysMsg_SessionError| IPC message.
-  // The primary use case is infobar permission callback, i.e., when infobar
-  // can decide user's intention either from interacting with the actual info
-  // bar or from the saved preference.
-  void CreateSessionIfPermitted(int media_keys_id,
-                                uint32 session_id,
-                                const std::string& content_type,
-                                const std::vector<uint8>& init_data,
-                                bool permitted);
-
-  // Constructs a MediaPlayerAndroid object. Declared static to permit embedders
-  // to override functionality.
-  //
-  // Objects must call |manager->RequestMediaResources()| before decoding
-  // and |manager->ReleaseMediaSources()| after finishing. This allows the
-  // manager to track decoding resources across the process and free them as
-  // needed.
-  static media::MediaPlayerAndroid* CreateMediaPlayer(
-      MediaPlayerHostMsg_Initialize_Type type,
-      int player_id,
-      const GURL& url,
-      const GURL& first_party_for_cookies,
-      int demuxer_client_id,
+  // Constructs a MediaPlayerAndroid object.
+  media::MediaPlayerAndroid* CreateMediaPlayer(
+      const MediaPlayerHostMsg_Initialize_Params& media_player_params,
       bool hide_url_log,
       media::MediaPlayerManager* manager,
       BrowserDemuxerAndroid* demuxer);
 
-  // An array of managed players.
-  ScopedVector<media::MediaPlayerAndroid> players_;
+  // MediaPlayerAndroid must call this before it is going to decode
+  // media streams. This helps the manager object maintain an array
+  // of active MediaPlayerAndroid objects and release the resources
+  // when needed. Currently we only count video resources as they are
+  // constrained by hardware and memory limits.
+  virtual void OnMediaResourcesRequested(int player_id);
 
-  // An array of managed media DRM bridges.
-  ScopedVector<media::MediaDrmBridge> drm_bridges_;
+  // Similar to the above call, MediaPlayerAndroid must call this method when
+  // releasing all the decoding resources.
+  virtual void OnMediaResourcesReleased(int player_id);
 
-  // a set of media keys IDs that are pending approval or approved to access
-  // device DRM credentials.
-  // These 2 sets does not cover all the EME videos. If a video only streams
-  // clear data, it will not be included in either set.
-  std::set<int> media_keys_ids_pending_approval_;
-  std::set<int> media_keys_ids_approved_;
+#if defined(VIDEO_HOLE)
+  void OnRequestExternalSurface(int player_id, const gfx::RectF& rect);
+#endif  // defined(VIDEO_HOLE)
+
+  RenderFrameHost* const render_frame_host_;
+
+  // An array of managed players.
+  ScopedVector<media::MediaPlayerAndroid> players_;
 
   // The fullscreen video view object or NULL if video is not played in
   // fullscreen.
   scoped_ptr<ContentVideoView> video_view_;
 
+#if defined(VIDEO_HOLE)
+  scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_;
+#endif
+
   // Player ID of the fullscreen media player.
   int fullscreen_player_id_;
 
-  // The player ID pending to enter fullscreen.
-  int pending_fullscreen_player_id_;
-
   // Whether the fullscreen player has been Release()-d.
   bool fullscreen_player_is_released_;
 
-  WebContents* web_contents_;
+  WebContents* const web_contents_;
 
   // Object for retrieving resources media players.
   scoped_ptr<media::MediaResourceGetter> media_resource_getter_;
 
+  // NOTE: Weak pointers must be invalidated before all other member variables.
   base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager);