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" |
11 #include "webkit/glue/webkit_glue.h" | 11 #include "webkit/glue/webkit_glue.h" |
12 #include "webkit/glue/plugins/plugin_instance.h" | 12 #include "webkit/glue/plugins/plugin_instance.h" |
13 | 13 |
14 | 14 |
15 struct NPObjectWrapper { | 15 struct NPObjectWrapper { |
16 NPObject object; | 16 NPObject object; |
17 NPObjectProxy* proxy; | 17 NPObjectProxy* proxy; |
18 }; | 18 }; |
19 | 19 |
20 NPClass NPObjectProxy::npclass_proxy_ = { | 20 NPClass NPObjectProxy::npclass_proxy_ = { |
21 2, | 21 NP_CLASS_STRUCT_VERSION, |
22 NPObjectProxy::NPAllocate, | 22 NPObjectProxy::NPAllocate, |
23 NPObjectProxy::NPDeallocate, | 23 NPObjectProxy::NPDeallocate, |
24 NPObjectProxy::NPPInvalidate, | 24 NPObjectProxy::NPPInvalidate, |
25 NPObjectProxy::NPHasMethod, | 25 NPObjectProxy::NPHasMethod, |
26 NPObjectProxy::NPInvoke, | 26 NPObjectProxy::NPInvoke, |
27 NPObjectProxy::NPInvokeDefault, | 27 NPObjectProxy::NPInvokeDefault, |
28 NPObjectProxy::NPHasProperty, | 28 NPObjectProxy::NPHasProperty, |
29 NPObjectProxy::NPGetProperty, | 29 NPObjectProxy::NPGetProperty, |
30 NPObjectProxy::NPSetProperty, | 30 NPObjectProxy::NPSetProperty, |
31 NPObjectProxy::NPRemoveProperty, | 31 NPObjectProxy::NPRemoveProperty, |
32 NPObjectProxy::NPNEnumerate | 32 NPObjectProxy::NPNEnumerate, |
| 33 NPObjectProxy::NPNConstruct |
33 }; | 34 }; |
34 | 35 |
35 NPObjectProxy* NPObjectProxy::GetProxy(NPObject* object) { | 36 NPObjectProxy* NPObjectProxy::GetProxy(NPObject* object) { |
36 NPObjectProxy* proxy = NULL; | 37 NPObjectProxy* proxy = NULL; |
37 | 38 |
38 // Wrapper exists only for NPObjects that we had created. | 39 // Wrapper exists only for NPObjects that we had created. |
39 if (&npclass_proxy_ == object->_class) { | 40 if (&npclass_proxy_ == object->_class) { |
40 NPObjectWrapper* wrapper = reinterpret_cast<NPObjectWrapper*>(object); | 41 NPObjectWrapper* wrapper = reinterpret_cast<NPObjectWrapper*>(object); |
41 proxy = wrapper->proxy; | 42 proxy = wrapper->proxy; |
42 } | 43 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 333 |
333 *count = static_cast<unsigned int>(value_param.size()); | 334 *count = static_cast<unsigned int>(value_param.size()); |
334 *value = static_cast<NPIdentifier *>( | 335 *value = static_cast<NPIdentifier *>( |
335 NPN_MemAlloc(sizeof(NPIdentifier) * *count)); | 336 NPN_MemAlloc(sizeof(NPIdentifier) * *count)); |
336 for (unsigned int i = 0; i < *count; ++i) | 337 for (unsigned int i = 0; i < *count; ++i) |
337 (*value)[i] = CreateNPIdentifier(value_param[i]); | 338 (*value)[i] = CreateNPIdentifier(value_param[i]); |
338 | 339 |
339 return true; | 340 return true; |
340 } | 341 } |
341 | 342 |
| 343 bool NPObjectProxy::NPNConstruct(NPObject *obj, |
| 344 const NPVariant *args, |
| 345 uint32_t arg_count, |
| 346 NPVariant *np_result) { |
| 347 NPObjectProxy* proxy = GetProxy(obj); |
| 348 if (!proxy) { |
| 349 return obj->_class->construct(obj, args, arg_count, np_result); |
| 350 } |
| 351 |
| 352 bool result = false; |
| 353 |
| 354 // Note: This instance can get destroyed in the context of |
| 355 // Send so addref the channel in this scope. |
| 356 scoped_refptr<PluginChannelBase> channel_copy = proxy->channel_; |
| 357 std::vector<NPVariant_Param> args_param; |
| 358 for (unsigned int i = 0; i < arg_count; ++i) { |
| 359 NPVariant_Param param; |
| 360 CreateNPVariantParam( |
| 361 args[i], channel_copy, ¶m, false, proxy->modal_dialog_event_); |
| 362 args_param.push_back(param); |
| 363 } |
| 364 |
| 365 NPVariant_Param param_result; |
| 366 NPObjectMsg_Construct* msg = new NPObjectMsg_Construct( |
| 367 proxy->route_id_, args_param, ¶m_result, &result); |
| 368 |
| 369 // See comment in NPObjectProxy::NPInvokePrivate. |
| 370 msg->set_pump_messages_event(proxy->modal_dialog_event_); |
| 371 |
| 372 base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; |
| 373 |
| 374 proxy->Send(msg); |
| 375 |
| 376 // Send may delete proxy. |
| 377 proxy = NULL; |
| 378 |
| 379 if (!result) |
| 380 return false; |
| 381 |
| 382 CreateNPVariant( |
| 383 param_result, channel_copy, np_result, modal_dialog_event_handle); |
| 384 return true; |
| 385 } |
| 386 |
342 bool NPObjectProxy::NPNEvaluate(NPP npp, | 387 bool NPObjectProxy::NPNEvaluate(NPP npp, |
343 NPObject *obj, | 388 NPObject *obj, |
344 NPString *script, | 389 NPString *script, |
345 NPVariant *result_var) { | 390 NPVariant *result_var) { |
346 bool result = false; | 391 bool result = false; |
347 NPObjectProxy* proxy = GetProxy(obj); | 392 NPObjectProxy* proxy = GetProxy(obj); |
348 if (!proxy) { | 393 if (!proxy) { |
349 return false; | 394 return false; |
350 } | 395 } |
351 | 396 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return; | 436 return; |
392 } | 437 } |
393 | 438 |
394 NPVariant_Param result_param; | 439 NPVariant_Param result_param; |
395 std::string message_str(message); | 440 std::string message_str(message); |
396 | 441 |
397 proxy->Send(new NPObjectMsg_SetException(proxy->route_id(), message_str)); | 442 proxy->Send(new NPObjectMsg_SetException(proxy->route_id(), message_str)); |
398 // Send may delete proxy. | 443 // Send may delete proxy. |
399 proxy = NULL; | 444 proxy = NULL; |
400 } | 445 } |
OLD | NEW |