Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: ppapi/proxy/ppp_content_decryptor_private_proxy.cc

Issue 10827280: Add PPAPI decryptor implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix proxied interface definition. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_private_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 NOTREACHED();
30 return PP_FALSE;
31 }
32
33 return PP_FromBool(dispatcher->Send(
34 new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest(
35 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
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 NOTREACHED();
47 return PP_FALSE;
48 }
49
50 return PP_FromBool(dispatcher->Send(
51 new PpapiMsg_PPPContentDecryptor_AddKey(
52 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
53 instance,
54 SerializedVarSendInput(dispatcher, session_id),
55 SerializedVarSendInput(dispatcher, key))));
56 }
57
58 PP_Bool CancelKeyRequest(PP_Instance instance, PP_Var session_id) {
59 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
60 if (!dispatcher) {
61 return PP_FALSE;
62 }
63
64 return PP_FromBool(dispatcher->Send(
65 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest(
66 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
67 instance,
68 SerializedVarSendInput(dispatcher, session_id))));
69 }
70
71 PP_Bool Decrypt(PP_Instance instance,
72 PP_Resource encrypted_block,
73 int32_t request_id) {
74 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
75 if (!dispatcher) {
76 NOTREACHED();
77 return PP_FALSE;
78 }
79
80 HostResource host_resource;
81 host_resource.SetHostResource(instance, encrypted_block);
82
83 return PP_FromBool(dispatcher->Send(
84 new PpapiMsg_PPPContentDecryptor_Decrypt(
85 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
86 instance,
87 host_resource,
88 request_id)));
89 }
90
91 PP_Bool DecryptAndDecode(PP_Instance instance,
92 PP_Resource encrypted_block,
93 int32_t request_id) {
94 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
95 if (!dispatcher) {
96 NOTREACHED();
97 return PP_FALSE;
98 }
99
100 HostResource host_resource;
101 host_resource.SetHostResource(instance, encrypted_block);
102
103 return PP_FromBool(dispatcher->Send(
104 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode(
105 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
106 instance,
107 host_resource,
108 request_id)));
109 }
110
111 static const PPP_ContentDecryptor_Private content_decryptor_interface = {
112 &GenerateKeyRequest,
113 &AddKey,
114 &CancelKeyRequest,
115 &Decrypt,
116 &DecryptAndDecode
117 };
118
119 InterfaceProxy* CreateContentDecryptorPPPProxy(Dispatcher* dispatcher) {
120 return new PPP_ContentDecryptor_Private_Proxy(dispatcher);
121 }
122
123 } // namespace
124
125 PPP_ContentDecryptor_Private_Proxy::PPP_ContentDecryptor_Private_Proxy(
126 Dispatcher* dispatcher)
127 : InterfaceProxy(dispatcher),
128 ppp_decryptor_impl_(NULL) {
129 if (dispatcher->IsPlugin()) {
130 ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Private*>(
131 dispatcher->local_get_interface()(
132 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE));
133 }
134 }
135
136 PPP_ContentDecryptor_Private_Proxy::~PPP_ContentDecryptor_Private_Proxy() {
137 }
138
139 // static
140 const InterfaceProxy::Info* PPP_ContentDecryptor_Private_Proxy::GetInfo() {
141 static const Info info = {
142 &content_decryptor_interface,
143 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE,
144 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
145 false,
146 &CreateContentDecryptorPPPProxy,
147 };
148 return &info;
149 }
150
151 bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived(
152 const IPC::Message& msg) {
153 bool handled = true;
154 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg)
155 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest,
156 OnMsgGenerateKeyRequest)
157 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey,
158 OnMsgAddKey)
159 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest,
160 OnMsgCancelKeyRequest)
161 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt,
162 OnMsgDecrypt)
163 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode,
164 OnMsgDecryptAndDecode)
165 IPC_MESSAGE_UNHANDLED(handled = false)
166 IPC_END_MESSAGE_MAP()
167 DCHECK(handled);
168 return handled;
169 }
170
171 void PPP_ContentDecryptor_Private_Proxy::OnMsgGenerateKeyRequest(
172 PP_Instance instance,
173 SerializedVarReceiveInput key_system,
174 SerializedVarReceiveInput init_data) {
175 if (ppp_decryptor_impl_) {
176 CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest,
177 instance,
178 key_system.Get(dispatcher()),
179 init_data.Get(dispatcher()));
180 }
181 }
182
183 void PPP_ContentDecryptor_Private_Proxy::OnMsgAddKey(
184 PP_Instance instance,
185 SerializedVarReceiveInput session_id,
186 SerializedVarReceiveInput key) {
187 if (ppp_decryptor_impl_) {
188 CallWhileUnlocked(ppp_decryptor_impl_->AddKey,
189 instance,
190 session_id.Get(dispatcher()),
191 key.Get(dispatcher()));
192 }
193 }
194
195 void PPP_ContentDecryptor_Private_Proxy::OnMsgCancelKeyRequest(
196 PP_Instance instance,
197 SerializedVarReceiveInput session_id) {
198 if (ppp_decryptor_impl_) {
199 CallWhileUnlocked(CancelKeyRequest,
200 instance,
201 session_id.Get(dispatcher()));
202 }
203 }
204
205 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt(
206 PP_Instance instance,
207 const HostResource& encrypted_block,
208 int32_t request_id) {
209 if (ppp_decryptor_impl_) {
210 PP_Resource plugin_resource =
211 PluginGlobals::Get()->plugin_resource_tracker()->
212 PluginResourceForHostResource(encrypted_block);
213 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt,
214 instance,
215 plugin_resource,
216 request_id);
217 }
218 }
219
220 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode(
221 PP_Instance instance,
222 const HostResource& encrypted_block,
223 int32_t request_id) {
224 if (ppp_decryptor_impl_) {
225 PP_Resource plugin_resource =
226 PluginGlobals::Get()->plugin_resource_tracker()->
227 PluginResourceForHostResource(encrypted_block);
228 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode,
229 instance,
230 plugin_resource,
231 request_id);
232 }
233 }
234
235 } // namespace proxy
236 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698