| Index: webkit/plugins/ppapi/ppapi_plugin_instance.cc
|
| diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
|
| index b711c8c3cdd8aef77064dc811f45bbb2313f10b1..035793e410be58f5ec6e8965e75c7639b01c8370 100644
|
| --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
|
| +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
|
| @@ -4,15 +4,21 @@
|
|
|
| #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
|
|
|
| +#include <utility>
|
| +
|
| #include "base/bind.h"
|
| #include "base/debug/trace_event.h"
|
| #include "base/logging.h"
|
| #include "base/memory/linked_ptr.h"
|
| #include "base/message_loop.h"
|
| +#include "base/stl_util.h"
|
| #include "base/stringprintf.h"
|
| #include "base/time.h"
|
| #include "base/utf_offset_string_conversions.h"
|
| #include "base/utf_string_conversions.h"
|
| +#include "media/base/decoder_buffer.h"
|
| +#include "media/base/decryptor_client.h"
|
| +#include "ppapi/c/dev/pp_decryption_buffer_dev.h"
|
| #include "ppapi/c/dev/ppb_find_dev.h"
|
| #include "ppapi/c/dev/ppb_zoom_dev.h"
|
| #include "ppapi/c/dev/ppp_find_dev.h"
|
| @@ -30,6 +36,7 @@
|
| #include "ppapi/c/private/ppp_instance_private.h"
|
| #include "ppapi/shared_impl/ppb_input_event_shared.h"
|
| #include "ppapi/shared_impl/ppb_url_util_shared.h"
|
| +#include "ppapi/shared_impl/ppb_var_shared.h"
|
| #include "ppapi/shared_impl/ppb_view_shared.h"
|
| #include "ppapi/shared_impl/ppp_instance_combined.h"
|
| #include "ppapi/shared_impl/resource.h"
|
| @@ -298,11 +305,11 @@ scoped_array<const char*> StringVectorToArgArray(
|
| // buffer resource, and returns it. Returns a PP_Resource equal to 0 on
|
| // failure.
|
| PP_Resource MakeBufferResource(PP_Instance instance,
|
| - const std::string& data) {
|
| - if (data.empty())
|
| + const char* data, size_t size) {
|
| + if (!data)
|
| return 0;
|
|
|
| - ScopedPPResource resource(PPB_Buffer_Impl::Create(instance, data.size()));
|
| + ScopedPPResource resource(PPB_Buffer_Impl::Create(instance, size));
|
| if (!resource.get())
|
| return 0;
|
|
|
| @@ -311,9 +318,9 @@ PP_Resource MakeBufferResource(PP_Instance instance,
|
| return 0;
|
|
|
| BufferAutoMapper mapper(enter.object());
|
| - if (!mapper.data() || mapper.size() < data.size())
|
| + if (!mapper.data() || mapper.size() < size)
|
| return 0;
|
| - memcpy(mapper.data(), data.data(), data.size());
|
| + memcpy(mapper.data(), data, size);
|
|
|
| // Add the resource to the tracker...
|
| // TODO(tomfinegan): wild guess/no idea if this is right.
|
| @@ -380,7 +387,9 @@ PluginInstance::PluginInstance(
|
| selection_caret_(0),
|
| selection_anchor_(0),
|
| pending_user_gesture_(0.0),
|
| - flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| + flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| + decryptor_client_(NULL),
|
| + next_decryption_buffer_id_(0) {
|
| pp_instance_ = HostGlobals::Get()->AddInstance(this);
|
|
|
| memset(¤t_print_settings_, 0, sizeof(current_print_settings_));
|
| @@ -1317,6 +1326,12 @@ void PluginInstance::RotateView(WebPlugin::RotationType type) {
|
| // NOTE: plugin instance may have been deleted.
|
| }
|
|
|
| +void PluginInstance::SetDecryptClient(
|
| + media::DecryptorClient* decryptor_client) {
|
| + DCHECK(decryptor_client);
|
| + decryptor_client_ = decryptor_client;
|
| +}
|
| +
|
| bool PluginInstance::GenerateKeyRequest(const std::string& key_system,
|
| const std::string& init_data) {
|
| if (!LoadContentDecryptionModuleInterface())
|
| @@ -1329,7 +1344,8 @@ bool PluginInstance::GenerateKeyRequest(const std::string& key_system,
|
| if (init_data.size()) {
|
| ScopedPPResource local_init_data(ScopedPPResource::PassRef(),
|
| MakeBufferResource(pp_instance(),
|
| - init_data));
|
| + init_data.data(),
|
| + init_data.size()));
|
|
|
| if (!local_init_data.get())
|
| return false;
|
| @@ -1352,7 +1368,9 @@ bool PluginInstance::AddKey(const std::string& session_id,
|
| return false;
|
|
|
| ScopedPPResource key_resource(ScopedPPResource::PassRef(),
|
| - MakeBufferResource(pp_instance(), key));
|
| + MakeBufferResource(pp_instance(),
|
| + key.data(),
|
| + key.size()));
|
| if (!key_resource.get())
|
| return false;
|
|
|
| @@ -1373,30 +1391,52 @@ bool PluginInstance::CancelKeyRequest(const std::string& session_id) {
|
| session_id_var.GetPPVar()));
|
| }
|
|
|
| -bool PluginInstance::Decrypt(const std::string& encrypted_block,
|
| - const CDMStatusCB& callback) {
|
| +bool PluginInstance::Decrypt(
|
| + const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
|
| + const CDMStatusCB& callback) {
|
| if (!LoadContentDecryptionModuleInterface())
|
| return false;
|
| - ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(),
|
| - MakeBufferResource(pp_instance(),
|
| - encrypted_block));
|
| +
|
| + DCHECK(encrypted_buffer->GetDecryptConfig());
|
| + DCHECK(encrypted_buffer->GetData());
|
| + DCHECK_GT(encrypted_buffer->GetDataSize(), 0);
|
| + ScopedPPResource encrypted_resource(
|
| + ScopedPPResource::PassRef(),
|
| + MakeBufferResource(
|
| + pp_instance(),
|
| + reinterpret_cast<const char*>(encrypted_buffer->GetData()),
|
| + encrypted_buffer->GetDataSize()));
|
| +
|
| if (!encrypted_resource.get())
|
| return false;
|
| // TODO(tomfinegan): wrap callback in PP_CompletionCallback and pass it to
|
| // the plugin.
|
| - PP_CompletionCallback pp_callback = {NULL, NULL, 0};
|
| +
|
| + const media::DecryptConfig& decrypt_config =
|
| + *encrypted_buffer->GetDecryptConfig();
|
| +
|
| + uint64_t buffer_id = next_decryption_buffer_id_++;
|
| + DCHECK(!ContainsKey(cdm_status_cb_map_, buffer_id));
|
| + cdm_status_cb_map_.insert(std::make_pair(buffer_id, callback));
|
| +
|
| + PP_DecryptionBuffer_Dev buffer;
|
| + buffer.data = encrypted_resource;
|
| + buffer.data_offset = decrypt_config.data_offset();
|
| + buffer.id = buffer_id;
|
| + // TODO(xhwang): Fill all fields here.
|
| +
|
| return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(),
|
| - encrypted_resource,
|
| - pp_callback));
|
| + &buffer));
|
| }
|
|
|
| bool PluginInstance::DecryptAndDecode(const std::string& encrypted_block,
|
| const CDMStatusCB& callback) {
|
| if (!LoadContentDecryptionModuleInterface())
|
| return false;
|
| - ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(),
|
| - MakeBufferResource(pp_instance(),
|
| - encrypted_block));
|
| + ScopedPPResource encrypted_resource(
|
| + ScopedPPResource::PassRef(),
|
| + MakeBufferResource(pp_instance(),
|
| + encrypted_block.data(), encrypted_block.size()));
|
| if (!encrypted_resource.get())
|
| return false;
|
| // TODO(tomfinegan): wrap callback in PP_CompletionCallback and pass it to
|
| @@ -2013,8 +2053,8 @@ void PluginInstance::NeedKey(PP_Instance instance,
|
| PP_Var key_system_var,
|
| PP_Var session_id_var,
|
| PP_Resource init_data) {
|
| - StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
|
| - StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
|
| + //StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
|
| + //StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
|
|
|
| // TODO(tomfinegan): Where does the call to this method come from? Or, where
|
| // does it go for handling. I need to read more of the EME proposed spec, but
|
| @@ -2032,6 +2072,8 @@ void PluginInstance::NeedKey(PP_Instance instance,
|
| void PluginInstance::KeyAdded(PP_Instance instance,
|
| PP_Var key_system,
|
| PP_Var session_id) {
|
| + DCHECK(decryptor_client_);
|
| +
|
| }
|
|
|
| void PluginInstance::KeyMessage(PP_Instance instance,
|
| @@ -2069,6 +2111,16 @@ void PluginInstance::KeyMessage(PP_Instance instance,
|
| return;
|
| }
|
|
|
| + DCHECK(decryptor_client_);
|
| + scoped_array<uint8> message_array(new uint8[message.size()]);
|
| + memcpy(message_array.get(), message.data(), message.size());
|
| +
|
| + decryptor_client_->KeyMessage(key_system_string->value(),
|
| + session_id_string->value(),
|
| + message_array.Pass(),
|
| + message.size(),
|
| + default_url_string->value());
|
| +
|
| // Release the PP_Vars.
|
| HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
|
| HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
|
| @@ -2084,8 +2136,8 @@ void PluginInstance::KeyError(PP_Instance instance,
|
| PP_Var session_id_var,
|
| uint16_t media_error,
|
| uint16_t system_error) {
|
| - StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
|
| - StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
|
| + //StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
|
| + //StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
|
|
|
| HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
|
| HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
|
| @@ -2093,11 +2145,23 @@ void PluginInstance::KeyError(PP_Instance instance,
|
|
|
| void PluginInstance::DeliverBlock(PP_Instance instance,
|
| PP_Resource decrypted_block,
|
| - PP_CompletionCallback callback) {
|
| + uint32_t id) {
|
| // TODO(tomfinegan): Determine where |decrypted_block| goes, and what
|
| // callback actually is (callback will likely be the result of some
|
| // base::Bind usage in the media stack. Hash this out with xhwang.
|
| //
|
| +
|
| + std::map<uint64_t, CDMStatusCB>::iterator found = cdm_status_cb_map_.find(id);
|
| + if (found != cdm_status_cb_map_.end()) {
|
| + DVLOG(3) << "DeliverBlock(): Buffer ID " << id << " found, callback fired.";
|
| + found->second.Run(NULL, 0);
|
| + cdm_status_cb_map_.erase(found);
|
| + }
|
| + else {
|
| + DVLOG(3) << "DeliverBlock(): Buffer ID " << id << " not found.";
|
| + NOTREACHED();
|
| + }
|
| +
|
| HostGlobals::Get()->GetResourceTracker()->ReleaseResource(decrypted_block);
|
| }
|
|
|
|
|