OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppp_class_proxy.h" | 5 #include "ppapi/proxy/ppp_class_proxy.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_var_deprecated.h" | 7 #include "ppapi/c/dev/ppb_var_deprecated.h" |
8 #include "ppapi/c/dev/ppp_class_deprecated.h" | 8 #include "ppapi/c/dev/ppp_class_deprecated.h" |
9 #include "ppapi/c/pp_var.h" | 9 #include "ppapi/c/pp_var.h" |
10 #include "ppapi/proxy/dispatcher.h" | 10 #include "ppapi/proxy/dispatcher.h" |
11 #include "ppapi/proxy/plugin_globals.h" | 11 #include "ppapi/proxy/plugin_globals.h" |
12 #include "ppapi/proxy/ppapi_messages.h" | 12 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/proxy/serialized_var.h" | 13 #include "ppapi/proxy/serialized_var.h" |
| 14 #include "ppapi/shared_impl/api_id.h" |
14 #include "ppapi/shared_impl/proxy_lock.h" | 15 #include "ppapi/shared_impl/proxy_lock.h" |
15 #include "ppapi/shared_impl/api_id.h" | |
16 | 16 |
17 namespace ppapi { | 17 namespace ppapi { |
18 namespace proxy { | 18 namespace proxy { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // PPP_Class in the browser implementation ------------------------------------- | 22 // PPP_Class in the browser implementation ------------------------------------- |
23 | 23 |
24 // Represents a plugin-implemented class in the browser process. This just | 24 // Represents a plugin-implemented class in the browser process. This just |
25 // stores the data necessary to call back the plugin. | 25 // stores the data necessary to call back the plugin. |
26 struct ObjectProxy { | 26 struct ObjectProxy { |
27 ObjectProxy(Dispatcher* d, int64 p, int64 ud) | 27 ObjectProxy(Dispatcher* d, int64_t p, int64_t ud) |
28 : dispatcher(d), | 28 : dispatcher(d), ppp_class(p), user_data(ud) {} |
29 ppp_class(p), | |
30 user_data(ud) { | |
31 } | |
32 | 29 |
33 Dispatcher* dispatcher; | 30 Dispatcher* dispatcher; |
34 int64 ppp_class; | 31 int64_t ppp_class; |
35 int64 user_data; | 32 int64_t user_data; |
36 }; | 33 }; |
37 | 34 |
38 ObjectProxy* ToObjectProxy(void* data) { | 35 ObjectProxy* ToObjectProxy(void* data) { |
39 ObjectProxy* obj = reinterpret_cast<ObjectProxy*>(data); | 36 ObjectProxy* obj = reinterpret_cast<ObjectProxy*>(data); |
40 if (!obj || !obj->dispatcher) | 37 if (!obj || !obj->dispatcher) |
41 return NULL; | 38 return NULL; |
42 if (!obj->dispatcher->permissions().HasPermission(PERMISSION_DEV)) | 39 if (!obj->dispatcher->permissions().HasPermission(PERMISSION_DEV)) |
43 return NULL; | 40 return NULL; |
44 return obj; | 41 return obj; |
45 } | 42 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 &GetAllPropertyNames, | 177 &GetAllPropertyNames, |
181 &SetProperty, | 178 &SetProperty, |
182 &RemoveProperty, | 179 &RemoveProperty, |
183 &Call, | 180 &Call, |
184 &Construct, | 181 &Construct, |
185 &Deallocate | 182 &Deallocate |
186 }; | 183 }; |
187 | 184 |
188 // Plugin helper functions ----------------------------------------------------- | 185 // Plugin helper functions ----------------------------------------------------- |
189 | 186 |
190 // Converts an int64 object from IPC to a PPP_Class* for calling into the | 187 // Converts an int64_t object from IPC to a PPP_Class* for calling into the |
191 // plugin's implementation. | 188 // plugin's implementation. |
192 const PPP_Class_Deprecated* ToPPPClass(int64 value) { | 189 const PPP_Class_Deprecated* ToPPPClass(int64_t value) { |
193 return reinterpret_cast<const PPP_Class_Deprecated*>( | 190 return reinterpret_cast<const PPP_Class_Deprecated*>( |
194 static_cast<intptr_t>(value)); | 191 static_cast<intptr_t>(value)); |
195 } | 192 } |
196 | 193 |
197 // Converts an int64 object from IPC to a void* for calling into the plugin's | 194 // Converts an int64_t object from IPC to a void* for calling into the plugin's |
198 // implementation as the user data. | 195 // implementation as the user data. |
199 void* ToUserData(int64 value) { | 196 void* ToUserData(int64_t value) { |
200 return reinterpret_cast<void*>(static_cast<intptr_t>(value)); | 197 return reinterpret_cast<void*>(static_cast<intptr_t>(value)); |
201 } | 198 } |
202 | 199 |
203 } // namespace | 200 } // namespace |
204 | 201 |
205 // PPP_Class_Proxy ------------------------------------------------------------- | 202 // PPP_Class_Proxy ------------------------------------------------------------- |
206 | 203 |
207 PPP_Class_Proxy::PPP_Class_Proxy(Dispatcher* dispatcher) | 204 PPP_Class_Proxy::PPP_Class_Proxy(Dispatcher* dispatcher) |
208 : InterfaceProxy(dispatcher) { | 205 : InterfaceProxy(dispatcher) { |
209 } | 206 } |
210 | 207 |
211 PPP_Class_Proxy::~PPP_Class_Proxy() { | 208 PPP_Class_Proxy::~PPP_Class_Proxy() { |
212 } | 209 } |
213 | 210 |
214 // static | 211 // static |
215 InterfaceProxy* PPP_Class_Proxy::Create(Dispatcher* dispatcher) { | 212 InterfaceProxy* PPP_Class_Proxy::Create(Dispatcher* dispatcher) { |
216 return new PPP_Class_Proxy(dispatcher); | 213 return new PPP_Class_Proxy(dispatcher); |
217 } | 214 } |
218 | 215 |
219 // static | 216 // static |
220 PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var, | 217 PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var, |
221 Dispatcher* dispatcher, | 218 Dispatcher* dispatcher, |
222 PP_Instance instance_id, | 219 PP_Instance instance_id, |
223 int64 ppp_class, | 220 int64_t ppp_class, |
224 int64 class_data) { | 221 int64_t class_data) { |
225 ObjectProxy* object_proxy = new ObjectProxy(dispatcher, | 222 ObjectProxy* object_proxy = new ObjectProxy(dispatcher, |
226 ppp_class, class_data); | 223 ppp_class, class_data); |
227 return var->CreateObject(instance_id, &class_interface, object_proxy); | 224 return var->CreateObject(instance_id, &class_interface, object_proxy); |
228 } | 225 } |
229 | 226 |
230 // static | 227 // static |
231 PP_Bool PPP_Class_Proxy::IsInstanceOf(const PPB_Var_Deprecated* ppb_var_impl, | 228 PP_Bool PPP_Class_Proxy::IsInstanceOf(const PPB_Var_Deprecated* ppb_var_impl, |
232 const PP_Var& var, | 229 const PP_Var& var, |
233 int64 ppp_class, | 230 int64_t ppp_class, |
234 int64* ppp_class_data) { | 231 int64_t* ppp_class_data) { |
235 void* proxied_object = NULL; | 232 void* proxied_object = NULL; |
236 if (ppb_var_impl->IsInstanceOf(var, | 233 if (ppb_var_impl->IsInstanceOf(var, |
237 &class_interface, | 234 &class_interface, |
238 &proxied_object)) { | 235 &proxied_object)) { |
239 if (static_cast<ObjectProxy*>(proxied_object)->ppp_class == ppp_class) { | 236 if (static_cast<ObjectProxy*>(proxied_object)->ppp_class == ppp_class) { |
240 DCHECK(ppp_class_data); | 237 DCHECK(ppp_class_data); |
241 *ppp_class_data = static_cast<ObjectProxy*>(proxied_object)->user_data; | 238 *ppp_class_data = static_cast<ObjectProxy*>(proxied_object)->user_data; |
242 return PP_TRUE; | 239 return PP_TRUE; |
243 } | 240 } |
244 } | 241 } |
(...skipping 20 matching lines...) Expand all Loading... |
265 OnMsgCall) | 262 OnMsgCall) |
266 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Construct, | 263 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Construct, |
267 OnMsgConstruct) | 264 OnMsgConstruct) |
268 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Deallocate, | 265 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Deallocate, |
269 OnMsgDeallocate) | 266 OnMsgDeallocate) |
270 IPC_MESSAGE_UNHANDLED(handled = false) | 267 IPC_MESSAGE_UNHANDLED(handled = false) |
271 IPC_END_MESSAGE_MAP() | 268 IPC_END_MESSAGE_MAP() |
272 return handled; | 269 return handled; |
273 } | 270 } |
274 | 271 |
275 void PPP_Class_Proxy::OnMsgHasProperty(int64 ppp_class, int64 object, | 272 void PPP_Class_Proxy::OnMsgHasProperty(int64_t ppp_class, |
| 273 int64_t object, |
276 SerializedVarReceiveInput property, | 274 SerializedVarReceiveInput property, |
277 SerializedVarOutParam exception, | 275 SerializedVarOutParam exception, |
278 bool* result) { | 276 bool* result) { |
279 if (!ValidateUserData(ppp_class, object, &exception)) | 277 if (!ValidateUserData(ppp_class, object, &exception)) |
280 return; | 278 return; |
281 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasProperty, | 279 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasProperty, |
282 ToUserData(object), | 280 ToUserData(object), |
283 property.Get(dispatcher()), | 281 property.Get(dispatcher()), |
284 exception.OutParam(dispatcher())); | 282 exception.OutParam(dispatcher())); |
285 } | 283 } |
286 | 284 |
287 void PPP_Class_Proxy::OnMsgHasMethod(int64 ppp_class, int64 object, | 285 void PPP_Class_Proxy::OnMsgHasMethod(int64_t ppp_class, |
| 286 int64_t object, |
288 SerializedVarReceiveInput property, | 287 SerializedVarReceiveInput property, |
289 SerializedVarOutParam exception, | 288 SerializedVarOutParam exception, |
290 bool* result) { | 289 bool* result) { |
291 if (!ValidateUserData(ppp_class, object, &exception)) | 290 if (!ValidateUserData(ppp_class, object, &exception)) |
292 return; | 291 return; |
293 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasMethod, | 292 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasMethod, |
294 ToUserData(object), | 293 ToUserData(object), |
295 property.Get(dispatcher()), | 294 property.Get(dispatcher()), |
296 exception.OutParam(dispatcher())); | 295 exception.OutParam(dispatcher())); |
297 } | 296 } |
298 | 297 |
299 void PPP_Class_Proxy::OnMsgGetProperty(int64 ppp_class, int64 object, | 298 void PPP_Class_Proxy::OnMsgGetProperty(int64_t ppp_class, |
| 299 int64_t object, |
300 SerializedVarReceiveInput property, | 300 SerializedVarReceiveInput property, |
301 SerializedVarOutParam exception, | 301 SerializedVarOutParam exception, |
302 SerializedVarReturnValue result) { | 302 SerializedVarReturnValue result) { |
303 if (!ValidateUserData(ppp_class, object, &exception)) | 303 if (!ValidateUserData(ppp_class, object, &exception)) |
304 return; | 304 return; |
305 result.Return(dispatcher(), CallWhileUnlocked( | 305 result.Return(dispatcher(), CallWhileUnlocked( |
306 ToPPPClass(ppp_class)->GetProperty, | 306 ToPPPClass(ppp_class)->GetProperty, |
307 ToUserData(object), property.Get(dispatcher()), | 307 ToUserData(object), property.Get(dispatcher()), |
308 exception.OutParam(dispatcher()))); | 308 exception.OutParam(dispatcher()))); |
309 } | 309 } |
310 | 310 |
311 void PPP_Class_Proxy::OnMsgEnumerateProperties( | 311 void PPP_Class_Proxy::OnMsgEnumerateProperties( |
312 int64 ppp_class, int64 object, | 312 int64_t ppp_class, |
| 313 int64_t object, |
313 std::vector<SerializedVar>* props, | 314 std::vector<SerializedVar>* props, |
314 SerializedVarOutParam exception) { | 315 SerializedVarOutParam exception) { |
315 if (!ValidateUserData(ppp_class, object, &exception)) | 316 if (!ValidateUserData(ppp_class, object, &exception)) |
316 return; | 317 return; |
317 NOTIMPLEMENTED(); | 318 NOTIMPLEMENTED(); |
318 // TODO(brettw) implement this. | 319 // TODO(brettw) implement this. |
319 } | 320 } |
320 | 321 |
321 void PPP_Class_Proxy::OnMsgSetProperty(int64 ppp_class, int64 object, | 322 void PPP_Class_Proxy::OnMsgSetProperty(int64_t ppp_class, |
| 323 int64_t object, |
322 SerializedVarReceiveInput property, | 324 SerializedVarReceiveInput property, |
323 SerializedVarReceiveInput value, | 325 SerializedVarReceiveInput value, |
324 SerializedVarOutParam exception) { | 326 SerializedVarOutParam exception) { |
325 if (!ValidateUserData(ppp_class, object, &exception)) | 327 if (!ValidateUserData(ppp_class, object, &exception)) |
326 return; | 328 return; |
327 CallWhileUnlocked(ToPPPClass(ppp_class)->SetProperty, | 329 CallWhileUnlocked(ToPPPClass(ppp_class)->SetProperty, |
328 ToUserData(object), property.Get(dispatcher()), value.Get(dispatcher()), | 330 ToUserData(object), property.Get(dispatcher()), value.Get(dispatcher()), |
329 exception.OutParam(dispatcher())); | 331 exception.OutParam(dispatcher())); |
330 } | 332 } |
331 | 333 |
332 void PPP_Class_Proxy::OnMsgRemoveProperty(int64 ppp_class, int64 object, | 334 void PPP_Class_Proxy::OnMsgRemoveProperty(int64_t ppp_class, |
| 335 int64_t object, |
333 SerializedVarReceiveInput property, | 336 SerializedVarReceiveInput property, |
334 SerializedVarOutParam exception) { | 337 SerializedVarOutParam exception) { |
335 if (!ValidateUserData(ppp_class, object, &exception)) | 338 if (!ValidateUserData(ppp_class, object, &exception)) |
336 return; | 339 return; |
337 CallWhileUnlocked(ToPPPClass(ppp_class)->RemoveProperty, | 340 CallWhileUnlocked(ToPPPClass(ppp_class)->RemoveProperty, |
338 ToUserData(object), property.Get(dispatcher()), | 341 ToUserData(object), property.Get(dispatcher()), |
339 exception.OutParam(dispatcher())); | 342 exception.OutParam(dispatcher())); |
340 } | 343 } |
341 | 344 |
342 void PPP_Class_Proxy::OnMsgCall( | 345 void PPP_Class_Proxy::OnMsgCall(int64_t ppp_class, |
343 int64 ppp_class, int64 object, | 346 int64_t object, |
344 SerializedVarReceiveInput method_name, | 347 SerializedVarReceiveInput method_name, |
345 SerializedVarVectorReceiveInput arg_vector, | 348 SerializedVarVectorReceiveInput arg_vector, |
346 SerializedVarOutParam exception, | 349 SerializedVarOutParam exception, |
347 SerializedVarReturnValue result) { | 350 SerializedVarReturnValue result) { |
348 if (!ValidateUserData(ppp_class, object, &exception)) | 351 if (!ValidateUserData(ppp_class, object, &exception)) |
349 return; | 352 return; |
350 uint32_t arg_count = 0; | 353 uint32_t arg_count = 0; |
351 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); | 354 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
352 result.Return(dispatcher(), CallWhileUnlocked(ToPPPClass(ppp_class)->Call, | 355 result.Return(dispatcher(), CallWhileUnlocked(ToPPPClass(ppp_class)->Call, |
353 ToUserData(object), method_name.Get(dispatcher()), | 356 ToUserData(object), method_name.Get(dispatcher()), |
354 arg_count, args, exception.OutParam(dispatcher()))); | 357 arg_count, args, exception.OutParam(dispatcher()))); |
355 } | 358 } |
356 | 359 |
357 void PPP_Class_Proxy::OnMsgConstruct( | 360 void PPP_Class_Proxy::OnMsgConstruct(int64_t ppp_class, |
358 int64 ppp_class, int64 object, | 361 int64_t object, |
359 SerializedVarVectorReceiveInput arg_vector, | 362 SerializedVarVectorReceiveInput arg_vector, |
360 SerializedVarOutParam exception, | 363 SerializedVarOutParam exception, |
361 SerializedVarReturnValue result) { | 364 SerializedVarReturnValue result) { |
362 if (!ValidateUserData(ppp_class, object, &exception)) | 365 if (!ValidateUserData(ppp_class, object, &exception)) |
363 return; | 366 return; |
364 uint32_t arg_count = 0; | 367 uint32_t arg_count = 0; |
365 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); | 368 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
366 result.Return(dispatcher(), CallWhileUnlocked( | 369 result.Return(dispatcher(), CallWhileUnlocked( |
367 ToPPPClass(ppp_class)->Construct, | 370 ToPPPClass(ppp_class)->Construct, |
368 ToUserData(object), arg_count, args, exception.OutParam(dispatcher()))); | 371 ToUserData(object), arg_count, args, exception.OutParam(dispatcher()))); |
369 } | 372 } |
370 | 373 |
371 void PPP_Class_Proxy::OnMsgDeallocate(int64 ppp_class, int64 object) { | 374 void PPP_Class_Proxy::OnMsgDeallocate(int64_t ppp_class, int64_t object) { |
372 if (!ValidateUserData(ppp_class, object, NULL)) | 375 if (!ValidateUserData(ppp_class, object, NULL)) |
373 return; | 376 return; |
374 PluginGlobals::Get()->plugin_var_tracker()->PluginImplementedObjectDestroyed( | 377 PluginGlobals::Get()->plugin_var_tracker()->PluginImplementedObjectDestroyed( |
375 ToUserData(object)); | 378 ToUserData(object)); |
376 CallWhileUnlocked(ToPPPClass(ppp_class)->Deallocate, ToUserData(object)); | 379 CallWhileUnlocked(ToPPPClass(ppp_class)->Deallocate, ToUserData(object)); |
377 } | 380 } |
378 | 381 |
379 bool PPP_Class_Proxy::ValidateUserData(int64 ppp_class, int64 class_data, | 382 bool PPP_Class_Proxy::ValidateUserData(int64_t ppp_class, |
| 383 int64_t class_data, |
380 SerializedVarOutParam* exception) { | 384 SerializedVarOutParam* exception) { |
381 if (!PluginGlobals::Get()->plugin_var_tracker()->ValidatePluginObjectCall( | 385 if (!PluginGlobals::Get()->plugin_var_tracker()->ValidatePluginObjectCall( |
382 ToPPPClass(ppp_class), ToUserData(class_data))) { | 386 ToPPPClass(ppp_class), ToUserData(class_data))) { |
383 // Set the exception. This is so the caller will know about the error and | 387 // Set the exception. This is so the caller will know about the error and |
384 // also that we won't assert that somebody forgot to call OutParam on the | 388 // also that we won't assert that somebody forgot to call OutParam on the |
385 // output parameter. Although this exception of "1" won't be very useful | 389 // output parameter. Although this exception of "1" won't be very useful |
386 // this shouldn't happen in normal usage, only when the renderer is being | 390 // this shouldn't happen in normal usage, only when the renderer is being |
387 // malicious. | 391 // malicious. |
388 if (exception) | 392 if (exception) |
389 *exception->OutParam(dispatcher()) = PP_MakeInt32(1); | 393 *exception->OutParam(dispatcher()) = PP_MakeInt32(1); |
390 return false; | 394 return false; |
391 } | 395 } |
392 return true; | 396 return true; |
393 } | 397 } |
394 | 398 |
395 } // namespace proxy | 399 } // namespace proxy |
396 } // namespace ppapi | 400 } // namespace ppapi |
OLD | NEW |