Chromium Code Reviews| 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/host_dispatcher.h" | |
| 11 #include "ppapi/proxy/plugin_globals.h" | 12 #include "ppapi/proxy/plugin_globals.h" |
| 12 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/proxy/serialized_var.h" | 14 #include "ppapi/proxy/serialized_var.h" |
| 14 #include "ppapi/shared_impl/api_id.h" | 15 #include "ppapi/shared_impl/api_id.h" |
| 15 #include "ppapi/shared_impl/proxy_lock.h" | 16 #include "ppapi/shared_impl/proxy_lock.h" |
| 16 | 17 |
| 17 namespace ppapi { | 18 namespace ppapi { |
| 18 namespace proxy { | 19 namespace proxy { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // PPP_Class in the browser implementation ------------------------------------- | 23 // PPP_Class in the browser implementation ------------------------------------- |
| 23 | 24 |
| 24 // Represents a plugin-implemented class in the browser process. This just | 25 // Represents a plugin-implemented class in the browser process. This just |
| 25 // stores the data necessary to call back the plugin. | 26 // stores the data necessary to call back the plugin. |
| 26 struct ObjectProxy { | 27 struct ObjectProxy { |
| 27 ObjectProxy(Dispatcher* d, int64_t p, int64_t ud) | 28 ObjectProxy(Dispatcher* d, int64_t p, int64_t ud, PP_Instance inst) |
| 28 : dispatcher(d), ppp_class(p), user_data(ud) {} | 29 : dispatcher(d), ppp_class(p), user_data(ud), instance(inst) {} |
| 29 | 30 |
| 30 Dispatcher* dispatcher; | 31 Dispatcher* dispatcher; |
| 31 int64_t ppp_class; | 32 int64_t ppp_class; |
| 32 int64_t user_data; | 33 int64_t user_data; |
| 34 PP_Instance instance; | |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 ObjectProxy* ToObjectProxy(void* data) { | 37 ObjectProxy* ToObjectProxy(void* data) { |
| 36 ObjectProxy* obj = reinterpret_cast<ObjectProxy*>(data); | 38 ObjectProxy* obj = reinterpret_cast<ObjectProxy*>(data); |
| 37 if (!obj || !obj->dispatcher) | 39 if (!obj) |
| 38 return NULL; | 40 return nullptr; |
| 41 Dispatcher* dispatcher = HostDispatcher::GetForInstance(obj->instance); | |
| 42 if (!dispatcher) | |
| 43 return nullptr; | |
| 44 DCHECK_EQ(dispatcher, obj->dispatcher); | |
| 39 if (!obj->dispatcher->permissions().HasPermission(PERMISSION_DEV)) | 45 if (!obj->dispatcher->permissions().HasPermission(PERMISSION_DEV)) |
| 40 return NULL; | 46 return nullptr; |
| 41 return obj; | 47 return obj; |
| 42 } | 48 } |
| 43 | 49 |
| 44 bool HasProperty(void* object, PP_Var name, PP_Var* exception) { | 50 bool HasProperty(void* object, PP_Var name, PP_Var* exception) { |
| 45 ObjectProxy* obj = ToObjectProxy(object); | 51 ObjectProxy* obj = ToObjectProxy(object); |
| 46 if (!obj) | 52 if (!obj) |
| 47 return false; | 53 return false; |
| 48 | 54 |
| 49 bool result = false; | 55 bool result = false; |
| 50 ReceiveSerializedException se(obj->dispatcher, exception); | 56 ReceiveSerializedException se(obj->dispatcher, exception); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 &argv_vect); | 161 &argv_vect); |
| 156 | 162 |
| 157 obj->dispatcher->Send(new PpapiMsg_PPPClass_Construct( | 163 obj->dispatcher->Send(new PpapiMsg_PPPClass_Construct( |
| 158 API_ID_PPP_CLASS, | 164 API_ID_PPP_CLASS, |
| 159 obj->ppp_class, obj->user_data, argv_vect, &se, &result)); | 165 obj->ppp_class, obj->user_data, argv_vect, &se, &result)); |
| 160 return result.Return(obj->dispatcher); | 166 return result.Return(obj->dispatcher); |
| 161 } | 167 } |
| 162 | 168 |
| 163 void Deallocate(void* object) { | 169 void Deallocate(void* object) { |
| 164 ObjectProxy* obj = ToObjectProxy(object); | 170 ObjectProxy* obj = ToObjectProxy(object); |
| 165 if (!obj) | 171 if (!obj) { |
| 172 // Take care to delete the object even if we can't use it to notify the | |
| 173 // plugin. | |
| 174 delete reinterpret_cast<ObjectProxy*>(object); | |
|
piman
2016/03/29 18:28:51
nit: static_cast
| |
| 166 return; | 175 return; |
| 176 } | |
| 167 | 177 |
| 168 obj->dispatcher->Send(new PpapiMsg_PPPClass_Deallocate( | 178 obj->dispatcher->Send(new PpapiMsg_PPPClass_Deallocate( |
| 169 API_ID_PPP_CLASS, obj->ppp_class, obj->user_data)); | 179 API_ID_PPP_CLASS, obj->ppp_class, obj->user_data)); |
| 170 delete obj; | 180 delete obj; |
| 171 } | 181 } |
| 172 | 182 |
| 173 const PPP_Class_Deprecated class_interface = { | 183 const PPP_Class_Deprecated class_interface = { |
| 174 &HasProperty, | 184 &HasProperty, |
| 175 &HasMethod, | 185 &HasMethod, |
| 176 &GetProperty, | 186 &GetProperty, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 InterfaceProxy* PPP_Class_Proxy::Create(Dispatcher* dispatcher) { | 222 InterfaceProxy* PPP_Class_Proxy::Create(Dispatcher* dispatcher) { |
| 213 return new PPP_Class_Proxy(dispatcher); | 223 return new PPP_Class_Proxy(dispatcher); |
| 214 } | 224 } |
| 215 | 225 |
| 216 // static | 226 // static |
| 217 PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var, | 227 PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var, |
| 218 Dispatcher* dispatcher, | 228 Dispatcher* dispatcher, |
| 219 PP_Instance instance_id, | 229 PP_Instance instance_id, |
| 220 int64_t ppp_class, | 230 int64_t ppp_class, |
| 221 int64_t class_data) { | 231 int64_t class_data) { |
| 222 ObjectProxy* object_proxy = new ObjectProxy(dispatcher, | 232 ObjectProxy* object_proxy = |
| 223 ppp_class, class_data); | 233 new ObjectProxy(dispatcher, ppp_class, class_data, instance_id); |
|
raymes
2016/04/05 07:48:46
piman: how about tracking these objects, either in
| |
| 224 return var->CreateObject(instance_id, &class_interface, object_proxy); | 234 return var->CreateObject(instance_id, &class_interface, object_proxy); |
| 225 } | 235 } |
| 226 | 236 |
| 227 // static | 237 // static |
| 228 PP_Bool PPP_Class_Proxy::IsInstanceOf(const PPB_Var_Deprecated* ppb_var_impl, | 238 PP_Bool PPP_Class_Proxy::IsInstanceOf(const PPB_Var_Deprecated* ppb_var_impl, |
| 229 const PP_Var& var, | 239 const PP_Var& var, |
| 230 int64_t ppp_class, | 240 int64_t ppp_class, |
| 231 int64_t* ppp_class_data) { | 241 int64_t* ppp_class_data) { |
| 232 void* proxied_object = NULL; | 242 void* proxied_object = NULL; |
| 233 if (ppb_var_impl->IsInstanceOf(var, | 243 if (ppb_var_impl->IsInstanceOf(var, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 // malicious. | 401 // malicious. |
| 392 if (exception) | 402 if (exception) |
| 393 *exception->OutParam(dispatcher()) = PP_MakeInt32(1); | 403 *exception->OutParam(dispatcher()) = PP_MakeInt32(1); |
| 394 return false; | 404 return false; |
| 395 } | 405 } |
| 396 return true; | 406 return true; |
| 397 } | 407 } |
| 398 | 408 |
| 399 } // namespace proxy | 409 } // namespace proxy |
| 400 } // namespace ppapi | 410 } // namespace ppapi |
| OLD | NEW |