OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DECRYPTOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
7 | 7 |
8 #include <map> | |
9 #include <set> | 8 #include <set> |
10 #include <string> | 9 #include <string> |
11 #include <vector> | 10 #include <vector> |
12 | 11 |
13 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
17 #include "media/base/decryptor.h" | 16 #include "media/base/decryptor.h" |
18 #include "media/base/media_keys.h" | 17 #include "media/base/media_keys.h" |
18 #include "media/base/media_keys_session_promise.h" | |
ddorwin
2014/05/05 18:35:42
Not used.
jrummell
2014/05/08 23:37:45
Done.
| |
19 | 19 |
20 #if defined(ENABLE_PEPPER_CDMS) | 20 #if defined(ENABLE_PEPPER_CDMS) |
21 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 21 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
22 #endif | 22 #endif |
23 | 23 |
24 class GURL; | 24 class GURL; |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
29 class RendererMediaPlayerManager; | 29 class RendererMediaPlayerManager; |
30 #endif // defined(OS_ANDROID) | 30 #endif // defined(OS_ANDROID) |
31 | 31 |
32 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. | 32 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. |
33 // A decryptor proxy that creates a real decryptor object on demand and | 33 // A decryptor proxy that creates a real decryptor object on demand and |
34 // forwards decryptor calls to it. | 34 // forwards decryptor calls to it. |
35 // | 35 // |
36 // Now that the Pepper API calls use session ID to match responses with | |
37 // requests, this class maintains a mapping between session ID and web session | |
38 // ID. Callers of this class expect web session IDs in the responses. | |
39 // Session IDs are internal unique references to the session. Web session IDs | |
40 // are the CDM generated ID for the session, and are what are visible to users. | |
41 // | |
42 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 36 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
43 // objects. Fix this when needed. | 37 // objects. Fix this when needed. |
44 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! | 38 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! |
45 class ProxyDecryptor { | 39 class ProxyDecryptor { |
46 public: | 40 public: |
47 // These are similar to the callbacks in media_keys.h, but pass back the | 41 // These are similar to the callbacks in media_keys.h, but pass back the |
48 // web session ID rather than the internal session ID. | 42 // web session ID rather than the internal session ID. |
49 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; | 43 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; |
50 typedef base::Callback<void(const std::string& session_id, | 44 typedef base::Callback<void(const std::string& session_id, |
51 media::MediaKeys::KeyError error_code, | 45 media::MediaKeys::KeyError error_code, |
(...skipping 30 matching lines...) Expand all Loading... | |
82 // May only be called after InitializeCDM() succeeds. | 76 // May only be called after InitializeCDM() succeeds. |
83 bool GenerateKeyRequest(const std::string& type, | 77 bool GenerateKeyRequest(const std::string& type, |
84 const uint8* init_data, | 78 const uint8* init_data, |
85 int init_data_length); | 79 int init_data_length); |
86 void AddKey(const uint8* key, int key_length, | 80 void AddKey(const uint8* key, int key_length, |
87 const uint8* init_data, int init_data_length, | 81 const uint8* init_data, int init_data_length, |
88 const std::string& session_id); | 82 const std::string& session_id); |
89 void CancelKeyRequest(const std::string& session_id); | 83 void CancelKeyRequest(const std::string& session_id); |
90 | 84 |
91 private: | 85 private: |
92 // Session_id <-> web_session_id map. | |
93 typedef std::map<uint32, std::string> SessionIdMap; | |
94 | |
95 // Helper function to create MediaKeys to handle the given |key_system|. | 86 // Helper function to create MediaKeys to handle the given |key_system|. |
96 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, | 87 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, |
97 const GURL& security_origin); | 88 const GURL& security_origin); |
98 | 89 |
99 // Callbacks for firing session events. | 90 // Callbacks for firing session events. |
100 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 91 void OnSessionMessage(const std::string& web_session_id, |
101 void OnSessionMessage(uint32 session_id, | |
102 const std::vector<uint8>& message, | 92 const std::vector<uint8>& message, |
103 const std::string& default_url); | 93 const std::string& default_url); |
104 void OnSessionReady(uint32 session_id); | 94 void OnSessionReady(const std::string& web_session_id); |
105 void OnSessionClosed(uint32 session_id); | 95 void OnSessionClosed(const std::string& web_session_id); |
106 void OnSessionError(uint32 session_id, | 96 void OnSessionError(const std::string& web_session_id, |
107 media::MediaKeys::KeyError error_code, | 97 const std::string& error_name, |
108 uint32 system_code); | 98 uint32 system_code, |
99 const std::string& error_message); | |
109 | 100 |
110 // Helper function to determine session_id for the provided |web_session_id|. | 101 // Called when a session is actually created or loaded. |
111 uint32 LookupSessionId(const std::string& web_session_id) const; | 102 void SetSessionId(bool persistent, const std::string& web_session_id); |
112 | |
113 // Helper function to determine web_session_id for the provided |session_id|. | |
114 // The returned web_session_id is only valid on the main thread, and should be | |
115 // stored by copy. | |
116 const std::string& LookupWebSessionId(uint32 session_id) const; | |
117 | 103 |
118 #if defined(ENABLE_PEPPER_CDMS) | 104 #if defined(ENABLE_PEPPER_CDMS) |
119 // Callback to create the Pepper plugin. | 105 // Callback to create the Pepper plugin. |
120 CreatePepperCdmCB create_pepper_cdm_cb_; | 106 CreatePepperCdmCB create_pepper_cdm_cb_; |
121 #elif defined(OS_ANDROID) | 107 #elif defined(OS_ANDROID) |
122 RendererMediaPlayerManager* manager_; | 108 RendererMediaPlayerManager* manager_; |
123 int cdm_id_; | 109 int cdm_id_; |
124 #endif // defined(ENABLE_PEPPER_CDMS) | 110 #endif // defined(ENABLE_PEPPER_CDMS) |
125 | 111 |
126 // The real MediaKeys that manages key operations for the ProxyDecryptor. | 112 // The real MediaKeys that manages key operations for the ProxyDecryptor. |
127 scoped_ptr<media::MediaKeys> media_keys_; | 113 scoped_ptr<media::MediaKeys> media_keys_; |
128 | 114 |
129 // Callbacks for firing key events. | 115 // Callbacks for firing key events. |
130 KeyAddedCB key_added_cb_; | 116 KeyAddedCB key_added_cb_; |
131 KeyErrorCB key_error_cb_; | 117 KeyErrorCB key_error_cb_; |
132 KeyMessageCB key_message_cb_; | 118 KeyMessageCB key_message_cb_; |
133 | 119 |
134 // Session IDs are used to uniquely track sessions so that CDM callbacks | 120 std::set<std::string> active_sessions_; |
135 // can get mapped to the correct session ID. Session ID should be unique | 121 std::set<std::string> persistent_sessions_; |
136 // per renderer process for debugging purposes. | |
137 static uint32 next_session_id_; | |
138 | |
139 SessionIdMap sessions_; | |
140 | |
141 std::set<uint32> persistent_sessions_; | |
142 | 122 |
143 bool is_clear_key_; | 123 bool is_clear_key_; |
144 | 124 |
145 // NOTE: Weak pointers must be invalidated before all other member variables. | 125 // NOTE: Weak pointers must be invalidated before all other member variables. |
146 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 126 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
147 | 127 |
148 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 128 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
149 }; | 129 }; |
150 | 130 |
151 } // namespace content | 131 } // namespace content |
152 | 132 |
153 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 133 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |