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 <string.h> | 7 #include <string.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "media/base/video_util.h" | 29 #include "media/base/video_util.h" |
30 #include "ppapi/shared_impl/array_var.h" | 30 #include "ppapi/shared_impl/array_var.h" |
31 #include "ppapi/shared_impl/scoped_pp_resource.h" | 31 #include "ppapi/shared_impl/scoped_pp_resource.h" |
32 #include "ppapi/shared_impl/time_conversion.h" | 32 #include "ppapi/shared_impl/time_conversion.h" |
33 #include "ppapi/shared_impl/var.h" | 33 #include "ppapi/shared_impl/var.h" |
34 #include "ppapi/shared_impl/var_tracker.h" | 34 #include "ppapi/shared_impl/var_tracker.h" |
35 #include "ppapi/thunk/enter.h" | 35 #include "ppapi/thunk/enter.h" |
36 #include "ppapi/thunk/ppb_buffer_api.h" | 36 #include "ppapi/thunk/ppb_buffer_api.h" |
37 #include "ui/gfx/geometry/rect.h" | 37 #include "ui/gfx/geometry/rect.h" |
38 | 38 |
| 39 using media::CdmPromise; |
39 using media::Decryptor; | 40 using media::Decryptor; |
40 using media::MediaKeys; | 41 using media::MediaKeys; |
41 using media::NewSessionCdmPromise; | 42 using media::NewSessionCdmPromise; |
42 using media::SimpleCdmPromise; | 43 using media::SimpleCdmPromise; |
43 using ppapi::ArrayBufferVar; | 44 using ppapi::ArrayBufferVar; |
44 using ppapi::ArrayVar; | 45 using ppapi::ArrayVar; |
45 using ppapi::PpapiGlobals; | 46 using ppapi::PpapiGlobals; |
46 using ppapi::ScopedPPResource; | 47 using ppapi::ScopedPPResource; |
47 using ppapi::StringVar; | 48 using ppapi::StringVar; |
48 using ppapi::thunk::EnterResourceNoLock; | 49 using ppapi::thunk::EnterResourceNoLock; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return PP_INITDATATYPE_KEYIDS; | 283 return PP_INITDATATYPE_KEYIDS; |
283 case media::EmeInitDataType::WEBM: | 284 case media::EmeInitDataType::WEBM: |
284 return PP_INITDATATYPE_WEBM; | 285 return PP_INITDATATYPE_WEBM; |
285 case media::EmeInitDataType::UNKNOWN: | 286 case media::EmeInitDataType::UNKNOWN: |
286 break; | 287 break; |
287 } | 288 } |
288 NOTREACHED(); | 289 NOTREACHED(); |
289 return PP_INITDATATYPE_KEYIDS; | 290 return PP_INITDATATYPE_KEYIDS; |
290 } | 291 } |
291 | 292 |
292 MediaKeys::Exception PpExceptionTypeToMediaException( | 293 CdmPromise::Exception PpExceptionTypeToCdmPromiseException( |
293 PP_CdmExceptionCode exception_code) { | 294 PP_CdmExceptionCode exception_code) { |
294 switch (exception_code) { | 295 switch (exception_code) { |
295 case PP_CDMEXCEPTIONCODE_NOTSUPPORTEDERROR: | 296 case PP_CDMEXCEPTIONCODE_NOTSUPPORTEDERROR: |
296 return MediaKeys::NOT_SUPPORTED_ERROR; | 297 return CdmPromise::NOT_SUPPORTED_ERROR; |
297 case PP_CDMEXCEPTIONCODE_INVALIDSTATEERROR: | 298 case PP_CDMEXCEPTIONCODE_INVALIDSTATEERROR: |
298 return MediaKeys::INVALID_STATE_ERROR; | 299 return CdmPromise::INVALID_STATE_ERROR; |
299 case PP_CDMEXCEPTIONCODE_INVALIDACCESSERROR: | 300 case PP_CDMEXCEPTIONCODE_INVALIDACCESSERROR: |
300 return MediaKeys::INVALID_ACCESS_ERROR; | 301 return CdmPromise::INVALID_ACCESS_ERROR; |
301 case PP_CDMEXCEPTIONCODE_QUOTAEXCEEDEDERROR: | 302 case PP_CDMEXCEPTIONCODE_QUOTAEXCEEDEDERROR: |
302 return MediaKeys::QUOTA_EXCEEDED_ERROR; | 303 return CdmPromise::QUOTA_EXCEEDED_ERROR; |
303 case PP_CDMEXCEPTIONCODE_UNKNOWNERROR: | 304 case PP_CDMEXCEPTIONCODE_UNKNOWNERROR: |
304 return MediaKeys::UNKNOWN_ERROR; | 305 return CdmPromise::UNKNOWN_ERROR; |
305 case PP_CDMEXCEPTIONCODE_CLIENTERROR: | 306 case PP_CDMEXCEPTIONCODE_CLIENTERROR: |
306 return MediaKeys::CLIENT_ERROR; | 307 return CdmPromise::CLIENT_ERROR; |
307 case PP_CDMEXCEPTIONCODE_OUTPUTERROR: | 308 case PP_CDMEXCEPTIONCODE_OUTPUTERROR: |
308 return MediaKeys::OUTPUT_ERROR; | 309 return CdmPromise::OUTPUT_ERROR; |
309 default: | 310 default: |
310 NOTREACHED(); | 311 NOTREACHED(); |
311 return MediaKeys::UNKNOWN_ERROR; | 312 return CdmPromise::UNKNOWN_ERROR; |
312 } | 313 } |
313 } | 314 } |
314 | 315 |
315 media::CdmKeyInformation::KeyStatus PpCdmKeyStatusToCdmKeyInformationKeyStatus( | 316 media::CdmKeyInformation::KeyStatus PpCdmKeyStatusToCdmKeyInformationKeyStatus( |
316 PP_CdmKeyStatus status) { | 317 PP_CdmKeyStatus status) { |
317 switch (status) { | 318 switch (status) { |
318 case PP_CDMKEYSTATUS_USABLE: | 319 case PP_CDMKEYSTATUS_USABLE: |
319 return media::CdmKeyInformation::USABLE; | 320 return media::CdmKeyInformation::USABLE; |
320 case PP_CDMKEYSTATUS_INVALID: | 321 case PP_CDMKEYSTATUS_INVALID: |
321 return media::CdmKeyInformation::INTERNAL_ERROR; | 322 return media::CdmKeyInformation::INTERNAL_ERROR; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 void ContentDecryptorDelegate::InstanceCrashed() { | 410 void ContentDecryptorDelegate::InstanceCrashed() { |
410 fatal_plugin_error_cb_.Run(); | 411 fatal_plugin_error_cb_.Run(); |
411 SatisfyAllPendingCallbacksOnError(); | 412 SatisfyAllPendingCallbacksOnError(); |
412 } | 413 } |
413 | 414 |
414 void ContentDecryptorDelegate::SetServerCertificate( | 415 void ContentDecryptorDelegate::SetServerCertificate( |
415 const std::vector<uint8_t>& certificate, | 416 const std::vector<uint8_t>& certificate, |
416 std::unique_ptr<media::SimpleCdmPromise> promise) { | 417 std::unique_ptr<media::SimpleCdmPromise> promise) { |
417 if (certificate.size() < media::limits::kMinCertificateLength || | 418 if (certificate.size() < media::limits::kMinCertificateLength || |
418 certificate.size() > media::limits::kMaxCertificateLength) { | 419 certificate.size() > media::limits::kMaxCertificateLength) { |
419 promise->reject( | 420 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, |
420 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate."); | 421 "Incorrect certificate."); |
421 return; | 422 return; |
422 } | 423 } |
423 | 424 |
424 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | 425 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
425 PP_Var certificate_array = | 426 PP_Var certificate_array = |
426 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 427 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
427 base::checked_cast<uint32_t>(certificate.size()), certificate.data()); | 428 base::checked_cast<uint32_t>(certificate.size()), certificate.data()); |
428 plugin_decryption_interface_->SetServerCertificate( | 429 plugin_decryption_interface_->SetServerCertificate( |
429 pp_instance_, promise_id, certificate_array); | 430 pp_instance_, promise_id, certificate_array); |
430 } | 431 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 base::checked_cast<uint32_t>(response.size()), response.data()); | 464 base::checked_cast<uint32_t>(response.size()), response.data()); |
464 plugin_decryption_interface_->UpdateSession( | 465 plugin_decryption_interface_->UpdateSession( |
465 pp_instance_, promise_id, StringVar::StringToPPVar(session_id), | 466 pp_instance_, promise_id, StringVar::StringToPPVar(session_id), |
466 response_array); | 467 response_array); |
467 } | 468 } |
468 | 469 |
469 void ContentDecryptorDelegate::CloseSession( | 470 void ContentDecryptorDelegate::CloseSession( |
470 const std::string& session_id, | 471 const std::string& session_id, |
471 std::unique_ptr<SimpleCdmPromise> promise) { | 472 std::unique_ptr<SimpleCdmPromise> promise) { |
472 if (session_id.length() > media::limits::kMaxSessionIdLength) { | 473 if (session_id.length() > media::limits::kMaxSessionIdLength) { |
473 promise->reject( | 474 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
474 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); | |
475 return; | 475 return; |
476 } | 476 } |
477 | 477 |
478 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | 478 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
479 plugin_decryption_interface_->CloseSession( | 479 plugin_decryption_interface_->CloseSession( |
480 pp_instance_, promise_id, StringVar::StringToPPVar(session_id)); | 480 pp_instance_, promise_id, StringVar::StringToPPVar(session_id)); |
481 } | 481 } |
482 | 482 |
483 void ContentDecryptorDelegate::RemoveSession( | 483 void ContentDecryptorDelegate::RemoveSession( |
484 const std::string& session_id, | 484 const std::string& session_id, |
485 std::unique_ptr<SimpleCdmPromise> promise) { | 485 std::unique_ptr<SimpleCdmPromise> promise) { |
486 if (session_id.length() > media::limits::kMaxSessionIdLength) { | 486 if (session_id.length() > media::limits::kMaxSessionIdLength) { |
487 promise->reject( | 487 promise->reject(CdmPromise::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
488 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); | |
489 return; | 488 return; |
490 } | 489 } |
491 | 490 |
492 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | 491 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
493 plugin_decryption_interface_->RemoveSession( | 492 plugin_decryption_interface_->RemoveSession( |
494 pp_instance_, promise_id, StringVar::StringToPPVar(session_id)); | 493 pp_instance_, promise_id, StringVar::StringToPPVar(session_id)); |
495 } | 494 } |
496 | 495 |
497 // TODO(xhwang): Remove duplication of code in Decrypt(), | 496 // TODO(xhwang): Remove duplication of code in Decrypt(), |
498 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 497 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 void ContentDecryptorDelegate::OnPromiseRejected( | 748 void ContentDecryptorDelegate::OnPromiseRejected( |
750 uint32_t promise_id, | 749 uint32_t promise_id, |
751 PP_CdmExceptionCode exception_code, | 750 PP_CdmExceptionCode exception_code, |
752 uint32_t system_code, | 751 uint32_t system_code, |
753 PP_Var error_description) { | 752 PP_Var error_description) { |
754 ReportSystemCodeUMA(key_system_, system_code); | 753 ReportSystemCodeUMA(key_system_, system_code); |
755 | 754 |
756 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 755 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
757 DCHECK(error_description_string); | 756 DCHECK(error_description_string); |
758 cdm_promise_adapter_.RejectPromise( | 757 cdm_promise_adapter_.RejectPromise( |
759 promise_id, PpExceptionTypeToMediaException(exception_code), system_code, | 758 promise_id, PpExceptionTypeToCdmPromiseException(exception_code), |
760 error_description_string->value()); | 759 system_code, error_description_string->value()); |
761 } | 760 } |
762 | 761 |
763 void ContentDecryptorDelegate::OnSessionMessage(PP_Var session_id, | 762 void ContentDecryptorDelegate::OnSessionMessage(PP_Var session_id, |
764 PP_CdmMessageType message_type, | 763 PP_CdmMessageType message_type, |
765 PP_Var message) { | 764 PP_Var message) { |
766 if (session_message_cb_.is_null()) | 765 if (session_message_cb_.is_null()) |
767 return; | 766 return; |
768 | 767 |
769 StringVar* session_id_string = StringVar::FromPPVar(session_id); | 768 StringVar* session_id_string = StringVar::FromPPVar(session_id); |
770 DCHECK(session_id_string); | 769 DCHECK(session_id_string); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 empty_frames); | 1253 empty_frames); |
1255 } | 1254 } |
1256 | 1255 |
1257 if (!video_decode_cb_.is_null()) | 1256 if (!video_decode_cb_.is_null()) |
1258 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1257 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
1259 | 1258 |
1260 cdm_promise_adapter_.Clear(); | 1259 cdm_promise_adapter_.Clear(); |
1261 } | 1260 } |
1262 | 1261 |
1263 } // namespace content | 1262 } // namespace content |
OLD | NEW |