| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include "chrome/browser/profiles/profile.h" | 62 #include "chrome/browser/profiles/profile.h" |
| 63 #include "chrome/browser/sessions/session_service.h" | 63 #include "chrome/browser/sessions/session_service.h" |
| 64 #include "chrome/browser/sessions/session_types.h" | 64 #include "chrome/browser/sessions/session_types.h" |
| 65 #include "chrome/browser/sessions/tab_restore_service.h" | 65 #include "chrome/browser/sessions/tab_restore_service.h" |
| 66 #include "chrome/browser/sync/profile_sync_service.h" | 66 #include "chrome/browser/sync/profile_sync_service.h" |
| 67 #include "chrome/browser/sync/sync_ui_util.h" | 67 #include "chrome/browser/sync/sync_ui_util.h" |
| 68 #include "chrome/browser/tab_closeable_state_watcher.h" | 68 #include "chrome/browser/tab_closeable_state_watcher.h" |
| 69 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 69 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
| 70 #include "chrome/browser/tabs/tab_finder.h" | 70 #include "chrome/browser/tabs/tab_finder.h" |
| 71 #include "chrome/browser/tabs/tab_strip_model.h" | 71 #include "chrome/browser/tabs/tab_strip_model.h" |
| 72 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
| 72 #include "chrome/browser/ui/find_bar/find_bar.h" | 73 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 73 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 74 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 74 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 75 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 75 #include "chrome/browser/ui/omnibox/location_bar.h" | 76 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 76 #include "chrome/browser/ui/options/options_window.h" | 77 #include "chrome/browser/ui/options/options_window.h" |
| 77 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 78 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 78 #include "chrome/browser/ui/status_bubble.h" | 79 #include "chrome/browser/ui/status_bubble.h" |
| 79 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 80 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 80 #include "chrome/browser/ui/tabs/dock_info.h" | 81 #include "chrome/browser/ui/tabs/dock_info.h" |
| 81 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 82 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 command_updater_(this), | 200 command_updater_(this), |
| 200 toolbar_model_(this), | 201 toolbar_model_(this), |
| 201 chrome_updater_factory_(this), | 202 chrome_updater_factory_(this), |
| 202 is_attempting_to_close_browser_(false), | 203 is_attempting_to_close_browser_(false), |
| 203 cancel_download_confirmation_state_(NOT_PROMPTED), | 204 cancel_download_confirmation_state_(NOT_PROMPTED), |
| 204 maximized_state_(MAXIMIZED_STATE_DEFAULT), | 205 maximized_state_(MAXIMIZED_STATE_DEFAULT), |
| 205 method_factory_(this), | 206 method_factory_(this), |
| 206 block_command_execution_(false), | 207 block_command_execution_(false), |
| 207 last_blocked_command_id_(-1), | 208 last_blocked_command_id_(-1), |
| 208 last_blocked_command_disposition_(CURRENT_TAB), | 209 last_blocked_command_disposition_(CURRENT_TAB), |
| 209 pending_web_app_action_(NONE) { | 210 pending_web_app_action_(NONE), |
| 211 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 212 tab_restore_service_delegate_( |
| 213 new BrowserTabRestoreServiceDelegate(this))) { |
| 210 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, | 214 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, |
| 211 NotificationService::AllSources()); | 215 NotificationService::AllSources()); |
| 212 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 216 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
| 213 NotificationService::AllSources()); | 217 NotificationService::AllSources()); |
| 214 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 218 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 215 NotificationService::AllSources()); | 219 NotificationService::AllSources()); |
| 216 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 220 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 217 NotificationService::AllSources()); | 221 NotificationService::AllSources()); |
| 218 registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED, | 222 registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED, |
| 219 NotificationService::AllSources()); | 223 NotificationService::AllSources()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 profile_->ResetTabRestoreService(); | 296 profile_->ResetTabRestoreService(); |
| 293 } | 297 } |
| 294 #endif | 298 #endif |
| 295 | 299 |
| 296 SessionService* session_service = profile_->GetSessionService(); | 300 SessionService* session_service = profile_->GetSessionService(); |
| 297 if (session_service) | 301 if (session_service) |
| 298 session_service->WindowClosed(session_id_); | 302 session_service->WindowClosed(session_id_); |
| 299 | 303 |
| 300 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); | 304 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); |
| 301 if (tab_restore_service) | 305 if (tab_restore_service) |
| 302 tab_restore_service->BrowserClosed(this); | 306 tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
| 303 | 307 |
| 304 encoding_auto_detect_.Destroy(); | 308 encoding_auto_detect_.Destroy(); |
| 305 printing_enabled_.Destroy(); | 309 printing_enabled_.Destroy(); |
| 306 dev_tools_disabled_.Destroy(); | 310 dev_tools_disabled_.Destroy(); |
| 307 incognito_mode_allowed_.Destroy(); | 311 incognito_mode_allowed_.Destroy(); |
| 308 instant_enabled_.Destroy(); | 312 instant_enabled_.Destroy(); |
| 309 use_vertical_tabs_.Destroy(); | 313 use_vertical_tabs_.Destroy(); |
| 310 | 314 |
| 311 if (profile_->IsOffTheRecord() && | 315 if (profile_->IsOffTheRecord() && |
| 312 !BrowserList::IsOffTheRecordSessionActive()) { | 316 !BrowserList::IsOffTheRecordSessionActive()) { |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 exiting = true; | 898 exiting = true; |
| 895 } | 899 } |
| 896 | 900 |
| 897 // Don't use HasSessionService here, we want to force creation of the | 901 // Don't use HasSessionService here, we want to force creation of the |
| 898 // session service so that user can restore what was open. | 902 // session service so that user can restore what was open. |
| 899 SessionService* session_service = profile()->GetSessionService(); | 903 SessionService* session_service = profile()->GetSessionService(); |
| 900 if (session_service) | 904 if (session_service) |
| 901 session_service->WindowClosing(session_id()); | 905 session_service->WindowClosing(session_id()); |
| 902 | 906 |
| 903 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); | 907 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); |
| 904 if (tab_restore_service) | 908 if (tab_restore_service && type() == TYPE_NORMAL && tab_count()) |
| 905 tab_restore_service->BrowserClosing(this); | 909 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 906 | 910 |
| 907 // TODO(sky): convert session/tab restore to use notification. | 911 // TODO(sky): convert session/tab restore to use notification. |
| 908 NotificationService::current()->Notify( | 912 NotificationService::current()->Notify( |
| 909 NotificationType::BROWSER_CLOSING, | 913 NotificationType::BROWSER_CLOSING, |
| 910 Source<Browser>(this), | 914 Source<Browser>(this), |
| 911 Details<bool>(&exiting)); | 915 Details<bool>(&exiting)); |
| 912 | 916 |
| 913 CloseAllTabs(); | 917 CloseAllTabs(); |
| 914 } | 918 } |
| 915 | 919 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); | 970 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 967 if (wrapper) | 971 if (wrapper) |
| 968 return wrapper->tab_contents(); | 972 return wrapper->tab_contents(); |
| 969 return NULL; | 973 return NULL; |
| 970 } | 974 } |
| 971 | 975 |
| 972 void Browser::SelectTabContentsAt(int index, bool user_gesture) { | 976 void Browser::SelectTabContentsAt(int index, bool user_gesture) { |
| 973 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture); | 977 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture); |
| 974 } | 978 } |
| 975 | 979 |
| 980 bool Browser::IsTabPinned(int index) const { |
| 981 return tabstrip_model()->IsTabPinned(index); |
| 982 } |
| 983 |
| 976 void Browser::CloseAllTabs() { | 984 void Browser::CloseAllTabs() { |
| 977 tab_handler_->GetTabStripModel()->CloseAllTabs(); | 985 tab_handler_->GetTabStripModel()->CloseAllTabs(); |
| 978 } | 986 } |
| 979 | 987 |
| 980 //////////////////////////////////////////////////////////////////////////////// | 988 //////////////////////////////////////////////////////////////////////////////// |
| 981 // Browser, Tab adding/showing functions: | 989 // Browser, Tab adding/showing functions: |
| 982 | 990 |
| 983 bool Browser::IsTabStripEditable() const { | 991 bool Browser::IsTabStripEditable() const { |
| 984 return window()->IsTabStripEditable(); | 992 return window()->IsTabStripEditable(); |
| 985 } | 993 } |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); | 1467 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); |
| 1460 DuplicateContentsAt(selected_index()); | 1468 DuplicateContentsAt(selected_index()); |
| 1461 } | 1469 } |
| 1462 | 1470 |
| 1463 void Browser::RestoreTab() { | 1471 void Browser::RestoreTab() { |
| 1464 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); | 1472 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); |
| 1465 TabRestoreService* service = profile_->GetTabRestoreService(); | 1473 TabRestoreService* service = profile_->GetTabRestoreService(); |
| 1466 if (!service) | 1474 if (!service) |
| 1467 return; | 1475 return; |
| 1468 | 1476 |
| 1469 service->RestoreMostRecentEntry(this); | 1477 service->RestoreMostRecentEntry(tab_restore_service_delegate()); |
| 1470 } | 1478 } |
| 1471 | 1479 |
| 1472 void Browser::WriteCurrentURLToClipboard() { | 1480 void Browser::WriteCurrentURLToClipboard() { |
| 1473 // TODO(ericu): There isn't currently a metric for this. Should there be? | 1481 // TODO(ericu): There isn't currently a metric for this. Should there be? |
| 1474 // We don't appear to track the action when it comes from the | 1482 // We don't appear to track the action when it comes from the |
| 1475 // RenderContextViewMenu. | 1483 // RenderContextViewMenu. |
| 1476 | 1484 |
| 1477 TabContents* contents = GetSelectedTabContents(); | 1485 TabContents* contents = GetSelectedTabContents(); |
| 1478 if (!contents->ShouldDisplayURL()) | 1486 if (!contents->ShouldDisplayURL()) |
| 1479 return; | 1487 return; |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2576 // We don't create historical tabs for incognito windows or windows without | 2584 // We don't create historical tabs for incognito windows or windows without |
| 2577 // profiles. | 2585 // profiles. |
| 2578 if (!profile() || profile()->IsOffTheRecord() || | 2586 if (!profile() || profile()->IsOffTheRecord() || |
| 2579 !profile()->GetTabRestoreService()) { | 2587 !profile()->GetTabRestoreService()) { |
| 2580 return; | 2588 return; |
| 2581 } | 2589 } |
| 2582 | 2590 |
| 2583 // We only create historical tab entries for tabbed browser windows. | 2591 // We only create historical tab entries for tabbed browser windows. |
| 2584 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { | 2592 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 2585 profile()->GetTabRestoreService()->CreateHistoricalTab( | 2593 profile()->GetTabRestoreService()->CreateHistoricalTab( |
| 2586 &contents->controller()); | 2594 &contents->controller(), |
| 2595 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); |
| 2587 } | 2596 } |
| 2588 } | 2597 } |
| 2589 | 2598 |
| 2590 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { | 2599 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
| 2591 return Browser::RunUnloadEventsHelper(contents->tab_contents()); | 2600 return Browser::RunUnloadEventsHelper(contents->tab_contents()); |
| 2592 } | 2601 } |
| 2593 | 2602 |
| 2594 bool Browser::CanReloadContents(TabContents* source) const { | 2603 bool Browser::CanReloadContents(TabContents* source) const { |
| 2595 return type() != TYPE_DEVTOOLS; | 2604 return type() != TYPE_DEVTOOLS; |
| 2596 } | 2605 } |
| (...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4414 // The page transition below is only for the purpose of inserting the tab. | 4423 // The page transition below is only for the purpose of inserting the tab. |
| 4415 browser->AddTab(view_source_contents, PageTransition::LINK); | 4424 browser->AddTab(view_source_contents, PageTransition::LINK); |
| 4416 } | 4425 } |
| 4417 | 4426 |
| 4418 if (profile_->HasSessionService()) { | 4427 if (profile_->HasSessionService()) { |
| 4419 SessionService* session_service = profile_->GetSessionService(); | 4428 SessionService* session_service = profile_->GetSessionService(); |
| 4420 if (session_service) | 4429 if (session_service) |
| 4421 session_service->TabRestored(&view_source_contents->controller(), false); | 4430 session_service->TabRestored(&view_source_contents->controller(), false); |
| 4422 } | 4431 } |
| 4423 } | 4432 } |
| OLD | NEW |