Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / crypto / proxy_media_keys.h
blobb256dfa5e29390936a6013b491e6cf95b3610acb
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_
8 #include <map>
9 #include <string>
10 #include <vector>
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"
21 class GURL;
23 namespace content {
25 class RendererCdmManager;
27 // A MediaKeys proxy that wraps the EME part of RendererCdmManager.
28 class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext {
29 public:
30 static void Create(
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;
69 // Callbacks.
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,
77 uint32_t system_code,
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,
90 uint32_t system_code,
91 const std::string& error_message);
93 private:
94 ProxyMediaKeys(
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_;
108 int cdm_id_;
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_