| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/plugin/npobject_proxy.h" | 5 #include "chrome/plugin/npobject_proxy.h" |
| 6 | 6 |
| 7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
| 8 #include "chrome/common/plugin_messages.h" | 8 #include "chrome/common/plugin_messages.h" |
| 9 #include "chrome/plugin/npobject_util.h" | 9 #include "chrome/plugin/npobject_util.h" |
| 10 #include "chrome/plugin/plugin_channel_base.h" | 10 #include "chrome/plugin/plugin_channel_base.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 void NPObjectProxy::OnChannelError() { | 105 void NPObjectProxy::OnChannelError() { |
| 106 // Release our ref count of the plugin channel object, as it addrefs the | 106 // Release our ref count of the plugin channel object, as it addrefs the |
| 107 // process. | 107 // process. |
| 108 channel_ = NULL; | 108 channel_ = NULL; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool NPObjectProxy::NPHasMethod(NPObject *obj, | 111 bool NPObjectProxy::NPHasMethod(NPObject *obj, |
| 112 NPIdentifier name) { | 112 NPIdentifier name) { |
| 113 if (obj == NULL) |
| 114 return false; |
| 115 |
| 113 bool result = false; | 116 bool result = false; |
| 114 NPObjectProxy* proxy = GetProxy(obj); | 117 NPObjectProxy* proxy = GetProxy(obj); |
| 115 | 118 |
| 116 if (!proxy) { | 119 if (!proxy) { |
| 117 return obj->_class->hasMethod(obj, name); | 120 return obj->_class->hasMethod(obj, name); |
| 118 } | 121 } |
| 119 | 122 |
| 120 NPIdentifier_Param name_param; | 123 NPIdentifier_Param name_param; |
| 121 CreateNPIdentifierParam(name, &name_param); | 124 CreateNPIdentifierParam(name, &name_param); |
| 122 | 125 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 140 return NPInvokePrivate(0, npobj, true, 0, args, arg_count, result); | 143 return NPInvokePrivate(0, npobj, true, 0, args, arg_count, result); |
| 141 } | 144 } |
| 142 | 145 |
| 143 bool NPObjectProxy::NPInvokePrivate(NPP npp, | 146 bool NPObjectProxy::NPInvokePrivate(NPP npp, |
| 144 NPObject *obj, | 147 NPObject *obj, |
| 145 bool is_default, | 148 bool is_default, |
| 146 NPIdentifier name, | 149 NPIdentifier name, |
| 147 const NPVariant *args, | 150 const NPVariant *args, |
| 148 uint32_t arg_count, | 151 uint32_t arg_count, |
| 149 NPVariant *np_result) { | 152 NPVariant *np_result) { |
| 153 if (obj == NULL) |
| 154 return false; |
| 155 |
| 150 NPObjectProxy* proxy = GetProxy(obj); | 156 NPObjectProxy* proxy = GetProxy(obj); |
| 151 if (!proxy) { | 157 if (!proxy) { |
| 152 return obj->_class->invoke(obj, name, args, arg_count, np_result); | 158 return obj->_class->invoke(obj, name, args, arg_count, np_result); |
| 153 } | 159 } |
| 154 | 160 |
| 155 bool result = false; | 161 bool result = false; |
| 156 NPIdentifier_Param name_param; | 162 NPIdentifier_Param name_param; |
| 157 if (is_default) { | 163 if (is_default) { |
| 158 // The data won't actually get used, but set it so we don't send random | 164 // The data won't actually get used, but set it so we don't send random |
| 159 // data. | 165 // data. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return false; | 204 return false; |
| 199 | 205 |
| 200 CreateNPVariant( | 206 CreateNPVariant( |
| 201 param_result, channel_copy, np_result, modal_dialog_event_handle, | 207 param_result, channel_copy, np_result, modal_dialog_event_handle, |
| 202 page_url); | 208 page_url); |
| 203 return true; | 209 return true; |
| 204 } | 210 } |
| 205 | 211 |
| 206 bool NPObjectProxy::NPHasProperty(NPObject *obj, | 212 bool NPObjectProxy::NPHasProperty(NPObject *obj, |
| 207 NPIdentifier name) { | 213 NPIdentifier name) { |
| 214 if (obj == NULL) |
| 215 return false; |
| 216 |
| 208 bool result = false; | 217 bool result = false; |
| 209 NPObjectProxy* proxy = GetProxy(obj); | 218 NPObjectProxy* proxy = GetProxy(obj); |
| 210 if (!proxy) { | 219 if (!proxy) { |
| 211 return obj->_class->hasProperty(obj, name); | 220 return obj->_class->hasProperty(obj, name); |
| 212 } | 221 } |
| 213 | 222 |
| 214 NPIdentifier_Param name_param; | 223 NPIdentifier_Param name_param; |
| 215 CreateNPIdentifierParam(name, &name_param); | 224 CreateNPIdentifierParam(name, &name_param); |
| 216 | 225 |
| 217 NPVariant_Param param; | 226 NPVariant_Param param; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 269 |
| 261 CreateNPVariant( | 270 CreateNPVariant( |
| 262 param, channel.get(), np_result, modal_dialog_event_handle, page_url); | 271 param, channel.get(), np_result, modal_dialog_event_handle, page_url); |
| 263 | 272 |
| 264 return true; | 273 return true; |
| 265 } | 274 } |
| 266 | 275 |
| 267 bool NPObjectProxy::NPSetProperty(NPObject *obj, | 276 bool NPObjectProxy::NPSetProperty(NPObject *obj, |
| 268 NPIdentifier name, | 277 NPIdentifier name, |
| 269 const NPVariant *value) { | 278 const NPVariant *value) { |
| 279 if (obj == NULL) |
| 280 return false; |
| 281 |
| 270 bool result = false; | 282 bool result = false; |
| 271 NPObjectProxy* proxy = GetProxy(obj); | 283 NPObjectProxy* proxy = GetProxy(obj); |
| 272 if (!proxy) { | 284 if (!proxy) { |
| 273 return obj->_class->setProperty(obj, name, value); | 285 return obj->_class->setProperty(obj, name, value); |
| 274 } | 286 } |
| 275 | 287 |
| 276 NPIdentifier_Param name_param; | 288 NPIdentifier_Param name_param; |
| 277 CreateNPIdentifierParam(name, &name_param); | 289 CreateNPIdentifierParam(name, &name_param); |
| 278 | 290 |
| 279 NPVariant_Param value_param; | 291 NPVariant_Param value_param; |
| 280 CreateNPVariantParam( | 292 CreateNPVariantParam( |
| 281 *value, proxy->channel(), &value_param, false, | 293 *value, proxy->channel(), &value_param, false, |
| 282 proxy->modal_dialog_event_, proxy->page_url_); | 294 proxy->modal_dialog_event_, proxy->page_url_); |
| 283 | 295 |
| 284 proxy->Send(new NPObjectMsg_SetProperty( | 296 proxy->Send(new NPObjectMsg_SetProperty( |
| 285 proxy->route_id(), name_param, value_param, &result)); | 297 proxy->route_id(), name_param, value_param, &result)); |
| 286 // Send may delete proxy. | 298 // Send may delete proxy. |
| 287 proxy = NULL; | 299 proxy = NULL; |
| 288 | 300 |
| 289 return result; | 301 return result; |
| 290 } | 302 } |
| 291 | 303 |
| 292 bool NPObjectProxy::NPRemoveProperty(NPObject *obj, | 304 bool NPObjectProxy::NPRemoveProperty(NPObject *obj, |
| 293 NPIdentifier name) { | 305 NPIdentifier name) { |
| 306 if (obj == NULL) |
| 307 return false; |
| 308 |
| 294 bool result = false; | 309 bool result = false; |
| 295 NPObjectProxy* proxy = GetProxy(obj); | 310 NPObjectProxy* proxy = GetProxy(obj); |
| 296 if (!proxy) { | 311 if (!proxy) { |
| 297 return obj->_class->removeProperty(obj, name); | 312 return obj->_class->removeProperty(obj, name); |
| 298 } | 313 } |
| 299 | 314 |
| 300 NPIdentifier_Param name_param; | 315 NPIdentifier_Param name_param; |
| 301 CreateNPIdentifierParam(name, &name_param); | 316 CreateNPIdentifierParam(name, &name_param); |
| 302 | 317 |
| 303 NPVariant_Param param; | 318 NPVariant_Param param; |
| 304 proxy->Send(new NPObjectMsg_RemoveProperty( | 319 proxy->Send(new NPObjectMsg_RemoveProperty( |
| 305 proxy->route_id(), name_param, &result)); | 320 proxy->route_id(), name_param, &result)); |
| 306 // Send may delete proxy. | 321 // Send may delete proxy. |
| 307 proxy = NULL; | 322 proxy = NULL; |
| 308 | 323 |
| 309 return result; | 324 return result; |
| 310 } | 325 } |
| 311 | 326 |
| 312 void NPObjectProxy::NPPInvalidate(NPObject *obj) { | 327 void NPObjectProxy::NPPInvalidate(NPObject *obj) { |
| 328 if (obj == NULL) |
| 329 return; |
| 330 |
| 313 NPObjectProxy* proxy = GetProxy(obj); | 331 NPObjectProxy* proxy = GetProxy(obj); |
| 314 if (!proxy) { | 332 if (!proxy) { |
| 315 obj->_class->invalidate(obj); | 333 obj->_class->invalidate(obj); |
| 316 return; | 334 return; |
| 317 } | 335 } |
| 318 | 336 |
| 319 proxy->Send(new NPObjectMsg_Invalidate(proxy->route_id())); | 337 proxy->Send(new NPObjectMsg_Invalidate(proxy->route_id())); |
| 320 // Send may delete proxy. | 338 // Send may delete proxy. |
| 321 proxy = NULL; | 339 proxy = NULL; |
| 322 } | 340 } |
| 323 | 341 |
| 324 bool NPObjectProxy::NPNEnumerate(NPObject *obj, | 342 bool NPObjectProxy::NPNEnumerate(NPObject *obj, |
| 325 NPIdentifier **value, | 343 NPIdentifier **value, |
| 326 uint32_t *count) { | 344 uint32_t *count) { |
| 345 if (obj == NULL) |
| 346 return false; |
| 347 |
| 327 bool result = false; | 348 bool result = false; |
| 328 NPObjectProxy* proxy = GetProxy(obj); | 349 NPObjectProxy* proxy = GetProxy(obj); |
| 329 if (!proxy) { | 350 if (!proxy) { |
| 330 return obj->_class->enumerate(obj, value, count); | 351 return obj->_class->enumerate(obj, value, count); |
| 331 } | 352 } |
| 332 | 353 |
| 333 std::vector<NPIdentifier_Param> value_param; | 354 std::vector<NPIdentifier_Param> value_param; |
| 334 proxy->Send(new NPObjectMsg_Enumeration( | 355 proxy->Send(new NPObjectMsg_Enumeration( |
| 335 proxy->route_id(), &value_param, &result)); | 356 proxy->route_id(), &value_param, &result)); |
| 336 // Send may delete proxy. | 357 // Send may delete proxy. |
| 337 proxy = NULL; | 358 proxy = NULL; |
| 338 | 359 |
| 339 if (!result) | 360 if (!result) |
| 340 return false; | 361 return false; |
| 341 | 362 |
| 342 *count = static_cast<unsigned int>(value_param.size()); | 363 *count = static_cast<unsigned int>(value_param.size()); |
| 343 *value = static_cast<NPIdentifier *>( | 364 *value = static_cast<NPIdentifier *>( |
| 344 NPN_MemAlloc(sizeof(NPIdentifier) * *count)); | 365 NPN_MemAlloc(sizeof(NPIdentifier) * *count)); |
| 345 for (unsigned int i = 0; i < *count; ++i) | 366 for (unsigned int i = 0; i < *count; ++i) |
| 346 (*value)[i] = CreateNPIdentifier(value_param[i]); | 367 (*value)[i] = CreateNPIdentifier(value_param[i]); |
| 347 | 368 |
| 348 return true; | 369 return true; |
| 349 } | 370 } |
| 350 | 371 |
| 351 bool NPObjectProxy::NPNConstruct(NPObject *obj, | 372 bool NPObjectProxy::NPNConstruct(NPObject *obj, |
| 352 const NPVariant *args, | 373 const NPVariant *args, |
| 353 uint32_t arg_count, | 374 uint32_t arg_count, |
| 354 NPVariant *np_result) { | 375 NPVariant *np_result) { |
| 376 if (obj == NULL) |
| 377 return false; |
| 378 |
| 355 NPObjectProxy* proxy = GetProxy(obj); | 379 NPObjectProxy* proxy = GetProxy(obj); |
| 356 if (!proxy) { | 380 if (!proxy) { |
| 357 return obj->_class->construct(obj, args, arg_count, np_result); | 381 return obj->_class->construct(obj, args, arg_count, np_result); |
| 358 } | 382 } |
| 359 | 383 |
| 360 bool result = false; | 384 bool result = false; |
| 361 | 385 |
| 362 // Note: This instance can get destroyed in the context of | 386 // Note: This instance can get destroyed in the context of |
| 363 // Send so addref the channel in this scope. | 387 // Send so addref the channel in this scope. |
| 364 scoped_refptr<PluginChannelBase> channel_copy = proxy->channel_; | 388 scoped_refptr<PluginChannelBase> channel_copy = proxy->channel_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 return; | 474 return; |
| 451 } | 475 } |
| 452 | 476 |
| 453 NPVariant_Param result_param; | 477 NPVariant_Param result_param; |
| 454 std::string message_str(message); | 478 std::string message_str(message); |
| 455 | 479 |
| 456 proxy->Send(new NPObjectMsg_SetException(proxy->route_id(), message_str)); | 480 proxy->Send(new NPObjectMsg_SetException(proxy->route_id(), message_str)); |
| 457 // Send may delete proxy. | 481 // Send may delete proxy. |
| 458 proxy = NULL; | 482 proxy = NULL; |
| 459 } | 483 } |
| OLD | NEW |