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_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "content/common/media/cdm_messages_enums.h"
14 #include "content/public/renderer/render_frame_observer.h"
15 #include "media/base/media_keys.h"
26 // Class for managing all the CDM objects in the same RenderFrame.
27 class RendererCdmManager
: public RenderFrameObserver
{
29 // Constructs a RendererCdmManager object for the |render_frame|.
30 explicit RendererCdmManager(RenderFrame
* render_frame
);
31 ~RendererCdmManager() override
;
33 // RenderFrameObserver overrides.
34 bool OnMessageReceived(const IPC::Message
& msg
) override
;
36 // Encrypted media related methods.
37 void InitializeCdm(int cdm_id
,
38 ProxyMediaKeys
* media_keys
,
39 const std::string
& key_system
,
40 const GURL
& security_origin
);
41 void SetServerCertificate(int cdm_id
,
43 const std::vector
<uint8
>& certificate
);
44 void CreateSessionAndGenerateRequest(
47 CdmHostMsg_CreateSession_InitDataType init_data_type
,
48 const std::vector
<uint8
>& init_data
);
49 void UpdateSession(int cdm_id
,
51 const std::string
& session_id
,
52 const std::vector
<uint8
>& response
);
53 void CloseSession(int cdm_id
,
55 const std::string
& session_id
);
56 void DestroyCdm(int cdm_id
);
58 // Registers a ProxyMediaKeys object. Returns allocated CDM ID.
59 int RegisterMediaKeys(ProxyMediaKeys
* media_keys
);
61 // Unregisters a ProxyMediaKeys object identified by |cdm_id|.
62 void UnregisterMediaKeys(int cdm_id
);
65 // Gets the pointer to ProxyMediaKeys given the |cdm_id|.
66 ProxyMediaKeys
* GetMediaKeys(int cdm_id
);
69 void OnSessionMessage(int cdm_id
,
70 const std::string
& session_id
,
71 media::MediaKeys::MessageType message_type
,
72 const std::vector
<uint8
>& message
,
73 const GURL
& legacy_destination_url
);
74 void OnSessionClosed(int cdm_id
, const std::string
& session_id
);
75 void OnLegacySessionError(int cdm_id
,
76 const std::string
& session_id
,
77 media::MediaKeys::Exception exception
,
79 const std::string
& error_message
);
80 void OnSessionKeysChange(
82 const std::string
& session_id
,
83 bool has_additional_usable_key
,
84 const std::vector
<media::CdmKeyInformation
>& key_info_vector
);
85 void OnSessionExpirationUpdate(int cdm_id
,
86 const std::string
& session_id
,
87 const base::Time
& new_expiry_time
);
89 void OnPromiseResolved(int cdm_id
, uint32_t promise_id
);
90 void OnPromiseResolvedWithSession(int cdm_id
,
92 const std::string
& session_id
);
93 void OnPromiseRejected(int cdm_id
,
95 media::MediaKeys::Exception exception
,
97 const std::string
& error_message
);
99 // CDM ID should be unique per renderer frame.
100 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior.
103 // CDM ID to ProxyMediaKeys mapping.
104 std::map
<int, ProxyMediaKeys
*> proxy_media_keys_map_
;
106 DISALLOW_COPY_AND_ASSIGN(RendererCdmManager
);
109 } // namespace content
111 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_