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 #include "content/renderer/media/crypto/proxy_decryptor.h" | 5 #include "content/renderer/media/crypto/proxy_decryptor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 DCHECK(!media_keys_); | 76 DCHECK(!media_keys_); |
77 media_keys_ = CreateMediaKeys(key_system, frame_url); | 77 media_keys_ = CreateMediaKeys(key_system, frame_url); |
78 if (!media_keys_) | 78 if (!media_keys_) |
79 return false; | 79 return false; |
80 | 80 |
81 is_clear_key_ = | 81 is_clear_key_ = |
82 media::IsClearKey(key_system) || media::IsExternalClearKey(key_system); | 82 media::IsClearKey(key_system) || media::IsExternalClearKey(key_system); |
83 return true; | 83 return true; |
84 } | 84 } |
85 | 85 |
86 bool ProxyDecryptor::GenerateKeyRequest(const std::string& type, | 86 bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type, |
87 const uint8* init_data, | 87 const uint8* init_data, |
88 int init_data_length) { | 88 int init_data_length) { |
89 // Use a unique reference id for this request. | 89 // Use a unique reference id for this request. |
90 uint32 session_id = next_session_id_++; | 90 uint32 session_id = next_session_id_++; |
91 if (!media_keys_->CreateSession( | 91 |
92 session_id, type, init_data, init_data_length)) { | 92 const uint8 kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; |
93 return false; | 93 const int kPrefixedApiLoadSessionHeaderLength = |
94 sizeof(kPrefixedApiLoadSessionHeader) - 1; | |
dcheng
2014/02/11 23:12:25
Nit: I'd prefer strlen here. It has the benefit of
xhwang
2014/02/12 02:22:45
kPrefixedApiLoadSessionHeader is uint8 array. So t
| |
95 | |
96 if (init_data_length > kPrefixedApiLoadSessionHeaderLength && | |
97 std::equal(init_data, | |
98 init_data + kPrefixedApiLoadSessionHeaderLength, | |
99 kPrefixedApiLoadSessionHeader)) { | |
100 // TODO(xhwang): Track loadable session to handle OnSessionClosed(). | |
101 // See: http://crbug.com/340859. | |
102 media_keys_->LoadSession( | |
103 session_id, | |
104 std::string(reinterpret_cast<const char*>( | |
105 init_data + kPrefixedApiLoadSessionHeaderLength), | |
106 init_data_length - kPrefixedApiLoadSessionHeaderLength)); | |
107 return true; | |
94 } | 108 } |
95 | 109 |
96 return true; | 110 return media_keys_->CreateSession( |
111 session_id, content_type, init_data, init_data_length); | |
97 } | 112 } |
98 | 113 |
99 void ProxyDecryptor::AddKey(const uint8* key, | 114 void ProxyDecryptor::AddKey(const uint8* key, |
100 int key_length, | 115 int key_length, |
101 const uint8* init_data, | 116 const uint8* init_data, |
102 int init_data_length, | 117 int init_data_length, |
103 const std::string& web_session_id) { | 118 const std::string& web_session_id) { |
104 DVLOG(1) << "AddKey()"; | 119 DVLOG(1) << "AddKey()"; |
105 | 120 |
106 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. | 121 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 // No closed event in EME v0.1b. | 222 // No closed event in EME v0.1b. |
208 } | 223 } |
209 | 224 |
210 void ProxyDecryptor::OnSessionError(uint32 session_id, | 225 void ProxyDecryptor::OnSessionError(uint32 session_id, |
211 media::MediaKeys::KeyError error_code, | 226 media::MediaKeys::KeyError error_code, |
212 int system_code) { | 227 int system_code) { |
213 // Assumes that OnSessionCreated() has been called before this. | 228 // Assumes that OnSessionCreated() has been called before this. |
214 key_error_cb_.Run(LookupWebSessionId(session_id), error_code, system_code); | 229 key_error_cb_.Run(LookupWebSessionId(session_id), error_code, system_code); |
215 } | 230 } |
216 | 231 |
217 uint32 ProxyDecryptor::LookupSessionId(const std::string& session_id) { | 232 uint32 ProxyDecryptor::LookupSessionId(const std::string& session_id) { |
dcheng
2014/02/11 23:12:25
Minor unrelated nit: I think both of these functio
xhwang
2014/02/12 02:22:45
Done.
| |
218 for (SessionIdMap::iterator it = sessions_.begin(); | 233 for (SessionIdMap::iterator it = sessions_.begin(); |
219 it != sessions_.end(); | 234 it != sessions_.end(); |
220 ++it) { | 235 ++it) { |
221 if (it->second == session_id) | 236 if (it->second == session_id) |
222 return it->first; | 237 return it->first; |
223 } | 238 } |
224 | 239 |
225 // If |session_id| is null, then use the single reference id. | 240 // If |session_id| is null, then use the single reference id. |
226 if (session_id.empty() && sessions_.size() == 1) | 241 if (session_id.empty() && sessions_.size() == 1) |
227 return sessions_.begin()->first; | 242 return sessions_.begin()->first; |
228 | 243 |
229 return kInvalidSessionId; | 244 return kInvalidSessionId; |
230 } | 245 } |
231 | 246 |
232 const std::string& ProxyDecryptor::LookupWebSessionId(uint32 session_id) { | 247 const std::string& ProxyDecryptor::LookupWebSessionId(uint32 session_id) { |
233 DCHECK_NE(session_id, kInvalidSessionId); | 248 DCHECK_NE(session_id, kInvalidSessionId); |
234 | 249 |
235 // Session may not exist if error happens during GenerateKeyRequest(). | 250 // Session may not exist if error happens during GenerateKeyRequest(). |
236 SessionIdMap::iterator it = sessions_.find(session_id); | 251 SessionIdMap::iterator it = sessions_.find(session_id); |
237 return (it != sessions_.end()) ? it->second : base::EmptyString(); | 252 return (it != sessions_.end()) ? it->second : base::EmptyString(); |
238 } | 253 } |
239 | 254 |
240 } // namespace content | 255 } // namespace content |
OLD | NEW |