Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/media/crypto/ppapi_decryptor.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "media/base/decoder_buffer.h" | |
| 9 #include "media/base/decryptor_client.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
| 13 #include "webkit/media/crypto/key_systems.h" | |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
| 15 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | |
| 16 | |
| 17 namespace webkit_media { | |
| 18 | |
| 19 static scoped_refptr<webkit::ppapi::PluginInstance> CreatePluginInstance( | |
| 20 const std::string& plugin_type, | |
| 21 WebKit::WebMediaPlayerClient* web_media_player_client, | |
| 22 WebKit::WebFrame* web_frame) { | |
| 23 DCHECK(web_media_player_client); | |
| 24 DCHECK(web_frame); | |
| 25 | |
| 26 WebKit::WebPlugin* web_plugin = web_media_player_client->createHelperPlugin( | |
| 27 WebKit::WebString::fromUTF8(plugin_type), web_frame); | |
| 28 if (!web_plugin) | |
| 29 return NULL; | |
| 30 | |
| 31 DCHECK(!web_plugin->isPlaceholder()); // Prevented by WebKit. | |
| 32 // Only Pepper plugins are supported, so it must be a ppapi object. | |
| 33 webkit::ppapi::WebPluginImpl* ppapi_plugin = | |
| 34 static_cast<webkit::ppapi::WebPluginImpl*>(web_plugin); | |
| 35 return scoped_refptr<webkit::ppapi::PluginInstance>(ppapi_plugin->instance()); | |
| 36 } | |
| 37 | |
| 38 PpapiDecryptor::PpapiDecryptor(media::DecryptorClient* client) | |
| 39 : client_(client) { | |
| 40 } | |
| 41 | |
| 42 PpapiDecryptor::~PpapiDecryptor() { | |
| 43 } | |
| 44 | |
| 45 bool PpapiDecryptor::Init(const std::string& key_system, | |
| 46 WebKit::WebMediaPlayerClient* web_media_player_client, | |
| 47 WebKit::WebFrame* web_frame) { | |
| 48 const char* plugin_type = GetPluginType(key_system); | |
| 49 DCHECK(plugin_type); | |
| 50 cdm_plugin_ = CreatePluginInstance(plugin_type, | |
| 51 web_media_player_client, web_frame); | |
| 52 if (!cdm_plugin_) { | |
| 53 DVLOG(1) << "PpapiDecryptor: plugin instance creation failed."; | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, | |
| 61 const uint8* init_data, | |
| 62 int init_data_length) { | |
| 63 DCHECK(cdm_plugin_); | |
| 64 // TODO(xhwang): Enable the following once we have updated PluginInstance. | |
| 65 // if (!cdm_plugin_->GenerateKeyRequest(key_system, | |
| 66 // init_data, init_data_length)) { | |
| 67 // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); | |
| 68 // } | |
| 69 } | |
| 70 | |
| 71 void PpapiDecryptor::AddKey(const std::string& key_system, | |
| 72 const uint8* key, | |
| 73 int key_length, | |
| 74 const uint8* init_data, | |
| 75 int init_data_length, | |
| 76 const std::string& session_id) { | |
| 77 DCHECK(cdm_plugin_); | |
| 78 // TODO(xhwang): Enable the following once we have updated PluginInstance. | |
| 79 // if (!cdm_plugin_->AddKey(key_system, key, key_length, | |
| 80 // init_data, init_data_length, session_id)) { | |
| 81 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); | |
| 82 // } | |
| 83 } | |
| 84 | |
| 85 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, | |
| 86 const std::string& session_id) { | |
| 87 DCHECK(cdm_plugin_); | |
| 88 // TODO(xhwang): Enable the following once we have updated PluginInstance. | |
| 89 // if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) | |
| 90 // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); | |
| 91 } | |
| 92 | |
| 93 void PpapiDecryptor::Decrypt( | |
| 94 const scoped_refptr<media::DecoderBuffer>& encrypted, | |
| 95 const DecryptCB& decrypt_cb) { | |
| 96 DCHECK(cdm_plugin_); | |
| 97 // TODO(xhwang): Enable the following once we have updated PluginInstance. | |
| 98 // TODO(xhwang): Need to figure out thread safety about PPP calls. | |
| 99 // if (!cdm_plugin_->Decrypt( | |
| 100 // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { | |
| 101 // decrypt_cb.Run(kError, NULL); | |
| 102 // } | |
| 103 } | |
| 104 | |
| 105 void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, | |
| 106 const uint8* data, int data_size ) { | |
| 107 DCHECK(!decrypt_cb.is_null()); | |
| 108 scoped_refptr<media::DecoderBuffer> decrypted_data = | |
| 109 media::DecoderBuffer::CopyFrom(data, data_size); | |
| 110 decrypt_cb.Run(kSuccess, decrypted_data); | |
| 111 } | |
| 112 | |
|
ddorwin
2012/07/19 01:12:34
Do we need KeyMessage, etc. here too?
xhwang
2012/07/19 15:54:34
Are we going to pass those KeyMessage etc into the
ddorwin
2012/07/19 20:50:09
SG, but we have to wrap that in this class, right?
xhwang
2012/07/19 21:54:03
I didn't pass it in anywhere because I don't know
| |
| 113 } // namespace webkit_media | |
| OLD | NEW |