Chromium Code Reviews| Index: ppapi/proxy/ppp_content_decryptor_proxy.cc |
| diff --git a/ppapi/proxy/ppp_content_decryptor_proxy.cc b/ppapi/proxy/ppp_content_decryptor_proxy.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9c1f54a5a9e31714ee900be90980782b9e8bf89f |
| --- /dev/null |
| +++ b/ppapi/proxy/ppp_content_decryptor_proxy.cc |
| @@ -0,0 +1,226 @@ |
| +// 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 "ppapi/proxy/ppp_content_decryptor_proxy.h" |
| + |
| +#include "ppapi/c/pp_bool.h" |
| +#include "ppapi/proxy/host_dispatcher.h" |
| +#include "ppapi/proxy/plugin_globals.h" |
| +#include "ppapi/proxy/plugin_resource_tracker.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/proxy/serialized_var.h" |
| +#include "ppapi/thunk/enter.h" |
| +#include "ppapi/thunk/ppb_instance_api.h" |
| +#include "ppapi/thunk/thunk.h" |
| + |
| +using ppapi::thunk::PPB_Instance_API; |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +namespace { |
| + |
| +PP_Bool GenerateKeyRequest(PP_Instance instance, |
| + PP_Var key_system, |
| + PP_Var init_data) { |
| + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| + if (!dispatcher) { |
| + // TODO(tomfinegan): NOTREACHED safe here/throughout? |
|
dmichael (off chromium)
2012/08/08 22:24:02
Should be fine. If the dispatcher's not there, we'
|
| + return PP_FALSE; |
| + } |
| + |
| + return PP_FromBool(dispatcher->Send( |
| + new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( |
| + API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| + instance, |
| + SerializedVarSendInput(dispatcher, key_system), |
| + SerializedVarSendInput(dispatcher, init_data)))); |
| +} |
| + |
| +PP_Bool AddKey(PP_Instance instance, |
| + PP_Var session_id, |
| + PP_Var key) { |
| + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| + if (!dispatcher) { |
| + return PP_FALSE; |
| + } |
| + |
| + return PP_FromBool(dispatcher->Send( |
| + new PpapiMsg_PPPContentDecryptor_AddKey( |
| + API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| + instance, |
| + SerializedVarSendInput(dispatcher, session_id), |
| + SerializedVarSendInput(dispatcher, key)))); |
| +} |
| + |
| +PP_Bool CancelKeyRequest(PP_Instance instance, PP_Var session_id) { |
| + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| + if (!dispatcher) { |
| + return PP_FALSE; |
| + } |
| + |
| + return PP_FromBool(dispatcher->Send( |
| + new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( |
| + API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| + instance, |
| + SerializedVarSendInput(dispatcher, session_id)))); |
| +} |
| + |
| +PP_Bool Decrypt(PP_Instance instance, |
| + PP_Resource encrypted_block, |
| + uint64_t request_id) { |
| + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| + if (!dispatcher) { |
| + return PP_FALSE; |
| + } |
| + |
| + HostResource host_resource; |
| + host_resource.SetHostResource(instance, encrypted_block); |
| + |
| + return PP_FromBool(dispatcher->Send( |
| + new PpapiMsg_PPPContentDecryptor_Decrypt( |
| + API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| + instance, |
| + host_resource, |
| + request_id))); |
| +} |
| + |
| +PP_Bool DecryptAndDecode(PP_Instance instance, |
| + PP_Resource encrypted_block, |
| + uint64_t request_id) { |
| + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| + if (!dispatcher) { |
| + return PP_FALSE; |
| + } |
| + |
| + HostResource host_resource; |
| + host_resource.SetHostResource(instance, encrypted_block); |
| + |
| + return PP_FromBool(dispatcher->Send( |
| + new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( |
| + API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| + instance, |
| + host_resource, |
| + request_id))); |
| +} |
| + |
| +static const PPP_ContentDecryptor_Dev content_decryptor_interface = { |
| + &GenerateKeyRequest, |
| + &AddKey, |
| + &CancelKeyRequest, |
| + &Decrypt, |
| + &DecryptAndDecode |
| +}; |
| + |
| +InterfaceProxy* CreateContentDecryptorPPPProxy(Dispatcher* dispatcher) { |
| + return new PPP_ContentDecryptor_Proxy(dispatcher); |
| +} |
| + |
| +} // namespace |
| + |
| +PPP_ContentDecryptor_Proxy::PPP_ContentDecryptor_Proxy(Dispatcher* dispatcher) |
| + : InterfaceProxy(dispatcher), |
| + ppp_decryptor_impl_(NULL) { |
| + if (dispatcher->IsPlugin()) { |
| + ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Dev*>( |
| + dispatcher->local_get_interface()(PPP_CONTENTDECRYPTOR_DEV_INTERFACE)); |
|
dmichael (off chromium)
2012/08/08 22:24:02
As mentioned elsewhere, you should instead be gett
|
| + } |
| +} |
| + |
| +PPP_ContentDecryptor_Proxy::~PPP_ContentDecryptor_Proxy() { |
| +} |
| + |
| +// static |
| +const InterfaceProxy::Info* PPP_ContentDecryptor_Proxy::GetInfo() { |
| + static const Info info = { |
| + &content_decryptor_interface, |
| + PPP_CONTENTDECRYPTOR_DEV_INTERFACE, |
| + API_ID_PPP_VIDEO_DECODER_DEV, |
| + false, |
| + &CreateContentDecryptorPPPProxy, |
| + }; |
| + return &info; |
| +} |
| + |
| +bool PPP_ContentDecryptor_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Proxy, msg) |
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, |
| + OnPluginMsgGenerateKeyRequest) |
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, |
| + OnPluginMsgAddKey) |
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest, |
| + OnPluginMsgCancelKeyRequest) |
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, |
| + OnPluginMsgDecrypt) |
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode, |
| + OnPluginMsgDecryptAndDecode) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + DCHECK(handled); |
| + return handled; |
| +} |
| + |
| +void PPP_ContentDecryptor_Proxy::OnPluginMsgGenerateKeyRequest( |
| + PP_Instance instance, |
| + SerializedVarReceiveInput key_system, |
| + SerializedVarReceiveInput init_data) { |
| + if (ppp_decryptor_impl_) { |
| + // TODO(tomfinegan): |
| + // 1) Is CallWhileUnlocked necessary here/throughout? |
|
dmichael (off chromium)
2012/08/08 22:24:02
Yes, you must do CallWhileUnlocked every time you
Tom Finegan
2012/08/09 22:45:17
Done.
|
| + // 2) What about return values? Log/DCHECK? |
|
dmichael (off chromium)
2012/08/08 22:24:02
I'm not sure what you mean? You definitely don't w
Tom Finegan
2012/08/09 22:45:17
You grokked what I was getting at; CallWhileUnlock
|
| + ppp_decryptor_impl_->GenerateKeyRequest(instance, |
| + key_system.Get(dispatcher()), |
| + init_data.Get(dispatcher())); |
| + } |
| +} |
| + |
| +void PPP_ContentDecryptor_Proxy::OnPluginMsgAddKey( |
| + PP_Instance instance, |
| + SerializedVarReceiveInput session_id, |
| + SerializedVarReceiveInput key) { |
| + if (ppp_decryptor_impl_) { |
| + ppp_decryptor_impl_->AddKey(instance, |
| + session_id.Get(dispatcher()), |
| + key.Get(dispatcher())); |
| + } |
| +} |
| + |
| +void PPP_ContentDecryptor_Proxy::OnPluginMsgCancelKeyRequest( |
| + PP_Instance instance, |
| + SerializedVarReceiveInput session_id) { |
| + if (ppp_decryptor_impl_) { |
| + ppp_decryptor_impl_->CancelKeyRequest(instance, |
| + session_id.Get(dispatcher())); |
| + } |
| +} |
| + |
| +void PPP_ContentDecryptor_Proxy::OnPluginMsgDecrypt( |
| + PP_Instance instance, |
| + const HostResource& encrypted_block, |
| + uint64_t request_id) { |
| + if (ppp_decryptor_impl_) { |
| + PP_Resource plugin_resource = |
| + PluginGlobals::Get()->plugin_resource_tracker()-> |
| + PluginResourceForHostResource(encrypted_block); |
| + ppp_decryptor_impl_->Decrypt(instance, plugin_resource, request_id); |
| + } |
| +} |
| + |
| +void PPP_ContentDecryptor_Proxy::OnPluginMsgDecryptAndDecode( |
| + PP_Instance instance, |
| + const HostResource& encrypted_block, |
| + uint64_t request_id) { |
| + if (ppp_decryptor_impl_) { |
| + PP_Resource plugin_resource = |
| + PluginGlobals::Get()->plugin_resource_tracker()-> |
| + PluginResourceForHostResource(encrypted_block); |
| + ppp_decryptor_impl_->DecryptAndDecode(instance, |
| + plugin_resource, |
| + request_id); |
| + } |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |