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 "base/memory/scoped_ptr.h"
11 #include "content/common/content_export.h"
12 #include "content/public/browser/web_contents_observer.h"
16 #if defined(OS_ANDROID)
17 class MediaPlayersObserver
;
18 #endif // defined(OS_ANDROID)
20 class BrowserCdmManager
;
21 class BrowserMediaPlayerManager
;
23 // This class manages all RenderFrame based media related managers at the
24 // browser side. It receives IPC messages from media RenderFrameObservers and
25 // forwards them to the corresponding managers. The managers are responsible
26 // for sending IPCs back to the RenderFrameObservers at the render side.
27 class CONTENT_EXPORT MediaWebContentsObserver
: public WebContentsObserver
{
29 explicit MediaWebContentsObserver(WebContents
* web_contents
);
30 ~MediaWebContentsObserver() override
;
32 // WebContentsObserver implementations.
33 void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) override
;
35 #if defined(OS_ANDROID)
36 bool OnMessageReceived(const IPC::Message
& message
,
37 RenderFrameHost
* render_frame_host
) override
;
39 // Helper functions to handle media player IPC messages. Returns whether the
40 // |message| is handled in the function.
41 bool OnMediaPlayerMessageReceived(const IPC::Message
& message
,
42 RenderFrameHost
* render_frame_host
);
43 bool OnMediaPlayerSetCdmMessageReceived(const IPC::Message
& message
,
44 RenderFrameHost
* render_frame_host
);
46 // Gets the media player manager associated with |render_frame_host|. Creates
47 // a new one if it doesn't exist. The caller doesn't own the returned pointer.
48 BrowserMediaPlayerManager
* GetMediaPlayerManager(
49 RenderFrameHost
* render_frame_host
);
51 void OnSetCdm(RenderFrameHost
* render_frame_host
, int player_id
, int cdm_id
);
53 MediaPlayersObserver
* GetMediaPlayersObserver() const;
55 #if defined(VIDEO_HOLE)
56 void OnFrameInfoUpdated();
57 #endif // defined(VIDEO_HOLE)
60 // Map from RenderFrameHost* to BrowserMediaPlayerManager.
61 typedef base::ScopedPtrHashMap
<uintptr_t, BrowserMediaPlayerManager
>
62 MediaPlayerManagerMap
;
63 MediaPlayerManagerMap media_player_managers_
;
64 #endif // defined(OS_ANDROID)
67 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver
);
70 } // namespace content
72 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_