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" |
19 | 18 |
20 #if defined(ENABLE_PEPPER_CDMS) | 19 #if defined(ENABLE_PEPPER_CDMS) |
21 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 20 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
22 #endif | 21 #endif |
23 | 22 |
24 class GURL; | 23 class GURL; |
25 | 24 |
26 namespace content { | 25 namespace content { |
27 | 26 |
28 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
29 class RendererMediaPlayerManager; | 28 class RendererMediaPlayerManager; |
30 #endif // defined(OS_ANDROID) | 29 #endif // defined(OS_ANDROID) |
31 | 30 |
32 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. | 31 // 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 | 32 // A decryptor proxy that creates a real decryptor object on demand and |
34 // forwards decryptor calls to it. | 33 // forwards decryptor calls to it. |
35 // | 34 // |
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 | 35 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
43 // objects. Fix this when needed. | 36 // objects. Fix this when needed. |
44 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! | 37 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! |
45 class ProxyDecryptor { | 38 class ProxyDecryptor { |
46 public: | 39 public: |
47 // These are similar to the callbacks in media_keys.h, but pass back the | 40 // These are similar to the callbacks in media_keys.h, but pass back the |
48 // web session ID rather than the internal session ID. | 41 // web session ID rather than the internal session ID. |
49 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; | 42 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; |
50 typedef base::Callback<void(const std::string& session_id, | 43 typedef base::Callback<void(const std::string& session_id, |
51 media::MediaKeys::KeyError error_code, | 44 media::MediaKeys::KeyError error_code, |
(...skipping 30 matching lines...) Expand all Loading... | |
82 // May only be called after InitializeCDM() succeeds. | 75 // May only be called after InitializeCDM() succeeds. |
83 bool GenerateKeyRequest(const std::string& type, | 76 bool GenerateKeyRequest(const std::string& type, |
84 const uint8* init_data, | 77 const uint8* init_data, |
85 int init_data_length); | 78 int init_data_length); |
86 void AddKey(const uint8* key, int key_length, | 79 void AddKey(const uint8* key, int key_length, |
87 const uint8* init_data, int init_data_length, | 80 const uint8* init_data, int init_data_length, |
88 const std::string& session_id); | 81 const std::string& session_id); |
89 void CancelKeyRequest(const std::string& session_id); | 82 void CancelKeyRequest(const std::string& session_id); |
90 | 83 |
91 private: | 84 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|. | 85 // Helper function to create MediaKeys to handle the given |key_system|. |
96 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, | 86 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, |
97 const GURL& security_origin); | 87 const GURL& security_origin); |
98 | 88 |
99 // Callbacks for firing session events. | 89 // Callbacks for firing session events. |
100 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 90 void OnSessionMessage(const std::string& web_session_id, |
101 void OnSessionMessage(uint32 session_id, | |
102 const std::vector<uint8>& message, | 91 const std::vector<uint8>& message, |
103 const std::string& default_url); | 92 const std::string& default_url); |
104 void OnSessionReady(uint32 session_id); | 93 void OnSessionReady(const std::string& web_session_id); |
105 void OnSessionClosed(uint32 session_id); | 94 void OnSessionClosed(const std::string& web_session_id); |
106 void OnSessionError(uint32 session_id, | 95 void OnSessionError(const std::string& web_session_id, |
107 media::MediaKeys::KeyError error_code, | 96 media::MediaKeys::Exception exception_code, |
108 uint32 system_code); | 97 uint32 system_code, |
98 const std::string& error_message); | |
109 | 99 |
110 // Helper function to determine session_id for the provided |web_session_id|. | 100 // Called when a session is actually created or loaded. |
111 uint32 LookupSessionId(const std::string& web_session_id) const; | 101 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 | 102 |
118 #if defined(ENABLE_PEPPER_CDMS) | 103 #if defined(ENABLE_PEPPER_CDMS) |
119 // Callback to create the Pepper plugin. | 104 // Callback to create the Pepper plugin. |
120 CreatePepperCdmCB create_pepper_cdm_cb_; | 105 CreatePepperCdmCB create_pepper_cdm_cb_; |
121 #elif defined(OS_ANDROID) | 106 #elif defined(OS_ANDROID) |
122 RendererMediaPlayerManager* manager_; | 107 RendererMediaPlayerManager* manager_; |
123 int cdm_id_; | 108 int cdm_id_; |
124 #endif // defined(ENABLE_PEPPER_CDMS) | 109 #endif // defined(ENABLE_PEPPER_CDMS) |
125 | 110 |
126 // The real MediaKeys that manages key operations for the ProxyDecryptor. | 111 // The real MediaKeys that manages key operations for the ProxyDecryptor. |
127 scoped_ptr<media::MediaKeys> media_keys_; | 112 scoped_ptr<media::MediaKeys> media_keys_; |
128 | 113 |
129 // Callbacks for firing key events. | 114 // Callbacks for firing key events. |
130 KeyAddedCB key_added_cb_; | 115 KeyAddedCB key_added_cb_; |
131 KeyErrorCB key_error_cb_; | 116 KeyErrorCB key_error_cb_; |
132 KeyMessageCB key_message_cb_; | 117 KeyMessageCB key_message_cb_; |
133 | 118 |
134 // Session IDs are used to uniquely track sessions so that CDM callbacks | 119 std::set<std::string> active_sessions_; |
xhwang
2014/05/23 06:01:23
comment that this includes both persistent and non
jrummell
2014/05/29 00:54:40
Updated to a single hash_map.
| |
135 // can get mapped to the correct session ID. Session ID should be unique | 120 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 | 121 |
143 bool is_clear_key_; | 122 bool is_clear_key_; |
144 | 123 |
145 // NOTE: Weak pointers must be invalidated before all other member variables. | 124 // NOTE: Weak pointers must be invalidated before all other member variables. |
146 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 125 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
147 | 126 |
148 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 127 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
149 }; | 128 }; |
150 | 129 |
151 } // namespace content | 130 } // namespace content |
152 | 131 |
153 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 132 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |