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..ecc85fecd82e7c89c207402fd4018dac45bab230 100644 |
--- a/chrome/browser/ui/fast_unload_controller.cc |
+++ b/chrome/browser/ui/fast_unload_controller.cc |
@@ -73,6 +73,11 @@ bool FastUnloadController::CanCloseContents(content::WebContents* contents) { |
// static |
bool FastUnloadController::RunUnloadEventsHelper( |
content::WebContents* contents) { |
+ // If there's a devtools window attached to the web contents, |
+ // then we would like to run its beforeunload handlers first. |
+ 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 +95,9 @@ bool FastUnloadController::RunUnloadEventsHelper( |
bool FastUnloadController::BeforeUnloadFired(content::WebContents* contents, |
bool proceed) { |
+ if (!proceed) |
+ DevToolsWindow::PageCancelClose(contents); |
+ |
if (!is_attempting_to_close_browser_) { |
if (!proceed) { |
contents->SetClosedByUserGesture(false); |
@@ -126,6 +134,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 +166,9 @@ bool FastUnloadController::ShouldCloseWindow() { |
bool FastUnloadController::CallBeforeUnloadHandlers( |
const base::Callback<void(bool)>& on_close_confirmed) { |
- if (!TabsNeedBeforeUnloadFired()) |
+ // DevTools browser will get its beforeunload events triggered on |
+ // inspected tab closing |
+ if (browser_->is_devtools() || !TabsNeedBeforeUnloadFired()) |
return false; |
on_close_confirmed_ = on_close_confirmed; |
@@ -182,7 +197,8 @@ bool FastUnloadController::TabsNeedBeforeUnloadFired() { |
if (!ContainsKey(tabs_needing_unload_, contents) && |
!ContainsKey(tabs_needing_unload_ack_, contents) && |
tab_needing_before_unload_ack_ != contents && |
- contents->NeedToFireBeforeUnload()) |
+ (contents->NeedToFireBeforeUnload() || |
+ DevToolsWindow::NeedToFireBeforeUnload(contents))) |
tabs_needing_before_unload_.insert(contents); |
} |
return !tabs_needing_before_unload_.empty(); |
@@ -314,7 +330,8 @@ void FastUnloadController::ProcessPendingTabs() { |
CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
core_tab_helper->OnCloseStarted(); |
- contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
+ if (!DevToolsWindow::InterceptPageBeforeUnload(contents)) |
+ contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
} else { |
ProcessPendingTabs(); |
} |
@@ -325,7 +342,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 +399,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::PageCancelClose(tab_needing_before_unload_ack_); |
tab_needing_before_unload_ack_ = NULL; |
} |
for (WebContentsSet::iterator it = tabs_needing_unload_.begin(); |
@@ -395,6 +411,7 @@ void FastUnloadController::CancelWindowClose() { |
CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
core_tab_helper->OnCloseCanceled(); |
+ DevToolsWindow::PageCancelClose(contents); |
} |
tabs_needing_unload_.clear(); |