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