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 class BrowserMediaPlayerManager
;
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
{
25 explicit MediaWebContentsObserver(RenderViewHost
* render_view_host
);
26 virtual ~MediaWebContentsObserver();
28 // WebContentsObserver implementations.
29 virtual void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) override
;
31 #if defined(OS_ANDROID)
32 virtual bool OnMessageReceived(const IPC::Message
& message
,
33 RenderFrameHost
* render_frame_host
) override
;
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
);
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
);
47 void OnSetCdm(RenderFrameHost
* render_frame_host
, int player_id
, int cdm_id
);
49 #if defined(VIDEO_HOLE)
50 void OnFrameInfoUpdated();
51 #endif // defined(VIDEO_HOLE)
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)
61 DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver
);
64 } // namespace content
66 #endif // CONTENT_BROWSER_MEDIA_MEDIA_WEB_CONTENTS_OBSERVER_H_