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 "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? | |
|
dmichael (off chromium)
2012/08/08 22:24:02
Should be fine. If the dispatcher's not there, we'
| |
| 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 HostResource host_resource; | |
| 79 host_resource.SetHostResource(instance, encrypted_block); | |
| 80 | |
| 81 return PP_FromBool(dispatcher->Send( | |
| 82 new PpapiMsg_PPPContentDecryptor_Decrypt( | |
| 83 API_ID_PPP_CONTENT_DECRYPTOR_DEV, | |
| 84 instance, | |
| 85 host_resource, | |
| 86 request_id))); | |
| 87 } | |
| 88 | |
| 89 PP_Bool DecryptAndDecode(PP_Instance instance, | |
| 90 PP_Resource encrypted_block, | |
| 91 uint64_t request_id) { | |
| 92 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | |
| 93 if (!dispatcher) { | |
| 94 return PP_FALSE; | |
| 95 } | |
| 96 | |
| 97 HostResource host_resource; | |
| 98 host_resource.SetHostResource(instance, encrypted_block); | |
| 99 | |
| 100 return PP_FromBool(dispatcher->Send( | |
| 101 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( | |
| 102 API_ID_PPP_CONTENT_DECRYPTOR_DEV, | |
| 103 instance, | |
| 104 host_resource, | |
| 105 request_id))); | |
| 106 } | |
| 107 | |
| 108 static const PPP_ContentDecryptor_Dev content_decryptor_interface = { | |
| 109 &GenerateKeyRequest, | |
| 110 &AddKey, | |
| 111 &CancelKeyRequest, | |
| 112 &Decrypt, | |
| 113 &DecryptAndDecode | |
| 114 }; | |
| 115 | |
| 116 InterfaceProxy* CreateContentDecryptorPPPProxy(Dispatcher* dispatcher) { | |
| 117 return new PPP_ContentDecryptor_Proxy(dispatcher); | |
| 118 } | |
| 119 | |
| 120 } // namespace | |
| 121 | |
| 122 PPP_ContentDecryptor_Proxy::PPP_ContentDecryptor_Proxy(Dispatcher* dispatcher) | |
| 123 : InterfaceProxy(dispatcher), | |
| 124 ppp_decryptor_impl_(NULL) { | |
| 125 if (dispatcher->IsPlugin()) { | |
| 126 ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Dev*>( | |
| 127 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
| |
| 128 } | |
| 129 } | |
| 130 | |
| 131 PPP_ContentDecryptor_Proxy::~PPP_ContentDecryptor_Proxy() { | |
| 132 } | |
| 133 | |
| 134 // static | |
| 135 const InterfaceProxy::Info* PPP_ContentDecryptor_Proxy::GetInfo() { | |
| 136 static const Info info = { | |
| 137 &content_decryptor_interface, | |
| 138 PPP_CONTENTDECRYPTOR_DEV_INTERFACE, | |
| 139 API_ID_PPP_VIDEO_DECODER_DEV, | |
| 140 false, | |
| 141 &CreateContentDecryptorPPPProxy, | |
| 142 }; | |
| 143 return &info; | |
| 144 } | |
| 145 | |
| 146 bool PPP_ContentDecryptor_Proxy::OnMessageReceived(const IPC::Message& msg) { | |
| 147 bool handled = true; | |
| 148 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Proxy, msg) | |
| 149 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, | |
| 150 OnPluginMsgGenerateKeyRequest) | |
| 151 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, | |
| 152 OnPluginMsgAddKey) | |
| 153 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest, | |
| 154 OnPluginMsgCancelKeyRequest) | |
| 155 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, | |
| 156 OnPluginMsgDecrypt) | |
| 157 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode, | |
| 158 OnPluginMsgDecryptAndDecode) | |
| 159 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 160 IPC_END_MESSAGE_MAP() | |
| 161 DCHECK(handled); | |
| 162 return handled; | |
| 163 } | |
| 164 | |
| 165 void PPP_ContentDecryptor_Proxy::OnPluginMsgGenerateKeyRequest( | |
| 166 PP_Instance instance, | |
| 167 SerializedVarReceiveInput key_system, | |
| 168 SerializedVarReceiveInput init_data) { | |
| 169 if (ppp_decryptor_impl_) { | |
| 170 // TODO(tomfinegan): | |
| 171 // 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.
| |
| 172 // 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
| |
| 173 ppp_decryptor_impl_->GenerateKeyRequest(instance, | |
| 174 key_system.Get(dispatcher()), | |
| 175 init_data.Get(dispatcher())); | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 void PPP_ContentDecryptor_Proxy::OnPluginMsgAddKey( | |
| 180 PP_Instance instance, | |
| 181 SerializedVarReceiveInput session_id, | |
| 182 SerializedVarReceiveInput key) { | |
| 183 if (ppp_decryptor_impl_) { | |
| 184 ppp_decryptor_impl_->AddKey(instance, | |
| 185 session_id.Get(dispatcher()), | |
| 186 key.Get(dispatcher())); | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 void PPP_ContentDecryptor_Proxy::OnPluginMsgCancelKeyRequest( | |
| 191 PP_Instance instance, | |
| 192 SerializedVarReceiveInput session_id) { | |
| 193 if (ppp_decryptor_impl_) { | |
| 194 ppp_decryptor_impl_->CancelKeyRequest(instance, | |
| 195 session_id.Get(dispatcher())); | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 void PPP_ContentDecryptor_Proxy::OnPluginMsgDecrypt( | |
| 200 PP_Instance instance, | |
| 201 const HostResource& encrypted_block, | |
| 202 uint64_t request_id) { | |
| 203 if (ppp_decryptor_impl_) { | |
| 204 PP_Resource plugin_resource = | |
| 205 PluginGlobals::Get()->plugin_resource_tracker()-> | |
| 206 PluginResourceForHostResource(encrypted_block); | |
| 207 ppp_decryptor_impl_->Decrypt(instance, plugin_resource, request_id); | |
| 208 } | |
| 209 } | |
| 210 | |
| 211 void PPP_ContentDecryptor_Proxy::OnPluginMsgDecryptAndDecode( | |
| 212 PP_Instance instance, | |
| 213 const HostResource& encrypted_block, | |
| 214 uint64_t request_id) { | |
| 215 if (ppp_decryptor_impl_) { | |
| 216 PP_Resource plugin_resource = | |
| 217 PluginGlobals::Get()->plugin_resource_tracker()-> | |
| 218 PluginResourceForHostResource(encrypted_block); | |
| 219 ppp_decryptor_impl_->DecryptAndDecode(instance, | |
| 220 plugin_resource, | |
| 221 request_id); | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 } // namespace proxy | |
| 226 } // namespace ppapi | |
| OLD | NEW |