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.
5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_
6 #define CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_
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"
15 class BrowserCdmManager
;
16 #if defined(OS_ANDROID)
17 class BrowserMediaPlayerManager
;
18 #endif // defined(OS_ANDROID)
21 // This class manages all RenderFrame based media related managers at the
22 // browser side. It receives IPC messages from media RenderFrameObservers and
23 // forwards them to the corresponding managers. The managers are responsible
24 // for sending IPCs back to the RenderFrameObservers at the render side.
25 class CONTENT_EXPORT MediaWebContentsObserver
: public WebContentsObserver
{
27 explicit MediaWebContentsObserver(RenderViewHost
* render_view_host
);
28 virtual ~MediaWebContentsObserver();
30 // WebContentsObserver implementations.
31 virtual void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) OVERRIDE
;
32 virtual bool OnMessageReceived(const IPC::Message
& message
,
33 RenderFrameHost
* render_frame_host
) OVERRIDE
;
35 // Helper function to handle CDM IPC messages. Returns whether the |message|
36 // is handled in the function.
37 bool OnCdmMessageReceived(const IPC::Message
& message
,
38 RenderFrameHost
* render_frame_host
);
40 // Gets the CDM manager associated with |render_frame_host|. Creates
41 // a new one if it doesn't exist. The caller doesn't own the returned pointer.
42 BrowserCdmManager
* GetCdmManager(RenderFrameHost
* render_frame_host
);
44 #if defined(OS_ANDROID)
45 // Helper functions to handle media player IPC messages. Returns whether the
46 // |message| is handled in the function.
47 bool OnMediaPlayerMessageReceived(const IPC::Message
& message
,
48 RenderFrameHost
* render_frame_host
);
49 bool OnMediaPlayerSetCdmMessageReceived(const IPC::Message
& message
,
50 RenderFrameHost
* render_frame_host
);
52 // Gets the media player manager associated with |render_frame_host|. Creates
53 // a new one if it doesn't exist. The caller doesn't own the returned pointer.
54 BrowserMediaPlayerManager
* GetMediaPlayerManager(
55 RenderFrameHost
* render_frame_host
);
57 void OnSetCdm(RenderFrameHost
* render_frame_host
, int player_id
, int cdm_id
);
59 // Pauses all media player.
62 #if defined(VIDEO_HOLE)
63 void OnFrameInfoUpdated();
64 #endif // defined(VIDEO_HOLE)
66 #endif // defined(OS_ANDROID)
69 // Map from RenderFrameHost* to BrowserCdmManager.
70 typedef base::ScopedPtrHashMap
<uintptr_t, BrowserCdmManager
> CdmManagerMap
;
71 CdmManagerMap cdm_managers_
;
73 #if defined(OS_ANDROID)
74 // Map from RenderFrameHost* to BrowserMediaPlayerManager.
75 typedef base::ScopedPtrHashMap
<uintptr_t, BrowserMediaPlayerManager
>
76 MediaPlayerManagerMap
;
77 MediaPlayerManagerMap media_player_managers_
;
78 #endif // defined(OS_ANDROID)
80 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver
);
83 } // namespace content
85 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_