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 <cstring> | 5 #include <cstring> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 virtual ~CdmWrapper(); | 491 virtual ~CdmWrapper(); |
| 492 | 492 |
| 493 // pp::Instance implementation. | 493 // pp::Instance implementation. |
| 494 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 494 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 495 return true; | 495 return true; |
| 496 } | 496 } |
| 497 | 497 |
| 498 // PPP_ContentDecryptor_Private implementation. | 498 // PPP_ContentDecryptor_Private implementation. |
| 499 // Note: Results of calls to these methods must be reported through the | 499 // Note: Results of calls to these methods must be reported through the |
| 500 // PPB_ContentDecryptor_Private interface. | 500 // PPB_ContentDecryptor_Private interface. |
| 501 virtual void GenerateKeyRequest(const std::string& key_system, | 501 virtual void Initialize(const std::string& key_system) OVERRIDE; |
| 502 const std::string& type, | 502 virtual void GenerateKeyRequest(const std::string& type, |
| 503 pp::VarArrayBuffer init_data) OVERRIDE; | 503 pp::VarArrayBuffer init_data) OVERRIDE; |
| 504 virtual void AddKey(const std::string& session_id, | 504 virtual void AddKey(const std::string& session_id, |
| 505 pp::VarArrayBuffer key, | 505 pp::VarArrayBuffer key, |
| 506 pp::VarArrayBuffer init_data) OVERRIDE; | 506 pp::VarArrayBuffer init_data) OVERRIDE; |
| 507 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; | 507 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; |
| 508 virtual void Decrypt( | 508 virtual void Decrypt( |
| 509 pp::Buffer_Dev encrypted_buffer, | 509 pp::Buffer_Dev encrypted_buffer, |
| 510 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 510 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
| 511 virtual void InitializeAudioDecoder( | 511 virtual void InitializeAudioDecoder( |
| 512 const PP_AudioDecoderConfig& decoder_config, | 512 const PP_AudioDecoderConfig& decoder_config, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 bool CdmWrapper::CreateCdmInstance(const std::string& key_system) { | 629 bool CdmWrapper::CreateCdmInstance(const std::string& key_system) { |
| 630 PP_DCHECK(!cdm_); | 630 PP_DCHECK(!cdm_); |
| 631 cdm_ = static_cast<cdm::ContentDecryptionModule*>( | 631 cdm_ = static_cast<cdm::ContentDecryptionModule*>( |
| 632 ::CreateCdmInstance(cdm::kCdmInterfaceVersion, | 632 ::CreateCdmInstance(cdm::kCdmInterfaceVersion, |
| 633 key_system.data(), key_system.size(), | 633 key_system.data(), key_system.size(), |
| 634 GetCdmHost, this)); | 634 GetCdmHost, this)); |
| 635 | 635 |
| 636 return (cdm_ != NULL); | 636 return (cdm_ != NULL); |
| 637 } | 637 } |
| 638 | 638 |
| 639 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, | 639 void CdmWrapper::Initialize(const std::string& key_system) { |
| 640 const std::string& type, | |
| 641 pp::VarArrayBuffer init_data) { | |
| 642 PP_DCHECK(!key_system.empty()); | 640 PP_DCHECK(!key_system.empty()); |
| 643 PP_DCHECK(key_system_.empty() || key_system_ == key_system); | 641 PP_DCHECK(key_system_.empty() || key_system_ == key_system); |
|
ddorwin
2013/09/17 23:15:42
Add && cdm_ to the second clause?
jrummell
2013/09/18 21:01:15
Done.
| |
| 644 | 642 |
| 643 if (!cdm_) { | |
| 644 if (!CreateCdmInstance(key_system)) { | |
| 645 SendUnknownKeyError(key_system, std::string()); | |
|
ddorwin
2013/09/17 23:15:42
TODO: Confirm we should fire a keyerror here.
jrummell
2013/09/18 21:01:15
Done.
| |
| 646 return; | |
| 647 } | |
| 648 } | |
| 649 PP_DCHECK(cdm_); | |
| 650 key_system_ = key_system; | |
| 651 } | |
| 652 | |
| 653 void CdmWrapper::GenerateKeyRequest(const std::string& type, | |
| 654 pp::VarArrayBuffer init_data) { | |
| 655 | |
|
ddorwin
2013/09/17 23:15:42
remove extra line
jrummell
2013/09/18 21:01:15
Done.
| |
| 645 #if defined(CHECK_DOCUMENT_URL) | 656 #if defined(CHECK_DOCUMENT_URL) |
| 646 PP_URLComponents_Dev url_components = {}; | 657 PP_URLComponents_Dev url_components = {}; |
| 647 pp::Var href = pp::URLUtil_Dev::Get()->GetDocumentURL( | 658 pp::Var href = pp::URLUtil_Dev::Get()->GetDocumentURL( |
| 648 pp::InstanceHandle(pp_instance()), &url_components); | 659 pp::InstanceHandle(pp_instance()), &url_components); |
| 649 PP_DCHECK(href.is_string()); | 660 PP_DCHECK(href.is_string()); |
| 650 PP_DCHECK(!href.AsString().empty()); | 661 PP_DCHECK(!href.AsString().empty()); |
| 651 PP_DCHECK(url_components.host.begin); | 662 PP_DCHECK(url_components.host.begin); |
| 652 PP_DCHECK(0 < url_components.host.len); | 663 PP_DCHECK(0 < url_components.host.len); |
| 653 #endif // defined(CHECK_DOCUMENT_URL) | 664 #endif // defined(CHECK_DOCUMENT_URL) |
| 654 | 665 |
| 655 if (!cdm_) { | |
| 656 if (!CreateCdmInstance(key_system)) { | |
| 657 SendUnknownKeyError(key_system, std::string()); | |
| 658 return; | |
| 659 } | |
| 660 } | |
| 661 PP_DCHECK(cdm_); | 666 PP_DCHECK(cdm_); |
| 662 | 667 |
|
ddorwin
2013/09/17 23:15:42
remove line
jrummell
2013/09/18 21:01:15
Done.
| |
| 663 // Must be set here in case the CDM synchronously calls a cdm::Host method. | |
| 664 // Clear below on error. | |
| 665 // TODO(ddorwin): Set/clear key_system_ & cdm_ at same time; clear both on | |
| 666 // error below. | |
| 667 key_system_ = key_system; | |
| 668 cdm::Status status = cdm_->GenerateKeyRequest( | 668 cdm::Status status = cdm_->GenerateKeyRequest( |
| 669 type.data(), type.size(), | 669 type.data(), type.size(), |
| 670 static_cast<const uint8_t*>(init_data.Map()), | 670 static_cast<const uint8_t*>(init_data.Map()), |
| 671 init_data.ByteLength()); | 671 init_data.ByteLength()); |
| 672 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 672 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
| 673 if (status != cdm::kSuccess) { | |
| 674 key_system_.clear(); // See comment above. | |
| 675 return; | |
| 676 } | |
| 677 | |
| 678 key_system_ = key_system; | |
| 679 } | 673 } |
| 680 | 674 |
| 681 void CdmWrapper::AddKey(const std::string& session_id, | 675 void CdmWrapper::AddKey(const std::string& session_id, |
| 682 pp::VarArrayBuffer key, | 676 pp::VarArrayBuffer key, |
| 683 pp::VarArrayBuffer init_data) { | 677 pp::VarArrayBuffer init_data) { |
| 684 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. | 678 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. |
| 685 if (!cdm_) { | 679 if (!cdm_) { |
| 686 SendUnknownKeyError(key_system_, session_id); | 680 SendUnknownKeyError(key_system_, session_id); |
| 687 return; | 681 return; |
| 688 } | 682 } |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 } // namespace media | 1183 } // namespace media |
| 1190 | 1184 |
| 1191 namespace pp { | 1185 namespace pp { |
| 1192 | 1186 |
| 1193 // Factory function for your specialization of the Module object. | 1187 // Factory function for your specialization of the Module object. |
| 1194 Module* CreateModule() { | 1188 Module* CreateModule() { |
| 1195 return new media::CdmWrapperModule(); | 1189 return new media::CdmWrapperModule(); |
| 1196 } | 1190 } |
| 1197 | 1191 |
| 1198 } // namespace pp | 1192 } // namespace pp |
| OLD | NEW |