Chromium Code Reviews| Index: chrome/browser/ui/fast_unload_controller.cc |
| diff --git a/chrome/browser/ui/fast_unload_controller.cc b/chrome/browser/ui/fast_unload_controller.cc |
| index 70b3a41cf97fc0a3b03489744adfc7c2fe3e3ec7..f6544e4b2d6b2f95642acc9c7c13d085a1117c39 100644 |
| --- a/chrome/browser/ui/fast_unload_controller.cc |
| +++ b/chrome/browser/ui/fast_unload_controller.cc |
| @@ -71,8 +71,22 @@ bool FastUnloadController::CanCloseContents(content::WebContents* contents) { |
| } |
| // static |
| +bool FastUnloadController::CanFastShutdownWebContents( |
| + content::WebContents* contents) { |
| + return DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| + contents->GetRenderViewHost()) == NULL; |
| +} |
| + |
| +// static |
| bool FastUnloadController::RunUnloadEventsHelper( |
| content::WebContents* contents) { |
| + // If there's a devtools window attached to |contents|, |
| + // we would like devtools to call its own beforeunload handlers first, |
| + // and then call beforeunload handlers for |contents|. |
| + // See DevToolsWindow::InterceptPageBeforeUnload for details. |
| + if (DevToolsWindow::InterceptPageBeforeUnload(contents)) { |
| + return true; |
| + } |
| // If the WebContents is not connected yet, then there's no unload |
| // handler we can fire even if the WebContents has an unload listener. |
| // One case where we hit this is in a tab that has an infinite loop |
| @@ -90,6 +104,9 @@ bool FastUnloadController::RunUnloadEventsHelper( |
| bool FastUnloadController::BeforeUnloadFired(content::WebContents* contents, |
| bool proceed) { |
| + if (!proceed) |
| + DevToolsWindow::OnPageCloseCanceled(contents); |
| + |
| if (!is_attempting_to_close_browser_) { |
| if (!proceed) { |
| contents->SetClosedByUserGesture(false); |
| @@ -126,6 +143,11 @@ bool FastUnloadController::ShouldCloseWindow() { |
| if (HasCompletedUnloadProcessing()) |
| return true; |
| + if (browser_->is_devtools() && |
| + DevToolsWindow::ShouldCloseDevToolsBrowser(browser_)) { |
| + return true; |
| + } |
| + |
| // The behavior followed here varies based on the current phase of the |
| // operation and whether a batched shutdown is in progress. |
| // |
| @@ -153,7 +175,9 @@ bool FastUnloadController::ShouldCloseWindow() { |
| bool FastUnloadController::CallBeforeUnloadHandlers( |
| const base::Callback<void(bool)>& on_close_confirmed) { |
| - if (!TabsNeedBeforeUnloadFired()) |
| + // DevTools browser gets its beforeunload events triggered on |
| + // inspected tab closing. |
| + if (browser_->is_devtools() || !TabsNeedBeforeUnloadFired()) |
| return false; |
| on_close_confirmed_ = on_close_confirmed; |
| @@ -179,10 +203,12 @@ bool FastUnloadController::TabsNeedBeforeUnloadFired() { |
| for (int i = 0; i < browser_->tab_strip_model()->count(); ++i) { |
| content::WebContents* contents = |
| browser_->tab_strip_model()->GetWebContentsAt(i); |
| + bool fire_beforeunload = contents->NeedToFireBeforeUnload() || |
|
jeremy
2013/11/10 12:50:30
Thanks!
nit: how about calling this should_fire_b
lushnikov
2013/11/11 15:22:54
Done.
|
| + DevToolsWindow::NeedToFireBeforeUnload(contents); |
| if (!ContainsKey(tabs_needing_unload_, contents) && |
| !ContainsKey(tabs_needing_unload_ack_, contents) && |
| tab_needing_before_unload_ack_ != contents && |
| - contents->NeedToFireBeforeUnload()) |
| + fire_beforeunload) |
| tabs_needing_before_unload_.insert(contents); |
| } |
| return !tabs_needing_before_unload_.empty(); |
| @@ -314,7 +340,12 @@ void FastUnloadController::ProcessPendingTabs() { |
| CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
| core_tab_helper->OnCloseStarted(); |
| - contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| + // If there's a devtools window attached to |contents|, |
| + // we would like devtools to call its own beforeunload handlers first, |
| + // and then call beforeunload handlers for |contents|. |
| + // See DevToolsWindow::InterceptPageBeforeUnload for details. |
| + if (!DevToolsWindow::InterceptPageBeforeUnload(contents)) |
| + contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| } else { |
| ProcessPendingTabs(); |
| } |
| @@ -325,7 +356,6 @@ void FastUnloadController::ProcessPendingTabs() { |
| on_close_confirmed_.Run(true); |
| return; |
| } |
| - |
| // Process all the unload handlers. (The beforeunload handlers have finished.) |
| if (!tabs_needing_unload_.empty()) { |
| browser_->OnWindowClosing(); |
| @@ -383,10 +413,10 @@ void FastUnloadController::CancelWindowClose() { |
| DCHECK(is_attempting_to_close_browser_); |
| tabs_needing_before_unload_.clear(); |
| if (tab_needing_before_unload_ack_ != NULL) { |
| - |
| CoreTabHelper* core_tab_helper = |
| CoreTabHelper::FromWebContents(tab_needing_before_unload_ack_); |
| core_tab_helper->OnCloseCanceled(); |
| + DevToolsWindow::OnPageCloseCanceled(tab_needing_before_unload_ack_); |
| tab_needing_before_unload_ack_ = NULL; |
| } |
| for (WebContentsSet::iterator it = tabs_needing_unload_.begin(); |
| @@ -395,6 +425,7 @@ void FastUnloadController::CancelWindowClose() { |
| CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
| core_tab_helper->OnCloseCanceled(); |
| + DevToolsWindow::OnPageCloseCanceled(contents); |
| } |
| tabs_needing_unload_.clear(); |