| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 void ClearKeyCdm::CreateSession(uint32 promise_id, | 242 void ClearKeyCdm::CreateSession(uint32 promise_id, |
| 243 const char* init_data_type, | 243 const char* init_data_type, |
| 244 uint32 init_data_type_size, | 244 uint32 init_data_type_size, |
| 245 const uint8* init_data, | 245 const uint8* init_data, |
| 246 uint32 init_data_size, | 246 uint32 init_data_size, |
| 247 cdm::SessionType session_type) { | 247 cdm::SessionType session_type) { |
| 248 DVLOG(1) << __FUNCTION__; | 248 DVLOG(1) << __FUNCTION__; |
| 249 | 249 |
| 250 scoped_ptr<media::NewSessionCdmPromise> promise( | 250 scoped_ptr<media::NewSessionCdmPromise> promise( |
| 251 new media::NewSessionCdmPromise(base::Bind(&ClearKeyCdm::OnSessionCreated, | 251 new media::CdmCallbackPromise<std::string>( |
| 252 base::Unretained(this), | 252 base::Bind(&ClearKeyCdm::OnSessionCreated, |
| 253 promise_id), | 253 base::Unretained(this), |
| 254 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 254 promise_id), |
| 255 base::Unretained(this), | 255 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 256 promise_id))); | 256 base::Unretained(this), |
| 257 promise_id))); |
| 257 decryptor_.CreateSession(std::string(init_data_type, init_data_type_size), | 258 decryptor_.CreateSession(std::string(init_data_type, init_data_type_size), |
| 258 init_data, | 259 init_data, |
| 259 init_data_size, | 260 init_data_size, |
| 260 ConvertSessionType(session_type), | 261 ConvertSessionType(session_type), |
| 261 promise.Pass()); | 262 promise.Pass()); |
| 262 | 263 |
| 263 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) | 264 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) |
| 264 StartFileIOTest(); | 265 StartFileIOTest(); |
| 265 } | 266 } |
| 266 | 267 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 278 std::string message("Incorrect session id specified for LoadSession()."); | 279 std::string message("Incorrect session id specified for LoadSession()."); |
| 279 host_->OnRejectPromise(promise_id, | 280 host_->OnRejectPromise(promise_id, |
| 280 cdm::kInvalidAccessError, | 281 cdm::kInvalidAccessError, |
| 281 0, | 282 0, |
| 282 message.data(), | 283 message.data(), |
| 283 message.length()); | 284 message.length()); |
| 284 return; | 285 return; |
| 285 } | 286 } |
| 286 | 287 |
| 287 scoped_ptr<media::NewSessionCdmPromise> promise( | 288 scoped_ptr<media::NewSessionCdmPromise> promise( |
| 288 new media::NewSessionCdmPromise(base::Bind(&ClearKeyCdm::OnSessionLoaded, | 289 new media::CdmCallbackPromise<std::string>( |
| 289 base::Unretained(this), | 290 base::Bind(&ClearKeyCdm::OnSessionLoaded, |
| 290 promise_id), | 291 base::Unretained(this), |
| 291 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 292 promise_id), |
| 292 base::Unretained(this), | 293 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 293 promise_id))); | 294 base::Unretained(this), |
| 295 promise_id))); |
| 294 decryptor_.CreateSession(std::string(kLoadableSessionContentType), | 296 decryptor_.CreateSession(std::string(kLoadableSessionContentType), |
| 295 NULL, | 297 NULL, |
| 296 0, | 298 0, |
| 297 MediaKeys::TEMPORARY_SESSION, | 299 MediaKeys::TEMPORARY_SESSION, |
| 298 promise.Pass()); | 300 promise.Pass()); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void ClearKeyCdm::UpdateSession(uint32 promise_id, | 303 void ClearKeyCdm::UpdateSession(uint32 promise_id, |
| 302 const char* web_session_id, | 304 const char* web_session_id, |
| 303 uint32_t web_session_id_length, | 305 uint32_t web_session_id_length, |
| 304 const uint8* response, | 306 const uint8* response, |
| 305 uint32 response_size) { | 307 uint32 response_size) { |
| 306 DVLOG(1) << __FUNCTION__; | 308 DVLOG(1) << __FUNCTION__; |
| 307 std::string web_session_str(web_session_id, web_session_id_length); | 309 std::string web_session_str(web_session_id, web_session_id_length); |
| 308 | 310 |
| 309 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( | 311 scoped_ptr<media::SimpleCdmPromise> promise( |
| 310 base::Bind(&ClearKeyCdm::OnSessionUpdated, | 312 new media::CdmCallbackPromise<void>( |
| 311 base::Unretained(this), | 313 base::Bind(&ClearKeyCdm::OnSessionUpdated, |
| 312 promise_id, | 314 base::Unretained(this), |
| 313 web_session_str), | 315 promise_id, |
| 314 base::Bind( | 316 web_session_str), |
| 315 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); | 317 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 318 base::Unretained(this), |
| 319 promise_id))); |
| 316 decryptor_.UpdateSession( | 320 decryptor_.UpdateSession( |
| 317 web_session_str, response, response_size, promise.Pass()); | 321 web_session_str, response, response_size, promise.Pass()); |
| 318 | 322 |
| 319 if (!heartbeat_timer_set_) { | 323 if (!heartbeat_timer_set_) { |
| 320 ScheduleNextHeartBeat(); | 324 ScheduleNextHeartBeat(); |
| 321 heartbeat_timer_set_ = true; | 325 heartbeat_timer_set_ = true; |
| 322 } | 326 } |
| 323 } | 327 } |
| 324 | 328 |
| 325 void ClearKeyCdm::CloseSession(uint32 promise_id, | 329 void ClearKeyCdm::CloseSession(uint32 promise_id, |
| 326 const char* web_session_id, | 330 const char* web_session_id, |
| 327 uint32_t web_session_id_length) { | 331 uint32_t web_session_id_length) { |
| 328 DVLOG(1) << __FUNCTION__; | 332 DVLOG(1) << __FUNCTION__; |
| 329 std::string web_session_str(web_session_id, web_session_id_length); | 333 std::string web_session_str(web_session_id, web_session_id_length); |
| 330 | 334 |
| 331 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( | 335 scoped_ptr<media::SimpleCdmPromise> |
| 336 promise(new media::CdmCallbackPromise<void>( |
| 332 base::Bind( | 337 base::Bind( |
| 333 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), | 338 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), |
| 334 base::Bind( | 339 base::Bind( |
| 335 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); | 340 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); |
| 336 decryptor_.CloseSession(web_session_str, promise.Pass()); | 341 decryptor_.CloseSession(web_session_str, promise.Pass()); |
| 337 } | 342 } |
| 338 | 343 |
| 339 void ClearKeyCdm::RemoveSession(uint32 promise_id, | 344 void ClearKeyCdm::RemoveSession(uint32 promise_id, |
| 340 const char* web_session_id, | 345 const char* web_session_id, |
| 341 uint32_t web_session_id_length) { | 346 uint32_t web_session_id_length) { |
| 342 DVLOG(1) << __FUNCTION__; | 347 DVLOG(1) << __FUNCTION__; |
| 343 // RemoveSession only allowed for persistent sessions. | 348 // RemoveSession only allowed for persistent sessions. |
| 344 bool is_persistent_session = | 349 bool is_persistent_session = |
| 345 std::string(kLoadableWebSessionId) == | 350 std::string(kLoadableWebSessionId) == |
| 346 std::string(web_session_id, web_session_id_length); | 351 std::string(web_session_id, web_session_id_length); |
| 347 if (is_persistent_session) { | 352 if (is_persistent_session) { |
| 348 std::string web_session_str(web_session_id, web_session_id_length); | 353 std::string web_session_str(web_session_id, web_session_id_length); |
| 349 | 354 |
| 350 scoped_ptr<media::SimpleCdmPromise> promise( | 355 scoped_ptr<media::SimpleCdmPromise> promise( |
| 351 new media::SimpleCdmPromise(base::Bind(&ClearKeyCdm::OnPromiseResolved, | 356 new media::CdmCallbackPromise<void>( |
| 352 base::Unretained(this), | 357 base::Bind(&ClearKeyCdm::OnPromiseResolved, |
| 353 promise_id), | 358 base::Unretained(this), |
| 354 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 359 promise_id), |
| 355 base::Unretained(this), | 360 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 356 promise_id))); | 361 base::Unretained(this), |
| 362 promise_id))); |
| 357 decryptor_.RemoveSession(web_session_str, promise.Pass()); | 363 decryptor_.RemoveSession(web_session_str, promise.Pass()); |
| 358 } else { | 364 } else { |
| 359 // TODO(jrummell): This should be a DCHECK once blink does the proper | 365 // TODO(jrummell): This should be a DCHECK once blink does the proper |
| 360 // checks. | 366 // checks. |
| 361 std::string message("Not supported for non-persistent sessions."); | 367 std::string message("Not supported for non-persistent sessions."); |
| 362 host_->OnRejectPromise(promise_id, | 368 host_->OnRejectPromise(promise_id, |
| 363 cdm::kInvalidAccessError, | 369 cdm::kInvalidAccessError, |
| 364 0, | 370 0, |
| 365 message.data(), | 371 message.data(), |
| 366 message.length()); | 372 message.length()); |
| 367 } | 373 } |
| 368 } | 374 } |
| 369 | 375 |
| 370 void ClearKeyCdm::SetServerCertificate(uint32 promise_id, | 376 void ClearKeyCdm::SetServerCertificate(uint32 promise_id, |
| 371 const uint8_t* server_certificate_data, | 377 const uint8_t* server_certificate_data, |
| 372 uint32_t server_certificate_data_size) { | 378 uint32_t server_certificate_data_size) { |
| 373 // ClearKey doesn't use a server certificate. | 379 // ClearKey doesn't use a server certificate. |
| 374 host_->OnResolvePromise(promise_id); | 380 host_->OnResolvePromise(promise_id); |
| 375 } | 381 } |
| 376 | 382 |
| 377 void ClearKeyCdm::GetUsableKeyIds(uint32_t promise_id, | 383 void ClearKeyCdm::GetUsableKeyIds(uint32_t promise_id, |
| 378 const char* web_session_id, | 384 const char* web_session_id, |
| 379 uint32_t web_session_id_length) { | 385 uint32_t web_session_id_length) { |
| 380 std::string web_session_str(web_session_id, web_session_id_length); | 386 std::string web_session_str(web_session_id, web_session_id_length); |
| 381 scoped_ptr<media::KeyIdsPromise> promise(new media::KeyIdsPromise( | 387 scoped_ptr<media::KeyIdsPromise> promise( |
| 382 base::Bind(&ClearKeyCdm::OnUsableKeyIdsObtained, | 388 new media::CdmCallbackPromise<KeyIdsVector>( |
| 383 base::Unretained(this), | 389 base::Bind(&ClearKeyCdm::OnUsableKeyIdsObtained, |
| 384 promise_id), | 390 base::Unretained(this), |
| 385 base::Bind( | 391 promise_id), |
| 386 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); | 392 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 393 base::Unretained(this), |
| 394 promise_id))); |
| 387 decryptor_.GetUsableKeyIds(web_session_str, promise.Pass()); | 395 decryptor_.GetUsableKeyIds(web_session_str, promise.Pass()); |
| 388 } | 396 } |
| 389 | 397 |
| 390 void ClearKeyCdm::TimerExpired(void* context) { | 398 void ClearKeyCdm::TimerExpired(void* context) { |
| 391 if (context == &session_id_for_emulated_loadsession_) { | 399 if (context == &session_id_for_emulated_loadsession_) { |
| 392 LoadLoadableSession(); | 400 LoadLoadableSession(); |
| 393 return; | 401 return; |
| 394 } | 402 } |
| 395 | 403 |
| 396 DCHECK(heartbeat_timer_set_); | 404 DCHECK(heartbeat_timer_set_); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 NOTIMPLEMENTED(); | 661 NOTIMPLEMENTED(); |
| 654 }; | 662 }; |
| 655 | 663 |
| 656 void ClearKeyCdm::LoadLoadableSession() { | 664 void ClearKeyCdm::LoadLoadableSession() { |
| 657 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, | 665 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, |
| 658 sizeof(kLoadableSessionKey), | 666 sizeof(kLoadableSessionKey), |
| 659 kLoadableSessionKeyId, | 667 kLoadableSessionKeyId, |
| 660 sizeof(kLoadableSessionKeyId) - 1); | 668 sizeof(kLoadableSessionKeyId) - 1); |
| 661 // TODO(xhwang): This triggers OnSessionUpdated(). For prefixed EME support, | 669 // TODO(xhwang): This triggers OnSessionUpdated(). For prefixed EME support, |
| 662 // this is okay. Check WD EME support. | 670 // this is okay. Check WD EME support. |
| 663 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( | 671 scoped_ptr<media::SimpleCdmPromise> promise( |
| 664 base::Bind(&ClearKeyCdm::OnSessionUpdated, | 672 new media::CdmCallbackPromise<void>( |
| 665 base::Unretained(this), | 673 base::Bind(&ClearKeyCdm::OnSessionUpdated, |
| 666 promise_id_for_emulated_loadsession_, | 674 base::Unretained(this), |
| 667 session_id_for_emulated_loadsession_), | 675 promise_id_for_emulated_loadsession_, |
| 668 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 676 session_id_for_emulated_loadsession_), |
| 669 base::Unretained(this), | 677 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 670 promise_id_for_emulated_loadsession_))); | 678 base::Unretained(this), |
| 679 promise_id_for_emulated_loadsession_))); |
| 671 decryptor_.UpdateSession(session_id_for_emulated_loadsession_, | 680 decryptor_.UpdateSession(session_id_for_emulated_loadsession_, |
| 672 reinterpret_cast<const uint8*>(jwk_set.data()), | 681 reinterpret_cast<const uint8*>(jwk_set.data()), |
| 673 jwk_set.size(), | 682 jwk_set.size(), |
| 674 promise.Pass()); | 683 promise.Pass()); |
| 675 } | 684 } |
| 676 | 685 |
| 677 void ClearKeyCdm::OnSessionMessage(const std::string& web_session_id, | 686 void ClearKeyCdm::OnSessionMessage(const std::string& web_session_id, |
| 678 const std::vector<uint8>& message, | 687 const std::vector<uint8>& message, |
| 679 const GURL& destination_url) { | 688 const GURL& destination_url) { |
| 680 DVLOG(1) << "OnSessionMessage: " << message.size(); | 689 DVLOG(1) << "OnSessionMessage: " << message.size(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 host_->OnSessionMessage(last_session_id_.data(), | 857 host_->OnSessionMessage(last_session_id_.data(), |
| 849 last_session_id_.length(), | 858 last_session_id_.length(), |
| 850 message.data(), | 859 message.data(), |
| 851 message.length(), | 860 message.length(), |
| 852 NULL, | 861 NULL, |
| 853 0); | 862 0); |
| 854 file_io_test_runner_.reset(); | 863 file_io_test_runner_.reset(); |
| 855 } | 864 } |
| 856 | 865 |
| 857 } // namespace media | 866 } // namespace media |
| OLD | NEW |