summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/webplugin_delegate_proxy.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-06 19:11:22 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-06 19:11:22 +0000
commit49f69aeb0f507096666e58e037a389712be4e585 (patch)
tree36d2b291928e0e1a539467b26d7186d096956dcf /chrome/renderer/webplugin_delegate_proxy.cc
parent519c21a5a3aefe5afc4123bda99d4e76d2a012bb (diff)
downloadchromium_src-49f69aeb0f507096666e58e037a389712be4e585.zip
chromium_src-49f69aeb0f507096666e58e037a389712be4e585.tar.gz
chromium_src-49f69aeb0f507096666e58e037a389712be4e585.tar.bz2
Fix scripting during NPP_Destroy. Note that if the plugin is making a call to the renderer so this instance is in the callstack, destruction will have to be asynchronous and so scripting still won't work. This change also fixes use of PluginChannel after it's deleted (if this was the last instance).
BUG=23713, 23706 TEST=added ui test Review URL: http://codereview.chromium.org/258026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/webplugin_delegate_proxy.cc')
-rw-r--r--chrome/renderer/webplugin_delegate_proxy.cc47
1 files changed, 21 insertions, 26 deletions
diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc
index af4760b..ab787b0 100644
--- a/chrome/renderer/webplugin_delegate_proxy.cc
+++ b/chrome/renderer/webplugin_delegate_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -165,7 +165,6 @@ WebPluginDelegateProxy::WebPluginDelegateProxy(
mime_type_(mime_type),
instance_id_(MSG_ROUTING_NONE),
npobject_(NULL),
- window_script_object_(NULL),
sad_plugin_(NULL),
invalidate_pending_(false),
transparent_(false),
@@ -176,30 +175,17 @@ WebPluginDelegateProxy::~WebPluginDelegateProxy() {
}
void WebPluginDelegateProxy::PluginDestroyed() {
- if (window_) {
+ if (window_)
WillDestroyWindow();
- }
- plugin_ = NULL;
-
- if (npobject_) {
- // When we destroy the plugin instance, the NPObjectStub NULLs out its
- // pointer to the npobject (see NPObjectStub::OnChannelError). Therefore,
- // we release the object before destroying the instance to avoid leaking.
- WebBindings::releaseObject(npobject_);
- npobject_ = NULL;
- }
-
- if (window_script_object_) {
- // The ScriptController deallocates this object independent of its ref count
- // to avoid leaks if the plugin forgets to release it. So mark the object
- // invalid to avoid accessing it past this point.
- window_script_object_->set_proxy(NULL);
- window_script_object_->set_invalid();
- }
if (channel_host_) {
- channel_host_->RemoveRoute(instance_id_);
Send(new PluginMsg_DestroyInstance(instance_id_));
+
+ // Must remove the route after sending the destroy message, since
+ // RemoveRoute can lead to all the outstanding NPObjects being told the
+ // channel went away if this was the last instance.
+ channel_host_->RemoveRoute(instance_id_);
+
// Release the channel host now. If we are is the last reference to the
// channel, this avoids a race where this renderer asks a new connection to
// the same plugin between now and the time 'this' is actually deleted.
@@ -210,6 +196,17 @@ void WebPluginDelegateProxy::PluginDestroyed() {
channel_host_ = NULL;
}
+ if (window_script_object_) {
+ // The ScriptController deallocates this object independent of its ref count
+ // to avoid leaks if the plugin forgets to release it. So mark the object
+ // invalid to avoid accessing it past this point. Note: only do this after
+ // the DestroyInstance message in case the window object is scripted by the
+ // plugin in NPP_Destroy.
+ window_script_object_->OnPluginDestroyed();
+ }
+
+ plugin_ = NULL;
+
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
@@ -828,10 +825,8 @@ void WebPluginDelegateProxy::OnGetWindowScriptNPObject(
// The stub will delete itself when the proxy tells it that it's released, or
// otherwise when the channel is closed.
- NPObjectStub* stub = new NPObjectStub(
- npobject, channel_host_.get(), route_id, 0, page_url_);
- window_script_object_ = stub;
- window_script_object_->set_proxy(this);
+ window_script_object_ = (new NPObjectStub(
+ npobject, channel_host_.get(), route_id, 0, page_url_))->AsWeakPtr();
*success = true;
*npobject_ptr = reinterpret_cast<intptr_t>(npobject);
}