Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: media/crypto/aes_decryptor.cc

Issue 15772012: Separate MediaKeys interface from Decryptor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/crypto/aes_decryptor.h ('k') | media/crypto/aes_decryptor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/crypto/aes_decryptor.h" 5 #include "media/crypto/aes_decryptor.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 const uint8* init_data, 162 const uint8* init_data,
163 int init_data_length, 163 int init_data_length,
164 const std::string& session_id) { 164 const std::string& session_id) {
165 CHECK(key); 165 CHECK(key);
166 CHECK_GT(key_length, 0); 166 CHECK_GT(key_length, 0);
167 167
168 // TODO(xhwang): Add |session_id| check after we figure out how: 168 // TODO(xhwang): Add |session_id| check after we figure out how:
169 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 169 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550
170 if (key_length != DecryptConfig::kDecryptionKeySize) { 170 if (key_length != DecryptConfig::kDecryptionKeySize) {
171 DVLOG(1) << "Invalid key length: " << key_length; 171 DVLOG(1) << "Invalid key length: " << key_length;
172 key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); 172 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0);
173 return; 173 return;
174 } 174 }
175 175
176 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See 176 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See
177 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. 177 // http://crbug.com/123265. Until then, ensure a non-empty value is passed.
178 static const uint8 kDummyInitData[1] = { 0 }; 178 static const uint8 kDummyInitData[1] = { 0 };
179 if (!init_data) { 179 if (!init_data) {
180 init_data = kDummyInitData; 180 init_data = kDummyInitData;
181 init_data_length = arraysize(kDummyInitData); 181 init_data_length = arraysize(kDummyInitData);
182 } 182 }
183 183
184 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec 184 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec
185 // compliant later (http://crbug.com/123262, http://crbug.com/123265). 185 // compliant later (http://crbug.com/123262, http://crbug.com/123265).
186 std::string key_id_string(reinterpret_cast<const char*>(init_data), 186 std::string key_id_string(reinterpret_cast<const char*>(init_data),
187 init_data_length); 187 init_data_length);
188 std::string key_string(reinterpret_cast<const char*>(key) , key_length); 188 std::string key_string(reinterpret_cast<const char*>(key) , key_length);
189 scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string)); 189 scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string));
190 if (!decryption_key) { 190 if (!decryption_key) {
191 DVLOG(1) << "Could not create key."; 191 DVLOG(1) << "Could not create key.";
192 key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); 192 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0);
193 return; 193 return;
194 } 194 }
195 195
196 if (!decryption_key->Init()) { 196 if (!decryption_key->Init()) {
197 DVLOG(1) << "Could not initialize decryption key."; 197 DVLOG(1) << "Could not initialize decryption key.";
198 key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); 198 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0);
199 return; 199 return;
200 } 200 }
201 201
202 SetKey(key_id_string, decryption_key.Pass()); 202 SetKey(key_id_string, decryption_key.Pass());
203 203
204 if (!new_audio_key_cb_.is_null()) 204 if (!new_audio_key_cb_.is_null())
205 new_audio_key_cb_.Run(); 205 new_audio_key_cb_.Run();
206 206
207 if (!new_video_key_cb_.is_null()) 207 if (!new_video_key_cb_.is_null())
208 new_video_key_cb_.Run(); 208 new_video_key_cb_.Run();
209 209
210 key_added_cb_.Run(key_system, session_id); 210 key_added_cb_.Run(key_system, session_id);
211 } 211 }
212 212
213 void AesDecryptor::CancelKeyRequest(const std::string& key_system, 213 void AesDecryptor::CancelKeyRequest(const std::string& key_system,
214 const std::string& session_id) { 214 const std::string& session_id) {
215 } 215 }
216 216
217 MediaKeys* AesDecryptor::GetMediaKeys() {
218 return this;
219 }
220
217 void AesDecryptor::RegisterNewKeyCB(StreamType stream_type, 221 void AesDecryptor::RegisterNewKeyCB(StreamType stream_type,
218 const NewKeyCB& new_key_cb) { 222 const NewKeyCB& new_key_cb) {
219 switch (stream_type) { 223 switch (stream_type) {
220 case kAudio: 224 case kAudio:
221 new_audio_key_cb_ = new_key_cb; 225 new_audio_key_cb_ = new_key_cb;
222 break; 226 break;
223 case kVideo: 227 case kVideo:
224 new_video_key_cb_ = new_key_cb; 228 new_video_key_cb_ = new_key_cb;
225 break; 229 break;
226 default: 230 default:
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 bool AesDecryptor::DecryptionKey::Init() { 332 bool AesDecryptor::DecryptionKey::Init() {
329 CHECK(!secret_.empty()); 333 CHECK(!secret_.empty());
330 decryption_key_.reset(crypto::SymmetricKey::Import( 334 decryption_key_.reset(crypto::SymmetricKey::Import(
331 crypto::SymmetricKey::AES, secret_)); 335 crypto::SymmetricKey::AES, secret_));
332 if (!decryption_key_) 336 if (!decryption_key_)
333 return false; 337 return false;
334 return true; 338 return true;
335 } 339 }
336 340
337 } // namespace media 341 } // namespace media
OLDNEW
« no previous file with comments | « media/crypto/aes_decryptor.h ('k') | media/crypto/aes_decryptor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698