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..59fbd3388633ffbf4626ca727e404ab44257eda7 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::ShouldRunUnloadEventsHelper( |
+ content::WebContents* contents) { |
jeremy
2013/11/13 10:52:34
// If |contents| is being inspected, DevTools need
lushnikov
2013/11/13 13:39:08
Done.
|
+ 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() && |
jeremy
2013/11/13 10:52:34
// Special case for when we quit an application.
lushnikov
2013/11/13 13:39:08
Done.
|
+ DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(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. |
jeremy
2013/11/13 10:52:34
// The DevTools browser gets its beforeunload even
lushnikov
2013/11/13 13:39:08
Done.
|
+ 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 should_fire_beforeunload = contents->NeedToFireBeforeUnload() || |
+ DevToolsWindow::NeedsToInterceptBeforeUnload(contents); |
if (!ContainsKey(tabs_needing_unload_, contents) && |
!ContainsKey(tabs_needing_unload_ack_, contents) && |
tab_needing_before_unload_ack_ != contents && |
- contents->NeedToFireBeforeUnload()) |
+ should_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(); |