| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/unload_controller.h" | 5 #include "chrome/browser/ui/unload_controller.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 if (!tabs_needing_before_unload_fired_.empty()) { | 320 if (!tabs_needing_before_unload_fired_.empty()) { |
| 321 content::WebContents* web_contents = | 321 content::WebContents* web_contents = |
| 322 *(tabs_needing_before_unload_fired_.begin()); | 322 *(tabs_needing_before_unload_fired_.begin()); |
| 323 // Null check render_view_host here as this gets called on a PostTask and | 323 // Null check render_view_host here as this gets called on a PostTask and |
| 324 // the tab's render_view_host may have been nulled out. | 324 // the tab's render_view_host may have been nulled out. |
| 325 if (web_contents->GetRenderViewHost()) { | 325 if (web_contents->GetRenderViewHost()) { |
| 326 // If there's a devtools window attached to |web_contents|, | 326 // If there's a devtools window attached to |web_contents|, |
| 327 // we would like devtools to call its own beforeunload handlers first, | 327 // we would like devtools to call its own beforeunload handlers first, |
| 328 // and then call beforeunload handlers for |web_contents|. | 328 // and then call beforeunload handlers for |web_contents|. |
| 329 // See DevToolsWindow::InterceptPageBeforeUnload for details. | 329 // See DevToolsWindow::InterceptPageBeforeUnload for details. |
| 330 if (!DevToolsWindow::InterceptPageBeforeUnload(web_contents)) | 330 if (!DevToolsWindow::InterceptPageBeforeUnload(web_contents)) { |
| 331 web_contents->DispatchBeforeUnload(); | 331 if (web_contents->NeedToFireBeforeUnload()) { |
| 332 web_contents->DispatchBeforeUnload(); |
| 333 } else { |
| 334 ClearUnloadState(web_contents, true); |
| 335 } |
| 336 } |
| 332 } else { | 337 } else { |
| 333 ClearUnloadState(web_contents, true); | 338 ClearUnloadState(web_contents, true); |
| 334 } | 339 } |
| 335 } else if (is_calling_before_unload_handlers()) { | 340 } else if (is_calling_before_unload_handlers()) { |
| 336 base::Callback<void(bool)> on_close_confirmed = on_close_confirmed_; | 341 base::Callback<void(bool)> on_close_confirmed = on_close_confirmed_; |
| 337 // Reset |on_close_confirmed_| in case the callback tests | 342 // Reset |on_close_confirmed_| in case the callback tests |
| 338 // |is_calling_before_unload_handlers()|, we want to return that calling | 343 // |is_calling_before_unload_handlers()|, we want to return that calling |
| 339 // is complete. | 344 // is complete. |
| 340 if (tabs_needing_unload_fired_.empty()) | 345 if (tabs_needing_unload_fired_.empty()) |
| 341 on_close_confirmed_.Reset(); | 346 on_close_confirmed_.Reset(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 if (weak_factory_.HasWeakPtrs()) | 399 if (weak_factory_.HasWeakPtrs()) |
| 395 return; | 400 return; |
| 396 base::ThreadTaskRunnerHandle::Get()->PostTask( | 401 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 397 FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs, | 402 FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs, |
| 398 weak_factory_.GetWeakPtr(), false)); | 403 weak_factory_.GetWeakPtr(), false)); |
| 399 } | 404 } |
| 400 } | 405 } |
| 401 } | 406 } |
| 402 | 407 |
| 403 } // namespace chrome | 408 } // namespace chrome |
| OLD | NEW |