Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/tab_contents/render_view_host_manager.cc

Issue 159255: Fix a race condition where rapid back/forward clicks could close a tab... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser/tab_contents/render_view_host_manager.h" 5 #include "chrome/browser/tab_contents/render_view_host_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/dom_ui/dom_ui.h" 9 #include "chrome/browser/dom_ui/dom_ui.h"
10 #include "chrome/browser/dom_ui/dom_ui_factory.h" 10 #include "chrome/browser/dom_ui/dom_ui_factory.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // in this case because it took too long. 138 // in this case because it took too long.
139 if (pending_render_view_host_->are_navigations_suspended()) 139 if (pending_render_view_host_->are_navigations_suspended())
140 pending_render_view_host_->SetNavigationsSuspended(false); 140 pending_render_view_host_->SetNavigationsSuspended(false);
141 } else { 141 } else {
142 // The request has been started and paused, while we're waiting for the 142 // The request has been started and paused, while we're waiting for the
143 // unload handler to finish. We'll pretend that it did, by notifying the 143 // unload handler to finish. We'll pretend that it did, by notifying the
144 // IO thread to let the response continue. The pending renderer will then 144 // IO thread to let the response continue. The pending renderer will then
145 // be swapped in as part of the usual DidNavigate logic. (If the unload 145 // be swapped in as part of the usual DidNavigate logic. (If the unload
146 // handler later finishes, this call will be ignored because the state in 146 // handler later finishes, this call will be ignored because the state in
147 // CrossSiteResourceHandler will already be cleaned up.) 147 // CrossSiteResourceHandler will already be cleaned up.)
148 current_host()->process()->CrossSiteClosePageACK( 148 ViewMsg_ClosePage_Params params;
149 pending_render_view_host_->process()->pid(), pending_request_id); 149 params.closing_process_id = render_view_host_->process()->pid();
150 params.closing_route_id = render_view_host_->routing_id();
151 params.for_cross_site_transition = true;
152 params.new_render_process_host_id =
153 pending_render_view_host_->process()->pid();
154 params.new_request_id = pending_request_id;
155 current_host()->process()->CrossSiteClosePageACK(params);
150 } 156 }
151 return false; 157 return false;
152 } 158 }
153 159
154 void RenderViewHostManager::DidNavigateMainFrame( 160 void RenderViewHostManager::DidNavigateMainFrame(
155 RenderViewHost* render_view_host) { 161 RenderViewHost* render_view_host) {
156 if (!cross_navigation_pending_) { 162 if (!cross_navigation_pending_) {
157 DCHECK(!pending_render_view_host_); 163 DCHECK(!pending_render_view_host_);
158 164
159 // We should only hear this from our current renderer. 165 // We should only hear this from our current renderer.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void RenderViewHostManager::ShouldClosePage(bool proceed) { 214 void RenderViewHostManager::ShouldClosePage(bool proceed) {
209 // Should only see this while we have a pending renderer. Otherwise, we 215 // Should only see this while we have a pending renderer. Otherwise, we
210 // should ignore. 216 // should ignore.
211 if (!pending_render_view_host_) { 217 if (!pending_render_view_host_) {
212 bool proceed_to_fire_unload; 218 bool proceed_to_fire_unload;
213 delegate_->BeforeUnloadFiredFromRenderManager(proceed, 219 delegate_->BeforeUnloadFiredFromRenderManager(proceed,
214 &proceed_to_fire_unload); 220 &proceed_to_fire_unload);
215 221
216 if (proceed_to_fire_unload) { 222 if (proceed_to_fire_unload) {
217 // This is not a cross-site navigation, the tab is being closed. 223 // This is not a cross-site navigation, the tab is being closed.
218 render_view_host_->FirePageUnload(); 224 render_view_host_->ClosePage(true, -1, -1);
219 } 225 }
220 return; 226 return;
221 } 227 }
222 228
223 if (proceed) { 229 if (proceed) {
224 // Ok to unload the current page, so proceed with the cross-site 230 // Ok to unload the current page, so proceed with the cross-site
225 // navigation. Note that if navigations are not currently suspended, it 231 // navigation. Note that if navigations are not currently suspended, it
226 // might be because the renderer was deemed unresponsive and this call was 232 // might be because the renderer was deemed unresponsive and this call was
227 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it 233 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it
228 // is ok to do nothing here. 234 // is ok to do nothing here.
(...skipping 10 matching lines...) Expand all
239 int new_request_id) { 245 int new_request_id) {
240 // Should only see this while we have a pending renderer. 246 // Should only see this while we have a pending renderer.
241 if (!cross_navigation_pending_) 247 if (!cross_navigation_pending_)
242 return; 248 return;
243 DCHECK(pending_render_view_host_); 249 DCHECK(pending_render_view_host_);
244 250
245 // Tell the old renderer to run its onunload handler. When it finishes, it 251 // Tell the old renderer to run its onunload handler. When it finishes, it
246 // will send a ClosePage_ACK to the ResourceDispatcherHost with the given 252 // will send a ClosePage_ACK to the ResourceDispatcherHost with the given
247 // IDs (of the pending RVH's request), allowing the pending RVH's response to 253 // IDs (of the pending RVH's request), allowing the pending RVH's response to
248 // resume. 254 // resume.
249 render_view_host_->ClosePage(new_render_process_host_id, new_request_id); 255 render_view_host_->ClosePage(true,
256 new_render_process_host_id, new_request_id);
250 257
251 // ResourceDispatcherHost has told us to run the onunload handler, which 258 // ResourceDispatcherHost has told us to run the onunload handler, which
252 // means it is not a download or unsafe page, and we are going to perform the 259 // means it is not a download or unsafe page, and we are going to perform the
253 // navigation. Thus, we no longer need to remember that the RenderViewHost 260 // navigation. Thus, we no longer need to remember that the RenderViewHost
254 // is part of a pending cross-site request. 261 // is part of a pending cross-site request.
255 pending_render_view_host_->SetHasPendingCrossSiteRequest(false, 262 pending_render_view_host_->SetHasPendingCrossSiteRequest(false,
256 new_request_id); 263 new_request_id);
257 } 264 }
258 265
259 void RenderViewHostManager::OnCrossSiteNavigationCanceled() { 266 void RenderViewHostManager::OnCrossSiteNavigationCanceled() {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return render_view_host_; 588 return render_view_host_;
582 } 589 }
583 590
584 void RenderViewHostManager::CancelPending() { 591 void RenderViewHostManager::CancelPending() {
585 RenderViewHost* pending_render_view_host = pending_render_view_host_; 592 RenderViewHost* pending_render_view_host = pending_render_view_host_;
586 pending_render_view_host_ = NULL; 593 pending_render_view_host_ = NULL;
587 pending_render_view_host->Shutdown(); 594 pending_render_view_host->Shutdown();
588 595
589 pending_dom_ui_.reset(); 596 pending_dom_ui_.reset();
590 } 597 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/resource_dispatcher_host.cc ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698