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 const std::vector<uint8>& message, | 70 const std::vector<uint8>& message, |
71 const GURL& destination_url); | 71 const GURL& destination_url); |
72 void OnSessionReady(uint32 session_id); | 72 void OnSessionClosed(const std::string& session_id); |
73 void OnSessionClosed(uint32 session_id); | 73 void OnSessionError(const std::string& session_id, |
ddorwin
2015/01/14 23:09:20
_If_ you want, you can start renaming this to lega
xhwang
2015/01/15 08:13:13
Done. I'll rename the rest in a different CL.
| |
74 void OnSessionError(uint32 session_id, | 74 media::MediaKeys::Exception exception, |
75 media::MediaKeys::KeyError error_code, | 75 uint32 system_code, |
76 uint32 system_code); | 76 const std::string& error_message); |
77 void OnSessionKeysChange(const std::string& session_id, | |
78 bool has_additional_usable_key, | |
79 media::CdmKeysInfo keys_info); | |
80 void OnSessionExpirationUpdate(const std::string& session_id, | |
81 const base::Time& new_expiry_time); | |
82 | |
83 void OnPromiseResolved(uint32_t promise_id); | |
84 void OnPromiseResolvedWithSession(uint32_t promise_id, | |
85 const std::string& session_id); | |
86 void OnPromiseRejected(uint32_t promise_id, | |
87 media::MediaKeys::Exception exception, | |
88 uint32_t system_code, | |
89 const std::string& error_message); | |
77 | 90 |
78 private: | 91 private: |
79 // The Android-specific code that handles sessions uses integer session ids | 92 ProxyMediaKeys( |
80 // (basically a reference id), but media::MediaKeys bases everything on | 93 RendererCdmManager* manager, |
81 // web_session_id (a string representing the actual session id as generated | 94 const media::SessionMessageCB& session_message_cb, |
82 // by the CDM). SessionIdMap is used to map between the web_session_id and | 95 const media::SessionClosedCB& session_closed_cb, |
83 // the session_id used by the Android-specific code. | 96 const media::SessionErrorCB& session_error_cb, |
84 typedef base::hash_map<std::string, uint32_t> SessionIdMap; | 97 const media::SessionKeysChangeCB& session_keys_change_cb, |
85 | 98 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 | 99 |
96 void InitializeCdm(const std::string& key_system, | 100 void InitializeCdm(const std::string& key_system, |
97 const GURL& security_origin); | 101 const GURL& security_origin); |
98 | 102 |
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_; | 103 RendererCdmManager* manager_; |
116 int cdm_id_; | 104 int cdm_id_; |
117 | 105 |
118 media::SessionMessageCB session_message_cb_; | 106 media::SessionMessageCB session_message_cb_; |
119 media::SessionClosedCB session_closed_cb_; | 107 media::SessionClosedCB session_closed_cb_; |
120 media::SessionErrorCB session_error_cb_; | 108 media::SessionErrorCB session_error_cb_; |
109 media::SessionKeysChangeCB session_keys_change_cb_; | |
110 media::SessionExpirationUpdateCB session_expiration_update_cb_; | |
121 | 111 |
122 // Android-specific. See comment above CreateSessionId(). | 112 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 | 113 |
129 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); | 114 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); |
130 }; | 115 }; |
131 | 116 |
132 } // namespace content | 117 } // namespace content |
133 | 118 |
134 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ | 119 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ |
OLD | NEW |