| 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/ppapi/external_clear_key/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 scoped_ptr<media::NewSessionCdmPromise> promise( | 315 scoped_ptr<media::NewSessionCdmPromise> promise( |
| 316 new media::CdmCallbackPromise<std::string>( | 316 new media::CdmCallbackPromise<std::string>( |
| 317 base::Bind(&ClearKeyCdm::OnSessionCreated, | 317 base::Bind(&ClearKeyCdm::OnSessionCreated, |
| 318 base::Unretained(this), | 318 base::Unretained(this), |
| 319 promise_id), | 319 promise_id), |
| 320 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 320 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 321 base::Unretained(this), | 321 base::Unretained(this), |
| 322 promise_id))); | 322 promise_id))); |
| 323 decryptor_.CreateSessionAndGenerateRequest( | 323 decryptor_.CreateSessionAndGenerateRequest( |
| 324 ConvertSessionType(session_type), ConvertInitDataType(init_data_type), | 324 ConvertSessionType(session_type), ConvertInitDataType(init_data_type), |
| 325 init_data, init_data_size, promise.Pass()); | 325 std::vector<uint8_t>(init_data, init_data + init_data_size), |
| 326 promise.Pass()); |
| 326 | 327 |
| 327 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) | 328 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) |
| 328 StartFileIOTest(); | 329 StartFileIOTest(); |
| 329 } | 330 } |
| 330 | 331 |
| 331 // Loads a emulated stored session. Currently only |kLoadableSessionId| | 332 // Loads a emulated stored session. Currently only |kLoadableSessionId| |
| 332 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is | 333 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is |
| 333 // supported. | 334 // supported. |
| 334 void ClearKeyCdm::LoadSession(uint32 promise_id, | 335 void ClearKeyCdm::LoadSession(uint32 promise_id, |
| 335 cdm::SessionType session_type, | 336 cdm::SessionType session_type, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 354 DCHECK(session_id_for_emulated_loadsession_.empty()); | 355 DCHECK(session_id_for_emulated_loadsession_.empty()); |
| 355 | 356 |
| 356 scoped_ptr<media::NewSessionCdmPromise> promise( | 357 scoped_ptr<media::NewSessionCdmPromise> promise( |
| 357 new media::CdmCallbackPromise<std::string>( | 358 new media::CdmCallbackPromise<std::string>( |
| 358 base::Bind(&ClearKeyCdm::OnSessionLoaded, | 359 base::Bind(&ClearKeyCdm::OnSessionLoaded, |
| 359 base::Unretained(this), | 360 base::Unretained(this), |
| 360 promise_id), | 361 promise_id), |
| 361 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 362 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 362 base::Unretained(this), | 363 base::Unretained(this), |
| 363 promise_id))); | 364 promise_id))); |
| 364 decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, | 365 decryptor_.CreateSessionAndGenerateRequest( |
| 365 EmeInitDataType::WEBM, NULL, 0, | 366 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 366 promise.Pass()); | 367 std::vector<uint8_t>(), promise.Pass()); |
| 367 } | 368 } |
| 368 | 369 |
| 369 void ClearKeyCdm::UpdateSession(uint32 promise_id, | 370 void ClearKeyCdm::UpdateSession(uint32 promise_id, |
| 370 const char* session_id, | 371 const char* session_id, |
| 371 uint32_t session_id_length, | 372 uint32_t session_id_length, |
| 372 const uint8* response, | 373 const uint8* response, |
| 373 uint32 response_size) { | 374 uint32 response_size) { |
| 374 DVLOG(1) << __FUNCTION__; | 375 DVLOG(1) << __FUNCTION__; |
| 375 std::string web_session_str(session_id, session_id_length); | 376 std::string web_session_str(session_id, session_id_length); |
| 376 | 377 |
| 377 // If updating the loadable session, use the actual session id generated. | 378 // If updating the loadable session, use the actual session id generated. |
| 378 if (web_session_str == std::string(kLoadableSessionId)) | 379 if (web_session_str == std::string(kLoadableSessionId)) |
| 379 web_session_str = session_id_for_emulated_loadsession_; | 380 web_session_str = session_id_for_emulated_loadsession_; |
| 380 | 381 |
| 381 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 382 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
| 382 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), | 383 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
| 383 promise_id), | 384 promise_id), |
| 384 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 385 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 385 promise_id))); | 386 promise_id))); |
| 386 decryptor_.UpdateSession( | 387 decryptor_.UpdateSession( |
| 387 web_session_str, response, response_size, promise.Pass()); | 388 web_session_str, std::vector<uint8_t>(response, response + response_size), |
| 389 promise.Pass()); |
| 388 | 390 |
| 389 if (!renewal_timer_set_) { | 391 if (!renewal_timer_set_) { |
| 390 ScheduleNextRenewal(); | 392 ScheduleNextRenewal(); |
| 391 renewal_timer_set_ = true; | 393 renewal_timer_set_ = true; |
| 392 } | 394 } |
| 393 } | 395 } |
| 394 | 396 |
| 395 void ClearKeyCdm::CloseSession(uint32 promise_id, | 397 void ClearKeyCdm::CloseSession(uint32 promise_id, |
| 396 const char* session_id, | 398 const char* session_id, |
| 397 uint32_t session_id_length) { | 399 uint32_t session_id_length) { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 void ClearKeyCdm::LoadLoadableSession() { | 716 void ClearKeyCdm::LoadLoadableSession() { |
| 715 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, | 717 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, |
| 716 sizeof(kLoadableSessionKey), | 718 sizeof(kLoadableSessionKey), |
| 717 kLoadableSessionKeyId, | 719 kLoadableSessionKeyId, |
| 718 sizeof(kLoadableSessionKeyId) - 1); | 720 sizeof(kLoadableSessionKeyId) - 1); |
| 719 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 721 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
| 720 base::Bind(&ClearKeyCdm::OnLoadSessionUpdated, base::Unretained(this)), | 722 base::Bind(&ClearKeyCdm::OnLoadSessionUpdated, base::Unretained(this)), |
| 721 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 723 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 722 promise_id_for_emulated_loadsession_))); | 724 promise_id_for_emulated_loadsession_))); |
| 723 decryptor_.UpdateSession(session_id_for_emulated_loadsession_, | 725 decryptor_.UpdateSession(session_id_for_emulated_loadsession_, |
| 724 reinterpret_cast<const uint8*>(jwk_set.data()), | 726 std::vector<uint8_t>(jwk_set.begin(), jwk_set.end()), |
| 725 jwk_set.size(), | |
| 726 promise.Pass()); | 727 promise.Pass()); |
| 727 } | 728 } |
| 728 | 729 |
| 729 void ClearKeyCdm::OnSessionMessage(const std::string& session_id, | 730 void ClearKeyCdm::OnSessionMessage(const std::string& session_id, |
| 730 MediaKeys::MessageType message_type, | 731 MediaKeys::MessageType message_type, |
| 731 const std::vector<uint8>& message, | 732 const std::vector<uint8>& message, |
| 732 const GURL& legacy_destination_url) { | 733 const GURL& legacy_destination_url) { |
| 733 DVLOG(1) << "OnSessionMessage: " << message.size(); | 734 DVLOG(1) << "OnSessionMessage: " << message.size(); |
| 734 | 735 |
| 735 // Ignore the message when we are waiting to update the loadable session. | 736 // Ignore the message when we are waiting to update the loadable session. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 void ClearKeyCdm::OnFileIOTestComplete(bool success) { | 925 void ClearKeyCdm::OnFileIOTestComplete(bool success) { |
| 925 DVLOG(1) << __FUNCTION__ << ": " << success; | 926 DVLOG(1) << __FUNCTION__ << ": " << success; |
| 926 std::string message = GetFileIOTestResultMessage(success); | 927 std::string message = GetFileIOTestResultMessage(success); |
| 927 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), | 928 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), |
| 928 cdm::kLicenseRequest, message.data(), | 929 cdm::kLicenseRequest, message.data(), |
| 929 message.length(), NULL, 0); | 930 message.length(), NULL, 0); |
| 930 file_io_test_runner_.reset(); | 931 file_io_test_runner_.reset(); |
| 931 } | 932 } |
| 932 | 933 |
| 933 } // namespace media | 934 } // namespace media |
| OLD | NEW |