diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-24 02:47:58 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-24 02:47:58 +0000 |
commit | 505323e2bad435d4579cdd8c33b96c460816b97a (patch) | |
tree | 44c85b8af6f1e8c7a079d24ac38df19b4240e3ef /chrome/browser/browser.cc | |
parent | e993abfe81feaa374d476828a44942d296bdcc78 (diff) | |
download | chromium_src-505323e2bad435d4579cdd8c33b96c460816b97a.zip chromium_src-505323e2bad435d4579cdd8c33b96c460816b97a.tar.gz chromium_src-505323e2bad435d4579cdd8c33b96c460816b97a.tar.bz2 |
Two things:
- remove views dependencies from browser by moving profile related dialog actions into BrowserWindow.
- simplify the include dependencies in TabStripModel (making it easier to bring up on mac) by implementing more of its high level functionality in the delegate.
Review URL: http://codereview.chromium.org/18736
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser.cc')
-rw-r--r-- | chrome/browser/browser.cc | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 35e2be0..69fddec 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -60,8 +60,6 @@ #include "chrome/browser/view_ids.h" #include "chrome/browser/views/download_tab_view.h" #include "chrome/browser/views/location_bar_view.h" -#include "chrome/browser/views/new_profile_dialog.h" -#include "chrome/browser/views/select_profile_dialog.h" #include "chrome/browser/window_sizer.h" #include "chrome/common/l10n_util.h" #include "chrome/common/win_util.h" @@ -150,6 +148,18 @@ struct Browser::UIUpdate { unsigned changed_flags; }; +namespace { + +// Returns true if the specified TabContents has unload listeners registered. +bool TabHasUnloadListener(TabContents* contents) { + WebContents* web_contents = contents->AsWebContents(); + return web_contents && web_contents->notify_disconnection() && + !web_contents->showing_interstitial_page() && + web_contents->render_view_host()->HasUnloadListener(); +} + +} // namespace + /////////////////////////////////////////////////////////////////////////////// // Browser, Constructors, Creation, Showing: @@ -414,10 +424,9 @@ bool Browser::ShouldCloseWindow() { is_attempting_to_close_browser_ = true; for (int i = 0; i < tab_count(); ++i) { - if (tabstrip_model_.TabHasUnloadListener(i)) { - TabContents* tab = GetTabContentsAt(i); - tabs_needing_before_unload_fired_.insert(tab); - } + TabContents* contents = GetTabContentsAt(i); + if (TabHasUnloadListener(contents)) + tabs_needing_before_unload_fired_.insert(contents); } if (tabs_needing_before_unload_fired_.empty()) @@ -951,12 +960,12 @@ void Browser::OpenTaskManager() { void Browser::OpenSelectProfileDialog() { UserMetrics::RecordAction(L"SelectProfile", profile_); - SelectProfileDialog::RunDialog(); + window_->ShowSelectProfileDialog(); } void Browser::OpenNewProfileDialog() { UserMetrics::RecordAction(L"CreateProfile", profile_); - NewProfileDialog::RunDialog(); + window_->ShowNewProfileDialog(); } void Browser::OpenBugReportDialog() { @@ -1361,6 +1370,40 @@ void Browser::CloseFrameAfterDragSession() { method_factory_.NewRunnableMethod(&Browser::CloseFrame)); } +void Browser::CreateHistoricalTab(TabContents* contents) { + // We don't create historical tabs for incognito windows or windows without + // profiles. + if (!profile() || profile()->IsOffTheRecord() || + !profile()->GetTabRestoreService()) { + return; + } + + // We only create historical tab entries for normal tabbed browser windows. + if (type() == TYPE_NORMAL) { + profile()->GetTabRestoreService()->CreateHistoricalTab( + contents->controller()); + } +} + +bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { + WebContents* web_contents = contents->AsWebContents(); + if (web_contents) { + // If the WebContents is not connected yet, then there's no unload + // handler we can fire even if the WebContents has an unload listener. + // One case where we hit this is in a tab that has an infinite loop + // before load. + if (TabHasUnloadListener(contents)) { + // If the page has unload listeners, then we tell the renderer to fire + // them. Once they have fired, we'll get a message back saying whether + // to proceed closing the page or not, which sends us back to this method + // with the HasUnloadListener bit cleared. + web_contents->render_view_host()->FirePageBeforeUnload(); + return true; + } + } + return false; +} + /////////////////////////////////////////////////////////////////////////////// // Browser, TabStripModelObserver implementation: |