OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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_class_proxy.h" |
| 6 |
| 7 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 8 #include "ppapi/c/dev/ppp_class_deprecated.h" |
| 9 #include "ppapi/proxy/dispatcher.h" |
| 10 #include "ppapi/proxy/interface_id.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/serialized_var.h" |
| 13 |
| 14 namespace pp { |
| 15 namespace proxy { |
| 16 |
| 17 namespace { |
| 18 |
| 19 // PPP_Class in the browser implementation ------------------------------------- |
| 20 |
| 21 // Represents a plugin-implemented class in the browser process. This just |
| 22 // stores the data necessary to call back the plugin. |
| 23 struct ObjectProxy { |
| 24 ObjectProxy(Dispatcher* d, int64 p, int64 ud) |
| 25 : dispatcher(d), |
| 26 ppp_class(p), |
| 27 user_data(ud) { |
| 28 } |
| 29 |
| 30 Dispatcher* dispatcher; |
| 31 int64 ppp_class; |
| 32 int64 user_data; |
| 33 }; |
| 34 |
| 35 ObjectProxy* ToObjectProxy(void* data) { |
| 36 return reinterpret_cast<ObjectProxy*>(data); |
| 37 } |
| 38 |
| 39 bool HasProperty(void* object, PP_Var name, PP_Var* exception) { |
| 40 ObjectProxy* obj = ToObjectProxy(object); |
| 41 bool result = false; |
| 42 ReceiveSerializedException se(obj->dispatcher, exception); |
| 43 obj->dispatcher->Send(new PpapiMsg_PPPClass_HasProperty( |
| 44 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data, |
| 45 SerializedVarSendInput(obj->dispatcher, name), &se, &result)); |
| 46 return result; |
| 47 } |
| 48 |
| 49 bool HasMethod(void* object, PP_Var name, PP_Var* exception) { |
| 50 ObjectProxy* obj = ToObjectProxy(object); |
| 51 bool result = false; |
| 52 ReceiveSerializedException se(obj->dispatcher, exception); |
| 53 obj->dispatcher->Send(new PpapiMsg_PPPClass_HasMethod( |
| 54 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data, |
| 55 SerializedVarSendInput(obj->dispatcher, name), &se, &result)); |
| 56 return result; |
| 57 } |
| 58 |
| 59 PP_Var GetProperty(void* object, |
| 60 PP_Var name, |
| 61 PP_Var* exception) { |
| 62 ObjectProxy* obj = ToObjectProxy(object); |
| 63 ReceiveSerializedException se(obj->dispatcher, exception); |
| 64 ReceiveSerializedVarReturnValue result; |
| 65 obj->dispatcher->Send(new PpapiMsg_PPPClass_GetProperty( |
| 66 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data, |
| 67 SerializedVarSendInput(obj->dispatcher, name), &se, &result)); |
| 68 return result.Return(obj->dispatcher); |
| 69 } |
| 70 |
| 71 void GetAllPropertyNames(void* object, |
| 72 uint32_t* property_count, |
| 73 PP_Var** properties, |
| 74 PP_Var* exception) { |
| 75 NOTIMPLEMENTED(); |
| 76 // TODO(brettw) implement this. |
| 77 } |
| 78 |
| 79 void SetProperty(void* object, |
| 80 PP_Var name, |
| 81 PP_Var value, |
| 82 PP_Var* exception) { |
| 83 ObjectProxy* obj = ToObjectProxy(object); |
| 84 ReceiveSerializedException se(obj->dispatcher, exception); |
| 85 obj->dispatcher->Send(new PpapiMsg_PPPClass_SetProperty( |
| 86 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data, |
| 87 SerializedVarSendInput(obj->dispatcher, name), |
| 88 SerializedVarSendInput(obj->dispatcher, value), &se)); |
| 89 } |
| 90 |
| 91 void RemoveProperty(void* object, |
| 92 PP_Var name, |
| 93 PP_Var* exception) { |
| 94 ObjectProxy* obj = ToObjectProxy(object); |
| 95 ReceiveSerializedException se(obj->dispatcher, exception); |
| 96 obj->dispatcher->Send(new PpapiMsg_PPPClass_RemoveProperty( |
| 97 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data, |
| 98 SerializedVarSendInput(obj->dispatcher, name), &se)); |
| 99 } |
| 100 |
| 101 PP_Var Call(void* object, |
| 102 PP_Var method_name, |
| 103 uint32_t argc, |
| 104 PP_Var* argv, |
| 105 PP_Var* exception) { |
| 106 ObjectProxy* obj = ToObjectProxy(object); |
| 107 |
| 108 ReceiveSerializedVarReturnValue result; |
| 109 ReceiveSerializedException se(obj->dispatcher, exception); |
| 110 std::vector<SerializedVar> argv_vect; |
| 111 SerializedVarSendInput::ConvertVector(obj->dispatcher, argv, argc, |
| 112 &argv_vect); |
| 113 |
| 114 obj->dispatcher->Send(new PpapiMsg_PPPClass_Call( |
| 115 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data, |
| 116 SerializedVarSendInput(obj->dispatcher, method_name), argv_vect, |
| 117 &se, &result)); |
| 118 return result.Return(obj->dispatcher); |
| 119 } |
| 120 |
| 121 PP_Var Construct(void* object, |
| 122 uint32_t argc, |
| 123 PP_Var* argv, |
| 124 PP_Var* exception) { |
| 125 ObjectProxy* obj = ToObjectProxy(object); |
| 126 |
| 127 ReceiveSerializedVarReturnValue result; |
| 128 ReceiveSerializedException se(obj->dispatcher, exception); |
| 129 std::vector<SerializedVar> argv_vect; |
| 130 SerializedVarSendInput::ConvertVector(obj->dispatcher, argv, argc, |
| 131 &argv_vect); |
| 132 |
| 133 obj->dispatcher->Send(new PpapiMsg_PPPClass_Construct( |
| 134 INTERFACE_ID_PPP_CLASS, |
| 135 obj->ppp_class, obj->user_data, argv_vect, &se, &result)); |
| 136 return result.Return(obj->dispatcher); |
| 137 } |
| 138 |
| 139 void Deallocate(void* object) { |
| 140 ObjectProxy* obj = ToObjectProxy(object); |
| 141 obj->dispatcher->Send(new PpapiMsg_PPPClass_Deallocate( |
| 142 INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data)); |
| 143 delete obj; |
| 144 } |
| 145 |
| 146 const PPP_Class_Deprecated class_interface = { |
| 147 &HasProperty, |
| 148 &HasMethod, |
| 149 &GetProperty, |
| 150 &GetAllPropertyNames, |
| 151 &SetProperty, |
| 152 &RemoveProperty, |
| 153 &Call, |
| 154 &Construct, |
| 155 &Deallocate |
| 156 }; |
| 157 |
| 158 // Plugin helper functions ----------------------------------------------------- |
| 159 |
| 160 // Converts an int64 object from IPC to a PPP_Class* for calling into the |
| 161 // plugin's implementation. |
| 162 const PPP_Class_Deprecated* ToPPPClass(int64 value) { |
| 163 return reinterpret_cast<const PPP_Class_Deprecated*>( |
| 164 static_cast<intptr_t>(value)); |
| 165 } |
| 166 |
| 167 // Converts an int64 object from IPC to a void* for calling into the plugin's |
| 168 // implementation as the user data. |
| 169 void* ToUserData(int64 value) { |
| 170 return reinterpret_cast<void*>(static_cast<intptr_t>(value)); |
| 171 } |
| 172 |
| 173 } // namespace |
| 174 |
| 175 // PPP_Class_Proxy ------------------------------------------------------------- |
| 176 |
| 177 PPP_Class_Proxy::PPP_Class_Proxy(Dispatcher* dispatcher) |
| 178 : InterfaceProxy(dispatcher, NULL) { |
| 179 } |
| 180 |
| 181 PPP_Class_Proxy::~PPP_Class_Proxy() { |
| 182 } |
| 183 |
| 184 // static |
| 185 PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var, |
| 186 Dispatcher* dispatcher, |
| 187 PP_Module module_id, |
| 188 int64 ppp_class, |
| 189 int64 class_data) { |
| 190 ObjectProxy* object_proxy = new ObjectProxy(dispatcher, |
| 191 ppp_class, class_data); |
| 192 return var->CreateObject(module_id, &class_interface, object_proxy); |
| 193 } |
| 194 |
| 195 const void* PPP_Class_Proxy::GetSourceInterface() const { |
| 196 return &class_interface; |
| 197 } |
| 198 |
| 199 InterfaceID PPP_Class_Proxy::GetInterfaceId() const { |
| 200 return INTERFACE_ID_PPP_CLASS; |
| 201 } |
| 202 |
| 203 void PPP_Class_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 204 IPC_BEGIN_MESSAGE_MAP(PPP_Class_Proxy, msg) |
| 205 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_HasProperty, |
| 206 OnMsgHasProperty) |
| 207 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_HasMethod, |
| 208 OnMsgHasMethod) |
| 209 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_GetProperty, |
| 210 OnMsgGetProperty) |
| 211 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_EnumerateProperties, |
| 212 OnMsgEnumerateProperties) |
| 213 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_SetProperty, |
| 214 OnMsgSetProperty) |
| 215 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Call, |
| 216 OnMsgCall) |
| 217 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Construct, |
| 218 OnMsgConstruct) |
| 219 IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Deallocate, |
| 220 OnMsgDeallocate) |
| 221 IPC_END_MESSAGE_MAP() |
| 222 } |
| 223 |
| 224 void PPP_Class_Proxy::OnMsgHasProperty(int64 ppp_class, int64 object, |
| 225 SerializedVarReceiveInput property, |
| 226 SerializedVarOutParam exception, |
| 227 bool* result) { |
| 228 *result = ToPPPClass(ppp_class)->HasProperty(ToUserData(object), |
| 229 property.Get(dispatcher()), exception.OutParam(dispatcher())); |
| 230 } |
| 231 |
| 232 void PPP_Class_Proxy::OnMsgHasMethod(int64 ppp_class, int64 object, |
| 233 SerializedVarReceiveInput property, |
| 234 SerializedVarOutParam exception, |
| 235 bool* result) { |
| 236 *result = ToPPPClass(ppp_class)->HasMethod(ToUserData(object), |
| 237 property.Get(dispatcher()), exception.OutParam(dispatcher())); |
| 238 } |
| 239 |
| 240 void PPP_Class_Proxy::OnMsgGetProperty(int64 ppp_class, int64 object, |
| 241 SerializedVarReceiveInput property, |
| 242 SerializedVarOutParam exception, |
| 243 SerializedVarReturnValue result) { |
| 244 result.Return(dispatcher(), ToPPPClass(ppp_class)->GetProperty( |
| 245 ToUserData(object), property.Get(dispatcher()), |
| 246 exception.OutParam(dispatcher()))); |
| 247 } |
| 248 |
| 249 void PPP_Class_Proxy::OnMsgEnumerateProperties( |
| 250 int64 ppp_class, int64 object, |
| 251 std::vector<pp::proxy::SerializedVar>* props, |
| 252 SerializedVarOutParam exception) { |
| 253 NOTIMPLEMENTED(); |
| 254 // TODO(brettw) implement this. |
| 255 } |
| 256 |
| 257 void PPP_Class_Proxy::OnMsgSetProperty(int64 ppp_class, int64 object, |
| 258 SerializedVarReceiveInput property, |
| 259 SerializedVarReceiveInput value, |
| 260 SerializedVarOutParam exception) { |
| 261 ToPPPClass(ppp_class)->SetProperty( |
| 262 ToUserData(object), property.Get(dispatcher()), value.Get(dispatcher()), |
| 263 exception.OutParam(dispatcher())); |
| 264 } |
| 265 |
| 266 void PPP_Class_Proxy::OnMsgRemoveProperty(int64 ppp_class, int64 object, |
| 267 SerializedVarReceiveInput property, |
| 268 SerializedVarOutParam exception) { |
| 269 ToPPPClass(ppp_class)->RemoveProperty( |
| 270 ToUserData(object), property.Get(dispatcher()), |
| 271 exception.OutParam(dispatcher())); |
| 272 } |
| 273 |
| 274 void PPP_Class_Proxy::OnMsgCall( |
| 275 int64 ppp_class, int64 object, |
| 276 SerializedVarReceiveInput method_name, |
| 277 SerializedVarVectorReceiveInput arg_vector, |
| 278 SerializedVarOutParam exception, |
| 279 SerializedVarReturnValue result) { |
| 280 uint32_t arg_count = 0; |
| 281 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
| 282 result.Return(dispatcher(), ToPPPClass(ppp_class)->Call( |
| 283 ToUserData(object), method_name.Get(dispatcher()), |
| 284 arg_count, args, exception.OutParam(dispatcher()))); |
| 285 } |
| 286 |
| 287 void PPP_Class_Proxy::OnMsgConstruct( |
| 288 int64 ppp_class, int64 object, |
| 289 SerializedVarVectorReceiveInput arg_vector, |
| 290 SerializedVarOutParam exception, |
| 291 SerializedVarReturnValue result) { |
| 292 uint32_t arg_count = 0; |
| 293 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
| 294 result.Return(dispatcher(), ToPPPClass(ppp_class)->Construct( |
| 295 ToUserData(object), arg_count, args, exception.OutParam(dispatcher()))); |
| 296 } |
| 297 |
| 298 void PPP_Class_Proxy::OnMsgDeallocate(int64 ppp_class, int64 object) { |
| 299 ToPPPClass(ppp_class)->Deallocate(ToUserData(object)); |
| 300 } |
| 301 |
| 302 } // namespace proxy |
| 303 } // namespace pp |
OLD | NEW |