OLD | NEW |
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 "content/renderer/pepper/content_decryptor_delegate.h" | 5 #include "content/renderer/pepper/content_decryptor_delegate.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 uint32_t certificate_length, | 356 uint32_t certificate_length, |
357 scoped_ptr<media::SimpleCdmPromise> promise) { | 357 scoped_ptr<media::SimpleCdmPromise> promise) { |
358 if (!certificate || | 358 if (!certificate || |
359 certificate_length < media::limits::kMinCertificateLength || | 359 certificate_length < media::limits::kMinCertificateLength || |
360 certificate_length > media::limits::kMaxCertificateLength) { | 360 certificate_length > media::limits::kMaxCertificateLength) { |
361 promise->reject( | 361 promise->reject( |
362 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate."); | 362 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate."); |
363 return; | 363 return; |
364 } | 364 } |
365 | 365 |
366 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 366 uint32_t promise_id = SavePromise(promise.Pass()); |
367 PP_Var certificate_array = | 367 PP_Var certificate_array = |
368 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 368 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
369 certificate_length, certificate); | 369 certificate_length, certificate); |
370 plugin_decryption_interface_->SetServerCertificate( | 370 plugin_decryption_interface_->SetServerCertificate( |
371 pp_instance_, promise_id, certificate_array); | 371 pp_instance_, promise_id, certificate_array); |
372 } | 372 } |
373 | 373 |
374 void ContentDecryptorDelegate::CreateSession( | 374 void ContentDecryptorDelegate::CreateSession( |
375 const std::string& init_data_type, | 375 const std::string& init_data_type, |
376 const uint8* init_data, | 376 const uint8* init_data, |
377 int init_data_length, | 377 int init_data_length, |
378 MediaKeys::SessionType session_type, | 378 MediaKeys::SessionType session_type, |
379 scoped_ptr<NewSessionCdmPromise> promise) { | 379 scoped_ptr<NewSessionCdmPromise> promise) { |
380 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 380 uint32_t promise_id = SavePromise(promise.Pass()); |
381 PP_Var init_data_array = | 381 PP_Var init_data_array = |
382 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 382 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
383 init_data_length, init_data); | 383 init_data_length, init_data); |
384 plugin_decryption_interface_->CreateSession( | 384 plugin_decryption_interface_->CreateSession( |
385 pp_instance_, | 385 pp_instance_, |
386 promise_id, | 386 promise_id, |
387 StringVar::StringToPPVar(init_data_type), | 387 StringVar::StringToPPVar(init_data_type), |
388 init_data_array, | 388 init_data_array, |
389 MediaSessionTypeToPpSessionType(session_type)); | 389 MediaSessionTypeToPpSessionType(session_type)); |
390 } | 390 } |
391 | 391 |
392 void ContentDecryptorDelegate::LoadSession( | 392 void ContentDecryptorDelegate::LoadSession( |
393 const std::string& web_session_id, | 393 const std::string& web_session_id, |
394 scoped_ptr<NewSessionCdmPromise> promise) { | 394 scoped_ptr<NewSessionCdmPromise> promise) { |
395 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 395 uint32_t promise_id = SavePromise(promise.Pass()); |
396 plugin_decryption_interface_->LoadSession( | 396 plugin_decryption_interface_->LoadSession( |
397 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 397 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
398 } | 398 } |
399 | 399 |
400 void ContentDecryptorDelegate::UpdateSession( | 400 void ContentDecryptorDelegate::UpdateSession( |
401 const std::string& web_session_id, | 401 const std::string& web_session_id, |
402 const uint8* response, | 402 const uint8* response, |
403 int response_length, | 403 int response_length, |
404 scoped_ptr<SimpleCdmPromise> promise) { | 404 scoped_ptr<SimpleCdmPromise> promise) { |
405 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 405 uint32_t promise_id = SavePromise(promise.Pass()); |
406 PP_Var response_array = | 406 PP_Var response_array = |
407 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 407 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
408 response_length, response); | 408 response_length, response); |
409 plugin_decryption_interface_->UpdateSession( | 409 plugin_decryption_interface_->UpdateSession( |
410 pp_instance_, | 410 pp_instance_, |
411 promise_id, | 411 promise_id, |
412 StringVar::StringToPPVar(web_session_id), | 412 StringVar::StringToPPVar(web_session_id), |
413 response_array); | 413 response_array); |
414 } | 414 } |
415 | 415 |
416 void ContentDecryptorDelegate::CloseSession( | 416 void ContentDecryptorDelegate::CloseSession( |
417 const std::string& web_session_id, | 417 const std::string& web_session_id, |
418 scoped_ptr<SimpleCdmPromise> promise) { | 418 scoped_ptr<SimpleCdmPromise> promise) { |
419 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { | 419 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { |
420 promise->reject( | 420 promise->reject( |
421 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); | 421 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
425 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 425 uint32_t promise_id = SavePromise(promise.Pass()); |
426 plugin_decryption_interface_->CloseSession( | 426 plugin_decryption_interface_->CloseSession( |
427 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 427 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
428 } | 428 } |
429 | 429 |
430 void ContentDecryptorDelegate::RemoveSession( | 430 void ContentDecryptorDelegate::RemoveSession( |
431 const std::string& web_session_id, | 431 const std::string& web_session_id, |
432 scoped_ptr<SimpleCdmPromise> promise) { | 432 scoped_ptr<SimpleCdmPromise> promise) { |
433 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { | 433 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { |
434 promise->reject( | 434 promise->reject( |
435 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); | 435 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
436 return; | 436 return; |
437 } | 437 } |
438 | 438 |
439 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 439 uint32_t promise_id = SavePromise(promise.Pass()); |
440 plugin_decryption_interface_->RemoveSession( | 440 plugin_decryption_interface_->RemoveSession( |
441 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 441 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
442 } | 442 } |
443 | 443 |
444 void ContentDecryptorDelegate::GetUsableKeyIds( | 444 void ContentDecryptorDelegate::GetUsableKeyIds( |
445 const std::string& web_session_id, | 445 const std::string& web_session_id, |
446 scoped_ptr<media::KeyIdsPromise> promise) { | 446 scoped_ptr<media::KeyIdsPromise> promise) { |
447 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { | 447 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { |
448 promise->reject( | 448 promise->reject( |
449 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); | 449 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
450 return; | 450 return; |
451 } | 451 } |
452 | 452 |
453 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 453 uint32_t promise_id = SavePromise(promise.Pass()); |
454 plugin_decryption_interface_->GetUsableKeyIds( | 454 plugin_decryption_interface_->GetUsableKeyIds( |
455 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 455 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
456 } | 456 } |
457 | 457 |
458 // TODO(xhwang): Remove duplication of code in Decrypt(), | 458 // TODO(xhwang): Remove duplication of code in Decrypt(), |
459 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 459 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
460 bool ContentDecryptorDelegate::Decrypt( | 460 bool ContentDecryptorDelegate::Decrypt( |
461 Decryptor::StreamType stream_type, | 461 Decryptor::StreamType stream_type, |
462 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 462 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
463 const Decryptor::DecryptCB& decrypt_cb) { | 463 const Decryptor::DecryptCB& decrypt_cb) { |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 | 1324 |
1325 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1325 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
1326 uint32_t promise_id) { | 1326 uint32_t promise_id) { |
1327 PromiseMap::iterator it = promises_.find(promise_id); | 1327 PromiseMap::iterator it = promises_.find(promise_id); |
1328 if (it == promises_.end()) | 1328 if (it == promises_.end()) |
1329 return scoped_ptr<CdmPromise>(); | 1329 return scoped_ptr<CdmPromise>(); |
1330 return promises_.take_and_erase(it); | 1330 return promises_.take_and_erase(it); |
1331 } | 1331 } |
1332 | 1332 |
1333 } // namespace content | 1333 } // namespace content |
OLD | NEW |