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/ppb_var_deprecated_proxy.h" |
| 6 |
| 7 #include <stdlib.h> // For malloc |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 11 #include "ppapi/c/pp_var.h" |
| 12 #include "ppapi/c/ppb_core.h" |
| 13 #include "ppapi/proxy/plugin_dispatcher.h" |
| 14 #include "ppapi/proxy/ppapi_message_helpers.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "ppapi/proxy/ppp_class_proxy.h" |
| 17 #include "ppapi/proxy/serialized_var.h" |
| 18 |
| 19 namespace pp { |
| 20 namespace proxy { |
| 21 |
| 22 namespace { |
| 23 |
| 24 // PPP_Var_Deprecated plugin --------------------------------------------------- |
| 25 |
| 26 void AddRefVar(PP_Var var) { |
| 27 PluginDispatcher::Get()->plugin_var_tracker()->AddRef(var); |
| 28 } |
| 29 |
| 30 void ReleaseVar(PP_Var var) { |
| 31 PluginDispatcher::Get()->plugin_var_tracker()->Release(var); |
| 32 } |
| 33 |
| 34 PP_Var VarFromUtf8(PP_Module module_id, const char* data, uint32_t len) { |
| 35 PP_Var ret; |
| 36 ret.type = PP_VARTYPE_STRING; |
| 37 // TODO(brettw) avoid this extra copy. |
| 38 ret.value.as_id = PluginDispatcher::Get()->plugin_var_tracker()->MakeString( |
| 39 std::string(data, len)); |
| 40 return ret; |
| 41 } |
| 42 |
| 43 const char* VarToUtf8(PP_Var var, uint32_t* len) { |
| 44 const std::string* str = |
| 45 PluginDispatcher::Get()->plugin_var_tracker()->GetExistingString(var); |
| 46 if (str) { |
| 47 *len = static_cast<uint32_t>(str->size()); |
| 48 return str->c_str(); |
| 49 } else { |
| 50 *len = 0; |
| 51 return NULL; |
| 52 } |
| 53 } |
| 54 |
| 55 bool HasProperty(PP_Var var, |
| 56 PP_Var name, |
| 57 PP_Var* exception) { |
| 58 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 59 ReceiveSerializedException se(dispatcher, exception); |
| 60 bool result = false; |
| 61 if (!se.IsThrown()) { |
| 62 dispatcher->Send(new PpapiHostMsg_PPBVar_HasProperty( |
| 63 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 64 SerializedVarSendInput(dispatcher, var), |
| 65 SerializedVarSendInput(dispatcher, name), &se, &result)); |
| 66 } |
| 67 return result; |
| 68 } |
| 69 |
| 70 bool HasMethod(PP_Var var, |
| 71 PP_Var name, |
| 72 PP_Var* exception) { |
| 73 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 74 ReceiveSerializedException se(dispatcher, exception); |
| 75 bool result = false; |
| 76 if (!se.IsThrown()) { |
| 77 dispatcher->Send(new PpapiHostMsg_PPBVar_HasMethodDeprecated( |
| 78 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 79 SerializedVarSendInput(dispatcher, var), |
| 80 SerializedVarSendInput(dispatcher, name), &se, &result)); |
| 81 } |
| 82 return result; |
| 83 } |
| 84 |
| 85 PP_Var GetProperty(PP_Var var, |
| 86 PP_Var name, |
| 87 PP_Var* exception) { |
| 88 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 89 ReceiveSerializedException se(dispatcher, exception); |
| 90 ReceiveSerializedVarReturnValue result; |
| 91 if (!se.IsThrown()) { |
| 92 dispatcher->Send(new PpapiHostMsg_PPBVar_GetProperty( |
| 93 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 94 SerializedVarSendInput(dispatcher, var), |
| 95 SerializedVarSendInput(dispatcher, name), &se, &result)); |
| 96 } |
| 97 return result.Return(dispatcher); |
| 98 } |
| 99 |
| 100 void EnumerateProperties(PP_Var var, |
| 101 uint32_t* property_count, |
| 102 PP_Var** properties, |
| 103 PP_Var* exception) { |
| 104 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 105 |
| 106 ReceiveSerializedVarVectorOutParam out_vector(dispatcher, |
| 107 property_count, properties); |
| 108 ReceiveSerializedException se(dispatcher, exception); |
| 109 if (!se.IsThrown()) { |
| 110 dispatcher->Send(new PpapiHostMsg_PPBVar_EnumerateProperties( |
| 111 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 112 SerializedVarSendInput(dispatcher, var), |
| 113 out_vector.OutParam(), &se)); |
| 114 } |
| 115 } |
| 116 |
| 117 void SetProperty(PP_Var var, |
| 118 PP_Var name, |
| 119 PP_Var value, |
| 120 PP_Var* exception) { |
| 121 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 122 ReceiveSerializedException se(dispatcher, exception); |
| 123 if (!se.IsThrown()) { |
| 124 dispatcher->Send(new PpapiHostMsg_PPBVar_SetPropertyDeprecated( |
| 125 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 126 SerializedVarSendInput(dispatcher, var), |
| 127 SerializedVarSendInput(dispatcher, name), |
| 128 SerializedVarSendInput(dispatcher, value), &se)); |
| 129 } |
| 130 } |
| 131 |
| 132 void RemoveProperty(PP_Var var, |
| 133 PP_Var name, |
| 134 PP_Var* exception) { |
| 135 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 136 ReceiveSerializedException se(dispatcher, exception); |
| 137 bool result = false; |
| 138 if (!se.IsThrown()) { |
| 139 dispatcher->Send(new PpapiHostMsg_PPBVar_DeleteProperty( |
| 140 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 141 SerializedVarSendInput(dispatcher, var), |
| 142 SerializedVarSendInput(dispatcher, name), &se, &result)); |
| 143 } |
| 144 } |
| 145 |
| 146 PP_Var Call(PP_Var object, |
| 147 PP_Var method_name, |
| 148 uint32_t argc, |
| 149 PP_Var* argv, |
| 150 PP_Var* exception) { |
| 151 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 152 ReceiveSerializedVarReturnValue result; |
| 153 ReceiveSerializedException se(dispatcher, exception); |
| 154 if (!se.IsThrown()) { |
| 155 std::vector<SerializedVar> argv_vect; |
| 156 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); |
| 157 |
| 158 dispatcher->Send(new PpapiHostMsg_PPBVar_CallDeprecated( |
| 159 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 160 SerializedVarSendInput(dispatcher, object), |
| 161 SerializedVarSendInput(dispatcher, method_name), argv_vect, |
| 162 &se, &result)); |
| 163 } |
| 164 return result.Return(dispatcher); |
| 165 } |
| 166 |
| 167 PP_Var Construct(PP_Var object, |
| 168 uint32_t argc, |
| 169 PP_Var* argv, |
| 170 PP_Var* exception) { |
| 171 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 172 ReceiveSerializedVarReturnValue result; |
| 173 ReceiveSerializedException se(dispatcher, exception); |
| 174 if (!se.IsThrown()) { |
| 175 std::vector<SerializedVar> argv_vect; |
| 176 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); |
| 177 |
| 178 dispatcher->Send(new PpapiHostMsg_PPBVar_Construct( |
| 179 INTERFACE_ID_PPB_VAR_DEPRECATED, |
| 180 SerializedVarSendInput(dispatcher, object), |
| 181 argv_vect, &se, &result)); |
| 182 } |
| 183 return result.Return(dispatcher); |
| 184 } |
| 185 |
| 186 bool IsInstanceOf(PP_Var var, |
| 187 const PPP_Class_Deprecated* ppp_class, |
| 188 void** ppp_class_data) { |
| 189 bool result = false; |
| 190 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 191 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); |
| 192 int64 class_data_int = 0; |
| 193 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated( |
| 194 INTERFACE_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var), |
| 195 class_int, &class_data_int, &result)); |
| 196 *ppp_class_data = |
| 197 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int)); |
| 198 return result; |
| 199 } |
| 200 |
| 201 PP_Var CreateObject(PP_Module module_id, |
| 202 const PPP_Class_Deprecated* ppp_class, |
| 203 void* ppp_class_data) { |
| 204 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 205 ReceiveSerializedVarReturnValue result; |
| 206 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); |
| 207 int64 data_int = |
| 208 static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class_data)); |
| 209 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated( |
| 210 INTERFACE_ID_PPB_VAR_DEPRECATED, module_id, class_int, data_int, |
| 211 &result)); |
| 212 return result.Return(dispatcher); |
| 213 } |
| 214 |
| 215 const PPB_Var_Deprecated var_deprecated_interface = { |
| 216 &AddRefVar, |
| 217 &ReleaseVar, |
| 218 &VarFromUtf8, |
| 219 &VarToUtf8, |
| 220 &HasProperty, |
| 221 &HasMethod, |
| 222 &GetProperty, |
| 223 &EnumerateProperties, |
| 224 &SetProperty, |
| 225 &RemoveProperty, |
| 226 &Call, |
| 227 &Construct, |
| 228 &IsInstanceOf, |
| 229 &CreateObject |
| 230 }; |
| 231 |
| 232 } // namespace |
| 233 |
| 234 PPB_Var_Deprecated_Proxy::PPB_Var_Deprecated_Proxy( |
| 235 Dispatcher* dispatcher, |
| 236 const void* target_interface) |
| 237 : InterfaceProxy(dispatcher, target_interface) { |
| 238 } |
| 239 |
| 240 PPB_Var_Deprecated_Proxy::~PPB_Var_Deprecated_Proxy() { |
| 241 } |
| 242 |
| 243 const void* PPB_Var_Deprecated_Proxy::GetSourceInterface() const { |
| 244 return &var_deprecated_interface; |
| 245 } |
| 246 |
| 247 InterfaceID PPB_Var_Deprecated_Proxy::GetInterfaceId() const { |
| 248 return INTERFACE_ID_PPB_VAR_DEPRECATED; |
| 249 } |
| 250 |
| 251 void PPB_Var_Deprecated_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 252 IPC_BEGIN_MESSAGE_MAP(PPB_Var_Deprecated_Proxy, msg) |
| 253 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_HasProperty, |
| 254 OnMsgHasProperty) |
| 255 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_HasMethodDeprecated, |
| 256 OnMsgHasMethodDeprecated) |
| 257 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_GetProperty, |
| 258 OnMsgGetProperty) |
| 259 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_DeleteProperty, |
| 260 OnMsgDeleteProperty) |
| 261 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_EnumerateProperties, |
| 262 OnMsgEnumerateProperties) |
| 263 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_SetPropertyDeprecated, |
| 264 OnMsgSetPropertyDeprecated) |
| 265 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_CallDeprecated, |
| 266 OnMsgCallDeprecated) |
| 267 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_Construct, |
| 268 OnMsgConstruct) |
| 269 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_IsInstanceOfDeprecated, |
| 270 OnMsgIsInstanceOfDeprecated) |
| 271 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVar_CreateObjectDeprecated, |
| 272 OnMsgCreateObjectDeprecated) |
| 273 IPC_END_MESSAGE_MAP() |
| 274 // FIXME(brettw) handle bad messages! |
| 275 } |
| 276 |
| 277 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( |
| 278 SerializedVarReceiveInput var, |
| 279 SerializedVarReceiveInput name, |
| 280 SerializedVarOutParam exception, |
| 281 bool* result) { |
| 282 *result = ppb_var_target()->HasProperty(var.Get(dispatcher()), |
| 283 name.Get(dispatcher()), |
| 284 exception.OutParam(dispatcher())); |
| 285 } |
| 286 |
| 287 void PPB_Var_Deprecated_Proxy::OnMsgHasMethodDeprecated( |
| 288 SerializedVarReceiveInput var, |
| 289 SerializedVarReceiveInput name, |
| 290 SerializedVarOutParam exception, |
| 291 bool* result) { |
| 292 *result = ppb_var_target()->HasMethod(var.Get(dispatcher()), |
| 293 name.Get(dispatcher()), |
| 294 exception.OutParam(dispatcher())); |
| 295 } |
| 296 |
| 297 void PPB_Var_Deprecated_Proxy::OnMsgGetProperty( |
| 298 SerializedVarReceiveInput var, |
| 299 SerializedVarReceiveInput name, |
| 300 SerializedVarOutParam exception, |
| 301 SerializedVarReturnValue result) { |
| 302 result.Return(dispatcher(), ppb_var_target()->GetProperty( |
| 303 var.Get(dispatcher()), name.Get(dispatcher()), |
| 304 exception.OutParam(dispatcher()))); |
| 305 } |
| 306 |
| 307 void PPB_Var_Deprecated_Proxy::OnMsgEnumerateProperties( |
| 308 SerializedVarReceiveInput var, |
| 309 SerializedVarVectorOutParam props, |
| 310 SerializedVarOutParam exception) { |
| 311 ppb_var_target()->GetAllPropertyNames(var.Get(dispatcher()), |
| 312 props.CountOutParam(), props.ArrayOutParam(dispatcher()), |
| 313 exception.OutParam(dispatcher())); |
| 314 } |
| 315 |
| 316 void PPB_Var_Deprecated_Proxy::OnMsgSetPropertyDeprecated( |
| 317 SerializedVarReceiveInput var, |
| 318 SerializedVarReceiveInput name, |
| 319 SerializedVarReceiveInput value, |
| 320 SerializedVarOutParam exception) { |
| 321 ppb_var_target()->SetProperty(var.Get(dispatcher()), |
| 322 name.Get(dispatcher()), |
| 323 value.Get(dispatcher()), |
| 324 exception.OutParam(dispatcher())); |
| 325 } |
| 326 |
| 327 void PPB_Var_Deprecated_Proxy::OnMsgDeleteProperty( |
| 328 SerializedVarReceiveInput var, |
| 329 SerializedVarReceiveInput name, |
| 330 SerializedVarOutParam exception, |
| 331 bool* result) { |
| 332 ppb_var_target()->RemoveProperty(var.Get(dispatcher()), |
| 333 name.Get(dispatcher()), |
| 334 exception.OutParam(dispatcher())); |
| 335 // This deprecated function doesn't actually return a value, but we re-use |
| 336 // the message from the non-deprecated interface with the return value. |
| 337 *result = true; |
| 338 } |
| 339 |
| 340 void PPB_Var_Deprecated_Proxy::OnMsgCallDeprecated( |
| 341 SerializedVarReceiveInput object, |
| 342 SerializedVarReceiveInput method_name, |
| 343 SerializedVarVectorReceiveInput arg_vector, |
| 344 SerializedVarOutParam exception, |
| 345 SerializedVarReturnValue result) { |
| 346 uint32_t arg_count = 0; |
| 347 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
| 348 result.Return(dispatcher(), ppb_var_target()->Call( |
| 349 object.Get(dispatcher()), |
| 350 method_name.Get(dispatcher()), |
| 351 arg_count, args, |
| 352 exception.OutParam(dispatcher()))); |
| 353 } |
| 354 |
| 355 void PPB_Var_Deprecated_Proxy::OnMsgConstruct( |
| 356 SerializedVarReceiveInput var, |
| 357 SerializedVarVectorReceiveInput arg_vector, |
| 358 SerializedVarOutParam exception, |
| 359 SerializedVarReturnValue result) { |
| 360 uint32_t arg_count = 0; |
| 361 PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); |
| 362 result.Return(dispatcher(), ppb_var_target()->Construct( |
| 363 var.Get(dispatcher()), arg_count, args, |
| 364 exception.OutParam(dispatcher()))); |
| 365 } |
| 366 |
| 367 void PPB_Var_Deprecated_Proxy::OnMsgIsInstanceOfDeprecated( |
| 368 pp::proxy::SerializedVarReceiveInput var, |
| 369 int64 ppp_class, |
| 370 int64* ppp_class_data, |
| 371 bool* result) { |
| 372 // TODO(brettw) write this. |
| 373 } |
| 374 |
| 375 void PPB_Var_Deprecated_Proxy::OnMsgCreateObjectDeprecated( |
| 376 PP_Module module_id, |
| 377 int64 ppp_class, |
| 378 int64 class_data, |
| 379 SerializedVarReturnValue result) { |
| 380 result.Return(dispatcher(), PPP_Class_Proxy::CreateProxiedObject( |
| 381 ppb_var_target(), dispatcher(), module_id, ppp_class, class_data)); |
| 382 } |
| 383 |
| 384 } // namespace proxy |
| 385 } // namespace pp |
OLD | NEW |