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_stub.h" | 5 #include "chrome/plugin/npobject_stub.h" |
6 | 6 |
| 7 #include "chrome/common/child_process_logging.h" |
7 #include "chrome/common/plugin_messages.h" | 8 #include "chrome/common/plugin_messages.h" |
8 #include "chrome/plugin/npobject_util.h" | 9 #include "chrome/plugin/npobject_util.h" |
9 #include "chrome/plugin/plugin_channel_base.h" | 10 #include "chrome/plugin/plugin_channel_base.h" |
10 #include "chrome/renderer/webplugin_delegate_proxy.h" | 11 #include "chrome/renderer/webplugin_delegate_proxy.h" |
11 #include "third_party/npapi/bindings/npapi.h" | 12 #include "third_party/npapi/bindings/npapi.h" |
12 #include "third_party/npapi/bindings/npruntime.h" | 13 #include "third_party/npapi/bindings/npruntime.h" |
13 | 14 |
14 NPObjectStub::NPObjectStub( | 15 NPObjectStub::NPObjectStub( |
15 NPObject* npobject, | 16 NPObject* npobject, |
16 PluginChannelBase* channel, | 17 PluginChannelBase* channel, |
17 int route_id, | 18 int route_id, |
18 base::WaitableEvent* modal_dialog_event) | 19 base::WaitableEvent* modal_dialog_event, |
| 20 const GURL& page_url) |
19 : npobject_(npobject), | 21 : npobject_(npobject), |
20 channel_(channel), | 22 channel_(channel), |
21 route_id_(route_id), | 23 route_id_(route_id), |
22 valid_(true), | 24 valid_(true), |
23 web_plugin_delegate_proxy_(NULL), | 25 web_plugin_delegate_proxy_(NULL), |
24 modal_dialog_event_(modal_dialog_event) { | 26 modal_dialog_event_(modal_dialog_event), |
| 27 page_url_(page_url) { |
25 channel_->AddRoute(route_id, this, true); | 28 channel_->AddRoute(route_id, this, true); |
26 | 29 |
27 // We retain the object just as PluginHost does if everything was in-process. | 30 // We retain the object just as PluginHost does if everything was in-process. |
28 NPN_RetainObject(npobject_); | 31 NPN_RetainObject(npobject_); |
29 } | 32 } |
30 | 33 |
31 NPObjectStub::~NPObjectStub() { | 34 NPObjectStub::~NPObjectStub() { |
32 if (web_plugin_delegate_proxy_) | 35 if (web_plugin_delegate_proxy_) |
33 web_plugin_delegate_proxy_->DropWindowScriptObject(); | 36 web_plugin_delegate_proxy_->DropWindowScriptObject(); |
34 | 37 |
35 channel_->RemoveRoute(route_id_); | 38 channel_->RemoveRoute(route_id_); |
36 if (npobject_ && valid_) | 39 if (npobject_ && valid_) |
37 NPN_ReleaseObject(npobject_); | 40 NPN_ReleaseObject(npobject_); |
38 } | 41 } |
39 | 42 |
40 bool NPObjectStub::Send(IPC::Message* msg) { | 43 bool NPObjectStub::Send(IPC::Message* msg) { |
41 return channel_->Send(msg); | 44 return channel_->Send(msg); |
42 } | 45 } |
43 | 46 |
44 void NPObjectStub::OnMessageReceived(const IPC::Message& msg) { | 47 void NPObjectStub::OnMessageReceived(const IPC::Message& msg) { |
| 48 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); |
| 49 |
45 if (!valid_) { | 50 if (!valid_) { |
46 if (msg.is_sync()) { | 51 if (msg.is_sync()) { |
47 // The object could be garbage because the frame has gone away, so | 52 // The object could be garbage because the frame has gone away, so |
48 // just send an error reply to the caller. | 53 // just send an error reply to the caller. |
49 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 54 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
50 reply->set_reply_error(); | 55 reply->set_reply_error(); |
51 Send(reply); | 56 Send(reply); |
52 } | 57 } |
53 | 58 |
54 return; | 59 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 bool return_value = false; | 115 bool return_value = false; |
111 NPVariant_Param result_param; | 116 NPVariant_Param result_param; |
112 NPVariant result_var; | 117 NPVariant result_var; |
113 | 118 |
114 VOID_TO_NPVARIANT(result_var); | 119 VOID_TO_NPVARIANT(result_var); |
115 | 120 |
116 int arg_count = static_cast<int>(args.size()); | 121 int arg_count = static_cast<int>(args.size()); |
117 NPVariant* args_var = new NPVariant[arg_count]; | 122 NPVariant* args_var = new NPVariant[arg_count]; |
118 for (int i = 0; i < arg_count; ++i) { | 123 for (int i = 0; i < arg_count; ++i) { |
119 CreateNPVariant( | 124 CreateNPVariant( |
120 args[i], local_channel, &(args_var[i]), modal_dialog_event_); | 125 args[i], local_channel, &(args_var[i]), modal_dialog_event_, |
| 126 page_url_); |
121 } | 127 } |
122 | 128 |
123 if (is_default) { | 129 if (is_default) { |
124 if (IsPluginProcess()) { | 130 if (IsPluginProcess()) { |
125 if (npobject_->_class->invokeDefault) { | 131 if (npobject_->_class->invokeDefault) { |
126 return_value = npobject_->_class->invokeDefault( | 132 return_value = npobject_->_class->invokeDefault( |
127 npobject_, args_var, arg_count, &result_var); | 133 npobject_, args_var, arg_count, &result_var); |
128 } else { | 134 } else { |
129 return_value = false; | 135 return_value = false; |
130 } | 136 } |
(...skipping 15 matching lines...) Expand all Loading... |
146 0, npobject_, id, args_var, arg_count, &result_var); | 152 0, npobject_, id, args_var, arg_count, &result_var); |
147 } | 153 } |
148 } | 154 } |
149 | 155 |
150 for (int i = 0; i < arg_count; ++i) | 156 for (int i = 0; i < arg_count; ++i) |
151 NPN_ReleaseVariantValue(&(args_var[i])); | 157 NPN_ReleaseVariantValue(&(args_var[i])); |
152 | 158 |
153 delete[] args_var; | 159 delete[] args_var; |
154 | 160 |
155 CreateNPVariantParam( | 161 CreateNPVariantParam( |
156 result_var, local_channel, &result_param, true, modal_dialog_event_); | 162 result_var, local_channel, &result_param, true, modal_dialog_event_, |
| 163 page_url_); |
157 NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value); | 164 NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value); |
158 local_channel->Send(reply_msg); | 165 local_channel->Send(reply_msg); |
159 } | 166 } |
160 | 167 |
161 void NPObjectStub::OnHasProperty(const NPIdentifier_Param& name, | 168 void NPObjectStub::OnHasProperty(const NPIdentifier_Param& name, |
162 bool* result) { | 169 bool* result) { |
163 NPIdentifier id = CreateNPIdentifier(name); | 170 NPIdentifier id = CreateNPIdentifier(name); |
164 if (IsPluginProcess()) { | 171 if (IsPluginProcess()) { |
165 if (npobject_->_class->hasProperty) { | 172 if (npobject_->_class->hasProperty) { |
166 *result = npobject_->_class->hasProperty(npobject_, id); | 173 *result = npobject_->_class->hasProperty(npobject_, id); |
(...skipping 16 matching lines...) Expand all Loading... |
183 if (npobject_->_class->getProperty) { | 190 if (npobject_->_class->getProperty) { |
184 *result = npobject_->_class->getProperty(npobject_, id, &result_var); | 191 *result = npobject_->_class->getProperty(npobject_, id, &result_var); |
185 } else { | 192 } else { |
186 *result = false; | 193 *result = false; |
187 } | 194 } |
188 } else { | 195 } else { |
189 *result = NPN_GetProperty(0, npobject_, id, &result_var); | 196 *result = NPN_GetProperty(0, npobject_, id, &result_var); |
190 } | 197 } |
191 | 198 |
192 CreateNPVariantParam( | 199 CreateNPVariantParam( |
193 result_var, channel_, property, true, modal_dialog_event_); | 200 result_var, channel_, property, true, modal_dialog_event_, page_url_); |
194 } | 201 } |
195 | 202 |
196 void NPObjectStub::OnSetProperty(const NPIdentifier_Param& name, | 203 void NPObjectStub::OnSetProperty(const NPIdentifier_Param& name, |
197 const NPVariant_Param& property, | 204 const NPVariant_Param& property, |
198 bool* result) { | 205 bool* result) { |
199 NPVariant result_var; | 206 NPVariant result_var; |
200 VOID_TO_NPVARIANT(result_var); | 207 VOID_TO_NPVARIANT(result_var); |
201 NPIdentifier id = CreateNPIdentifier(name); | 208 NPIdentifier id = CreateNPIdentifier(name); |
202 NPVariant property_var; | 209 NPVariant property_var; |
203 CreateNPVariant(property, channel_, &property_var, modal_dialog_event_); | 210 CreateNPVariant( |
| 211 property, channel_, &property_var, modal_dialog_event_, page_url_); |
204 | 212 |
205 if (IsPluginProcess()) { | 213 if (IsPluginProcess()) { |
206 if (npobject_->_class->setProperty) { | 214 if (npobject_->_class->setProperty) { |
207 *result = npobject_->_class->setProperty(npobject_, id, &property_var); | 215 *result = npobject_->_class->setProperty(npobject_, id, &property_var); |
208 } else { | 216 } else { |
209 *result = false; | 217 *result = false; |
210 } | 218 } |
211 } else { | 219 } else { |
212 *result = NPN_SetProperty(0, npobject_, id, &property_var); | 220 *result = NPN_SetProperty(0, npobject_, id, &property_var); |
213 } | 221 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 bool return_value = false; | 282 bool return_value = false; |
275 NPVariant_Param result_param; | 283 NPVariant_Param result_param; |
276 NPVariant result_var; | 284 NPVariant result_var; |
277 | 285 |
278 VOID_TO_NPVARIANT(result_var); | 286 VOID_TO_NPVARIANT(result_var); |
279 | 287 |
280 int arg_count = static_cast<int>(args.size()); | 288 int arg_count = static_cast<int>(args.size()); |
281 NPVariant* args_var = new NPVariant[arg_count]; | 289 NPVariant* args_var = new NPVariant[arg_count]; |
282 for (int i = 0; i < arg_count; ++i) { | 290 for (int i = 0; i < arg_count; ++i) { |
283 CreateNPVariant( | 291 CreateNPVariant( |
284 args[i], local_channel, &(args_var[i]), modal_dialog_event_); | 292 args[i], local_channel, &(args_var[i]), modal_dialog_event_, page_url_); |
285 } | 293 } |
286 | 294 |
287 if (IsPluginProcess()) { | 295 if (IsPluginProcess()) { |
288 if (npobject_->_class->construct) { | 296 if (npobject_->_class->construct) { |
289 return_value = npobject_->_class->construct( | 297 return_value = npobject_->_class->construct( |
290 npobject_, args_var, arg_count, &result_var); | 298 npobject_, args_var, arg_count, &result_var); |
291 } else { | 299 } else { |
292 return_value = false; | 300 return_value = false; |
293 } | 301 } |
294 } else { | 302 } else { |
295 return_value = NPN_Construct( | 303 return_value = NPN_Construct( |
296 0, npobject_, args_var, arg_count, &result_var); | 304 0, npobject_, args_var, arg_count, &result_var); |
297 } | 305 } |
298 | 306 |
299 for (int i = 0; i < arg_count; ++i) | 307 for (int i = 0; i < arg_count; ++i) |
300 NPN_ReleaseVariantValue(&(args_var[i])); | 308 NPN_ReleaseVariantValue(&(args_var[i])); |
301 | 309 |
302 delete[] args_var; | 310 delete[] args_var; |
303 | 311 |
304 CreateNPVariantParam( | 312 CreateNPVariantParam( |
305 result_var, local_channel, &result_param, true, modal_dialog_event_); | 313 result_var, local_channel, &result_param, true, modal_dialog_event_, |
| 314 page_url_); |
306 NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value); | 315 NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value); |
307 local_channel->Send(reply_msg); | 316 local_channel->Send(reply_msg); |
308 } | 317 } |
309 | 318 |
310 void NPObjectStub::OnEvaluate(const std::string& script, | 319 void NPObjectStub::OnEvaluate(const std::string& script, |
311 bool popups_allowed, | 320 bool popups_allowed, |
312 IPC::Message* reply_msg) { | 321 IPC::Message* reply_msg) { |
313 if (IsPluginProcess()) { | 322 if (IsPluginProcess()) { |
314 NOTREACHED() << "Should only be called on NPObjects in the renderer"; | 323 NOTREACHED() << "Should only be called on NPObjects in the renderer"; |
315 return; | 324 return; |
316 } | 325 } |
317 | 326 |
318 // Grab a reference to the underlying channel, as the NPObjectStub | 327 // Grab a reference to the underlying channel, as the NPObjectStub |
319 // instance can be destroyed in the context of NPN_Evaluate. This | 328 // instance can be destroyed in the context of NPN_Evaluate. This |
320 // can happen if the containing plugin instance is destroyed in | 329 // can happen if the containing plugin instance is destroyed in |
321 // NPN_Evaluate. | 330 // NPN_Evaluate. |
322 scoped_refptr<PluginChannelBase> local_channel = channel_; | 331 scoped_refptr<PluginChannelBase> local_channel = channel_; |
323 | 332 |
324 NPVariant result_var; | 333 NPVariant result_var; |
325 NPString script_string; | 334 NPString script_string; |
326 script_string.UTF8Characters = script.c_str(); | 335 script_string.UTF8Characters = script.c_str(); |
327 script_string.UTF8Length = static_cast<unsigned int>(script.length()); | 336 script_string.UTF8Length = static_cast<unsigned int>(script.length()); |
328 | 337 |
329 bool return_value = NPN_EvaluateHelper(0, popups_allowed, npobject_, | 338 bool return_value = NPN_EvaluateHelper(0, popups_allowed, npobject_, |
330 &script_string, &result_var); | 339 &script_string, &result_var); |
331 | 340 |
332 NPVariant_Param result_param; | 341 NPVariant_Param result_param; |
333 CreateNPVariantParam( | 342 CreateNPVariantParam( |
334 result_var, local_channel, &result_param, true, modal_dialog_event_); | 343 result_var, local_channel, &result_param, true, modal_dialog_event_, |
| 344 page_url_); |
335 NPObjectMsg_Evaluate::WriteReplyParams(reply_msg, result_param, return_value); | 345 NPObjectMsg_Evaluate::WriteReplyParams(reply_msg, result_param, return_value); |
336 local_channel->Send(reply_msg); | 346 local_channel->Send(reply_msg); |
337 } | 347 } |
338 | 348 |
339 void NPObjectStub::OnSetException(const std::string& message) { | 349 void NPObjectStub::OnSetException(const std::string& message) { |
340 if (IsPluginProcess()) { | 350 if (IsPluginProcess()) { |
341 NOTREACHED() << "Should only be called on NPObjects in the renderer"; | 351 NOTREACHED() << "Should only be called on NPObjects in the renderer"; |
342 return; | 352 return; |
343 } | 353 } |
344 | 354 |
345 NPN_SetException(npobject_, message.c_str()); | 355 NPN_SetException(npobject_, message.c_str()); |
346 } | 356 } |
OLD | NEW |