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

Side by Side Diff: content/browser/web_contents/render_view_host_manager.cc

Issue 46403006: Prevent a browser crash if dialogs are shown when navigating away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/browser_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/web_contents/render_view_host_manager.h" 5 #include "content/browser/web_contents/render_view_host_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 // Run the unload handler of the current page. 419 // Run the unload handler of the current page.
420 SwapOutOldPage(); 420 SwapOutOldPage();
421 } 421 }
422 422
423 void RenderViewHostManager::SwapOutOldPage() { 423 void RenderViewHostManager::SwapOutOldPage() {
424 // Should only see this while we have a pending renderer or transfer. 424 // Should only see this while we have a pending renderer or transfer.
425 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); 425 CHECK(cross_navigation_pending_ || pending_nav_params_.get());
426 426
427 // First close any modal dialogs that would prevent us from swapping out. 427 // First close any modal dialogs that would prevent us from swapping out.
428 // TODO(creis): This is not a guarantee. The renderer could immediately
429 // create another dialog in a loop, potentially causing a renderer crash when
430 // we tell it to swap out with a nested message loop and PageGroupLoadDeferrer
431 // on the stack. We should prevent the renderer from showing more dialogs
432 // until the SwapOut. See http://crbug.com/312490.
428 delegate_->CancelModalDialogsForRenderManager(); 433 delegate_->CancelModalDialogsForRenderManager();
429 434
430 // Tell the old renderer it is being swapped out. This will fire the unload 435 // Tell the old renderer it is being swapped out. This will fire the unload
431 // handler (without firing the beforeunload handler a second time). When the 436 // handler (without firing the beforeunload handler a second time). When the
432 // unload handler finishes and the navigation completes, we will send a 437 // unload handler finishes and the navigation completes, we will send a
433 // message to the ResourceDispatcherHost, allowing the pending RVH's response 438 // message to the ResourceDispatcherHost, allowing the pending RVH's response
434 // to resume. 439 // to resume.
435 render_view_host_->SwapOut(); 440 render_view_host_->SwapOut();
436 441
437 // ResourceDispatcherHost has told us to run the onunload handler, which 442 // ResourceDispatcherHost has told us to run the onunload handler, which
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 opener_route_id); 753 opener_route_id);
749 } 754 }
750 755
751 void RenderViewHostManager::CommitPending() { 756 void RenderViewHostManager::CommitPending() {
752 // First check whether we're going to want to focus the location bar after 757 // First check whether we're going to want to focus the location bar after
753 // this commit. We do this now because the navigation hasn't formally 758 // this commit. We do this now because the navigation hasn't formally
754 // committed yet, so if we've already cleared |pending_web_ui_| the call chain 759 // committed yet, so if we've already cleared |pending_web_ui_| the call chain
755 // this triggers won't be able to figure out what's going on. 760 // this triggers won't be able to figure out what's going on.
756 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); 761 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault();
757 762
763 // We currently can't guarantee that the renderer isn't showing a new modal
764 // dialog, even though we canceled them in SwapOutOldPage. (It may have
765 // created another in the meantime.) Make sure we run and reset the callback
766 // now before we delete its RVH below.
767 // TODO(creis): Remove this if we can guarantee that no new dialogs will be
768 // shown after SwapOutOldPage. See http://crbug.com/312490.
769 delegate_->CancelModalDialogsForRenderManager();
770
758 // Next commit the Web UI, if any. Either replace |web_ui_| with 771 // Next commit the Web UI, if any. Either replace |web_ui_| with
759 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or 772 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or
760 // leave |web_ui_| as is if reusing it. 773 // leave |web_ui_| as is if reusing it.
761 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); 774 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get()));
762 if (pending_web_ui_) 775 if (pending_web_ui_)
763 web_ui_.reset(pending_web_ui_.release()); 776 web_ui_.reset(pending_web_ui_.release());
764 else if (!pending_and_current_web_ui_.get()) 777 else if (!pending_and_current_web_ui_.get())
765 web_ui_.reset(); 778 web_ui_.reset();
766 779
767 // It's possible for the pending_render_view_host_ to be NULL when we aren't 780 // It's possible for the pending_render_view_host_ to be NULL when we aren't
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( 1097 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost(
1085 SiteInstance* instance) { 1098 SiteInstance* instance) {
1086 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 1099 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
1087 if (iter != swapped_out_hosts_.end()) 1100 if (iter != swapped_out_hosts_.end())
1088 return iter->second; 1101 return iter->second;
1089 1102
1090 return NULL; 1103 return NULL;
1091 } 1104 }
1092 1105
1093 } // namespace content 1106 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698