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_CDM_BROWSER_CDM_MANAGER_H_
6 #define CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "content/common/content_export.h"
17 #include "content/common/media/cdm_messages_enums.h"
18 #include "ipc/ipc_message.h"
19 // TODO(xhwang): Drop this when KeyError is moved to a common header.
20 #include "media/base/media_keys.h"
29 class RenderFrameHost
;
32 // This class manages all CDM objects. It receives control operations from the
33 // the render process, and forwards them to corresponding CDM object. Callbacks
34 // from CDM objects are converted to IPCs and then sent to the render process.
35 class CONTENT_EXPORT BrowserCdmManager
{
37 // Creates a new BrowserCdmManager for |rfh|.
38 static BrowserCdmManager
* Create(RenderFrameHost
* rfh
);
42 media::BrowserCdm
* GetCdm(int cdm_id
);
45 void OnSessionCreated(int cdm_id
,
47 const std::string
& web_session_id
);
48 void OnSessionMessage(int cdm_id
,
50 const std::vector
<uint8
>& message
,
51 const GURL
& destination_url
);
52 void OnSessionReady(int cdm_id
, uint32 session_id
);
53 void OnSessionClosed(int cdm_id
, uint32 session_id
);
54 void OnSessionError(int cdm_id
,
56 media::MediaKeys::KeyError error_code
,
60 void OnInitializeCdm(int cdm_id
,
61 const std::string
& key_system
,
62 const GURL
& frame_url
);
63 void OnCreateSession(int cdm_id
,
65 CdmHostMsg_CreateSession_ContentType content_type
,
66 const std::vector
<uint8
>& init_data
);
67 void OnUpdateSession(int cdm_id
,
69 const std::vector
<uint8
>& response
);
70 void OnReleaseSession(int cdm_id
, uint32 session_id
);
71 void OnSetCdm(int player_id
, int cdm_id
);
72 void OnDestroyCdm(int cdm_id
);
75 // Clients must use Create() or subclass constructor.
76 explicit BrowserCdmManager(RenderFrameHost
* render_frame_host
);
78 // Cancels all pending session creations associated with |cdm_id|.
79 void CancelAllPendingSessionCreations(int cdm_id
);
81 // Adds a new CDM identified by |cdm_id| for the given |key_system| and
83 void AddCdm(int cdm_id
,
84 const std::string
& key_system
,
85 const GURL
& security_origin
);
87 // Removes the CDM with the specified id.
88 void RemoveCdm(int cdm_id
);
92 // Helper function to send messages to RenderFrameObserver.
93 bool Send(IPC::Message
* msg
);
95 // If |permitted| is false, it does nothing but send
96 // |CdmMsg_SessionError| IPC message.
97 // The primary use case is infobar permission callback, i.e., when infobar
98 // can decide user's intention either from interacting with the actual info
99 // bar or from the saved preference.
100 void CreateSessionIfPermitted(int cdm_id
,
102 const std::string
& content_type
,
103 const std::vector
<uint8
>& init_data
,
106 RenderFrameHost
* const render_frame_host_
;
108 WebContents
* const web_contents_
;
110 // A map from CDM IDs to managed CDMs.
111 typedef base::ScopedPtrHashMap
<int, media::BrowserCdm
> CdmMap
;
114 // Map from CDM ID to CDM's security origin.
115 std::map
<int, GURL
> cdm_security_origin_map_
;
117 // Map from CDM ID to a callback to cancel the permission request.
118 std::map
<int, base::Closure
> cdm_cancel_permision_map_
;
120 // NOTE: Weak pointers must be invalidated before all other member variables.
121 base::WeakPtrFactory
<BrowserCdmManager
> weak_ptr_factory_
;
123 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager
);
126 } // namespace content
128 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_