Chromium Code Reviews| 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 "media/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 // that do not support loadSession. See http://crbug.com/342481 | 322 // that do not support loadSession. See http://crbug.com/342481 |
| 323 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, | 323 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, |
| 324 "LoadSession() is not supported."); | 324 "LoadSession() is not supported."); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void AesDecryptor::UpdateSession(const std::string& session_id, | 327 void AesDecryptor::UpdateSession(const std::string& session_id, |
| 328 const std::vector<uint8_t>& response, | 328 const std::vector<uint8_t>& response, |
| 329 std::unique_ptr<SimpleCdmPromise> promise) { | 329 std::unique_ptr<SimpleCdmPromise> promise) { |
| 330 CHECK(!response.empty()); | 330 CHECK(!response.empty()); |
| 331 | 331 |
| 332 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. | 332 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. |
|
xhwang
2016/12/07 06:51:42
Can we do this now?
jrummell
2016/12/07 22:26:50
Nope (due to this being called asynchronously). Ad
| |
| 333 if (valid_sessions_.find(session_id) == valid_sessions_.end()) { | 333 if (valid_sessions_.find(session_id) == valid_sessions_.end()) { |
| 334 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, | 334 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
| 335 "Session does not exist."); | 335 "Session does not exist."); |
| 336 return; | 336 return; |
| 337 } | 337 } |
| 338 | 338 |
| 339 std::string key_string(response.begin(), response.end()); | 339 std::string key_string(response.begin(), response.end()); |
| 340 | 340 |
| 341 KeyIdAndKeyPairs keys; | 341 KeyIdAndKeyPairs keys; |
| 342 SessionType session_type = MediaKeys::TEMPORARY_SESSION; | 342 SessionType session_type = MediaKeys::TEMPORARY_SESSION; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 session_keys_change_cb_.Run(session_id, key_added, std::move(keys_info)); | 402 session_keys_change_cb_.Run(session_id, key_added, std::move(keys_info)); |
| 403 } | 403 } |
| 404 | 404 |
| 405 // Runs the parallel steps from https://w3c.github.io/encrypted-media/#close. | 405 // Runs the parallel steps from https://w3c.github.io/encrypted-media/#close. |
| 406 void AesDecryptor::CloseSession(const std::string& session_id, | 406 void AesDecryptor::CloseSession(const std::string& session_id, |
| 407 std::unique_ptr<SimpleCdmPromise> promise) { | 407 std::unique_ptr<SimpleCdmPromise> promise) { |
| 408 // Validate that this is a reference to an active session and then forget it. | 408 // Validate that this is a reference to an active session. close() shouldn't |
| 409 // be called if the session is already closed. However, the operation is | |
| 410 // asynchronous, so there is a window where close() was called a second time | |
| 411 // just before the closed event arrives. As a result it is possible that the | |
| 412 // session is already closed, so assume that the session is closed if it | |
| 413 // doesn't exist. | |
| 414 // | |
| 415 // close() is called from a MediaKeySession object, so it is unlikely that | |
| 416 // this method will be called with a previously unseen |session_id|. | |
| 409 std::set<std::string>::iterator it = valid_sessions_.find(session_id); | 417 std::set<std::string>::iterator it = valid_sessions_.find(session_id); |
| 410 DCHECK(it != valid_sessions_.end()); | 418 if (it == valid_sessions_.end()) { |
|
xhwang
2016/12/07 06:51:42
Now we cannot detect an invalid sesion_id... Since
jrummell
2016/12/07 22:26:50
I don't think there is any way to get a invalid se
| |
| 419 promise->resolve(); | |
| 420 return; | |
| 421 } | |
| 411 | 422 |
| 412 // 5.1. Let cdm be the CDM instance represented by session's cdm instance | 423 // 5.1. Let cdm be the CDM instance represented by session's cdm instance |
| 413 // value. | 424 // value. |
| 414 // 5.2. Use cdm to close the session associated with session. | 425 // 5.2. Use cdm to close the session associated with session. |
| 415 valid_sessions_.erase(it); | 426 valid_sessions_.erase(it); |
| 416 DeleteKeysForSession(session_id); | 427 DeleteKeysForSession(session_id); |
| 417 | 428 |
| 418 // 5.3. Queue a task to run the following steps: | 429 // 5.3. Queue a task to run the following steps: |
| 419 // 5.3.1. Run the Session Closed algorithm on the session. | 430 // 5.3.1. Run the Session Closed algorithm on the session. |
| 420 session_closed_cb_.Run(session_id); | 431 session_closed_cb_.Run(session_id); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 bool AesDecryptor::DecryptionKey::Init() { | 613 bool AesDecryptor::DecryptionKey::Init() { |
| 603 CHECK(!secret_.empty()); | 614 CHECK(!secret_.empty()); |
| 604 decryption_key_ = | 615 decryption_key_ = |
| 605 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_); | 616 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_); |
| 606 if (!decryption_key_) | 617 if (!decryption_key_) |
| 607 return false; | 618 return false; |
| 608 return true; | 619 return true; |
| 609 } | 620 } |
| 610 | 621 |
| 611 } // namespace media | 622 } // namespace media |
| OLD | NEW |