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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 exiting = true; | 891 exiting = true; |
888 } | 892 } |
889 | 893 |
890 // Don't use HasSessionService here, we want to force creation of the | 894 // Don't use HasSessionService here, we want to force creation of the |
891 // session service so that user can restore what was open. | 895 // session service so that user can restore what was open. |
892 SessionService* session_service = profile()->GetSessionService(); | 896 SessionService* session_service = profile()->GetSessionService(); |
893 if (session_service) | 897 if (session_service) |
894 session_service->WindowClosing(session_id()); | 898 session_service->WindowClosing(session_id()); |
895 | 899 |
896 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); | 900 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); |
897 if (tab_restore_service) | 901 if (tab_restore_service && type() == TYPE_NORMAL && tab_count()) |
898 tab_restore_service->BrowserClosing(this); | 902 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
899 | 903 |
900 // TODO(sky): convert session/tab restore to use notification. | 904 // TODO(sky): convert session/tab restore to use notification. |
901 NotificationService::current()->Notify( | 905 NotificationService::current()->Notify( |
902 NotificationType::BROWSER_CLOSING, | 906 NotificationType::BROWSER_CLOSING, |
903 Source<Browser>(this), | 907 Source<Browser>(this), |
904 Details<bool>(&exiting)); | 908 Details<bool>(&exiting)); |
905 | 909 |
906 CloseAllTabs(); | 910 CloseAllTabs(); |
907 } | 911 } |
908 | 912 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); | 963 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
960 if (wrapper) | 964 if (wrapper) |
961 return wrapper->tab_contents(); | 965 return wrapper->tab_contents(); |
962 return NULL; | 966 return NULL; |
963 } | 967 } |
964 | 968 |
965 void Browser::SelectTabContentsAt(int index, bool user_gesture) { | 969 void Browser::SelectTabContentsAt(int index, bool user_gesture) { |
966 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture); | 970 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture); |
967 } | 971 } |
968 | 972 |
| 973 bool Browser::IsTabPinned(int index) const { |
| 974 return tabstrip_model()->IsTabPinned(index); |
| 975 } |
| 976 |
969 void Browser::CloseAllTabs() { | 977 void Browser::CloseAllTabs() { |
970 tab_handler_->GetTabStripModel()->CloseAllTabs(); | 978 tab_handler_->GetTabStripModel()->CloseAllTabs(); |
971 } | 979 } |
972 | 980 |
973 //////////////////////////////////////////////////////////////////////////////// | 981 //////////////////////////////////////////////////////////////////////////////// |
974 // Browser, Tab adding/showing functions: | 982 // Browser, Tab adding/showing functions: |
975 | 983 |
976 bool Browser::IsTabStripEditable() const { | 984 bool Browser::IsTabStripEditable() const { |
977 return window()->IsTabStripEditable(); | 985 return window()->IsTabStripEditable(); |
978 } | 986 } |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); | 1457 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); |
1450 DuplicateContentsAt(selected_index()); | 1458 DuplicateContentsAt(selected_index()); |
1451 } | 1459 } |
1452 | 1460 |
1453 void Browser::RestoreTab() { | 1461 void Browser::RestoreTab() { |
1454 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); | 1462 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); |
1455 TabRestoreService* service = profile_->GetTabRestoreService(); | 1463 TabRestoreService* service = profile_->GetTabRestoreService(); |
1456 if (!service) | 1464 if (!service) |
1457 return; | 1465 return; |
1458 | 1466 |
1459 service->RestoreMostRecentEntry(this); | 1467 service->RestoreMostRecentEntry(tab_restore_service_delegate()); |
1460 } | 1468 } |
1461 | 1469 |
1462 void Browser::WriteCurrentURLToClipboard() { | 1470 void Browser::WriteCurrentURLToClipboard() { |
1463 // TODO(ericu): There isn't currently a metric for this. Should there be? | 1471 // TODO(ericu): There isn't currently a metric for this. Should there be? |
1464 // We don't appear to track the action when it comes from the | 1472 // We don't appear to track the action when it comes from the |
1465 // RenderContextViewMenu. | 1473 // RenderContextViewMenu. |
1466 | 1474 |
1467 TabContents* contents = GetSelectedTabContents(); | 1475 TabContents* contents = GetSelectedTabContents(); |
1468 if (!contents->ShouldDisplayURL()) | 1476 if (!contents->ShouldDisplayURL()) |
1469 return; | 1477 return; |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2562 // We don't create historical tabs for incognito windows or windows without | 2570 // We don't create historical tabs for incognito windows or windows without |
2563 // profiles. | 2571 // profiles. |
2564 if (!profile() || profile()->IsOffTheRecord() || | 2572 if (!profile() || profile()->IsOffTheRecord() || |
2565 !profile()->GetTabRestoreService()) { | 2573 !profile()->GetTabRestoreService()) { |
2566 return; | 2574 return; |
2567 } | 2575 } |
2568 | 2576 |
2569 // We only create historical tab entries for tabbed browser windows. | 2577 // We only create historical tab entries for tabbed browser windows. |
2570 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { | 2578 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
2571 profile()->GetTabRestoreService()->CreateHistoricalTab( | 2579 profile()->GetTabRestoreService()->CreateHistoricalTab( |
2572 &contents->controller()); | 2580 &contents->controller(), |
| 2581 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); |
2573 } | 2582 } |
2574 } | 2583 } |
2575 | 2584 |
2576 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { | 2585 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
2577 return Browser::RunUnloadEventsHelper(contents->tab_contents()); | 2586 return Browser::RunUnloadEventsHelper(contents->tab_contents()); |
2578 } | 2587 } |
2579 | 2588 |
2580 bool Browser::CanReloadContents(TabContents* source) const { | 2589 bool Browser::CanReloadContents(TabContents* source) const { |
2581 return type() != TYPE_DEVTOOLS; | 2590 return type() != TYPE_DEVTOOLS; |
2582 } | 2591 } |
(...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4386 // The page transition below is only for the purpose of inserting the tab. | 4395 // The page transition below is only for the purpose of inserting the tab. |
4387 browser->AddTab(view_source_contents, PageTransition::LINK); | 4396 browser->AddTab(view_source_contents, PageTransition::LINK); |
4388 } | 4397 } |
4389 | 4398 |
4390 if (profile_->HasSessionService()) { | 4399 if (profile_->HasSessionService()) { |
4391 SessionService* session_service = profile_->GetSessionService(); | 4400 SessionService* session_service = profile_->GetSessionService(); |
4392 if (session_service) | 4401 if (session_service) |
4393 session_service->TabRestored(&view_source_contents->controller(), false); | 4402 session_service->TabRestored(&view_source_contents->controller(), false); |
4394 } | 4403 } |
4395 } | 4404 } |
OLD | NEW |