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_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 PPP_ContentDecryptor_Private* | |
141 PPP_ContentDecryptor_Private_Proxy::GetProxyInterface() { | |
142 return &content_decryptor_interface; | |
143 } | |
144 | |
145 bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived( | |
146 const IPC::Message& msg) { | |
147 bool handled = true; | |
148 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg) | |
149 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, | |
150 OnMsgGenerateKeyRequest) | |
151 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, | |
152 OnMsgAddKey) | |
153 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest, | |
154 OnMsgCancelKeyRequest) | |
155 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, | |
156 OnMsgDecrypt) | |
157 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode, | |
158 OnMsgDecryptAndDecode) | |
159 IPC_MESSAGE_UNHANDLED(handled = false) | |
160 IPC_END_MESSAGE_MAP() | |
161 DCHECK(handled); | |
162 return handled; | |
163 } | |
164 | |
165 void PPP_ContentDecryptor_Private_Proxy::OnMsgGenerateKeyRequest( | |
166 PP_Instance instance, | |
167 SerializedVarReceiveInput key_system, | |
168 SerializedVarReceiveInput init_data) { | |
dmichael (off chromium)
2012/08/15 19:01:00
I think you might need to AddRef your key_system a
dmichael (off chromium)
2012/08/16 17:02:28
ping? See PPP_Messaging_Proxy for an example. As-i
Tom Finegan
2012/08/16 18:10:58
Done.
| |
169 if (ppp_decryptor_impl_) { | |
170 CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest, | |
171 instance, | |
172 key_system.Get(dispatcher()), | |
173 init_data.Get(dispatcher())); | |
174 } | |
175 } | |
176 | |
177 void PPP_ContentDecryptor_Private_Proxy::OnMsgAddKey( | |
178 PP_Instance instance, | |
179 SerializedVarReceiveInput session_id, | |
180 SerializedVarReceiveInput key) { | |
181 if (ppp_decryptor_impl_) { | |
182 CallWhileUnlocked(ppp_decryptor_impl_->AddKey, | |
183 instance, | |
184 session_id.Get(dispatcher()), | |
185 key.Get(dispatcher())); | |
186 } | |
187 } | |
188 | |
189 void PPP_ContentDecryptor_Private_Proxy::OnMsgCancelKeyRequest( | |
190 PP_Instance instance, | |
191 SerializedVarReceiveInput session_id) { | |
192 if (ppp_decryptor_impl_) { | |
193 CallWhileUnlocked(CancelKeyRequest, | |
194 instance, | |
195 session_id.Get(dispatcher())); | |
196 } | |
197 } | |
198 | |
199 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( | |
200 PP_Instance instance, | |
201 const HostResource& encrypted_block, | |
202 int32_t request_id) { | |
203 if (ppp_decryptor_impl_) { | |
204 PP_Resource plugin_resource = | |
205 PluginGlobals::Get()->plugin_resource_tracker()-> | |
206 PluginResourceForHostResource(encrypted_block); | |
207 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, | |
208 instance, | |
209 plugin_resource, | |
210 request_id); | |
211 } | |
212 } | |
213 | |
214 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( | |
215 PP_Instance instance, | |
216 const HostResource& encrypted_block, | |
217 int32_t request_id) { | |
218 if (ppp_decryptor_impl_) { | |
219 PP_Resource plugin_resource = | |
220 PluginGlobals::Get()->plugin_resource_tracker()-> | |
221 PluginResourceForHostResource(encrypted_block); | |
222 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, | |
223 instance, | |
224 plugin_resource, | |
225 request_id); | |
226 } | |
227 } | |
228 | |
229 } // namespace proxy | |
230 } // namespace ppapi | |
OLD | NEW |