| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/fast_unload_controller.h" | 5 #include "chrome/browser/ui/fast_unload_controller.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 browser_->tab_strip_model()->RemoveObserver(this); | 66 browser_->tab_strip_model()->RemoveObserver(this); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool FastUnloadController::CanCloseContents(content::WebContents* contents) { | 69 bool FastUnloadController::CanCloseContents(content::WebContents* contents) { |
| 70 // Don't try to close the tab when the whole browser is being closed, since | 70 // Don't try to close the tab when the whole browser is being closed, since |
| 71 // that avoids the fast shutdown path where we just kill all the renderers. | 71 // that avoids the fast shutdown path where we just kill all the renderers. |
| 72 return !is_attempting_to_close_browser_ || | 72 return !is_attempting_to_close_browser_ || |
| 73 is_calling_before_unload_handlers(); | 73 is_calling_before_unload_handlers(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // static | |
| 77 bool FastUnloadController::ShouldRunUnloadEventsHelper( | 76 bool FastUnloadController::ShouldRunUnloadEventsHelper( |
| 78 content::WebContents* contents) { | 77 content::WebContents* contents) { |
| 79 // If |contents| is being inspected, devtools needs to intercept beforeunload | 78 // If |contents| is being inspected, devtools needs to intercept beforeunload |
| 80 // events. | 79 // events. |
| 81 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; | 80 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; |
| 82 } | 81 } |
| 83 | 82 |
| 84 // static | |
| 85 bool FastUnloadController::RunUnloadEventsHelper( | 83 bool FastUnloadController::RunUnloadEventsHelper( |
| 86 content::WebContents* contents) { | 84 content::WebContents* contents) { |
| 85 // Special case for when we quit an application. The Devtools window can |
| 86 // close if it's beforeunload event has already fired which will happen due |
| 87 // to the interception of it's content's beforeunload. |
| 88 if (browser_->is_devtools() && |
| 89 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) |
| 90 return false; |
| 91 |
| 87 // If there's a devtools window attached to |contents|, | 92 // If there's a devtools window attached to |contents|, |
| 88 // we would like devtools to call its own beforeunload handlers first, | 93 // we would like devtools to call its own beforeunload handlers first, |
| 89 // and then call beforeunload handlers for |contents|. | 94 // and then call beforeunload handlers for |contents|. |
| 90 // See DevToolsWindow::InterceptPageBeforeUnload for details. | 95 // See DevToolsWindow::InterceptPageBeforeUnload for details. |
| 91 if (DevToolsWindow::InterceptPageBeforeUnload(contents)) { | 96 if (DevToolsWindow::InterceptPageBeforeUnload(contents)) { |
| 92 return true; | 97 return true; |
| 93 } | 98 } |
| 94 // If the WebContents is not connected yet, then there's no unload | 99 // If the WebContents is not connected yet, then there's no unload |
| 95 // handler we can fire even if the WebContents has an unload listener. | 100 // handler we can fire even if the WebContents has an unload listener. |
| 96 // One case where we hit this is in a tab that has an infinite loop | 101 // One case where we hit this is in a tab that has an infinite loop |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } | 480 } |
| 476 } | 481 } |
| 477 | 482 |
| 478 void FastUnloadController::PostTaskForProcessPendingTabs() { | 483 void FastUnloadController::PostTaskForProcessPendingTabs() { |
| 479 base::ThreadTaskRunnerHandle::Get()->PostTask( | 484 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 480 FROM_HERE, base::Bind(&FastUnloadController::ProcessPendingTabs, | 485 FROM_HERE, base::Bind(&FastUnloadController::ProcessPendingTabs, |
| 481 weak_factory_.GetWeakPtr())); | 486 weak_factory_.GetWeakPtr())); |
| 482 } | 487 } |
| 483 | 488 |
| 484 } // namespace chrome | 489 } // namespace chrome |
| OLD | NEW |