Home | History | Annotate | Download | only in media
      1 // Copyright 2014 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.
      4 
      5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_
      6 #define CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/containers/scoped_ptr_hash_map.h"
     10 #include "content/common/content_export.h"
     11 #include "content/public/browser/web_contents_observer.h"
     12 
     13 namespace content {
     14 
     15 class BrowserCdmManager;
     16 class BrowserMediaPlayerManager;
     17 class RenderViewHost;
     18 
     19 // This class manages all RenderFrame based media related managers at the
     20 // browser side. It receives IPC messages from media RenderFrameObservers and
     21 // forwards them to the corresponding managers. The managers are responsible
     22 // for sending IPCs back to the RenderFrameObservers at the render side.
     23 class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver {
     24  public:
     25   explicit MediaWebContentsObserver(RenderViewHost* render_view_host);
     26   virtual ~MediaWebContentsObserver();
     27 
     28   // WebContentsObserver implementations.
     29   virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE;
     30 
     31 #if defined(OS_ANDROID)
     32   virtual bool OnMessageReceived(const IPC::Message& message,
     33                                  RenderFrameHost* render_frame_host) OVERRIDE;
     34 
     35   // Helper functions to handle media player IPC messages. Returns whether the
     36   // |message| is handled in the function.
     37   bool OnMediaPlayerMessageReceived(const IPC::Message& message,
     38                                     RenderFrameHost* render_frame_host);
     39   bool OnMediaPlayerSetCdmMessageReceived(const IPC::Message& message,
     40                                           RenderFrameHost* render_frame_host);
     41 
     42   // Gets the media player manager associated with |render_frame_host|. Creates
     43   // a new one if it doesn't exist. The caller doesn't own the returned pointer.
     44   BrowserMediaPlayerManager* GetMediaPlayerManager(
     45       RenderFrameHost* render_frame_host);
     46 
     47   void OnSetCdm(RenderFrameHost* render_frame_host, int player_id, int cdm_id);
     48 
     49 #if defined(VIDEO_HOLE)
     50   void OnFrameInfoUpdated();
     51 #endif  // defined(VIDEO_HOLE)
     52 
     53  private:
     54   // Map from RenderFrameHost* to BrowserMediaPlayerManager.
     55   typedef base::ScopedPtrHashMap<uintptr_t, BrowserMediaPlayerManager>
     56       MediaPlayerManagerMap;
     57   MediaPlayerManagerMap media_player_managers_;
     58 #endif  // defined(OS_ANDROID)
     59 
     60  private:
     61   DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver);
     62 };
     63 
     64 }  // namespace content
     65 
     66 #endif  // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_
     67