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_PROXY_MEDIA_KEYS_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "media/base/cdm_context.h"
16 #include "media/base/cdm_factory.h"
17 #include "media/base/cdm_promise.h"
18 #include "media/base/cdm_promise_adapter.h"
19 #include "media/base/media_keys.h"
25 class RendererCdmManager
;
27 // A MediaKeys proxy that wraps the EME part of RendererCdmManager.
28 class ProxyMediaKeys
: public media::MediaKeys
, public media::CdmContext
{
31 const std::string
& key_system
,
32 const GURL
& security_origin
,
33 bool use_hw_secure_codecs
,
34 RendererCdmManager
* manager
,
35 const media::SessionMessageCB
& session_message_cb
,
36 const media::SessionClosedCB
& session_closed_cb
,
37 const media::LegacySessionErrorCB
& legacy_session_error_cb
,
38 const media::SessionKeysChangeCB
& session_keys_change_cb
,
39 const media::SessionExpirationUpdateCB
& session_expiration_update_cb
,
40 const media::CdmCreatedCB
& cdm_created_cb
);
42 ~ProxyMediaKeys() override
;
44 // MediaKeys implementation.
45 void SetServerCertificate(
46 const std::vector
<uint8_t>& certificate
,
47 scoped_ptr
<media::SimpleCdmPromise
> promise
) override
;
48 void CreateSessionAndGenerateRequest(
49 SessionType session_type
,
50 media::EmeInitDataType init_data_type
,
51 const std::vector
<uint8_t>& init_data
,
52 scoped_ptr
<media::NewSessionCdmPromise
> promise
) override
;
53 void LoadSession(SessionType session_type
,
54 const std::string
& session_id
,
55 scoped_ptr
<media::NewSessionCdmPromise
> promise
) override
;
56 void UpdateSession(const std::string
& session_id
,
57 const std::vector
<uint8_t>& response
,
58 scoped_ptr
<media::SimpleCdmPromise
> promise
) override
;
59 void CloseSession(const std::string
& session_id
,
60 scoped_ptr
<media::SimpleCdmPromise
> promise
) override
;
61 void RemoveSession(const std::string
& session_id
,
62 scoped_ptr
<media::SimpleCdmPromise
> promise
) override
;
63 media::CdmContext
* GetCdmContext() override
;
65 // media::CdmContext implementation.
66 media::Decryptor
* GetDecryptor() override
;
67 int GetCdmId() const override
;
70 void OnSessionMessage(const std::string
& session_id
,
71 media::MediaKeys::MessageType message_type
,
72 const std::vector
<uint8_t>& message
,
73 const GURL
& legacy_destination_url
);
74 void OnSessionClosed(const std::string
& session_id
);
75 void OnLegacySessionError(const std::string
& session_id
,
76 media::MediaKeys::Exception exception
,
78 const std::string
& error_message
);
79 void OnSessionKeysChange(const std::string
& session_id
,
80 bool has_additional_usable_key
,
81 media::CdmKeysInfo keys_info
);
82 void OnSessionExpirationUpdate(const std::string
& session_id
,
83 const base::Time
& new_expiry_time
);
85 void OnPromiseResolved(uint32_t promise_id
);
86 void OnPromiseResolvedWithSession(uint32_t promise_id
,
87 const std::string
& session_id
);
88 void OnPromiseRejected(uint32_t promise_id
,
89 media::MediaKeys::Exception exception
,
91 const std::string
& error_message
);
95 RendererCdmManager
* manager
,
96 const media::SessionMessageCB
& session_message_cb
,
97 const media::SessionClosedCB
& session_closed_cb
,
98 const media::LegacySessionErrorCB
& legacy_session_error_cb
,
99 const media::SessionKeysChangeCB
& session_keys_change_cb
,
100 const media::SessionExpirationUpdateCB
& session_expiration_update_cb
);
102 void InitializeCdm(const std::string
& key_system
,
103 const GURL
& security_origin
,
104 bool use_hw_secure_codecs
,
105 scoped_ptr
<media::SimpleCdmPromise
> promise
);
107 RendererCdmManager
* manager_
;
110 media::SessionMessageCB session_message_cb_
;
111 media::SessionClosedCB session_closed_cb_
;
112 media::LegacySessionErrorCB legacy_session_error_cb_
;
113 media::SessionKeysChangeCB session_keys_change_cb_
;
114 media::SessionExpirationUpdateCB session_expiration_update_cb_
;
116 media::CdmPromiseAdapter cdm_promise_adapter_
;
118 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys
);
121 } // namespace content
123 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_