Chromium Code Reviews| Index: webkit/media/crypto/ppapi_decryptor.cc |
| diff --git a/webkit/media/crypto/ppapi_decryptor.cc b/webkit/media/crypto/ppapi_decryptor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aa664c182ee36da1747b45df34099a10a869ee08 |
| --- /dev/null |
| +++ b/webkit/media/crypto/ppapi_decryptor.cc |
| @@ -0,0 +1,113 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "webkit/media/crypto/ppapi_decryptor.h" |
| + |
| +#include "base/logging.h" |
| +#include "media/base/decoder_buffer.h" |
| +#include "media/base/decryptor_client.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| +#include "webkit/media/crypto/key_systems.h" |
| +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| +#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
| + |
| +namespace webkit_media { |
| + |
| +static scoped_refptr<webkit::ppapi::PluginInstance> CreatePluginInstance( |
| + const std::string& plugin_type, |
| + WebKit::WebMediaPlayerClient* web_media_player_client, |
| + WebKit::WebFrame* web_frame) { |
| + DCHECK(web_media_player_client); |
| + DCHECK(web_frame); |
| + |
| + WebKit::WebPlugin* web_plugin = web_media_player_client->createHelperPlugin( |
| + WebKit::WebString::fromUTF8(plugin_type), web_frame); |
| + if (!web_plugin) |
| + return NULL; |
| + |
| + DCHECK(!web_plugin->isPlaceholder()); // Prevented by WebKit. |
| + // Only Pepper plugins are supported, so it must be a ppapi object. |
| + webkit::ppapi::WebPluginImpl* ppapi_plugin = |
| + static_cast<webkit::ppapi::WebPluginImpl*>(web_plugin); |
| + return scoped_refptr<webkit::ppapi::PluginInstance>(ppapi_plugin->instance()); |
| +} |
| + |
| +PpapiDecryptor::PpapiDecryptor(media::DecryptorClient* client) |
| + : client_(client) { |
| +} |
| + |
| +PpapiDecryptor::~PpapiDecryptor() { |
| +} |
| + |
| +bool PpapiDecryptor::Init(const std::string& key_system, |
| + WebKit::WebMediaPlayerClient* web_media_player_client, |
| + WebKit::WebFrame* web_frame) { |
| + const char* plugin_type = GetPluginType(key_system); |
| + DCHECK(plugin_type); |
| + cdm_plugin_ = CreatePluginInstance(plugin_type, |
| + web_media_player_client, web_frame); |
| + if (!cdm_plugin_) { |
| + DVLOG(1) << "PpapiDecryptor: plugin instance creation failed."; |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +void PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
| + const uint8* init_data, |
| + int init_data_length) { |
| + DCHECK(cdm_plugin_); |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + // if (!cdm_plugin_->GenerateKeyRequest(key_system, |
| + // init_data, init_data_length)) { |
| + // client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
| + // } |
| +} |
| + |
| +void PpapiDecryptor::AddKey(const std::string& key_system, |
| + const uint8* key, |
| + int key_length, |
| + const uint8* init_data, |
| + int init_data_length, |
| + const std::string& session_id) { |
| + DCHECK(cdm_plugin_); |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + // if (!cdm_plugin_->AddKey(key_system, key, key_length, |
| + // init_data, init_data_length, session_id)) { |
| + // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
| + // } |
| +} |
| + |
| +void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
| + const std::string& session_id) { |
| + DCHECK(cdm_plugin_); |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + // if (!cdm_plugin_->CancelKeyRequest(key_system, session_id)) |
| + // client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0); |
| +} |
| + |
| +void PpapiDecryptor::Decrypt( |
| + const scoped_refptr<media::DecoderBuffer>& encrypted, |
| + const DecryptCB& decrypt_cb) { |
| + DCHECK(cdm_plugin_); |
| + // TODO(xhwang): Enable the following once we have updated PluginInstance. |
| + // TODO(xhwang): Need to figure out thread safety about PPP calls. |
| + // if (!cdm_plugin_->Decrypt( |
| + // encrypted, base::Bind(&PpapiDecryptor::DataReady, this, decrypt_cb))) { |
| + // decrypt_cb.Run(kError, NULL); |
| + // } |
| +} |
| + |
| +void PpapiDecryptor::DataReady(const DecryptCB& decrypt_cb, |
| + const uint8* data, int data_size ) { |
| + DCHECK(!decrypt_cb.is_null()); |
| + scoped_refptr<media::DecoderBuffer> decrypted_data = |
| + media::DecoderBuffer::CopyFrom(data, data_size); |
| + decrypt_cb.Run(kSuccess, decrypted_data); |
| +} |
| + |
|
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
|
| +} // namespace webkit_media |