OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common_child/npobject_proxy.h" | 5 #include "content/common_child/npobject_proxy.h" |
6 | 6 |
7 #include "content/common_child/np_channel_base.h" | 7 #include "content/common_child/np_channel_base.h" |
8 #include "content/common_child/npobject_util.h" | 8 #include "content/common_child/npobject_util.h" |
9 #include "content/common_child/plugin_messages.h" | 9 #include "content/common_child/plugin_messages.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 int render_view_id, | 63 int render_view_id, |
64 const GURL& page_url) | 64 const GURL& page_url) |
65 : channel_(channel), | 65 : channel_(channel), |
66 route_id_(route_id), | 66 route_id_(route_id), |
67 render_view_id_(render_view_id), | 67 render_view_id_(render_view_id), |
68 page_url_(page_url) { | 68 page_url_(page_url) { |
69 channel_->AddRoute(route_id, this, this); | 69 channel_->AddRoute(route_id, this, this); |
70 } | 70 } |
71 | 71 |
72 NPObjectProxy::~NPObjectProxy() { | 72 NPObjectProxy::~NPObjectProxy() { |
73 if (channel_) { | 73 if (channel_.get()) { |
74 // This NPObjectProxy instance is now invalid and should not be reused for | 74 // This NPObjectProxy instance is now invalid and should not be reused for |
75 // requests initiated by plugins. We may receive requests for the | 75 // requests initiated by plugins. We may receive requests for the |
76 // same NPObject in the context of the outgoing NPObjectMsg_Release call. | 76 // same NPObject in the context of the outgoing NPObjectMsg_Release call. |
77 // We should be creating new NPObjectProxy instances to wrap these | 77 // We should be creating new NPObjectProxy instances to wrap these |
78 // NPObjects. | 78 // NPObjects. |
79 channel_->RemoveMappingForNPObjectProxy(route_id_); | 79 channel_->RemoveMappingForNPObjectProxy(route_id_); |
80 channel_->RemoveRoute(route_id_); | 80 channel_->RemoveRoute(route_id_); |
81 Send(new NPObjectMsg_Release(route_id_)); | 81 Send(new NPObjectMsg_Release(route_id_)); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 NPObject* NPObjectProxy::Create(NPChannelBase* channel, | 85 NPObject* NPObjectProxy::Create(NPChannelBase* channel, |
86 int route_id, | 86 int route_id, |
87 int render_view_id, | 87 int render_view_id, |
88 const GURL& page_url) { | 88 const GURL& page_url) { |
89 NPObjectWrapper* obj = reinterpret_cast<NPObjectWrapper*>( | 89 NPObjectWrapper* obj = reinterpret_cast<NPObjectWrapper*>( |
90 WebBindings::createObject(0, &npclass_proxy_)); | 90 WebBindings::createObject(0, &npclass_proxy_)); |
91 obj->proxy = new NPObjectProxy(channel, route_id, render_view_id, page_url); | 91 obj->proxy = new NPObjectProxy(channel, route_id, render_view_id, page_url); |
92 channel->AddMappingForNPObjectProxy(route_id, &obj->object); | 92 channel->AddMappingForNPObjectProxy(route_id, &obj->object); |
93 return reinterpret_cast<NPObject*>(obj); | 93 return reinterpret_cast<NPObject*>(obj); |
94 } | 94 } |
95 | 95 |
96 bool NPObjectProxy::Send(IPC::Message* msg) { | 96 bool NPObjectProxy::Send(IPC::Message* msg) { |
97 if (channel_) | 97 if (channel_.get()) |
98 return channel_->Send(msg); | 98 return channel_->Send(msg); |
99 | 99 |
100 delete msg; | 100 delete msg; |
101 return false; | 101 return false; |
102 } | 102 } |
103 | 103 |
104 NPObject* NPObjectProxy::NPAllocate(NPP, NPClass*) { | 104 NPObject* NPObjectProxy::NPAllocate(NPP, NPClass*) { |
105 return reinterpret_cast<NPObject*>(new NPObjectWrapper); | 105 return reinterpret_cast<NPObject*>(new NPObjectWrapper); |
106 } | 106 } |
107 | 107 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } else { | 186 } else { |
187 CreateNPIdentifierParam(name, &name_param); | 187 CreateNPIdentifierParam(name, &name_param); |
188 } | 188 } |
189 | 189 |
190 // Note: This instance can get destroyed in the context of | 190 // Note: This instance can get destroyed in the context of |
191 // Send so addref the channel in this scope. | 191 // Send so addref the channel in this scope. |
192 scoped_refptr<NPChannelBase> channel_copy = proxy->channel_; | 192 scoped_refptr<NPChannelBase> channel_copy = proxy->channel_; |
193 std::vector<NPVariant_Param> args_param; | 193 std::vector<NPVariant_Param> args_param; |
194 for (unsigned int i = 0; i < arg_count; ++i) { | 194 for (unsigned int i = 0; i < arg_count; ++i) { |
195 NPVariant_Param param; | 195 NPVariant_Param param; |
196 CreateNPVariantParam( | 196 CreateNPVariantParam(args[i], |
197 args[i], channel_copy, ¶m, false, render_view_id, | 197 channel_copy.get(), |
198 proxy->page_url_); | 198 ¶m, |
| 199 false, |
| 200 render_view_id, |
| 201 proxy->page_url_); |
199 args_param.push_back(param); | 202 args_param.push_back(param); |
200 } | 203 } |
201 | 204 |
202 NPVariant_Param param_result; | 205 NPVariant_Param param_result; |
203 NPObjectMsg_Invoke* msg = new NPObjectMsg_Invoke( | 206 NPObjectMsg_Invoke* msg = new NPObjectMsg_Invoke( |
204 proxy->route_id_, is_default, name_param, args_param, ¶m_result, | 207 proxy->route_id_, is_default, name_param, args_param, ¶m_result, |
205 &result); | 208 &result); |
206 | 209 |
207 // If we're in the plugin process and this invoke leads to a dialog box, the | 210 // If we're in the plugin process and this invoke leads to a dialog box, the |
208 // plugin will hang the window hierarchy unless we pump the window message | 211 // plugin will hang the window hierarchy unless we pump the window message |
209 // queue while waiting for a reply. We need to do this to simulate what | 212 // queue while waiting for a reply. We need to do this to simulate what |
210 // happens when everything runs in-process (while calling MessageBox window | 213 // happens when everything runs in-process (while calling MessageBox window |
211 // messages are pumped). | 214 // messages are pumped). |
212 if (IsPluginProcess() && proxy->channel()) { | 215 if (IsPluginProcess() && proxy->channel()) { |
213 msg->set_pump_messages_event( | 216 msg->set_pump_messages_event( |
214 proxy->channel()->GetModalDialogEvent(render_view_id)); | 217 proxy->channel()->GetModalDialogEvent(render_view_id)); |
215 } | 218 } |
216 | 219 |
217 GURL page_url = proxy->page_url_; | 220 GURL page_url = proxy->page_url_; |
218 proxy->Send(msg); | 221 proxy->Send(msg); |
219 | 222 |
220 // Send may delete proxy. | 223 // Send may delete proxy. |
221 proxy = NULL; | 224 proxy = NULL; |
222 | 225 |
223 if (!result) | 226 if (!result) |
224 return false; | 227 return false; |
225 | 228 |
226 CreateNPVariant( | 229 CreateNPVariant( |
227 param_result, channel_copy, np_result, render_view_id, page_url); | 230 param_result, channel_copy.get(), np_result, render_view_id, page_url); |
228 return true; | 231 return true; |
229 } | 232 } |
230 | 233 |
231 bool NPObjectProxy::NPHasProperty(NPObject *obj, | 234 bool NPObjectProxy::NPHasProperty(NPObject *obj, |
232 NPIdentifier name) { | 235 NPIdentifier name) { |
233 if (obj == NULL) | 236 if (obj == NULL) |
234 return false; | 237 return false; |
235 | 238 |
236 bool result = false; | 239 bool result = false; |
237 NPObjectProxy* proxy = GetProxy(obj); | 240 NPObjectProxy* proxy = GetProxy(obj); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 415 |
413 bool result = false; | 416 bool result = false; |
414 int render_view_id = proxy->render_view_id_; | 417 int render_view_id = proxy->render_view_id_; |
415 | 418 |
416 // Note: This instance can get destroyed in the context of | 419 // Note: This instance can get destroyed in the context of |
417 // Send so addref the channel in this scope. | 420 // Send so addref the channel in this scope. |
418 scoped_refptr<NPChannelBase> channel_copy = proxy->channel_; | 421 scoped_refptr<NPChannelBase> channel_copy = proxy->channel_; |
419 std::vector<NPVariant_Param> args_param; | 422 std::vector<NPVariant_Param> args_param; |
420 for (unsigned int i = 0; i < arg_count; ++i) { | 423 for (unsigned int i = 0; i < arg_count; ++i) { |
421 NPVariant_Param param; | 424 NPVariant_Param param; |
422 CreateNPVariantParam( | 425 CreateNPVariantParam(args[i], |
423 args[i], channel_copy, ¶m, false, render_view_id, | 426 channel_copy.get(), |
424 proxy->page_url_); | 427 ¶m, |
| 428 false, |
| 429 render_view_id, |
| 430 proxy->page_url_); |
425 args_param.push_back(param); | 431 args_param.push_back(param); |
426 } | 432 } |
427 | 433 |
428 NPVariant_Param param_result; | 434 NPVariant_Param param_result; |
429 NPObjectMsg_Construct* msg = new NPObjectMsg_Construct( | 435 NPObjectMsg_Construct* msg = new NPObjectMsg_Construct( |
430 proxy->route_id_, args_param, ¶m_result, &result); | 436 proxy->route_id_, args_param, ¶m_result, &result); |
431 | 437 |
432 // See comment in NPObjectProxy::NPInvokePrivate. | 438 // See comment in NPObjectProxy::NPInvokePrivate. |
433 if (IsPluginProcess() && proxy->channel()) { | 439 if (IsPluginProcess() && proxy->channel()) { |
434 msg->set_pump_messages_event( | 440 msg->set_pump_messages_event( |
435 proxy->channel()->GetModalDialogEvent(proxy->render_view_id_)); | 441 proxy->channel()->GetModalDialogEvent(proxy->render_view_id_)); |
436 } | 442 } |
437 | 443 |
438 GURL page_url = proxy->page_url_; | 444 GURL page_url = proxy->page_url_; |
439 proxy->Send(msg); | 445 proxy->Send(msg); |
440 | 446 |
441 // Send may delete proxy. | 447 // Send may delete proxy. |
442 proxy = NULL; | 448 proxy = NULL; |
443 | 449 |
444 if (!result) | 450 if (!result) |
445 return false; | 451 return false; |
446 | 452 |
447 CreateNPVariant( | 453 CreateNPVariant( |
448 param_result, channel_copy, np_result, render_view_id, page_url); | 454 param_result, channel_copy.get(), np_result, render_view_id, page_url); |
449 return true; | 455 return true; |
450 } | 456 } |
451 | 457 |
452 bool NPObjectProxy::NPNEvaluate(NPP npp, | 458 bool NPObjectProxy::NPNEvaluate(NPP npp, |
453 NPObject *obj, | 459 NPObject *obj, |
454 NPString *script, | 460 NPString *script, |
455 NPVariant *result_var) { | 461 NPVariant *result_var) { |
456 NPObjectProxy* proxy = GetProxy(obj); | 462 NPObjectProxy* proxy = GetProxy(obj); |
457 if (!proxy) { | 463 if (!proxy) { |
458 return false; | 464 return false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 proxy = NULL; | 498 proxy = NULL; |
493 if (!result) | 499 if (!result) |
494 return false; | 500 return false; |
495 | 501 |
496 CreateNPVariant( | 502 CreateNPVariant( |
497 result_param, channel.get(), result_var, render_view_id, page_url); | 503 result_param, channel.get(), result_var, render_view_id, page_url); |
498 return true; | 504 return true; |
499 } | 505 } |
500 | 506 |
501 } // namespace content | 507 } // namespace content |
OLD | NEW |