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

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

Issue 50223002: Prevent modal dialogs when preparing to swap out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/frame_host/render_view_host_manager.h" 5 #include "content/browser/frame_host/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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 page_transition, frame_id)); 430 page_transition, frame_id));
431 431
432 // Run the unload handler of the current page. 432 // Run the unload handler of the current page.
433 SwapOutOldPage(); 433 SwapOutOldPage();
434 } 434 }
435 435
436 void RenderViewHostManager::SwapOutOldPage() { 436 void RenderViewHostManager::SwapOutOldPage() {
437 // Should only see this while we have a pending renderer or transfer. 437 // Should only see this while we have a pending renderer or transfer.
438 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); 438 CHECK(cross_navigation_pending_ || pending_nav_params_.get());
439 439
440 // First close any modal dialogs that would prevent us from swapping out. 440 // Tell the renderer to suppress any further modal dialogs so that we can swap
441 // TODO(creis): This is not a guarantee. The renderer could immediately 441 // it out. This must be done before canceling any current dialog, in case
442 // create another dialog in a loop, potentially causing a renderer crash when 442 // there is a loop creating additional dialogs.
443 // we tell it to swap out with a nested message loop and PageGroupLoadDeferrer 443 render_view_host_->SuppressDialogsUntilSwapOut();
444 // on the stack. We should prevent the renderer from showing more dialogs 444
445 // until the SwapOut. See http://crbug.com/312490. 445 // Now close any modal dialogs that would prevent us from swapping out. This
446 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is
447 // no longer on the stack when we send the SwapOut message.
446 delegate_->CancelModalDialogsForRenderManager(); 448 delegate_->CancelModalDialogsForRenderManager();
447 449
448 // Tell the old renderer it is being swapped out. This will fire the unload 450 // Tell the old renderer it is being swapped out. This will fire the unload
449 // handler (without firing the beforeunload handler a second time). When the 451 // handler (without firing the beforeunload handler a second time). When the
450 // unload handler finishes and the navigation completes, we will send a 452 // unload handler finishes and the navigation completes, we will send a
451 // message to the ResourceDispatcherHost, allowing the pending RVH's response 453 // message to the ResourceDispatcherHost, allowing the pending RVH's response
452 // to resume. 454 // to resume.
453 render_view_host_->SwapOut(); 455 render_view_host_->SwapOut();
454 456
455 // ResourceDispatcherHost has told us to run the onunload handler, which 457 // ResourceDispatcherHost has told us to run the onunload handler, which
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 opener_route_id); 768 opener_route_id);
767 } 769 }
768 770
769 void RenderViewHostManager::CommitPending() { 771 void RenderViewHostManager::CommitPending() {
770 // First check whether we're going to want to focus the location bar after 772 // First check whether we're going to want to focus the location bar after
771 // this commit. We do this now because the navigation hasn't formally 773 // this commit. We do this now because the navigation hasn't formally
772 // committed yet, so if we've already cleared |pending_web_ui_| the call chain 774 // committed yet, so if we've already cleared |pending_web_ui_| the call chain
773 // this triggers won't be able to figure out what's going on. 775 // this triggers won't be able to figure out what's going on.
774 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); 776 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault();
775 777
776 // We currently can't guarantee that the renderer isn't showing a new modal
777 // dialog, even though we canceled them in SwapOutOldPage. (It may have
778 // created another in the meantime.) Make sure we run and reset the callback
779 // now before we delete its RVH below.
780 // TODO(creis): Remove this if we can guarantee that no new dialogs will be
781 // shown after SwapOutOldPage. See http://crbug.com/312490.
782 delegate_->CancelModalDialogsForRenderManager();
783
784 // Next commit the Web UI, if any. Either replace |web_ui_| with 778 // Next commit the Web UI, if any. Either replace |web_ui_| with
785 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or 779 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or
786 // leave |web_ui_| as is if reusing it. 780 // leave |web_ui_| as is if reusing it.
787 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); 781 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get()));
788 if (pending_web_ui_) 782 if (pending_web_ui_)
789 web_ui_.reset(pending_web_ui_.release()); 783 web_ui_.reset(pending_web_ui_.release());
790 else if (!pending_and_current_web_ui_.get()) 784 else if (!pending_and_current_web_ui_.get())
791 web_ui_.reset(); 785 web_ui_.reset();
792 786
793 // It's possible for the pending_render_view_host_ to be NULL when we aren't 787 // 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
1110 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( 1104 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost(
1111 SiteInstance* instance) { 1105 SiteInstance* instance) {
1112 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 1106 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
1113 if (iter != swapped_out_hosts_.end()) 1107 if (iter != swapped_out_hosts_.end())
1114 return iter->second; 1108 return iter->second;
1115 1109
1116 return NULL; 1110 return NULL;
1117 } 1111 }
1118 1112
1119 } // namespace content 1113 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_browsertest.cc ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698