| 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 "webkit/media/crypto/ppapi_decryptor.h" | 5 #include "webkit/media/crypto/ppapi_decryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, | 35 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
| 36 const uint8* init_data, | 36 const uint8* init_data, |
| 37 int init_data_length) { | 37 int init_data_length) { |
| 38 DVLOG(1) << "GenerateKeyRequest()"; | 38 DVLOG(1) << "GenerateKeyRequest()"; |
| 39 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 39 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 40 DCHECK(cdm_plugin_); | 40 DCHECK(cdm_plugin_); |
| 41 | 41 |
| 42 // TODO(xhwang): Finalize the data type for |init_data| to avoid unnecessary | 42 // TODO(xhwang): Finalize the data type for |init_data| to avoid unnecessary |
| 43 // data type conversions. | 43 // data type conversions. |
| 44 if (!cdm_plugin_->GenerateKeyRequest( | 44 cdm_plugin_->GenerateKeyRequest( |
| 45 key_system, | 45 key_system, |
| 46 std::string(reinterpret_cast<const char*>(init_data), | 46 std::string(reinterpret_cast<const char*>(init_data), |
| 47 init_data_length))) { | 47 init_data_length)); |
| 48 ReportFailureToCallPlugin(key_system, ""); | |
| 49 return false; | |
| 50 } | |
| 51 | |
| 52 return true; | 48 return true; |
| 53 } | 49 } |
| 54 | 50 |
| 55 void PpapiDecryptor::AddKey(const std::string& key_system, | 51 void PpapiDecryptor::AddKey(const std::string& key_system, |
| 56 const uint8* key, | 52 const uint8* key, |
| 57 int key_length, | 53 int key_length, |
| 58 const uint8* init_data, | 54 const uint8* init_data, |
| 59 int init_data_length, | 55 int init_data_length, |
| 60 const std::string& session_id) { | 56 const std::string& session_id) { |
| 61 DVLOG(1) << "AddKey()"; | 57 DVLOG(1) << "AddKey()"; |
| 62 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 58 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 63 DCHECK(cdm_plugin_); | 59 DCHECK(cdm_plugin_); |
| 64 | 60 |
| 65 if (!cdm_plugin_->AddKey(session_id, | 61 cdm_plugin_->AddKey(session_id, |
| 66 std::string(reinterpret_cast<const char*>(key), | 62 std::string(reinterpret_cast<const char*>(key), |
| 67 key_length), | 63 key_length), |
| 68 std::string(reinterpret_cast<const char*>(init_data), | 64 std::string(reinterpret_cast<const char*>(init_data), |
| 69 init_data_length))) { | 65 init_data_length)); |
| 70 ReportFailureToCallPlugin(key_system, session_id); | |
| 71 } | |
| 72 } | 66 } |
| 73 | 67 |
| 74 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, | 68 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
| 75 const std::string& session_id) { | 69 const std::string& session_id) { |
| 76 DVLOG(1) << "CancelKeyRequest()"; | 70 DVLOG(1) << "CancelKeyRequest()"; |
| 77 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 71 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 78 DCHECK(cdm_plugin_); | 72 DCHECK(cdm_plugin_); |
| 79 | 73 |
| 80 if (!cdm_plugin_->CancelKeyRequest(session_id)) | 74 cdm_plugin_->CancelKeyRequest(session_id); |
| 81 ReportFailureToCallPlugin(key_system, session_id); | |
| 82 } | 75 } |
| 83 | 76 |
| 84 void PpapiDecryptor::Decrypt( | 77 void PpapiDecryptor::Decrypt( |
| 85 const scoped_refptr<media::DecoderBuffer>& encrypted, | 78 const scoped_refptr<media::DecoderBuffer>& encrypted, |
| 86 const DecryptCB& decrypt_cb) { | 79 const DecryptCB& decrypt_cb) { |
| 87 DVLOG(1) << "Decrypt()"; | 80 DVLOG(1) << "Decrypt()"; |
| 88 if (!render_loop_proxy_->BelongsToCurrentThread()) { | 81 if (!render_loop_proxy_->BelongsToCurrentThread()) { |
| 89 render_loop_proxy_->PostTask( | 82 render_loop_proxy_->PostTask( |
| 90 FROM_HERE, | 83 FROM_HERE, |
| 91 base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this), | 84 base::Bind(&PpapiDecryptor::Decrypt, base::Unretained(this), |
| 92 encrypted, decrypt_cb)); | 85 encrypted, decrypt_cb)); |
| 93 return; | 86 return; |
| 94 } | 87 } |
| 95 | 88 |
| 96 if (!cdm_plugin_->Decrypt(encrypted, decrypt_cb)) | 89 cdm_plugin_->Decrypt(encrypted, decrypt_cb); |
| 97 decrypt_cb.Run(kError, NULL); | |
| 98 } | 90 } |
| 99 | 91 |
| 100 void PpapiDecryptor::Stop() { | 92 void PpapiDecryptor::Stop() { |
| 101 } | 93 } |
| 102 | 94 |
| 103 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, | |
| 104 const std::string& session_id) { | |
| 105 DVLOG(1) << "Failed to call plugin."; | |
| 106 client_->KeyError(key_system, session_id, kUnknownError, 0); | |
| 107 } | |
| 108 | |
| 109 } // namespace webkit_media | 95 } // namespace webkit_media |
| OLD | NEW |