OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sessions/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
50 #include "content/public/browser/web_contents_view.h" | 50 #include "content/public/browser/web_contents_view.h" |
51 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
52 #include "extensions/common/extension_set.h" | 52 #include "extensions/common/extension_set.h" |
53 #include "net/base/network_change_notifier.h" | 53 #include "net/base/network_change_notifier.h" |
54 | 54 |
55 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
56 #include "chrome/browser/chromeos/boot_times_loader.h" | 56 #include "chrome/browser/chromeos/boot_times_loader.h" |
57 #endif | 57 #endif |
58 | 58 |
59 #if defined(OS_WIN) | |
60 #include "win8/util/win8_util.h" | |
61 #endif | |
62 | |
63 using content::NavigationController; | 59 using content::NavigationController; |
64 using content::RenderWidgetHost; | 60 using content::RenderWidgetHost; |
65 using content::WebContents; | 61 using content::WebContents; |
66 | 62 |
67 namespace { | 63 namespace { |
68 | 64 |
69 class SessionRestoreImpl; | 65 class SessionRestoreImpl; |
70 class TabLoader; | 66 class TabLoader; |
71 | 67 |
72 TabLoader* shared_tab_loader = NULL; | 68 TabLoader* shared_tab_loader = NULL; |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 Browser* browser = NULL; | 822 Browser* browser = NULL; |
827 if (!has_tabbed_browser && (*i)->type == Browser::TYPE_TABBED) | 823 if (!has_tabbed_browser && (*i)->type == Browser::TYPE_TABBED) |
828 has_tabbed_browser = true; | 824 has_tabbed_browser = true; |
829 if (i == windows->begin() && (*i)->type == Browser::TYPE_TABBED && | 825 if (i == windows->begin() && (*i)->type == Browser::TYPE_TABBED && |
830 browser_ && browser_->is_type_tabbed() && | 826 browser_ && browser_->is_type_tabbed() && |
831 !browser_->profile()->IsOffTheRecord()) { | 827 !browser_->profile()->IsOffTheRecord()) { |
832 // The first set of tabs is added to the existing browser. | 828 // The first set of tabs is added to the existing browser. |
833 browser = browser_; | 829 browser = browser_; |
834 } else { | 830 } else { |
835 #if defined(OS_CHROMEOS) | 831 #if defined(OS_CHROMEOS) |
836 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 832 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
837 "SessionRestore-CreateRestoredBrowser-Start", false); | 833 "SessionRestore-CreateRestoredBrowser-Start", false); |
838 #endif | 834 #endif |
839 // Show the first window if none are visible. | 835 // Show the first window if none are visible. |
840 ui::WindowShowState show_state = (*i)->show_state; | 836 ui::WindowShowState show_state = (*i)->show_state; |
841 if (!has_visible_browser) { | 837 if (!has_visible_browser) { |
842 show_state = ui::SHOW_STATE_NORMAL; | 838 show_state = ui::SHOW_STATE_NORMAL; |
843 has_visible_browser = true; | 839 has_visible_browser = true; |
844 } | 840 } |
845 browser = NULL; | 841 browser = CreateRestoredBrowser( |
846 #if defined(OS_WIN) | 842 static_cast<Browser::Type>((*i)->type), |
847 if (win8::IsSingleWindowMetroMode()) { | 843 (*i)->bounds, |
848 // We don't want to add tabs to the off the record browser. | 844 show_state, |
849 if (browser_ && !browser_->profile()->IsOffTheRecord()) { | 845 (*i)->app_name); |
850 browser = browser_; | |
851 } else { | |
852 browser = last_browser; | |
853 // last_browser should never be off the record either. | |
854 // We don't set browser higher above when browser_ is offtherecord, | |
855 // and CreateRestoredBrowser below, is never created offtherecord. | |
856 DCHECK(!browser || !browser->profile()->IsOffTheRecord()); | |
857 } | |
858 // Metro should only have tabbed browsers. | |
859 // It never creates any non-tabbed browser, and thus should never | |
860 // restore non-tabbed items... | |
861 DCHECK(!browser || browser->is_type_tabbed()); | |
862 DCHECK((*i)->type == Browser::TYPE_TABBED); | |
863 } | |
864 #endif | |
865 if (!browser) { | |
866 browser = CreateRestoredBrowser( | |
867 static_cast<Browser::Type>((*i)->type), | |
868 (*i)->bounds, | |
869 show_state, | |
870 (*i)->app_name); | |
871 } | |
872 #if defined(OS_CHROMEOS) | 846 #if defined(OS_CHROMEOS) |
873 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 847 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
874 "SessionRestore-CreateRestoredBrowser-End", false); | 848 "SessionRestore-CreateRestoredBrowser-End", false); |
875 #endif | 849 #endif |
876 } | 850 } |
877 if ((*i)->type == Browser::TYPE_TABBED) | 851 if ((*i)->type == Browser::TYPE_TABBED) |
878 last_browser = browser; | 852 last_browser = browser; |
879 WebContents* active_tab = | 853 WebContents* active_tab = |
880 browser->tab_strip_model()->GetActiveWebContents(); | 854 browser->tab_strip_model()->GetActiveWebContents(); |
881 int initial_tab_count = browser->tab_strip_model()->count(); | 855 int initial_tab_count = browser->tab_strip_model()->count(); |
882 bool close_active_tab = clobber_existing_tab_ && | 856 bool close_active_tab = clobber_existing_tab_ && |
883 i == windows->begin() && | 857 i == windows->begin() && |
884 (*i)->type == Browser::TYPE_TABBED && | 858 (*i)->type == Browser::TYPE_TABBED && |
(...skipping 26 matching lines...) Expand all Loading... |
911 | 885 |
912 if (browser_to_activate && browser_to_activate->is_type_tabbed()) | 886 if (browser_to_activate && browser_to_activate->is_type_tabbed()) |
913 last_browser = browser_to_activate; | 887 last_browser = browser_to_activate; |
914 | 888 |
915 if (last_browser && !urls_to_open_.empty()) | 889 if (last_browser && !urls_to_open_.empty()) |
916 AppendURLsToBrowser(last_browser, urls_to_open_); | 890 AppendURLsToBrowser(last_browser, urls_to_open_); |
917 #if defined(OS_CHROMEOS) | 891 #if defined(OS_CHROMEOS) |
918 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 892 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
919 "SessionRestore-CreatingTabs-End", false); | 893 "SessionRestore-CreatingTabs-End", false); |
920 #endif | 894 #endif |
921 if (browser_to_activate) { | 895 if (browser_to_activate) |
922 browser_to_activate->window()->Activate(); | 896 browser_to_activate->window()->Activate(); |
923 #if defined(OS_WIN) | |
924 // On Win8 Metro, we merge all browsers together, so if we need to | |
925 // activate one of the previously separated window, we need to activate | |
926 // the tab. Also, selected_tab_to_activate can be -1 if we clobbered the | |
927 // tab that would have been activated. | |
928 // In that case we'll leave activation to last tab. | |
929 // The only current usage of clobber is for crash recovery, so it's fine. | |
930 if (win8::IsSingleWindowMetroMode() && selected_tab_to_activate != -1) | |
931 ShowBrowser(browser_to_activate, selected_tab_to_activate); | |
932 #endif | |
933 } | |
934 | 897 |
935 // If last_browser is NULL and urls_to_open_ is non-empty, | 898 // If last_browser is NULL and urls_to_open_ is non-empty, |
936 // FinishedTabCreation will create a new TabbedBrowser and add the urls to | 899 // FinishedTabCreation will create a new TabbedBrowser and add the urls to |
937 // it. | 900 // it. |
938 Browser* finished_browser = FinishedTabCreation(true, has_tabbed_browser); | 901 Browser* finished_browser = FinishedTabCreation(true, has_tabbed_browser); |
939 if (finished_browser) | 902 if (finished_browser) |
940 last_browser = finished_browser; | 903 last_browser = finished_browser; |
941 | 904 |
942 // sessionStorages needed for the session restore have now been recreated | 905 // sessionStorages needed for the session restore have now been recreated |
943 // by RestoreTab. Now it's safe for the DOM storage system to start | 906 // by RestoreTab. Now it's safe for the DOM storage system to start |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 if (!active_session_restorers) | 1235 if (!active_session_restorers) |
1273 return false; | 1236 return false; |
1274 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1237 for (std::set<SessionRestoreImpl*>::const_iterator it = |
1275 active_session_restorers->begin(); | 1238 active_session_restorers->begin(); |
1276 it != active_session_restorers->end(); ++it) { | 1239 it != active_session_restorers->end(); ++it) { |
1277 if ((*it)->synchronous()) | 1240 if ((*it)->synchronous()) |
1278 return true; | 1241 return true; |
1279 } | 1242 } |
1280 return false; | 1243 return false; |
1281 } | 1244 } |
OLD | NEW |