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 "ppapi/proxy/ppp_content_decryptor_proxy.h" |
| 6 |
| 7 #include "ppapi/c/pp_bool.h" |
| 8 #include "ppapi/proxy/host_dispatcher.h" |
| 9 #include "ppapi/proxy/plugin_globals.h" |
| 10 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/serialized_var.h" |
| 13 #include "ppapi/thunk/enter.h" |
| 14 #include "ppapi/thunk/ppb_instance_api.h" |
| 15 #include "ppapi/thunk/thunk.h" |
| 16 |
| 17 using ppapi::thunk::PPB_Instance_API; |
| 18 |
| 19 namespace ppapi { |
| 20 namespace proxy { |
| 21 |
| 22 namespace { |
| 23 |
| 24 PP_Bool GenerateKeyRequest(PP_Instance instance, |
| 25 PP_Var key_system, |
| 26 PP_Var init_data) { |
| 27 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 28 if (!dispatcher) { |
| 29 // TODO(tomfinegan): NOTREACHED safe here/throughout? |
| 30 return PP_FALSE; |
| 31 } |
| 32 |
| 33 return PP_FromBool(dispatcher->Send( |
| 34 new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( |
| 35 API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| 36 instance, |
| 37 SerializedVarSendInput(dispatcher, key_system), |
| 38 SerializedVarSendInput(dispatcher, init_data)))); |
| 39 } |
| 40 |
| 41 PP_Bool AddKey(PP_Instance instance, |
| 42 PP_Var session_id, |
| 43 PP_Var key) { |
| 44 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 45 if (!dispatcher) { |
| 46 return PP_FALSE; |
| 47 } |
| 48 |
| 49 return PP_FromBool(dispatcher->Send( |
| 50 new PpapiMsg_PPPContentDecryptor_AddKey( |
| 51 API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| 52 instance, |
| 53 SerializedVarSendInput(dispatcher, session_id), |
| 54 SerializedVarSendInput(dispatcher, key)))); |
| 55 } |
| 56 |
| 57 PP_Bool CancelKeyRequest(PP_Instance instance, PP_Var session_id) { |
| 58 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 59 if (!dispatcher) { |
| 60 return PP_FALSE; |
| 61 } |
| 62 |
| 63 return PP_FromBool(dispatcher->Send( |
| 64 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( |
| 65 API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| 66 instance, |
| 67 SerializedVarSendInput(dispatcher, session_id)))); |
| 68 } |
| 69 |
| 70 PP_Bool Decrypt(PP_Instance instance, |
| 71 PP_Resource encrypted_block, |
| 72 uint64_t request_id) { |
| 73 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 74 if (!dispatcher) { |
| 75 return PP_FALSE; |
| 76 } |
| 77 |
| 78 return PP_FromBool(dispatcher->Send( |
| 79 new PpapiMsg_PPPContentDecryptor_Decrypt( |
| 80 API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| 81 instance, |
| 82 encrypted_block, |
| 83 request_id))); |
| 84 } |
| 85 |
| 86 PP_Bool DecryptAndDecode(PP_Instance instance, |
| 87 PP_Resource encrypted_block, |
| 88 uint64_t request_id) { |
| 89 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 90 if (!dispatcher) { |
| 91 return PP_FALSE; |
| 92 } |
| 93 |
| 94 return PP_FromBool(dispatcher->Send( |
| 95 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( |
| 96 API_ID_PPP_CONTENT_DECRYPTOR_DEV, |
| 97 instance, |
| 98 encrypted_block, |
| 99 request_id))); |
| 100 } |
| 101 |
| 102 static const PPP_ContentDecryptor_Dev content_decryptor_interface = { |
| 103 &GenerateKeyRequest, |
| 104 &AddKey, |
| 105 &CancelKeyRequest, |
| 106 &Decrypt, |
| 107 &DecryptAndDecode |
| 108 }; |
| 109 |
| 110 InterfaceProxy* CreateContentDecryptorPPPProxy(Dispatcher* dispatcher) { |
| 111 return new PPP_ContentDecryptor_Proxy(dispatcher); |
| 112 } |
| 113 |
| 114 } // namespace |
| 115 |
| 116 PPP_ContentDecryptor_Proxy::PPP_ContentDecryptor_Proxy(Dispatcher* dispatcher) |
| 117 : InterfaceProxy(dispatcher), |
| 118 ppp_decryptor_impl_(NULL) { |
| 119 if (dispatcher->IsPlugin()) { |
| 120 ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Dev*>( |
| 121 dispatcher->local_get_interface()(PPP_CONTENTDECRYPTOR_DEV_INTERFACE)); |
| 122 } |
| 123 } |
| 124 |
| 125 PPP_ContentDecryptor_Proxy::~PPP_ContentDecryptor_Proxy() { |
| 126 } |
| 127 |
| 128 // static |
| 129 const InterfaceProxy::Info* PPP_ContentDecryptor_Proxy::GetInfo() { |
| 130 static const Info info = { |
| 131 &content_decryptor_interface, |
| 132 PPP_CONTENTDECRYPTOR_DEV_INTERFACE, |
| 133 API_ID_PPP_VIDEO_DECODER_DEV, |
| 134 false, |
| 135 &CreateContentDecryptorPPPProxy, |
| 136 }; |
| 137 return &info; |
| 138 } |
| 139 |
| 140 bool PPP_ContentDecryptor_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 141 bool handled = true; |
| 142 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Proxy, msg) |
| 143 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, |
| 144 OnPluginMsgGenerateKeyRequest) |
| 145 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, |
| 146 OnPluginMsgAddKey) |
| 147 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest, |
| 148 OnPluginMsgCancelKeyRequest) |
| 149 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, |
| 150 OnPluginMsgDecrypt) |
| 151 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode, |
| 152 OnPluginMsgDecryptAndDecode) |
| 153 IPC_MESSAGE_UNHANDLED(handled = false) |
| 154 IPC_END_MESSAGE_MAP() |
| 155 DCHECK(handled); |
| 156 return handled; |
| 157 } |
| 158 |
| 159 void PPP_ContentDecryptor_Proxy::OnPluginMsgGenerateKeyRequest( |
| 160 PP_Instance instance, |
| 161 SerializedVarReceiveInput key_system, |
| 162 SerializedVarReceiveInput init_data) { |
| 163 if (ppp_decryptor_impl_) { |
| 164 // TODO(tomfinegan): |
| 165 // 1) Is CallWhileUnlocked necessary here/throughout? |
| 166 // 2) What about return values? Log/DCHECK? |
| 167 ppp_decryptor_impl_->GenerateKeyRequest(instance, |
| 168 key_system.Get(dispatcher()), |
| 169 init_data.Get(dispatcher())); |
| 170 } |
| 171 } |
| 172 |
| 173 void PPP_ContentDecryptor_Proxy::OnPluginMsgAddKey( |
| 174 PP_Instance instance, |
| 175 SerializedVarReceiveInput session_id, |
| 176 SerializedVarReceiveInput key) { |
| 177 if (ppp_decryptor_impl_) { |
| 178 ppp_decryptor_impl_->AddKey(instance, |
| 179 session_id.Get(dispatcher()), |
| 180 key.Get(dispatcher())); |
| 181 } |
| 182 } |
| 183 |
| 184 void PPP_ContentDecryptor_Proxy::OnPluginMsgCancelKeyRequest( |
| 185 PP_Instance instance, |
| 186 SerializedVarReceiveInput session_id) { |
| 187 if (ppp_decryptor_impl_) { |
| 188 ppp_decryptor_impl_->CancelKeyRequest(instance, |
| 189 session_id.Get(dispatcher())); |
| 190 } |
| 191 } |
| 192 |
| 193 void PPP_ContentDecryptor_Proxy::OnPluginMsgDecrypt( |
| 194 PP_Instance instance, |
| 195 //const HostResource& encrypted_block, |
| 196 PP_Resource encrypted_block, |
| 197 uint64_t request_id) { |
| 198 if (ppp_decryptor_impl_) { |
| 199 // PP_Resource plugin_resource = |
| 200 // PluginGlobals::Get()->plugin_resource_tracker()-> |
| 201 // PluginResourceForHostResource(encrypted_block); |
| 202 ppp_decryptor_impl_->Decrypt(instance, encrypted_block, request_id); |
| 203 } |
| 204 } |
| 205 |
| 206 void PPP_ContentDecryptor_Proxy::OnPluginMsgDecryptAndDecode( |
| 207 PP_Instance instance, |
| 208 //const HostResource& encrypted_block, |
| 209 PP_Resource encrypted_block, |
| 210 uint64_t request_id) { |
| 211 if (ppp_decryptor_impl_) { |
| 212 // PP_Resource plugin_resource = |
| 213 // PluginGlobals::Get()->plugin_resource_tracker()-> |
| 214 // PluginResourceForHostResource(encrypted_block); |
| 215 ppp_decryptor_impl_->DecryptAndDecode(instance, |
| 216 //plugin_resource, |
| 217 encrypted_block, |
| 218 request_id); |
| 219 } |
| 220 } |
| 221 |
| 222 } // namespace proxy |
| 223 } // namespace ppapi |
OLD | NEW |