| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 idle_task_->Start(); | 220 idle_task_->Start(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 Browser::~Browser() { | 223 Browser::~Browser() { |
| 224 // The tab strip should be empty at this point. | 224 // The tab strip should be empty at this point. |
| 225 DCHECK(tabstrip_model_.empty()); | 225 DCHECK(tabstrip_model_.empty()); |
| 226 tabstrip_model_.RemoveObserver(this); | 226 tabstrip_model_.RemoveObserver(this); |
| 227 | 227 |
| 228 BrowserList::RemoveBrowser(this); | 228 BrowserList::RemoveBrowser(this); |
| 229 | 229 |
| 230 #if defined(OS_WIN) || defined(OS_LINUX) | 230 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD) |
| 231 if (!BrowserList::HasBrowserWithProfile(profile_)) { | 231 if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| 232 // We're the last browser window with this profile. We need to nuke the | 232 // We're the last browser window with this profile. We need to nuke the |
| 233 // TabRestoreService, which will start the shutdown of the | 233 // TabRestoreService, which will start the shutdown of the |
| 234 // NavigationControllers and allow for proper shutdown. If we don't do this | 234 // NavigationControllers and allow for proper shutdown. If we don't do this |
| 235 // chrome won't shutdown cleanly, and may end up crashing when some | 235 // chrome won't shutdown cleanly, and may end up crashing when some |
| 236 // thread tries to use the IO thread (or another thread) that is no longer | 236 // thread tries to use the IO thread (or another thread) that is no longer |
| 237 // valid. | 237 // valid. |
| 238 // This isn't a valid assumption for Mac OS, as it stays running after | 238 // This isn't a valid assumption for Mac OS, as it stays running after |
| 239 // the last browser has closed. The Mac equivalent is in its app | 239 // the last browser has closed. The Mac equivalent is in its app |
| 240 // controller. | 240 // controller. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (contents) { | 464 if (contents) { |
| 465 title = contents->GetTitle(); | 465 title = contents->GetTitle(); |
| 466 FormatTitleForDisplay(&title); | 466 FormatTitleForDisplay(&title); |
| 467 } | 467 } |
| 468 if (title.empty()) | 468 if (title.empty()) |
| 469 title = l10n_util::GetStringUTF16(IDS_TAB_UNTITLED_TITLE); | 469 title = l10n_util::GetStringUTF16(IDS_TAB_UNTITLED_TITLE); |
| 470 | 470 |
| 471 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 471 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 472 // On Mac, we don't want to suffix the page title with the application name. | 472 // On Mac, we don't want to suffix the page title with the application name. |
| 473 return title; | 473 return title; |
| 474 #elif defined(OS_WIN) || defined(OS_LINUX) | 474 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD) |
| 475 int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; | 475 int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
| 476 // Don't append the app name to window titles when we're not displaying a | 476 // Don't append the app name to window titles when we're not displaying a |
| 477 // distributor logo for the frame. | 477 // distributor logo for the frame. |
| 478 if (!ShouldShowDistributorLogo()) | 478 if (!ShouldShowDistributorLogo()) |
| 479 string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; | 479 string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
| 480 return l10n_util::GetStringFUTF16(string_id, title); | 480 return l10n_util::GetStringFUTF16(string_id, title); |
| 481 #endif | 481 #endif |
| 482 } | 482 } |
| 483 | 483 |
| 484 // static | 484 // static |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 return true; | 519 return true; |
| 520 | 520 |
| 521 ProcessPendingTabs(); | 521 ProcessPendingTabs(); |
| 522 return false; | 522 return false; |
| 523 } | 523 } |
| 524 | 524 |
| 525 void Browser::OnWindowClosing() { | 525 void Browser::OnWindowClosing() { |
| 526 if (!ShouldCloseWindow()) | 526 if (!ShouldCloseWindow()) |
| 527 return; | 527 return; |
| 528 | 528 |
| 529 #if defined(OS_WIN) || defined(OS_LINUX) | 529 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD) |
| 530 // We don't want to do this on Mac since closing all windows isn't a sign | 530 // We don't want to do this on Mac since closing all windows isn't a sign |
| 531 // that the app is shutting down. | 531 // that the app is shutting down. |
| 532 if (BrowserList::size() == 1) | 532 if (BrowserList::size() == 1) |
| 533 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); | 533 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
| 534 #endif | 534 #endif |
| 535 | 535 |
| 536 // Don't use HasSessionService here, we want to force creation of the | 536 // Don't use HasSessionService here, we want to force creation of the |
| 537 // session service so that user can restore what was open. | 537 // session service so that user can restore what was open. |
| 538 SessionService* session_service = profile()->GetSessionService(); | 538 SessionService* session_service = profile()->GetSessionService(); |
| 539 if (session_service) | 539 if (session_service) |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 int tab_strip_index = tabstrip_model_.selected_index(); | 908 int tab_strip_index = tabstrip_model_.selected_index(); |
| 909 TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index); | 909 TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index); |
| 910 Browser* browser = Browser::Create(profile_); | 910 Browser* browser = Browser::Create(profile_); |
| 911 browser->tabstrip_model()->AppendTabContents(contents, true); | 911 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 912 browser->window()->Show(); | 912 browser->window()->Show(); |
| 913 } | 913 } |
| 914 | 914 |
| 915 void Browser::ToggleFullscreenMode() { | 915 void Browser::ToggleFullscreenMode() { |
| 916 UserMetrics::RecordAction(L"ToggleFullscreen", profile_); | 916 UserMetrics::RecordAction(L"ToggleFullscreen", profile_); |
| 917 window_->SetFullscreen(!window_->IsFullscreen()); | 917 window_->SetFullscreen(!window_->IsFullscreen()); |
| 918 // On Linux, setting fullscreen mode is an async call to the X server, which | 918 // On X/11, setting fullscreen mode is an async call to the X server, which |
| 919 // may or may not support fullscreen mode. | 919 // may or may not support fullscreen mode. |
| 920 #if !defined(OS_LINUX) | 920 #if !defined(USE_X11) |
| 921 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); | 921 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 922 #endif | 922 #endif |
| 923 } | 923 } |
| 924 | 924 |
| 925 void Browser::Exit() { | 925 void Browser::Exit() { |
| 926 UserMetrics::RecordAction(L"Exit", profile_); | 926 UserMetrics::RecordAction(L"Exit", profile_); |
| 927 BrowserList::CloseAllBrowsers(true); | 927 BrowserList::CloseAllBrowsers(true); |
| 928 } | 928 } |
| 929 | 929 |
| 930 void Browser::BookmarkCurrentPage() { | 930 void Browser::BookmarkCurrentPage() { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 990 |
| 991 #if defined(OS_WIN) | 991 #if defined(OS_WIN) |
| 992 void Browser::ClosePopups() { | 992 void Browser::ClosePopups() { |
| 993 UserMetrics::RecordAction(L"CloseAllSuppressedPopups", profile_); | 993 UserMetrics::RecordAction(L"CloseAllSuppressedPopups", profile_); |
| 994 GetSelectedTabContents()->CloseAllSuppressedPopups(); | 994 GetSelectedTabContents()->CloseAllSuppressedPopups(); |
| 995 } | 995 } |
| 996 #endif | 996 #endif |
| 997 | 997 |
| 998 void Browser::Print() { | 998 void Browser::Print() { |
| 999 UserMetrics::RecordAction(L"PrintPreview", profile_); | 999 UserMetrics::RecordAction(L"PrintPreview", profile_); |
| 1000 #if defined(OS_WIN) || defined(OS_LINUX) | 1000 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD) |
| 1001 GetSelectedTabContents()->PrintPreview(); | 1001 GetSelectedTabContents()->PrintPreview(); |
| 1002 #else | 1002 #else |
| 1003 NOTIMPLEMENTED(); | 1003 NOTIMPLEMENTED(); |
| 1004 #endif | 1004 #endif |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 void Browser::ToggleEncodingAutoDetect() { | 1007 void Browser::ToggleEncodingAutoDetect() { |
| 1008 UserMetrics::RecordAction(L"AutoDetectChange", profile_); | 1008 UserMetrics::RecordAction(L"AutoDetectChange", profile_); |
| 1009 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); | 1009 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
| 1010 // Reload the page so we can try to auto-detect the charset. | 1010 // Reload the page so we can try to auto-detect the charset. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 // TODO(beng): figure out how to juggle this. | 1112 // TODO(beng): figure out how to juggle this. |
| 1113 gfx::NativeWindow parent_window = window_->GetNativeHandle(); | 1113 gfx::NativeWindow parent_window = window_->GetNativeHandle(); |
| 1114 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | 1114 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
| 1115 string16(), FilePath(), | 1115 string16(), FilePath(), |
| 1116 NULL, 0, FILE_PATH_LITERAL(""), | 1116 NULL, 0, FILE_PATH_LITERAL(""), |
| 1117 parent_window, NULL); | 1117 parent_window, NULL); |
| 1118 } | 1118 } |
| 1119 | 1119 |
| 1120 void Browser::OpenCreateShortcutsDialog() { | 1120 void Browser::OpenCreateShortcutsDialog() { |
| 1121 UserMetrics::RecordAction(L"CreateShortcut", profile_); | 1121 UserMetrics::RecordAction(L"CreateShortcut", profile_); |
| 1122 #if defined(OS_WIN) || defined(OS_LINUX) | 1122 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD) |
| 1123 GetSelectedTabContents()->CreateShortcut(); | 1123 GetSelectedTabContents()->CreateShortcut(); |
| 1124 #else | 1124 #else |
| 1125 NOTIMPLEMENTED(); | 1125 NOTIMPLEMENTED(); |
| 1126 #endif | 1126 #endif |
| 1127 } | 1127 } |
| 1128 | 1128 |
| 1129 void Browser::ToggleDevToolsWindow() { | 1129 void Browser::ToggleDevToolsWindow() { |
| 1130 UserMetrics::RecordAction(L"ShowJSConsole", profile_); | 1130 UserMetrics::RecordAction(L"ShowJSConsole", profile_); |
| 1131 DevToolsManager::GetInstance()->ToggleDevToolsWindow( | 1131 DevToolsManager::GetInstance()->ToggleDevToolsWindow( |
| 1132 GetSelectedTabContents()->render_view_host()); | 1132 GetSelectedTabContents()->render_view_host()); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 } | 1609 } |
| 1610 | 1610 |
| 1611 if (profile_->HasSessionService()) { | 1611 if (profile_->HasSessionService()) { |
| 1612 SessionService* session_service = profile_->GetSessionService(); | 1612 SessionService* session_service = profile_->GetSessionService(); |
| 1613 if (session_service) | 1613 if (session_service) |
| 1614 session_service->TabRestored(&new_contents->controller(), pinned); | 1614 session_service->TabRestored(&new_contents->controller(), pinned); |
| 1615 } | 1615 } |
| 1616 } | 1616 } |
| 1617 | 1617 |
| 1618 void Browser::CloseFrameAfterDragSession() { | 1618 void Browser::CloseFrameAfterDragSession() { |
| 1619 #if defined(OS_WIN) || defined(OS_LINUX) | 1619 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_FREEBSD) |
| 1620 // This is scheduled to run after we return to the message loop because | 1620 // This is scheduled to run after we return to the message loop because |
| 1621 // otherwise the frame will think the drag session is still active and ignore | 1621 // otherwise the frame will think the drag session is still active and ignore |
| 1622 // the request. | 1622 // the request. |
| 1623 // TODO(port): figure out what is required here in a cross-platform world | 1623 // TODO(port): figure out what is required here in a cross-platform world |
| 1624 MessageLoop::current()->PostTask(FROM_HERE, | 1624 MessageLoop::current()->PostTask(FROM_HERE, |
| 1625 method_factory_.NewRunnableMethod(&Browser::CloseFrame)); | 1625 method_factory_.NewRunnableMethod(&Browser::CloseFrame)); |
| 1626 #endif | 1626 #endif |
| 1627 } | 1627 } |
| 1628 | 1628 |
| 1629 void Browser::CreateHistoricalTab(TabContents* contents) { | 1629 void Browser::CreateHistoricalTab(TabContents* contents) { |
| (...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 /////////////////////////////////////////////////////////////////////////////// | 2894 /////////////////////////////////////////////////////////////////////////////// |
| 2895 // BrowserToolbarModel (private): | 2895 // BrowserToolbarModel (private): |
| 2896 | 2896 |
| 2897 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2897 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
| 2898 // This |current_tab| can be NULL during the initialization of the | 2898 // This |current_tab| can be NULL during the initialization of the |
| 2899 // toolbar during window creation (i.e. before any tabs have been added | 2899 // toolbar during window creation (i.e. before any tabs have been added |
| 2900 // to the window). | 2900 // to the window). |
| 2901 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2901 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 2902 return current_tab ? ¤t_tab->controller() : NULL; | 2902 return current_tab ? ¤t_tab->controller() : NULL; |
| 2903 } | 2903 } |
| OLD | NEW |