| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 | 6 |
| 7 #include "app/animation.h" | 7 #include "app/animation.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/idle_timer.h" | 10 #include "base/idle_timer.h" |
| (...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { | 1556 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { |
| 1557 // If the TabContents is not connected yet, then there's no unload | 1557 // If the TabContents is not connected yet, then there's no unload |
| 1558 // handler we can fire even if the TabContents has an unload listener. | 1558 // handler we can fire even if the TabContents has an unload listener. |
| 1559 // One case where we hit this is in a tab that has an infinite loop | 1559 // One case where we hit this is in a tab that has an infinite loop |
| 1560 // before load. | 1560 // before load. |
| 1561 if (TabHasUnloadListener(contents)) { | 1561 if (TabHasUnloadListener(contents)) { |
| 1562 // If the page has unload listeners, then we tell the renderer to fire | 1562 // If the page has unload listeners, then we tell the renderer to fire |
| 1563 // them. Once they have fired, we'll get a message back saying whether | 1563 // them. Once they have fired, we'll get a message back saying whether |
| 1564 // to proceed closing the page or not, which sends us back to this method | 1564 // to proceed closing the page or not, which sends us back to this method |
| 1565 // with the HasUnloadListener bit cleared. | 1565 // with the HasUnloadListener bit cleared. |
| 1566 contents->render_view_host()->FirePageBeforeUnload(); | 1566 contents->render_view_host()->FirePageBeforeUnload(false); |
| 1567 return true; | 1567 return true; |
| 1568 } | 1568 } |
| 1569 return false; | 1569 return false; |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 bool Browser::CanCloseContentsAt(int index) { | 1572 bool Browser::CanCloseContentsAt(int index) { |
| 1573 if (tabstrip_model_.count() > 1) | 1573 if (tabstrip_model_.count() > 1) |
| 1574 return true; | 1574 return true; |
| 1575 // We are closing the last tab for this browser. Make sure to check for | 1575 // We are closing the last tab for this browser. Make sure to check for |
| 1576 // in-progress downloads. | 1576 // in-progress downloads. |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 return; | 2469 return; |
| 2470 } | 2470 } |
| 2471 | 2471 |
| 2472 // Process beforeunload tabs first. When that queue is empty, process | 2472 // Process beforeunload tabs first. When that queue is empty, process |
| 2473 // unload tabs. | 2473 // unload tabs. |
| 2474 if (!tabs_needing_before_unload_fired_.empty()) { | 2474 if (!tabs_needing_before_unload_fired_.empty()) { |
| 2475 TabContents* tab = *(tabs_needing_before_unload_fired_.begin()); | 2475 TabContents* tab = *(tabs_needing_before_unload_fired_.begin()); |
| 2476 // Null check render_view_host here as this gets called on a PostTask and | 2476 // Null check render_view_host here as this gets called on a PostTask and |
| 2477 // the tab's render_view_host may have been nulled out. | 2477 // the tab's render_view_host may have been nulled out. |
| 2478 if (tab->render_view_host()) { | 2478 if (tab->render_view_host()) { |
| 2479 tab->render_view_host()->FirePageBeforeUnload(); | 2479 tab->render_view_host()->FirePageBeforeUnload(false); |
| 2480 } else { | 2480 } else { |
| 2481 ClearUnloadState(tab); | 2481 ClearUnloadState(tab); |
| 2482 } | 2482 } |
| 2483 } else if (!tabs_needing_unload_fired_.empty()) { | 2483 } else if (!tabs_needing_unload_fired_.empty()) { |
| 2484 // We've finished firing all beforeunload events and can proceed with unload | 2484 // We've finished firing all beforeunload events and can proceed with unload |
| 2485 // events. | 2485 // events. |
| 2486 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting | 2486 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
| 2487 // somewhere around here so that we have accurate measurements of shutdown | 2487 // somewhere around here so that we have accurate measurements of shutdown |
| 2488 // time. | 2488 // time. |
| 2489 // TODO(ojan): We can probably fire all the unload events in parallel and | 2489 // TODO(ojan): We can probably fire all the unload events in parallel and |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2776 /////////////////////////////////////////////////////////////////////////////// | 2776 /////////////////////////////////////////////////////////////////////////////// |
| 2777 // BrowserToolbarModel (private): | 2777 // BrowserToolbarModel (private): |
| 2778 | 2778 |
| 2779 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2779 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
| 2780 // This |current_tab| can be NULL during the initialization of the | 2780 // This |current_tab| can be NULL during the initialization of the |
| 2781 // toolbar during window creation (i.e. before any tabs have been added | 2781 // toolbar during window creation (i.e. before any tabs have been added |
| 2782 // to the window). | 2782 // to the window). |
| 2783 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2783 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 2784 return current_tab ? ¤t_tab->controller() : NULL; | 2784 return current_tab ? ¤t_tab->controller() : NULL; |
| 2785 } | 2785 } |
| OLD | NEW |