| 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/proxy/dispatcher.h" | 10 #include "ppapi/proxy/dispatcher.h" |
| 11 #include "ppapi/proxy/plugin_globals.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 12 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/proxy/serialized_var.h" |
| 11 #include "ppapi/shared_impl/proxy_lock.h" | 14 #include "ppapi/shared_impl/proxy_lock.h" |
| 12 #include "ppapi/proxy/serialized_var.h" | |
| 13 #include "ppapi/shared_impl/api_id.h" | 15 #include "ppapi/shared_impl/api_id.h" |
| 14 | 16 |
| 15 namespace ppapi { | 17 namespace ppapi { |
| 16 namespace proxy { | 18 namespace proxy { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // PPP_Class in the browser implementation ------------------------------------- | 22 // PPP_Class in the browser implementation ------------------------------------- |
| 21 | 23 |
| 22 // Represents a plugin-implemented class in the browser process. This just | 24 // Represents a plugin-implemented class in the browser process. This just |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 OnMsgDeallocate) | 239 OnMsgDeallocate) |
| 238 IPC_MESSAGE_UNHANDLED(handled = false) | 240 IPC_MESSAGE_UNHANDLED(handled = false) |
| 239 IPC_END_MESSAGE_MAP() | 241 IPC_END_MESSAGE_MAP() |
| 240 return handled; | 242 return handled; |
| 241 } | 243 } |
| 242 | 244 |
| 243 void PPP_Class_Proxy::OnMsgHasProperty(int64 ppp_class, int64 object, | 245 void PPP_Class_Proxy::OnMsgHasProperty(int64 ppp_class, int64 object, |
| 244 SerializedVarReceiveInput property, | 246 SerializedVarReceiveInput property, |
| 245 SerializedVarOutParam exception, | 247 SerializedVarOutParam exception, |
| 246 bool* result) { | 248 bool* result) { |
| 249 if (!ValidateUserData(ppp_class, object, &exception)) |
| 250 return; |
| 247 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasProperty, | 251 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasProperty, |
| 248 ToUserData(object), | 252 ToUserData(object), |
| 249 property.Get(dispatcher()), | 253 property.Get(dispatcher()), |
| 250 exception.OutParam(dispatcher())); | 254 exception.OutParam(dispatcher())); |
| 251 } | 255 } |
| 252 | 256 |
| 253 void PPP_Class_Proxy::OnMsgHasMethod(int64 ppp_class, int64 object, | 257 void PPP_Class_Proxy::OnMsgHasMethod(int64 ppp_class, int64 object, |
| 254 SerializedVarReceiveInput property, | 258 SerializedVarReceiveInput property, |
| 255 SerializedVarOutParam exception, | 259 SerializedVarOutParam exception, |
| 256 bool* result) { | 260 bool* result) { |
| 261 if (!ValidateUserData(ppp_class, object, &exception)) |
| 262 return; |
| 257 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasMethod, | 263 *result = CallWhileUnlocked(ToPPPClass(ppp_class)->HasMethod, |
| 258 ToUserData(object), | 264 ToUserData(object), |
| 259 property.Get(dispatcher()), | 265 property.Get(dispatcher()), |
| 260 exception.OutParam(dispatcher())); | 266 exception.OutParam(dispatcher())); |
| 261 } | 267 } |
| 262 | 268 |
| 263 void PPP_Class_Proxy::OnMsgGetProperty(int64 ppp_class, int64 object, | 269 void PPP_Class_Proxy::OnMsgGetProperty(int64 ppp_class, int64 object, |
| 264 SerializedVarReceiveInput property, | 270 SerializedVarReceiveInput property, |
| 265 SerializedVarOutParam exception, | 271 SerializedVarOutParam exception, |
| 266 SerializedVarReturnValue result) { | 272 SerializedVarReturnValue result) { |
| 273 if (!ValidateUserData(ppp_class, object, &exception)) |
| 274 return; |
| 267 result.Return(dispatcher(), CallWhileUnlocked( | 275 result.Return(dispatcher(), CallWhileUnlocked( |
| 268 ToPPPClass(ppp_class)->GetProperty, | 276 ToPPPClass(ppp_class)->GetProperty, |
| 269 ToUserData(object), property.Get(dispatcher()), | 277 ToUserData(object), property.Get(dispatcher()), |
| 270 exception.OutParam(dispatcher()))); | 278 exception.OutParam(dispatcher()))); |
| 271 } | 279 } |
| 272 | 280 |
| 273 void PPP_Class_Proxy::OnMsgEnumerateProperties( | 281 void PPP_Class_Proxy::OnMsgEnumerateProperties( |
| 274 int64 ppp_class, int64 object, | 282 int64 ppp_class, int64 object, |
| 275 std::vector<SerializedVar>* props, | 283 std::vector<SerializedVar>* props, |
| 276 SerializedVarOutParam exception) { | 284 SerializedVarOutParam exception) { |
| 285 if (!ValidateUserData(ppp_class, object, &exception)) |
| 286 return; |
| 277 NOTIMPLEMENTED(); | 287 NOTIMPLEMENTED(); |
| 278 // TODO(brettw) implement this. | 288 // TODO(brettw) implement this. |
| 279 } | 289 } |
| 280 | 290 |
| 281 void PPP_Class_Proxy::OnMsgSetProperty(int64 ppp_class, int64 object, | 291 void PPP_Class_Proxy::OnMsgSetProperty(int64 ppp_class, int64 object, |
| 282 SerializedVarReceiveInput property, | 292 SerializedVarReceiveInput property, |
| 283 SerializedVarReceiveInput value, | 293 SerializedVarReceiveInput value, |
| 284 SerializedVarOutParam exception) { | 294 SerializedVarOutParam exception) { |
| 295 if (!ValidateUserData(ppp_class, object, &exception)) |
| 296 return; |
| 285 CallWhileUnlocked(ToPPPClass(ppp_class)->SetProperty, | 297 CallWhileUnlocked(ToPPPClass(ppp_class)->SetProperty, |
| 286 ToUserData(object), property.Get(dispatcher()), value.Get(dispatcher()), | 298 ToUserData(object), property.Get(dispatcher()), value.Get(dispatcher()), |
| 287 exception.OutParam(dispatcher())); | 299 exception.OutParam(dispatcher())); |
| 288 } | 300 } |
| 289 | 301 |
| 290 void PPP_Class_Proxy::OnMsgRemoveProperty(int64 ppp_class, int64 object, | 302 void PPP_Class_Proxy::OnMsgRemoveProperty(int64 ppp_class, int64 object, |
| 291 SerializedVarReceiveInput property, | 303 SerializedVarReceiveInput property, |
| 292 SerializedVarOutParam exception) { | 304 SerializedVarOutParam exception) { |
| 305 if (!ValidateUserData(ppp_class, object, &exception)) |
| 306 return; |
| 293 CallWhileUnlocked(ToPPPClass(ppp_class)->RemoveProperty, | 307 CallWhileUnlocked(ToPPPClass(ppp_class)->RemoveProperty, |
| 294 ToUserData(object), property.Get(dispatcher()), | 308 ToUserData(object), property.Get(dispatcher()), |
| 295 exception.OutParam(dispatcher())); | 309 exception.OutParam(dispatcher())); |
| 296 } | 310 } |
| 297 | 311 |
| 298 void PPP_Class_Proxy::OnMsgCall( | 312 void PPP_Class_Proxy::OnMsgCall( |
| 299 int64 ppp_class, int64 object, | 313 int64 ppp_class, int64 object, |
| 300 SerializedVarReceiveInput method_name, | 314 SerializedVarReceiveInput method_name, |
| 301 SerializedVarVectorReceiveInput arg_vector, | 315 SerializedVarVectorReceiveInput arg_vector, |
| 302 SerializedVarOutParam exception, | 316 SerializedVarOutParam exception, |
| 303 SerializedVarReturnValue result) { | 317 SerializedVarReturnValue result) { |
| 318 if (!ValidateUserData(ppp_class, object, &exception)) |
| 319 return; |
| 304 uint32_t arg_count = 0; | 320 uint32_t arg_count = 0; |
| 305 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); | 321 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
| 306 result.Return(dispatcher(), CallWhileUnlocked(ToPPPClass(ppp_class)->Call, | 322 result.Return(dispatcher(), CallWhileUnlocked(ToPPPClass(ppp_class)->Call, |
| 307 ToUserData(object), method_name.Get(dispatcher()), | 323 ToUserData(object), method_name.Get(dispatcher()), |
| 308 arg_count, args, exception.OutParam(dispatcher()))); | 324 arg_count, args, exception.OutParam(dispatcher()))); |
| 309 } | 325 } |
| 310 | 326 |
| 311 void PPP_Class_Proxy::OnMsgConstruct( | 327 void PPP_Class_Proxy::OnMsgConstruct( |
| 312 int64 ppp_class, int64 object, | 328 int64 ppp_class, int64 object, |
| 313 SerializedVarVectorReceiveInput arg_vector, | 329 SerializedVarVectorReceiveInput arg_vector, |
| 314 SerializedVarOutParam exception, | 330 SerializedVarOutParam exception, |
| 315 SerializedVarReturnValue result) { | 331 SerializedVarReturnValue result) { |
| 332 if (!ValidateUserData(ppp_class, object, &exception)) |
| 333 return; |
| 316 uint32_t arg_count = 0; | 334 uint32_t arg_count = 0; |
| 317 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); | 335 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
| 318 result.Return(dispatcher(), CallWhileUnlocked( | 336 result.Return(dispatcher(), CallWhileUnlocked( |
| 319 ToPPPClass(ppp_class)->Construct, | 337 ToPPPClass(ppp_class)->Construct, |
| 320 ToUserData(object), arg_count, args, exception.OutParam(dispatcher()))); | 338 ToUserData(object), arg_count, args, exception.OutParam(dispatcher()))); |
| 321 } | 339 } |
| 322 | 340 |
| 323 void PPP_Class_Proxy::OnMsgDeallocate(int64 ppp_class, int64 object) { | 341 void PPP_Class_Proxy::OnMsgDeallocate(int64 ppp_class, int64 object) { |
| 342 if (!ValidateUserData(ppp_class, object, NULL)) |
| 343 return; |
| 324 CallWhileUnlocked(ToPPPClass(ppp_class)->Deallocate, ToUserData(object)); | 344 CallWhileUnlocked(ToPPPClass(ppp_class)->Deallocate, ToUserData(object)); |
| 325 } | 345 } |
| 326 | 346 |
| 347 bool PPP_Class_Proxy::ValidateUserData(int64 ppp_class, int64 class_data, |
| 348 SerializedVarOutParam* exception) { |
| 349 if (!PluginGlobals::Get()->plugin_var_tracker()->ValidatePluginObjectCall( |
| 350 ToPPPClass(ppp_class), ToUserData(class_data))) { |
| 351 // Set the exception. This is so the caller will know about the error and |
| 352 // also that we won't assert that somebody forgot to call OutParam on the |
| 353 // output parameter. Although this exception of "1" won't be very useful |
| 354 // this shouldn't happen in normal usage, only when the renderer is being |
| 355 // malicious. |
| 356 if (exception) |
| 357 *exception->OutParam(dispatcher()) = PP_MakeInt32(1); |
| 358 return false; |
| 359 } |
| 360 return true; |
| 361 } |
| 362 |
| 327 } // namespace proxy | 363 } // namespace proxy |
| 328 } // namespace ppapi | 364 } // namespace ppapi |
| OLD | NEW |