OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/webplugin_delegate_proxy.h" | 5 #include "content/renderer/webplugin_delegate_proxy.h" |
6 | 6 |
7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #elif defined(USE_X11) | 9 #elif defined(USE_X11) |
10 #include <cairo/cairo.h> | 10 #include <cairo/cairo.h> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 render_view_->UnregisterPluginDelegate(this); | 251 render_view_->UnregisterPluginDelegate(this); |
252 | 252 |
253 if (channel_host_.get()) { | 253 if (channel_host_.get()) { |
254 Send(new PluginMsg_DestroyInstance(instance_id_)); | 254 Send(new PluginMsg_DestroyInstance(instance_id_)); |
255 | 255 |
256 // Must remove the route after sending the destroy message, since | 256 // Must remove the route after sending the destroy message, since |
257 // RemoveRoute can lead to all the outstanding NPObjects being told the | 257 // RemoveRoute can lead to all the outstanding NPObjects being told the |
258 // channel went away if this was the last instance. | 258 // channel went away if this was the last instance. |
259 channel_host_->RemoveRoute(instance_id_); | 259 channel_host_->RemoveRoute(instance_id_); |
260 | 260 |
| 261 // Remove the mapping between our instance-Id and NPP identifiers, used by |
| 262 // the channel to track object ownership, before releasing it. |
| 263 channel_host_->RemoveMappingForNPObjectOwner(instance_id_); |
| 264 |
261 // Release the channel host now. If we are is the last reference to the | 265 // Release the channel host now. If we are is the last reference to the |
262 // channel, this avoids a race where this renderer asks a new connection to | 266 // channel, this avoids a race where this renderer asks a new connection to |
263 // the same plugin between now and the time 'this' is actually deleted. | 267 // the same plugin between now and the time 'this' is actually deleted. |
264 // Destroying the channel host is what releases the channel name -> FD | 268 // Destroying the channel host is what releases the channel name -> FD |
265 // association on POSIX, and if we ask for a new connection before it is | 269 // association on POSIX, and if we ask for a new connection before it is |
266 // released, the plugin will give us a new FD, and we'll assert when trying | 270 // released, the plugin will give us a new FD, and we'll assert when trying |
267 // to associate it with the channel name. | 271 // to associate it with the channel name. |
268 channel_host_ = NULL; | 272 channel_host_ = NULL; |
269 } | 273 } |
270 | 274 |
271 if (window_script_object_.get()) { | 275 if (window_script_object_.get()) { |
272 // Release the window script object, if the plugin didn't already. | 276 // Release the window script object, if the plugin didn't already. |
273 // If we don't do this then it will linger until the last plugin instance is | 277 // If we don't do this then it will linger until the last plugin instance is |
274 // destroyed. In the meantime, though, the frame that it refers to may have | 278 // destroyed. In the meantime, though, the frame that it refers to may have |
275 // been destroyed by WebKit, at which point WebKit will forcibly deallocate | 279 // been destroyed by WebKit, at which point WebKit will forcibly deallocate |
276 // the window script object. The window script object stub is unique to the | 280 // the window script object. The window script object stub is unique to the |
277 // plugin instance, so this won't affect other instances. | 281 // plugin instance, so this won't affect other instances. |
| 282 // TODO(wez): Remove this hack. |
278 window_script_object_->DeleteSoon(); | 283 window_script_object_->DeleteSoon(); |
279 } | 284 } |
280 | 285 |
281 plugin_ = NULL; | 286 plugin_ = NULL; |
282 | 287 |
283 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 288 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
284 } | 289 } |
285 | 290 |
286 bool WebPluginDelegateProxy::Initialize( | 291 bool WebPluginDelegateProxy::Initialize( |
287 const GURL& url, | 292 const GURL& url, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 361 |
357 // Failed too often, give up. | 362 // Failed too often, give up. |
358 if (!result) | 363 if (!result) |
359 return false; | 364 return false; |
360 | 365 |
361 channel_host_ = channel_host; | 366 channel_host_ = channel_host; |
362 instance_id_ = instance_id; | 367 instance_id_ = instance_id; |
363 | 368 |
364 channel_host_->AddRoute(instance_id_, this, NULL); | 369 channel_host_->AddRoute(instance_id_, this, NULL); |
365 | 370 |
| 371 // Inform the channel of the mapping between our instance-Id and dummy NPP |
| 372 // identifier, for use in object ownership tracking. |
| 373 channel_host_->AddMappingForNPObjectOwner(instance_id_, GetPluginNPP()); |
| 374 |
366 // Now tell the PluginInstance in the plugin process to initialize. | 375 // Now tell the PluginInstance in the plugin process to initialize. |
367 PluginMsg_Init_Params params; | 376 PluginMsg_Init_Params params; |
368 params.url = url; | 377 params.url = url; |
369 params.page_url = page_url_; | 378 params.page_url = page_url_; |
370 params.arg_names = arg_names; | 379 params.arg_names = arg_names; |
371 params.arg_values = arg_values; | 380 params.arg_values = arg_values; |
372 params.host_render_view_routing_id = render_view_->routing_id(); | 381 params.host_render_view_routing_id = render_view_->routing_id(); |
373 params.load_manually = load_manually; | 382 params.load_manually = load_manually; |
374 | 383 |
375 plugin_ = plugin; | 384 plugin_ = plugin; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { | 741 NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { |
733 if (npobject_) | 742 if (npobject_) |
734 return WebBindings::retainObject(npobject_); | 743 return WebBindings::retainObject(npobject_); |
735 | 744 |
736 int route_id = MSG_ROUTING_NONE; | 745 int route_id = MSG_ROUTING_NONE; |
737 Send(new PluginMsg_GetPluginScriptableObject(instance_id_, &route_id)); | 746 Send(new PluginMsg_GetPluginScriptableObject(instance_id_, &route_id)); |
738 if (route_id == MSG_ROUTING_NONE) | 747 if (route_id == MSG_ROUTING_NONE) |
739 return NULL; | 748 return NULL; |
740 | 749 |
741 npobject_ = NPObjectProxy::Create( | 750 npobject_ = NPObjectProxy::Create( |
742 channel_host_.get(), route_id, 0, page_url_); | 751 channel_host_.get(), route_id, 0, page_url_, GetPluginNPP()); |
743 | 752 |
744 return WebBindings::retainObject(npobject_); | 753 return WebBindings::retainObject(npobject_); |
745 } | 754 } |
746 | 755 |
747 NPP WebPluginDelegateProxy::GetPluginNPP() { | 756 NPP WebPluginDelegateProxy::GetPluginNPP() { |
748 // Return a dummy NPP for WebKit to use to identify this plugin. | 757 // Return a dummy NPP for WebKit to use to identify this plugin. |
749 return npp_.get(); | 758 return npp_.get(); |
750 } | 759 } |
751 | 760 |
752 bool WebPluginDelegateProxy::GetFormValue(string16* value) { | 761 bool WebPluginDelegateProxy::GetFormValue(string16* value) { |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 | 1213 |
1205 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, | 1214 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, |
1206 int resource_id) { | 1215 int resource_id) { |
1207 if (!plugin_) | 1216 if (!plugin_) |
1208 return; | 1217 return; |
1209 | 1218 |
1210 plugin_->URLRedirectResponse(allow, resource_id); | 1219 plugin_->URLRedirectResponse(allow, resource_id); |
1211 } | 1220 } |
1212 | 1221 |
1213 } // namespace content | 1222 } // namespace content |
OLD | NEW |