| 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 "webkit/renderer/media/crypto/ppapi_decryptor.h" | 5 #include "webkit/renderer/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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 22 | 22 |
| 23 namespace webkit_media { | 23 namespace webkit_media { |
| 24 | 24 |
| 25 scoped_ptr<webkit_media::PpapiDecryptor> PpapiDecryptor::Create( | 25 scoped_ptr<webkit_media::PpapiDecryptor> PpapiDecryptor::Create( |
| 26 const std::string& key_system, | 26 const std::string& key_system, |
| 27 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, | 27 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, |
| 28 const media::KeyAddedCB& key_added_cb, | 28 const media::KeyAddedCB& key_added_cb, |
| 29 const media::KeyErrorCB& key_error_cb, | 29 const media::KeyErrorCB& key_error_cb, |
| 30 const media::KeyMessageCB& key_message_cb, | 30 const media::KeyMessageCB& key_message_cb, |
| 31 const media::NeedKeyCB& need_key_cb, | |
| 32 const base::Closure& destroy_plugin_cb) { | 31 const base::Closure& destroy_plugin_cb) { |
| 33 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate = | 32 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate = |
| 34 plugin_instance->GetContentDecryptorDelegate(); | 33 plugin_instance->GetContentDecryptorDelegate(); |
| 35 if (!plugin_cdm_delegate) { | 34 if (!plugin_cdm_delegate) { |
| 36 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed."; | 35 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed."; |
| 37 return scoped_ptr<webkit_media::PpapiDecryptor>(); | 36 return scoped_ptr<webkit_media::PpapiDecryptor>(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 plugin_cdm_delegate->Initialize(key_system); | 39 plugin_cdm_delegate->Initialize(key_system); |
| 41 | 40 |
| 42 return scoped_ptr<webkit_media::PpapiDecryptor>( | 41 return scoped_ptr<webkit_media::PpapiDecryptor>( |
| 43 new PpapiDecryptor(plugin_instance, | 42 new PpapiDecryptor(plugin_instance, |
| 44 plugin_cdm_delegate, | 43 plugin_cdm_delegate, |
| 45 key_added_cb, | 44 key_added_cb, |
| 46 key_error_cb, | 45 key_error_cb, |
| 47 key_message_cb, | 46 key_message_cb, |
| 48 need_key_cb, | |
| 49 destroy_plugin_cb)); | 47 destroy_plugin_cb)); |
| 50 } | 48 } |
| 51 | 49 |
| 52 PpapiDecryptor::PpapiDecryptor( | 50 PpapiDecryptor::PpapiDecryptor( |
| 53 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, | 51 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, |
| 54 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate, | 52 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate, |
| 55 const media::KeyAddedCB& key_added_cb, | 53 const media::KeyAddedCB& key_added_cb, |
| 56 const media::KeyErrorCB& key_error_cb, | 54 const media::KeyErrorCB& key_error_cb, |
| 57 const media::KeyMessageCB& key_message_cb, | 55 const media::KeyMessageCB& key_message_cb, |
| 58 const media::NeedKeyCB& need_key_cb, | |
| 59 const base::Closure& destroy_plugin_cb) | 56 const base::Closure& destroy_plugin_cb) |
| 60 : plugin_instance_(plugin_instance), | 57 : plugin_instance_(plugin_instance), |
| 61 plugin_cdm_delegate_(plugin_cdm_delegate), | 58 plugin_cdm_delegate_(plugin_cdm_delegate), |
| 62 key_added_cb_(key_added_cb), | 59 key_added_cb_(key_added_cb), |
| 63 key_error_cb_(key_error_cb), | 60 key_error_cb_(key_error_cb), |
| 64 key_message_cb_(key_message_cb), | 61 key_message_cb_(key_message_cb), |
| 65 need_key_cb_(need_key_cb), | |
| 66 destroy_plugin_cb_(destroy_plugin_cb), | 62 destroy_plugin_cb_(destroy_plugin_cb), |
| 67 render_loop_proxy_(base::MessageLoopProxy::current()), | 63 render_loop_proxy_(base::MessageLoopProxy::current()), |
| 68 weak_ptr_factory_(this), | 64 weak_ptr_factory_(this), |
| 69 weak_this_(weak_ptr_factory_.GetWeakPtr()) { | 65 weak_this_(weak_ptr_factory_.GetWeakPtr()) { |
| 70 DCHECK(plugin_instance_.get()); | 66 DCHECK(plugin_instance_.get()); |
| 71 | 67 |
| 72 plugin_cdm_delegate_->SetKeyEventCallbacks( | 68 plugin_cdm_delegate_->SetKeyEventCallbacks( |
| 73 base::Bind(&PpapiDecryptor::KeyAdded, weak_this_), | 69 base::Bind(&PpapiDecryptor::KeyAdded, weak_this_), |
| 74 base::Bind(&PpapiDecryptor::KeyError, weak_this_), | 70 base::Bind(&PpapiDecryptor::KeyError, weak_this_), |
| 75 base::Bind(&PpapiDecryptor::KeyMessage, weak_this_), | 71 base::Bind(&PpapiDecryptor::KeyMessage, weak_this_)); |
| 76 base::Bind(&PpapiDecryptor::NeedKey, weak_this_)); | |
| 77 } | 72 } |
| 78 | 73 |
| 79 PpapiDecryptor::~PpapiDecryptor() { | 74 PpapiDecryptor::~PpapiDecryptor() { |
| 80 plugin_cdm_delegate_ = NULL; | 75 plugin_cdm_delegate_ = NULL; |
| 81 plugin_instance_ = NULL; | 76 plugin_instance_ = NULL; |
| 82 destroy_plugin_cb_.Run(); | 77 destroy_plugin_cb_.Run(); |
| 83 } | 78 } |
| 84 | 79 |
| 85 bool PpapiDecryptor::GenerateKeyRequest(const std::string& type, | 80 bool PpapiDecryptor::GenerateKeyRequest(const std::string& type, |
| 86 const uint8* init_data, | 81 const uint8* init_data, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 key_error_cb_.Run(session_id, error_code, system_code); | 287 key_error_cb_.Run(session_id, error_code, system_code); |
| 293 } | 288 } |
| 294 | 289 |
| 295 void PpapiDecryptor::KeyMessage(const std::string& session_id, | 290 void PpapiDecryptor::KeyMessage(const std::string& session_id, |
| 296 const std::string& message, | 291 const std::string& message, |
| 297 const std::string& default_url) { | 292 const std::string& default_url) { |
| 298 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 293 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 299 key_message_cb_.Run(session_id, message, default_url); | 294 key_message_cb_.Run(session_id, message, default_url); |
| 300 } | 295 } |
| 301 | 296 |
| 302 void PpapiDecryptor::NeedKey(const std::string& session_id, | |
| 303 const std::string& type, | |
| 304 scoped_ptr<uint8[]> init_data, | |
| 305 int init_data_size) { | |
| 306 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | |
| 307 need_key_cb_.Run(session_id, type, init_data.Pass(), init_data_size); | |
| 308 } | |
| 309 | |
| 310 } // namespace webkit_media | 297 } // namespace webkit_media |
| OLD | NEW |