Index: content/browser/web_contents/web_contents_impl.cc |
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
index f7bee53452acc678511175979851aa1a5d09b18d..6e7c16d17fe43021abbd168e52ef85c4f735708e 100644 |
--- a/content/browser/web_contents/web_contents_impl.cc |
+++ b/content/browser/web_contents/web_contents_impl.cc |
@@ -1225,7 +1225,20 @@ void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) { |
registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, |
Source<WebContents>(opener_)); |
opener_ = NULL; |
+ return; |
} |
+ // Clear a pending contents that has been closed before being shown. |
+ for (PendingContents::iterator iter = pending_contents_.begin(); |
+ iter != pending_contents_.end(); |
+ ++iter) { |
+ if (iter->second != web_contents) |
+ continue; |
+ pending_contents_.erase(iter); |
+ registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, |
+ Source<WebContents>(web_contents)); |
+ return; |
+ } |
+ NOTREACHED(); |
} |
void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
@@ -1407,6 +1420,8 @@ void WebContentsImpl::CreateNewWindow( |
// later. |
DCHECK_NE(MSG_ROUTING_NONE, route_id); |
pending_contents_[route_id] = new_contents; |
+ registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, |
+ Source<WebContents>(new_contents)); |
} |
if (delegate_) { |
@@ -1540,6 +1555,8 @@ WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) { |
WebContentsImpl* new_contents = iter->second; |
pending_contents_.erase(route_id); |
+ registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED, |
+ Source<WebContents>(new_contents)); |
if (!new_contents->GetRenderProcessHost()->HasConnection() || |
!new_contents->GetRenderViewHost()->GetView()) |