OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ |
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ | 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/containers/scoped_ptr_hash_map.h" | 13 #include "base/containers/scoped_ptr_hash_map.h" |
14 #include "media/base/cdm_context.h" | 14 #include "media/base/cdm_context.h" |
15 #include "media/base/cdm_promise.h" | 15 #include "media/base/cdm_promise.h" |
| 16 #include "media/base/cdm_promise_adapter.h" |
16 #include "media/base/media_keys.h" | 17 #include "media/base/media_keys.h" |
17 | 18 |
18 class GURL; | 19 class GURL; |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 class RendererCdmManager; | 23 class RendererCdmManager; |
23 | 24 |
24 // A MediaKeys proxy that wraps the EME part of RendererCdmManager. | 25 // A MediaKeys proxy that wraps the EME part of RendererCdmManager. |
25 class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext { | 26 class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 scoped_ptr<media::SimpleCdmPromise> promise) override; | 59 scoped_ptr<media::SimpleCdmPromise> promise) override; |
59 void RemoveSession(const std::string& web_session_id, | 60 void RemoveSession(const std::string& web_session_id, |
60 scoped_ptr<media::SimpleCdmPromise> promise) override; | 61 scoped_ptr<media::SimpleCdmPromise> promise) override; |
61 media::CdmContext* GetCdmContext() override; | 62 media::CdmContext* GetCdmContext() override; |
62 | 63 |
63 // media::CdmContext implementation. | 64 // media::CdmContext implementation. |
64 media::Decryptor* GetDecryptor() override; | 65 media::Decryptor* GetDecryptor() override; |
65 int GetCdmId() const override; | 66 int GetCdmId() const override; |
66 | 67 |
67 // Callbacks. | 68 // Callbacks. |
68 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 69 void OnSessionMessage(const std::string& session_id, |
69 void OnSessionMessage(uint32 session_id, | 70 media::MediaKeys::MessageType message_type, |
70 const std::vector<uint8>& message, | 71 const std::vector<uint8>& message, |
71 const GURL& legacy_destination_url); | 72 const GURL& legacy_destination_url); |
72 void OnSessionReady(uint32 session_id); | 73 void OnSessionClosed(const std::string& session_id); |
73 void OnSessionClosed(uint32 session_id); | 74 void OnLegacySessionError(const std::string& session_id, |
74 void OnSessionError(uint32 session_id, | 75 media::MediaKeys::Exception exception, |
75 media::MediaKeys::KeyError error_code, | 76 uint32 system_code, |
76 uint32 system_code); | 77 const std::string& error_message); |
| 78 void OnSessionKeysChange(const std::string& session_id, |
| 79 bool has_additional_usable_key, |
| 80 media::CdmKeysInfo keys_info); |
| 81 void OnSessionExpirationUpdate(const std::string& session_id, |
| 82 const base::Time& new_expiry_time); |
| 83 |
| 84 void OnPromiseResolved(uint32_t promise_id); |
| 85 void OnPromiseResolvedWithSession(uint32_t promise_id, |
| 86 const std::string& session_id); |
| 87 void OnPromiseRejected(uint32_t promise_id, |
| 88 media::MediaKeys::Exception exception, |
| 89 uint32_t system_code, |
| 90 const std::string& error_message); |
77 | 91 |
78 private: | 92 private: |
79 // The Android-specific code that handles sessions uses integer session ids | 93 ProxyMediaKeys( |
80 // (basically a reference id), but media::MediaKeys bases everything on | 94 RendererCdmManager* manager, |
81 // web_session_id (a string representing the actual session id as generated | 95 const media::SessionMessageCB& session_message_cb, |
82 // by the CDM). SessionIdMap is used to map between the web_session_id and | 96 const media::SessionClosedCB& session_closed_cb, |
83 // the session_id used by the Android-specific code. | 97 const media::SessionErrorCB& session_error_cb, |
84 typedef base::hash_map<std::string, uint32_t> SessionIdMap; | 98 const media::SessionKeysChangeCB& session_keys_change_cb, |
85 | 99 const media::SessionExpirationUpdateCB& session_expiration_update_cb); |
86 // The following types keep track of Promises. The index is the | |
87 // Android-specific session_id, so that returning results can be matched to | |
88 // the corresponding promise. | |
89 typedef base::ScopedPtrHashMap<uint32_t, media::CdmPromise> PromiseMap; | |
90 | |
91 ProxyMediaKeys(RendererCdmManager* manager, | |
92 const media::SessionMessageCB& session_message_cb, | |
93 const media::SessionClosedCB& session_closed_cb, | |
94 const media::SessionErrorCB& session_error_cb); | |
95 | 100 |
96 void InitializeCdm(const std::string& key_system, | 101 void InitializeCdm(const std::string& key_system, |
97 const GURL& security_origin); | 102 const GURL& security_origin); |
98 | 103 |
99 // These functions keep track of Android-specific session_ids <-> | |
100 // web_session_ids mappings. | |
101 // TODO(jrummell): Remove this once the Android-specific code changes to | |
102 // support string web session ids. | |
103 uint32_t CreateSessionId(); | |
104 void AssignWebSessionId(uint32_t session_id, | |
105 const std::string& web_session_id); | |
106 uint32_t LookupSessionId(const std::string& web_session_id) const; | |
107 std::string LookupWebSessionId(uint32_t session_id) const; | |
108 void DropWebSessionId(const std::string& web_session_id); | |
109 | |
110 // Helper function to keep track of promises. Adding takes ownership of the | |
111 // promise, transferred back to caller on take. | |
112 void SavePromise(uint32_t session_id, scoped_ptr<media::CdmPromise> promise); | |
113 scoped_ptr<media::CdmPromise> TakePromise(uint32_t session_id); | |
114 | |
115 RendererCdmManager* manager_; | 104 RendererCdmManager* manager_; |
116 int cdm_id_; | 105 int cdm_id_; |
117 | 106 |
118 media::SessionMessageCB session_message_cb_; | 107 media::SessionMessageCB session_message_cb_; |
119 media::SessionClosedCB session_closed_cb_; | 108 media::SessionClosedCB session_closed_cb_; |
120 media::SessionErrorCB session_error_cb_; | 109 media::SessionErrorCB session_error_cb_; |
| 110 media::SessionKeysChangeCB session_keys_change_cb_; |
| 111 media::SessionExpirationUpdateCB session_expiration_update_cb_; |
121 | 112 |
122 // Android-specific. See comment above CreateSessionId(). | 113 media::CdmPromiseAdapter cdm_promise_adapter_; |
123 uint32_t next_session_id_; | |
124 SessionIdMap web_session_to_session_id_map_; | |
125 | |
126 // Keep track of outstanding promises. This map owns the promise object. | |
127 PromiseMap session_id_to_promise_map_; | |
128 | 114 |
129 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); | 115 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); |
130 }; | 116 }; |
131 | 117 |
132 } // namespace content | 118 } // namespace content |
133 | 119 |
134 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ | 120 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ |
OLD | NEW |