Chromium Code Reviews| Index: chrome/browser/devtools/devtools_window.cc |
| diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc |
| index c94d9aaf0560d4606d8f256b93c2e062a99f0000..2e9997e1ce03c3c9474302f598b95724e49ef7b1 100644 |
| --- a/chrome/browser/devtools/devtools_window.cc |
| +++ b/chrome/browser/devtools/devtools_window.cc |
| @@ -580,6 +580,73 @@ void DevToolsWindow::Show(const DevToolsToggleAction& action) { |
| ScheduleAction(action); |
| } |
| +// static |
| +bool DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, |
| + bool proceed, bool* proceed_to_fire_unload) { |
| + DevToolsWindow* window = AsDevToolsWindow( |
| + frontend_contents->GetRenderViewHost()); |
| + DCHECK(window); |
| + if (!window->inspected_page_is_closing_) |
| + return false; |
| + window->BeforeUnloadFired(frontend_contents, proceed, |
| + proceed_to_fire_unload); |
| + return true; |
| +} |
| + |
| +// static |
| +bool DevToolsWindow::InterceptPageBeforeUnload(content::WebContents* contents) { |
| + DevToolsWindow* window = |
| + DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| + contents->GetRenderViewHost()); |
| + if (!window || window->inspected_page_is_closing_) |
| + return false; |
| + |
| + window->inspected_page_is_closing_ = true; |
| + // Handling devtools on devtools case. |
|
jeremy
2013/11/13 10:52:34
// Handle case of DevTools inspecting another DevT
lushnikov
2013/11/13 13:39:08
Done.
|
| + if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents())) { |
| + window->web_contents()->GetRenderViewHost()->FirePageBeforeUnload(false); |
| + } |
| + return true; |
| +} |
| + |
| +// static |
| +bool DevToolsWindow::NeedsToInterceptBeforeUnload( |
| + content::WebContents* contents) { |
| + DevToolsWindow* window = |
| + DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| + contents->GetRenderViewHost()); |
| + return window && !window->inspected_page_is_closing_; |
| +} |
| + |
| +// static |
| +bool DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser( |
| + Browser* browser) { |
| + DCHECK(browser->is_devtools()); |
| + if (browser->tab_strip_model()->empty()) |
|
jeremy
2013/11/13 10:52:34
// When FastUnloadController is used, we may detac
lushnikov
2013/11/13 13:39:08
Done.
|
| + return true; |
| + content::WebContents* contents = |
| + browser->tab_strip_model()->GetWebContentsAt(0); |
| + DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost()); |
| + DCHECK(window); |
| + return window->inspected_page_is_closing_; |
| +} |
| + |
| +// static |
| +void DevToolsWindow::OnPageCloseCanceled(content::WebContents* contents) { |
| + DevToolsWindow *window = |
| + DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| + contents->GetRenderViewHost()); |
| + if (!window) |
| + return; |
| + window->inspected_page_is_closing_ = false; |
| + // Propagate to DevTools opened on DevTools if any. |
| + DevToolsWindow::OnPageCloseCanceled(window->web_contents()); |
| +} |
| + |
| +void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { |
| + SetDockSide(SideToString(dock_side)); |
| +} |
| + |
| DevToolsWindow::DevToolsWindow(Profile* profile, |
| const GURL& url, |
| content::RenderViewHost* inspected_rvh, |
| @@ -592,6 +659,7 @@ DevToolsWindow::DevToolsWindow(Profile* profile, |
| width_(-1), |
| height_(-1), |
| dock_side_before_minimized_(dock_side), |
| + inspected_page_is_closing_(false), |
| weak_factory_(this) { |
| web_contents_ = |
| content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| @@ -813,11 +881,24 @@ void DevToolsWindow::CloseContents(content::WebContents* source) { |
| void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, |
| bool proceed, |
| bool* proceed_to_fire_unload) { |
| - if (proceed) { |
| - content::DevToolsManager::GetInstance()->ClientHostClosing( |
| - frontend_host_.get()); |
| + if (!inspected_page_is_closing_) { |
|
jeremy
2013/11/13 10:52:34
// Docked devtools window closed directly.
lushnikov
2013/11/13 13:39:08
Done.
|
| + if (proceed) { |
| + content::DevToolsManager::GetInstance()->ClientHostClosing( |
| + frontend_host_.get()); |
| + } |
| + *proceed_to_fire_unload = proceed; |
| + } else { |
|
jeremy
2013/11/13 10:52:34
Closing as result of event from devtools content.
lushnikov
2013/11/13 13:39:08
Reworded, done.
|
| + content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
| + if (proceed) { |
| + inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| + } else { |
| + bool should_proceed; |
| + inspected_web_contents->GetDelegate()->BeforeUnloadFired( |
| + inspected_web_contents, false, &should_proceed); |
| + DCHECK(!should_proceed); |
| + } |
| + *proceed_to_fire_unload = false; |
| } |
| - *proceed_to_fire_unload = proceed; |
| } |
| bool DevToolsWindow::PreHandleKeyboardEvent( |