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

Side by Side Diff: content/browser/web_contents/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: 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 (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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 global_request_id, is_transfer, transfer_url, referrer, frame_id)); 417 global_request_id, is_transfer, transfer_url, referrer, frame_id));
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 // Tell the renderer to suppress any further modal dialogs so that we can swap
428 // TODO(creis): This is not a guarantee. The renderer could immediately 428 // it out. This must be done before canceling any current dialog, in case
429 // create another dialog in a loop, potentially causing a renderer crash when 429 // there is a loop creating additional dialogs.
430 // we tell it to swap out with a nested message loop and PageGroupLoadDeferrer 430 render_view_host_->SuppressDialogsUntilSwapOut();
431 // on the stack. We should prevent the renderer from showing more dialogs 431
432 // until the SwapOut. See http://crbug.com/312490. 432 // Now close any modal dialogs that would prevent us from swapping out. This
433 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is
434 // no longer on the stack when we send the SwapOut message.
433 delegate_->CancelModalDialogsForRenderManager(); 435 delegate_->CancelModalDialogsForRenderManager();
434 436
435 // Tell the old renderer it is being swapped out. This will fire the unload 437 // Tell the old renderer it is being swapped out. This will fire the unload
436 // handler (without firing the beforeunload handler a second time). When the 438 // handler (without firing the beforeunload handler a second time). When the
437 // unload handler finishes and the navigation completes, we will send a 439 // unload handler finishes and the navigation completes, we will send a
438 // message to the ResourceDispatcherHost, allowing the pending RVH's response 440 // message to the ResourceDispatcherHost, allowing the pending RVH's response
439 // to resume. 441 // to resume.
440 render_view_host_->SwapOut(); 442 render_view_host_->SwapOut();
441 443
442 // ResourceDispatcherHost has told us to run the onunload handler, which 444 // ResourceDispatcherHost has told us to run the onunload handler, which
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 opener_route_id); 755 opener_route_id);
754 } 756 }
755 757
756 void RenderViewHostManager::CommitPending() { 758 void RenderViewHostManager::CommitPending() {
757 // First check whether we're going to want to focus the location bar after 759 // First check whether we're going to want to focus the location bar after
758 // this commit. We do this now because the navigation hasn't formally 760 // this commit. We do this now because the navigation hasn't formally
759 // committed yet, so if we've already cleared |pending_web_ui_| the call chain 761 // committed yet, so if we've already cleared |pending_web_ui_| the call chain
760 // this triggers won't be able to figure out what's going on. 762 // this triggers won't be able to figure out what's going on.
761 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); 763 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault();
762 764
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 mean time.) 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
771 // Next commit the Web UI, if any. Either replace |web_ui_| with 765 // Next commit the Web UI, if any. Either replace |web_ui_| with
772 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or 766 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or
773 // leave |web_ui_| as is if reusing it. 767 // leave |web_ui_| as is if reusing it.
774 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); 768 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get()));
775 if (pending_web_ui_) 769 if (pending_web_ui_)
776 web_ui_.reset(pending_web_ui_.release()); 770 web_ui_.reset(pending_web_ui_.release());
777 else if (!pending_and_current_web_ui_.get()) 771 else if (!pending_and_current_web_ui_.get())
778 web_ui_.reset(); 772 web_ui_.reset();
779 773
780 // It's possible for the pending_render_view_host_ to be NULL when we aren't 774 // 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
1097 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( 1091 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost(
1098 SiteInstance* instance) { 1092 SiteInstance* instance) {
1099 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 1093 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
1100 if (iter != swapped_out_hosts_.end()) 1094 if (iter != swapped_out_hosts_.end())
1101 return iter->second; 1095 return iter->second;
1102 1096
1103 return NULL; 1097 return NULL;
1104 } 1098 }
1105 1099
1106 } // namespace content 1100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698