| 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 "chrome/common/plugin_messages.h" | 8 #include "chrome/common/plugin_messages.h" |
| 8 #include "chrome/common/win_util.h" | 9 #include "chrome/common/win_util.h" |
| 9 #include "chrome/plugin/npobject_util.h" | 10 #include "chrome/plugin/npobject_util.h" |
| 10 #include "chrome/plugin/plugin_channel_base.h" | 11 #include "chrome/plugin/plugin_channel_base.h" |
| 11 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
| 12 #include "webkit/glue/plugins/plugin_instance.h" | 13 #include "webkit/glue/plugins/plugin_instance.h" |
| 13 | 14 |
| 14 | 15 |
| 15 struct NPObjectWrapper { | 16 struct NPObjectWrapper { |
| 16 NPObject object; | 17 NPObject object; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 41 proxy = wrapper->proxy; | 42 proxy = wrapper->proxy; |
| 42 } | 43 } |
| 43 | 44 |
| 44 return proxy; | 45 return proxy; |
| 45 } | 46 } |
| 46 | 47 |
| 47 NPObjectProxy::NPObjectProxy( | 48 NPObjectProxy::NPObjectProxy( |
| 48 PluginChannelBase* channel, | 49 PluginChannelBase* channel, |
| 49 int route_id, | 50 int route_id, |
| 50 void* npobject_ptr, | 51 void* npobject_ptr, |
| 51 HANDLE modal_dialog_event) | 52 base::WaitableEvent* modal_dialog_event) |
| 52 : channel_(channel), | 53 : channel_(channel), |
| 53 route_id_(route_id), | 54 route_id_(route_id), |
| 54 npobject_ptr_(npobject_ptr), | 55 npobject_ptr_(npobject_ptr), |
| 55 modal_dialog_event_(modal_dialog_event) { | 56 modal_dialog_event_(modal_dialog_event) { |
| 56 channel_->AddRoute(route_id, this, true); | 57 channel_->AddRoute(route_id, this, true); |
| 57 } | 58 } |
| 58 | 59 |
| 59 NPObjectProxy::~NPObjectProxy() { | 60 NPObjectProxy::~NPObjectProxy() { |
| 60 if (channel_.get()) { | 61 if (channel_.get()) { |
| 61 Send(new NPObjectMsg_Release(route_id_)); | 62 Send(new NPObjectMsg_Release(route_id_)); |
| 62 if (channel_.get()) | 63 if (channel_.get()) |
| 63 channel_->RemoveRoute(route_id_); | 64 channel_->RemoveRoute(route_id_); |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 67 NPObject* NPObjectProxy::Create(PluginChannelBase* channel, | 68 NPObject* NPObjectProxy::Create(PluginChannelBase* channel, |
| 68 int route_id, | 69 int route_id, |
| 69 void* npobject_ptr, | 70 void* npobject_ptr, |
| 70 HANDLE modal_dialog_event) { | 71 base::WaitableEvent* modal_dialog_event) { |
| 71 NPObjectWrapper* obj = reinterpret_cast<NPObjectWrapper*>( | 72 NPObjectWrapper* obj = reinterpret_cast<NPObjectWrapper*>( |
| 72 NPN_CreateObject(0, &npclass_proxy_)); | 73 NPN_CreateObject(0, &npclass_proxy_)); |
| 73 obj->proxy = new NPObjectProxy( | 74 obj->proxy = new NPObjectProxy( |
| 74 channel, route_id, npobject_ptr, modal_dialog_event); | 75 channel, route_id, npobject_ptr, modal_dialog_event); |
| 75 | 76 |
| 76 return reinterpret_cast<NPObject*>(obj); | 77 return reinterpret_cast<NPObject*>(obj); |
| 77 } | 78 } |
| 78 | 79 |
| 79 bool NPObjectProxy::Send(IPC::Message* msg) { | 80 bool NPObjectProxy::Send(IPC::Message* msg) { |
| 80 if (channel_.get()) | 81 if (channel_.get()) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 proxy->route_id_, is_default, name_param, args_param, ¶m_result, | 172 proxy->route_id_, is_default, name_param, args_param, ¶m_result, |
| 172 &result); | 173 &result); |
| 173 | 174 |
| 174 // If we're in the plugin process and this invoke leads to a dialog box, the | 175 // If we're in the plugin process and this invoke leads to a dialog box, the |
| 175 // plugin will hang the window hierarchy unless we pump the window message | 176 // plugin will hang the window hierarchy unless we pump the window message |
| 176 // queue while waiting for a reply. We need to do this to simulate what | 177 // queue while waiting for a reply. We need to do this to simulate what |
| 177 // happens when everything runs in-process (while calling MessageBox window | 178 // happens when everything runs in-process (while calling MessageBox window |
| 178 // messages are pumped). | 179 // messages are pumped). |
| 179 msg->set_pump_messages_event(proxy->modal_dialog_event_); | 180 msg->set_pump_messages_event(proxy->modal_dialog_event_); |
| 180 | 181 |
| 181 HANDLE modal_dialog_event_handle = proxy->modal_dialog_event_; | 182 base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; |
| 182 | 183 |
| 183 proxy->Send(msg); | 184 proxy->Send(msg); |
| 184 | 185 |
| 185 // Send may delete proxy. | 186 // Send may delete proxy. |
| 186 proxy = NULL; | 187 proxy = NULL; |
| 187 | 188 |
| 188 if (!result) | 189 if (!result) |
| 189 return false; | 190 return false; |
| 190 | 191 |
| 191 CreateNPVariant( | 192 CreateNPVariant( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 bool result = false; | 231 bool result = false; |
| 231 NPObjectProxy* proxy = GetProxy(obj); | 232 NPObjectProxy* proxy = GetProxy(obj); |
| 232 if (!proxy) { | 233 if (!proxy) { |
| 233 return obj->_class->getProperty(obj, name, np_result); | 234 return obj->_class->getProperty(obj, name, np_result); |
| 234 } | 235 } |
| 235 | 236 |
| 236 NPIdentifier_Param name_param; | 237 NPIdentifier_Param name_param; |
| 237 CreateNPIdentifierParam(name, &name_param); | 238 CreateNPIdentifierParam(name, &name_param); |
| 238 | 239 |
| 239 NPVariant_Param param; | 240 NPVariant_Param param; |
| 240 HANDLE modal_dialog_event_handle = proxy->modal_dialog_event_; | 241 base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; |
| 241 scoped_refptr<PluginChannelBase> channel(proxy->channel_); | 242 scoped_refptr<PluginChannelBase> channel(proxy->channel_); |
| 242 proxy->Send(new NPObjectMsg_GetProperty( | 243 proxy->Send(new NPObjectMsg_GetProperty( |
| 243 proxy->route_id(), name_param, ¶m, &result)); | 244 proxy->route_id(), name_param, ¶m, &result)); |
| 244 // Send may delete proxy. | 245 // Send may delete proxy. |
| 245 proxy = NULL; | 246 proxy = NULL; |
| 246 if (!result) | 247 if (!result) |
| 247 return false; | 248 return false; |
| 248 | 249 |
| 249 CreateNPVariant( | 250 CreateNPVariant( |
| 250 param, channel.get(), np_result, modal_dialog_event_handle); | 251 param, channel.get(), np_result, modal_dialog_event_handle); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 NPObjectMsg_Evaluate* msg = new NPObjectMsg_Evaluate(proxy->route_id(), | 361 NPObjectMsg_Evaluate* msg = new NPObjectMsg_Evaluate(proxy->route_id(), |
| 361 script_str, | 362 script_str, |
| 362 popups_allowed, | 363 popups_allowed, |
| 363 &result_param, | 364 &result_param, |
| 364 &result); | 365 &result); |
| 365 | 366 |
| 366 // Please refer to the comments in NPObjectProxy::NPInvokePrivate for | 367 // Please refer to the comments in NPObjectProxy::NPInvokePrivate for |
| 367 // the reasoning behind setting the pump messages event in the sync message. | 368 // the reasoning behind setting the pump messages event in the sync message. |
| 368 msg->set_pump_messages_event(proxy->modal_dialog_event_); | 369 msg->set_pump_messages_event(proxy->modal_dialog_event_); |
| 369 scoped_refptr<PluginChannelBase> channel(proxy->channel_); | 370 scoped_refptr<PluginChannelBase> channel(proxy->channel_); |
| 370 HANDLE modal_dialog_event_handle = proxy->modal_dialog_event_; | 371 base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; |
| 371 proxy->Send(msg); | 372 proxy->Send(msg); |
| 372 // Send may delete proxy. | 373 // Send may delete proxy. |
| 373 proxy = NULL; | 374 proxy = NULL; |
| 374 if (!result) | 375 if (!result) |
| 375 return false; | 376 return false; |
| 376 | 377 |
| 377 CreateNPVariant( | 378 CreateNPVariant( |
| 378 result_param, channel.get(), result_var, modal_dialog_event_handle); | 379 result_param, channel.get(), result_var, modal_dialog_event_handle); |
| 379 return true; | 380 return true; |
| 380 } | 381 } |
| 381 | 382 |
| 382 void NPObjectProxy::NPNSetException(NPObject *obj, | 383 void NPObjectProxy::NPNSetException(NPObject *obj, |
| 383 const NPUTF8 *message) { | 384 const NPUTF8 *message) { |
| 384 NPObjectProxy* proxy = GetProxy(obj); | 385 NPObjectProxy* proxy = GetProxy(obj); |
| 385 if (!proxy) { | 386 if (!proxy) { |
| 386 return; | 387 return; |
| 387 } | 388 } |
| 388 | 389 |
| 389 NPVariant_Param result_param; | 390 NPVariant_Param result_param; |
| 390 std::string message_str(message); | 391 std::string message_str(message); |
| 391 | 392 |
| 392 proxy->Send(new NPObjectMsg_SetException(proxy->route_id(), message_str)); | 393 proxy->Send(new NPObjectMsg_SetException(proxy->route_id(), message_str)); |
| 393 // Send may delete proxy. | 394 // Send may delete proxy. |
| 394 proxy = NULL; | 395 proxy = NULL; |
| 395 } | 396 } |
| 396 | 397 |
| OLD | NEW |