| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 #include "chrome/browser/metrics/user_metrics.h" | 56 #include "chrome/browser/metrics/user_metrics.h" |
| 57 #include "chrome/browser/net/browser_url_util.h" | 57 #include "chrome/browser/net/browser_url_util.h" |
| 58 #include "chrome/browser/net/url_fixer_upper.h" | 58 #include "chrome/browser/net/url_fixer_upper.h" |
| 59 #include "chrome/browser/notifications/notification_ui_manager.h" | 59 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 60 #include "chrome/browser/platform_util.h" | 60 #include "chrome/browser/platform_util.h" |
| 61 #include "chrome/browser/prefs/pref_service.h" | 61 #include "chrome/browser/prefs/pref_service.h" |
| 62 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 62 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
| 63 #include "chrome/browser/printing/print_preview_tab_controller.h" | 63 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 64 #include "chrome/browser/profiles/profile.h" | 64 #include "chrome/browser/profiles/profile.h" |
| 65 #include "chrome/browser/sessions/session_service.h" | 65 #include "chrome/browser/sessions/session_service.h" |
| 66 #include "chrome/browser/sessions/session_service_factory.h" |
| 66 #include "chrome/browser/sessions/session_types.h" | 67 #include "chrome/browser/sessions/session_types.h" |
| 67 #include "chrome/browser/sessions/tab_restore_service.h" | 68 #include "chrome/browser/sessions/tab_restore_service.h" |
| 69 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 68 #include "chrome/browser/sync/profile_sync_service.h" | 70 #include "chrome/browser/sync/profile_sync_service.h" |
| 69 #include "chrome/browser/sync/sync_ui_util.h" | 71 #include "chrome/browser/sync/sync_ui_util.h" |
| 70 #include "chrome/browser/tab_closeable_state_watcher.h" | 72 #include "chrome/browser/tab_closeable_state_watcher.h" |
| 71 #include "chrome/browser/tab_contents/background_contents.h" | 73 #include "chrome/browser/tab_contents/background_contents.h" |
| 72 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 74 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
| 73 #include "chrome/browser/tabs/tab_finder.h" | 75 #include "chrome/browser/tabs/tab_finder.h" |
| 74 #include "chrome/browser/tabs/tab_strip_model.h" | 76 #include "chrome/browser/tabs/tab_strip_model.h" |
| 75 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 77 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 76 #include "chrome/browser/ui/browser_list.h" | 78 #include "chrome/browser/ui/browser_list.h" |
| 77 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 79 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 profile_->GetPrefs(), NULL); | 259 profile_->GetPrefs(), NULL); |
| 258 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); | 260 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); |
| 259 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this); | 261 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this); |
| 260 if (!TabMenuModel::AreVerticalTabsEnabled()) { | 262 if (!TabMenuModel::AreVerticalTabsEnabled()) { |
| 261 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we | 263 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we |
| 262 // might show vertical tabs but not show an option to turn them off. | 264 // might show vertical tabs but not show an option to turn them off. |
| 263 use_vertical_tabs_.SetValue(false); | 265 use_vertical_tabs_.SetValue(false); |
| 264 } | 266 } |
| 265 UpdateTabStripModelInsertionPolicy(); | 267 UpdateTabStripModelInsertionPolicy(); |
| 266 | 268 |
| 267 tab_restore_service_ = profile->GetTabRestoreService(); | 269 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile); |
| 268 if (tab_restore_service_) { | 270 if (tab_restore_service_) { |
| 269 tab_restore_service_->AddObserver(this); | 271 tab_restore_service_->AddObserver(this); |
| 270 TabRestoreServiceChanged(tab_restore_service_); | 272 TabRestoreServiceChanged(tab_restore_service_); |
| 271 } | 273 } |
| 272 | 274 |
| 273 if (profile_->GetProfileSyncService()) | 275 if (profile_->GetProfileSyncService()) |
| 274 profile_->GetProfileSyncService()->AddObserver(this); | 276 profile_->GetProfileSyncService()->AddObserver(this); |
| 275 | 277 |
| 276 CreateInstantIfNecessary(); | 278 CreateInstantIfNecessary(); |
| 277 | 279 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 294 if (!BrowserList::HasBrowserWithProfile(profile_)) { | 296 if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| 295 // We're the last browser window with this profile. We need to nuke the | 297 // We're the last browser window with this profile. We need to nuke the |
| 296 // TabRestoreService, which will start the shutdown of the | 298 // TabRestoreService, which will start the shutdown of the |
| 297 // NavigationControllers and allow for proper shutdown. If we don't do this | 299 // NavigationControllers and allow for proper shutdown. If we don't do this |
| 298 // chrome won't shutdown cleanly, and may end up crashing when some | 300 // chrome won't shutdown cleanly, and may end up crashing when some |
| 299 // thread tries to use the IO thread (or another thread) that is no longer | 301 // thread tries to use the IO thread (or another thread) that is no longer |
| 300 // valid. | 302 // valid. |
| 301 // This isn't a valid assumption for Mac OS, as it stays running after | 303 // This isn't a valid assumption for Mac OS, as it stays running after |
| 302 // the last browser has closed. The Mac equivalent is in its app | 304 // the last browser has closed. The Mac equivalent is in its app |
| 303 // controller. | 305 // controller. |
| 304 profile_->ResetTabRestoreService(); | 306 TabRestoreServiceFactory::ResetForProfile(profile_); |
| 305 } | 307 } |
| 306 #endif | 308 #endif |
| 307 | 309 |
| 308 SessionService* session_service = profile_->GetSessionService(); | 310 SessionService* session_service = |
| 311 SessionServiceFactory::GetForProfile(profile_); |
| 309 if (session_service) | 312 if (session_service) |
| 310 session_service->WindowClosed(session_id_); | 313 session_service->WindowClosed(session_id_); |
| 311 | 314 |
| 312 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); | 315 TabRestoreService* tab_restore_service = |
| 316 TabRestoreServiceFactory::GetForProfile(profile()); |
| 313 if (tab_restore_service) | 317 if (tab_restore_service) |
| 314 tab_restore_service->BrowserClosed(tab_restore_service_delegate()); | 318 tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
| 315 | 319 |
| 316 encoding_auto_detect_.Destroy(); | 320 encoding_auto_detect_.Destroy(); |
| 317 printing_enabled_.Destroy(); | 321 printing_enabled_.Destroy(); |
| 318 dev_tools_disabled_.Destroy(); | 322 dev_tools_disabled_.Destroy(); |
| 319 incognito_mode_allowed_.Destroy(); | 323 incognito_mode_allowed_.Destroy(); |
| 320 instant_enabled_.Destroy(); | 324 instant_enabled_.Destroy(); |
| 321 use_vertical_tabs_.Destroy(); | 325 use_vertical_tabs_.Destroy(); |
| 322 edit_bookmarks_enabled_.Destroy(); | 326 edit_bookmarks_enabled_.Destroy(); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 496 |
| 493 // static | 497 // static |
| 494 void Browser::OpenEmptyWindow(Profile* profile) { | 498 void Browser::OpenEmptyWindow(Profile* profile) { |
| 495 Browser* browser = Browser::Create(profile); | 499 Browser* browser = Browser::Create(profile); |
| 496 browser->AddBlankTab(true); | 500 browser->AddBlankTab(true); |
| 497 browser->window()->Show(); | 501 browser->window()->Show(); |
| 498 } | 502 } |
| 499 | 503 |
| 500 // static | 504 // static |
| 501 void Browser::OpenWindowWithRestoredTabs(Profile* profile) { | 505 void Browser::OpenWindowWithRestoredTabs(Profile* profile) { |
| 502 TabRestoreService* service = profile->GetTabRestoreService(); | 506 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); |
| 503 if (service) | 507 if (service) |
| 504 service->RestoreMostRecentEntry(NULL); | 508 service->RestoreMostRecentEntry(NULL); |
| 505 } | 509 } |
| 506 | 510 |
| 507 // static | 511 // static |
| 508 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { | 512 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
| 509 Browser* browser = GetOrCreateTabbedBrowser( | 513 Browser* browser = GetOrCreateTabbedBrowser( |
| 510 profile->GetOffTheRecordProfile()); | 514 profile->GetOffTheRecordProfile()); |
| 511 browser->AddSelectedTabWithURL(url, PageTransition::LINK); | 515 browser->AddSelectedTabWithURL(url, PageTransition::LINK); |
| 512 browser->window()->Show(); | 516 browser->window()->Show(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 bool Browser::ShouldSaveWindowPlacement() const { | 772 bool Browser::ShouldSaveWindowPlacement() const { |
| 769 // Only save the window placement of popups if they are restored. | 773 // Only save the window placement of popups if they are restored. |
| 770 return (type() & TYPE_POPUP) == 0 || browser_defaults::kRestorePopups; | 774 return (type() & TYPE_POPUP) == 0 || browser_defaults::kRestorePopups; |
| 771 } | 775 } |
| 772 | 776 |
| 773 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { | 777 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { |
| 774 // Save to the session storage service, used when reloading a past session. | 778 // Save to the session storage service, used when reloading a past session. |
| 775 // Note that we don't want to be the ones who cause lazy initialization of | 779 // Note that we don't want to be the ones who cause lazy initialization of |
| 776 // the session service. This function gets called during initial window | 780 // the session service. This function gets called during initial window |
| 777 // showing, and we don't want to bring in the session service this early. | 781 // showing, and we don't want to bring in the session service this early. |
| 778 if (profile()->HasSessionService()) { | 782 SessionService* session_service = |
| 779 SessionService* session_service = profile()->GetSessionService(); | 783 SessionServiceFactory::GetForProfileIfExisting(profile()); |
| 780 if (session_service) | 784 if (session_service) |
| 781 session_service->SetWindowBounds(session_id_, bounds, maximized); | 785 session_service->SetWindowBounds(session_id_, bounds, maximized); |
| 782 } | |
| 783 } | 786 } |
| 784 | 787 |
| 785 gfx::Rect Browser::GetSavedWindowBounds() const { | 788 gfx::Rect Browser::GetSavedWindowBounds() const { |
| 786 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 789 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 787 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); | 790 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
| 788 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); | 791 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
| 789 if (record_mode || playback_mode) { | 792 if (record_mode || playback_mode) { |
| 790 // In playback/record mode we always fix the size of the browser and | 793 // In playback/record mode we always fix the size of the browser and |
| 791 // move it to (0,0). The reason for this is two reasons: First we want | 794 // move it to (0,0). The reason for this is two reasons: First we want |
| 792 // resize/moves in the playback to still work, and Second we want | 795 // resize/moves in the playback to still work, and Second we want |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 // AppController on the Mac, or BackgroundContentsService for background | 908 // AppController on the Mac, or BackgroundContentsService for background |
| 906 // pages). | 909 // pages). |
| 907 bool should_quit_if_last_browser = | 910 bool should_quit_if_last_browser = |
| 908 browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive(); | 911 browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive(); |
| 909 | 912 |
| 910 if (should_quit_if_last_browser && BrowserList::size() == 1) { | 913 if (should_quit_if_last_browser && BrowserList::size() == 1) { |
| 911 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); | 914 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
| 912 exiting = true; | 915 exiting = true; |
| 913 } | 916 } |
| 914 | 917 |
| 915 // Don't use HasSessionService here, we want to force creation of the | 918 // Don't use GetForProfileIfExisting here, we want to force creation of the |
| 916 // session service so that user can restore what was open. | 919 // session service so that user can restore what was open. |
| 917 SessionService* session_service = profile()->GetSessionService(); | 920 SessionService* session_service = |
| 921 SessionServiceFactory::GetForProfile(profile()); |
| 918 if (session_service) | 922 if (session_service) |
| 919 session_service->WindowClosing(session_id()); | 923 session_service->WindowClosing(session_id()); |
| 920 | 924 |
| 921 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); | 925 TabRestoreService* tab_restore_service = |
| 926 TabRestoreServiceFactory::GetForProfile(profile()); |
| 922 if (tab_restore_service && type() == TYPE_NORMAL && tab_count()) | 927 if (tab_restore_service && type() == TYPE_NORMAL && tab_count()) |
| 923 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); | 928 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 924 | 929 |
| 925 // TODO(sky): convert session/tab restore to use notification. | 930 // TODO(sky): convert session/tab restore to use notification. |
| 926 NotificationService::current()->Notify( | 931 NotificationService::current()->Notify( |
| 927 NotificationType::BROWSER_CLOSING, | 932 NotificationType::BROWSER_CLOSING, |
| 928 Source<Browser>(this), | 933 Source<Browser>(this), |
| 929 Details<bool>(&exiting)); | 934 Details<bool>(&exiting)); |
| 930 | 935 |
| 931 CloseAllTabs(); | 936 CloseAllTabs(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 } else { | 1086 } else { |
| 1082 // We set the size of the view here, before WebKit does its initial | 1087 // We set the size of the view here, before WebKit does its initial |
| 1083 // layout. If we don't, the initial layout of background tabs will be | 1088 // layout. If we don't, the initial layout of background tabs will be |
| 1084 // performed with a view width of 0, which may cause script outputs and | 1089 // performed with a view width of 0, which may cause script outputs and |
| 1085 // anchor link location calculations to be incorrect even after a new | 1090 // anchor link location calculations to be incorrect even after a new |
| 1086 // layout with proper view dimensions. TabStripModel::AddTabContents() | 1091 // layout with proper view dimensions. TabStripModel::AddTabContents() |
| 1087 // contains similar logic. | 1092 // contains similar logic. |
| 1088 new_tab->view()->SizeContents(window_->GetRestoredBounds().size()); | 1093 new_tab->view()->SizeContents(window_->GetRestoredBounds().size()); |
| 1089 new_tab->HideContents(); | 1094 new_tab->HideContents(); |
| 1090 } | 1095 } |
| 1091 if (profile_->HasSessionService()) { | 1096 SessionService* session_service = |
| 1092 SessionService* session_service = profile_->GetSessionService(); | 1097 SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 1093 if (session_service) | 1098 if (session_service) |
| 1094 session_service->TabRestored(&new_tab->controller(), pin); | 1099 session_service->TabRestored(&new_tab->controller(), pin); |
| 1095 } | |
| 1096 return new_tab; | 1100 return new_tab; |
| 1097 } | 1101 } |
| 1098 | 1102 |
| 1099 void Browser::ReplaceRestoredTab( | 1103 void Browser::ReplaceRestoredTab( |
| 1100 const std::vector<TabNavigation>& navigations, | 1104 const std::vector<TabNavigation>& navigations, |
| 1101 int selected_navigation, | 1105 int selected_navigation, |
| 1102 bool from_last_session, | 1106 bool from_last_session, |
| 1103 const std::string& extension_app_id, | 1107 const std::string& extension_app_id, |
| 1104 SessionStorageNamespace* session_storage_namespace) { | 1108 SessionStorageNamespace* session_storage_namespace) { |
| 1105 TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, | 1109 TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 | 1383 |
| 1380 void Browser::NewWindow() { | 1384 void Browser::NewWindow() { |
| 1381 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 1385 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
| 1382 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) && | 1386 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) && |
| 1383 incognito_mode_allowed_.GetValue()) { | 1387 incognito_mode_allowed_.GetValue()) { |
| 1384 NewIncognitoWindow(); | 1388 NewIncognitoWindow(); |
| 1385 return; | 1389 return; |
| 1386 } | 1390 } |
| 1387 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_); | 1391 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_); |
| 1388 SessionService* session_service = | 1392 SessionService* session_service = |
| 1389 profile_->GetOriginalProfile()->GetSessionService(); | 1393 SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile()); |
| 1390 if (!session_service || | 1394 if (!session_service || |
| 1391 !session_service->RestoreIfNecessary(std::vector<GURL>())) { | 1395 !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 1392 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); | 1396 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); |
| 1393 } | 1397 } |
| 1394 } | 1398 } |
| 1395 | 1399 |
| 1396 void Browser::NewIncognitoWindow() { | 1400 void Browser::NewIncognitoWindow() { |
| 1397 if (!incognito_mode_allowed_.GetValue()) { | 1401 if (!incognito_mode_allowed_.GetValue()) { |
| 1398 NewWindow(); | 1402 NewWindow(); |
| 1399 return; | 1403 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 tab_handler_->GetTabStripModel()->SelectLastTab(); | 1483 tab_handler_->GetTabStripModel()->SelectLastTab(); |
| 1480 } | 1484 } |
| 1481 | 1485 |
| 1482 void Browser::DuplicateTab() { | 1486 void Browser::DuplicateTab() { |
| 1483 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); | 1487 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); |
| 1484 DuplicateContentsAt(active_index()); | 1488 DuplicateContentsAt(active_index()); |
| 1485 } | 1489 } |
| 1486 | 1490 |
| 1487 void Browser::RestoreTab() { | 1491 void Browser::RestoreTab() { |
| 1488 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); | 1492 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); |
| 1489 TabRestoreService* service = profile_->GetTabRestoreService(); | 1493 TabRestoreService* service = |
| 1494 TabRestoreServiceFactory::GetForProfile(profile_); |
| 1490 if (!service) | 1495 if (!service) |
| 1491 return; | 1496 return; |
| 1492 | 1497 |
| 1493 service->RestoreMostRecentEntry(tab_restore_service_delegate()); | 1498 service->RestoreMostRecentEntry(tab_restore_service_delegate()); |
| 1494 } | 1499 } |
| 1495 | 1500 |
| 1496 void Browser::WriteCurrentURLToClipboard() { | 1501 void Browser::WriteCurrentURLToClipboard() { |
| 1497 // TODO(ericu): There isn't currently a metric for this. Should there be? | 1502 // TODO(ericu): There isn't currently a metric for this. Should there be? |
| 1498 // We don't appear to track the action when it comes from the | 1503 // We don't appear to track the action when it comes from the |
| 1499 // RenderContextViewMenu. | 1504 // RenderContextViewMenu. |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2586 window()->GetRestoredBounds().size())); | 2591 window()->GetRestoredBounds().size())); |
| 2587 | 2592 |
| 2588 // We need to show the browser now. Otherwise ContainerWin assumes the | 2593 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 2589 // TabContents is invisible and won't size it. | 2594 // TabContents is invisible and won't size it. |
| 2590 browser->window()->Show(); | 2595 browser->window()->Show(); |
| 2591 | 2596 |
| 2592 // The page transition below is only for the purpose of inserting the tab. | 2597 // The page transition below is only for the purpose of inserting the tab. |
| 2593 browser->AddTab(contents_dupe, PageTransition::LINK); | 2598 browser->AddTab(contents_dupe, PageTransition::LINK); |
| 2594 } | 2599 } |
| 2595 | 2600 |
| 2596 if (profile_->HasSessionService()) { | 2601 SessionService* session_service = |
| 2597 SessionService* session_service = profile_->GetSessionService(); | 2602 SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 2598 if (session_service) | 2603 if (session_service) |
| 2599 session_service->TabRestored(&new_contents->controller(), pinned); | 2604 session_service->TabRestored(&new_contents->controller(), pinned); |
| 2600 } | |
| 2601 } | 2605 } |
| 2602 | 2606 |
| 2603 void Browser::CloseFrameAfterDragSession() { | 2607 void Browser::CloseFrameAfterDragSession() { |
| 2604 #if defined(OS_WIN) || defined(OS_LINUX) | 2608 #if defined(OS_WIN) || defined(OS_LINUX) |
| 2605 // This is scheduled to run after we return to the message loop because | 2609 // This is scheduled to run after we return to the message loop because |
| 2606 // otherwise the frame will think the drag session is still active and ignore | 2610 // otherwise the frame will think the drag session is still active and ignore |
| 2607 // the request. | 2611 // the request. |
| 2608 // TODO(port): figure out what is required here in a cross-platform world | 2612 // TODO(port): figure out what is required here in a cross-platform world |
| 2609 MessageLoop::current()->PostTask( | 2613 MessageLoop::current()->PostTask( |
| 2610 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); | 2614 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); |
| 2611 #endif | 2615 #endif |
| 2612 } | 2616 } |
| 2613 | 2617 |
| 2614 void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { | 2618 void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { |
| 2615 // We don't create historical tabs for incognito windows or windows without | 2619 // We don't create historical tabs for incognito windows or windows without |
| 2616 // profiles. | 2620 // profiles. |
| 2617 if (!profile() || profile()->IsOffTheRecord() || | 2621 if (!profile() || profile()->IsOffTheRecord()) |
| 2618 !profile()->GetTabRestoreService()) { | |
| 2619 return; | 2622 return; |
| 2620 } | 2623 |
| 2624 TabRestoreService* service = |
| 2625 TabRestoreServiceFactory::GetForProfile(profile()); |
| 2621 | 2626 |
| 2622 // We only create historical tab entries for tabbed browser windows. | 2627 // We only create historical tab entries for tabbed browser windows. |
| 2623 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { | 2628 if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 2624 profile()->GetTabRestoreService()->CreateHistoricalTab( | 2629 service->CreateHistoricalTab(&contents->controller(), |
| 2625 &contents->controller(), | |
| 2626 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); | 2630 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); |
| 2627 } | 2631 } |
| 2628 } | 2632 } |
| 2629 | 2633 |
| 2630 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { | 2634 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
| 2631 return Browser::RunUnloadEventsHelper(contents->tab_contents()); | 2635 return Browser::RunUnloadEventsHelper(contents->tab_contents()); |
| 2632 } | 2636 } |
| 2633 | 2637 |
| 2634 bool Browser::CanReloadContents(TabContents* source) const { | 2638 bool Browser::CanReloadContents(TabContents* source) const { |
| 2635 return type() != TYPE_DEVTOOLS; | 2639 return type() != TYPE_DEVTOOLS; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2777 status_bubble->SetStatus(GetSelectedTabContentsWrapper()->GetStatusText()); | 2781 status_bubble->SetStatus(GetSelectedTabContentsWrapper()->GetStatusText()); |
| 2778 } | 2782 } |
| 2779 | 2783 |
| 2780 if (HasFindBarController()) { | 2784 if (HasFindBarController()) { |
| 2781 find_bar_controller_->ChangeTabContents(new_contents); | 2785 find_bar_controller_->ChangeTabContents(new_contents); |
| 2782 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); | 2786 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 2783 } | 2787 } |
| 2784 | 2788 |
| 2785 // Update sessions. Don't force creation of sessions. If sessions doesn't | 2789 // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 2786 // exist, the change will be picked up by sessions when created. | 2790 // exist, the change will be picked up by sessions when created. |
| 2787 if (profile_->HasSessionService()) { | 2791 SessionService* session_service = |
| 2788 SessionService* session_service = profile_->GetSessionService(); | 2792 SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 2789 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { | 2793 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { |
| 2790 session_service->SetSelectedTabInWindow( | 2794 session_service->SetSelectedTabInWindow( |
| 2791 session_id(), tab_handler_->GetTabStripModel()->active_index()); | 2795 session_id(), tab_handler_->GetTabStripModel()->active_index()); |
| 2792 } | |
| 2793 } | 2796 } |
| 2794 } | 2797 } |
| 2795 | 2798 |
| 2796 void Browser::TabMoved(TabContentsWrapper* contents, | 2799 void Browser::TabMoved(TabContentsWrapper* contents, |
| 2797 int from_index, | 2800 int from_index, |
| 2798 int to_index) { | 2801 int to_index) { |
| 2799 DCHECK(from_index >= 0 && to_index >= 0); | 2802 DCHECK(from_index >= 0 && to_index >= 0); |
| 2800 // Notify the history service. | 2803 // Notify the history service. |
| 2801 SyncHistoryWithTabs(std::min(from_index, to_index)); | 2804 SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 2802 } | 2805 } |
| 2803 | 2806 |
| 2804 void Browser::TabReplacedAt(TabStripModel* tab_strip_model, | 2807 void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
| 2805 TabContentsWrapper* old_contents, | 2808 TabContentsWrapper* old_contents, |
| 2806 TabContentsWrapper* new_contents, | 2809 TabContentsWrapper* new_contents, |
| 2807 int index) { | 2810 int index) { |
| 2808 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); | 2811 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
| 2809 TabInsertedAt(new_contents, index, | 2812 TabInsertedAt(new_contents, index, |
| 2810 (index == tab_handler_->GetTabStripModel()->active_index())); | 2813 (index == tab_handler_->GetTabStripModel()->active_index())); |
| 2811 | 2814 |
| 2812 int entry_count = new_contents->controller().entry_count(); | 2815 int entry_count = new_contents->controller().entry_count(); |
| 2813 if (entry_count > 0) { | 2816 if (entry_count > 0) { |
| 2814 // Send out notification so that observers are updated appropriately. | 2817 // Send out notification so that observers are updated appropriately. |
| 2815 new_contents->controller().NotifyEntryChanged( | 2818 new_contents->controller().NotifyEntryChanged( |
| 2816 new_contents->controller().GetEntryAtIndex(entry_count - 1), | 2819 new_contents->controller().GetEntryAtIndex(entry_count - 1), |
| 2817 entry_count - 1); | 2820 entry_count - 1); |
| 2818 } | 2821 } |
| 2819 | 2822 |
| 2820 SessionService* session_service = profile()->GetSessionService(); | 2823 SessionService* session_service = |
| 2824 SessionServiceFactory::GetForProfile(profile()); |
| 2821 if (session_service) { | 2825 if (session_service) { |
| 2822 // The new_contents may end up with a different navigation stack. Force | 2826 // The new_contents may end up with a different navigation stack. Force |
| 2823 // the session service to update itself. | 2827 // the session service to update itself. |
| 2824 session_service->TabRestored( | 2828 session_service->TabRestored( |
| 2825 &new_contents->controller(), | 2829 &new_contents->controller(), |
| 2826 tab_handler_->GetTabStripModel()->IsTabPinned(index)); | 2830 tab_handler_->GetTabStripModel()->IsTabPinned(index)); |
| 2827 } | 2831 } |
| 2828 | 2832 |
| 2829 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 2833 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 2830 if (devtools_manager) // NULL in unit tests. | 2834 if (devtools_manager) // NULL in unit tests. |
| 2831 devtools_manager->TabReplaced(old_contents, new_contents); | 2835 devtools_manager->TabReplaced(old_contents, new_contents); |
| 2832 } | 2836 } |
| 2833 | 2837 |
| 2834 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { | 2838 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { |
| 2835 if (!profile()->HasSessionService()) | 2839 SessionService* session_service = |
| 2836 return; | 2840 SessionServiceFactory::GetForProfileIfExisting(profile()); |
| 2837 SessionService* session_service = profile()->GetSessionService(); | |
| 2838 if (session_service) { | 2841 if (session_service) { |
| 2839 session_service->SetPinnedState( | 2842 session_service->SetPinnedState( |
| 2840 session_id(), | 2843 session_id(), |
| 2841 GetTabContentsAt(index)->controller().session_id(), | 2844 GetTabContentsAt(index)->controller().session_id(), |
| 2842 tab_handler_->GetTabStripModel()->IsTabPinned(index)); | 2845 tab_handler_->GetTabStripModel()->IsTabPinned(index)); |
| 2843 } | 2846 } |
| 2844 } | 2847 } |
| 2845 | 2848 |
| 2846 void Browser::TabStripEmpty() { | 2849 void Browser::TabStripEmpty() { |
| 2847 // Close the frame after we return to the message loop (not immediately, | 2850 // Close the frame after we return to the message loop (not immediately, |
| (...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3993 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 3996 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 3994 return NULL; | 3997 return NULL; |
| 3995 #endif | 3998 #endif |
| 3996 return window_ ? window_->GetStatusBubble() : NULL; | 3999 return window_ ? window_->GetStatusBubble() : NULL; |
| 3997 } | 4000 } |
| 3998 | 4001 |
| 3999 /////////////////////////////////////////////////////////////////////////////// | 4002 /////////////////////////////////////////////////////////////////////////////// |
| 4000 // Browser, Session restore functions (private): | 4003 // Browser, Session restore functions (private): |
| 4001 | 4004 |
| 4002 void Browser::SyncHistoryWithTabs(int index) { | 4005 void Browser::SyncHistoryWithTabs(int index) { |
| 4003 if (!profile()->HasSessionService()) | 4006 SessionService* session_service = |
| 4004 return; | 4007 SessionServiceFactory::GetForProfileIfExisting(profile()); |
| 4005 SessionService* session_service = profile()->GetSessionService(); | |
| 4006 if (session_service) { | 4008 if (session_service) { |
| 4007 for (int i = index; i < tab_count(); ++i) { | 4009 for (int i = index; i < tab_count(); ++i) { |
| 4008 TabContents* contents = GetTabContentsAt(i); | 4010 TabContents* contents = GetTabContentsAt(i); |
| 4009 if (contents) { | 4011 if (contents) { |
| 4010 session_service->SetTabIndexInWindow( | 4012 session_service->SetTabIndexInWindow( |
| 4011 session_id(), contents->controller().session_id(), i); | 4013 session_id(), contents->controller().session_id(), i); |
| 4012 session_service->SetPinnedState( | 4014 session_service->SetPinnedState( |
| 4013 session_id(), | 4015 session_id(), |
| 4014 contents->controller().session_id(), | 4016 contents->controller().session_id(), |
| 4015 tab_handler_->GetTabStripModel()->IsTabPinned(i)); | 4017 tab_handler_->GetTabStripModel()->IsTabPinned(i)); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4449 window()->GetRestoredBounds().size())); | 4451 window()->GetRestoredBounds().size())); |
| 4450 | 4452 |
| 4451 // We need to show the browser now. Otherwise ContainerWin assumes the | 4453 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 4452 // TabContents is invisible and won't size it. | 4454 // TabContents is invisible and won't size it. |
| 4453 browser->window()->Show(); | 4455 browser->window()->Show(); |
| 4454 | 4456 |
| 4455 // The page transition below is only for the purpose of inserting the tab. | 4457 // The page transition below is only for the purpose of inserting the tab. |
| 4456 browser->AddTab(view_source_contents, PageTransition::LINK); | 4458 browser->AddTab(view_source_contents, PageTransition::LINK); |
| 4457 } | 4459 } |
| 4458 | 4460 |
| 4459 if (profile_->HasSessionService()) { | 4461 SessionService* session_service = |
| 4460 SessionService* session_service = profile_->GetSessionService(); | 4462 SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 4461 if (session_service) | 4463 if (session_service) |
| 4462 session_service->TabRestored(&view_source_contents->controller(), false); | 4464 session_service->TabRestored(&view_source_contents->controller(), false); |
| 4463 } | |
| 4464 } | 4465 } |
| 4465 | 4466 |
| 4466 int Browser::GetContentRestrictionsForSelectedTab() { | 4467 int Browser::GetContentRestrictionsForSelectedTab() { |
| 4467 int content_restrictions = 0; | 4468 int content_restrictions = 0; |
| 4468 TabContents* current_tab = GetSelectedTabContents(); | 4469 TabContents* current_tab = GetSelectedTabContents(); |
| 4469 if (current_tab) { | 4470 if (current_tab) { |
| 4470 content_restrictions = current_tab->content_restrictions(); | 4471 content_restrictions = current_tab->content_restrictions(); |
| 4471 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); | 4472 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
| 4472 // See comment in UpdateCommandsForTabState about why we call url(). | 4473 // See comment in UpdateCommandsForTabState about why we call url(). |
| 4473 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) | 4474 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
| 4474 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 4475 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 4475 } | 4476 } |
| 4476 return content_restrictions; | 4477 return content_restrictions; |
| 4477 } | 4478 } |
| OLD | NEW |