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/ui/browser_tabrestore.h" | 5 #include "chrome/browser/ui/browser_tabrestore.h" |
6 | 6 |
7 #include "chrome/browser/extensions/tab_helper.h" | 7 #include "chrome/browser/extensions/tab_helper.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sessions/session_service.h" | 9 #include "chrome/browser/sessions/session_service.h" |
10 #include "chrome/browser/sessions/session_service_factory.h" | 10 #include "chrome/browser/sessions/session_service_factory.h" |
11 #include "chrome/browser/tab_contents/tab_util.h" | 11 #include "chrome/browser/tab_contents/tab_util.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/session_storage_namespace.h" | 17 #include "content/public/browser/session_storage_namespace.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
20 | 20 |
21 using content::WebContents; | 21 using content::WebContents; |
22 using content::NavigationController; | 22 using content::NavigationController; |
23 using content::NavigationEntry; | 23 using content::NavigationEntry; |
| 24 using sessions::SerializedNavigationEntry; |
24 | 25 |
25 namespace chrome { | 26 namespace chrome { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 NavigationController::RestoreType GetRestoreType(Browser* browser, | 30 NavigationController::RestoreType GetRestoreType(Browser* browser, |
30 bool from_last_session) { | 31 bool from_last_session) { |
31 if (!from_last_session) | 32 if (!from_last_session) |
32 return NavigationController::RESTORE_CURRENT_SESSION; | 33 return NavigationController::RESTORE_CURRENT_SESSION; |
33 return browser->profile()->GetLastSessionExitType() == Profile::EXIT_CRASHED ? | 34 return browser->profile()->GetLastSessionExitType() == Profile::EXIT_CRASHED ? |
34 NavigationController::RESTORE_LAST_SESSION_CRASHED : | 35 NavigationController::RESTORE_LAST_SESSION_CRASHED : |
35 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY; | 36 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY; |
36 } | 37 } |
37 | 38 |
38 WebContents* CreateRestoredTab( | 39 WebContents* CreateRestoredTab( |
39 Browser* browser, | 40 Browser* browser, |
40 const std::vector<TabNavigation>& navigations, | 41 const std::vector<SerializedNavigationEntry>& navigations, |
41 int selected_navigation, | 42 int selected_navigation, |
42 const std::string& extension_app_id, | 43 const std::string& extension_app_id, |
43 bool from_last_session, | 44 bool from_last_session, |
44 content::SessionStorageNamespace* session_storage_namespace, | 45 content::SessionStorageNamespace* session_storage_namespace, |
45 const std::string& user_agent_override) { | 46 const std::string& user_agent_override) { |
46 GURL restore_url = navigations.at(selected_navigation).virtual_url(); | 47 GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
47 // TODO(ajwong): Remove the temporary session_storage_namespace_map when | 48 // TODO(ajwong): Remove the temporary session_storage_namespace_map when |
48 // we teach session restore to understand that one tab can have multiple | 49 // we teach session restore to understand that one tab can have multiple |
49 // SessionStorageNamespace objects. Also remove the | 50 // SessionStorageNamespace objects. Also remove the |
50 // session_storage_namespace.h include since we only need that to assign | 51 // session_storage_namespace.h include since we only need that to assign |
51 // into the map. | 52 // into the map. |
52 content::SessionStorageNamespaceMap session_storage_namespace_map; | 53 content::SessionStorageNamespaceMap session_storage_namespace_map; |
53 session_storage_namespace_map[std::string()] = session_storage_namespace; | 54 session_storage_namespace_map[std::string()] = session_storage_namespace; |
54 WebContents::CreateParams create_params( | 55 WebContents::CreateParams create_params( |
55 browser->profile(), | 56 browser->profile(), |
56 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url)); | 57 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url)); |
57 WebContents* base_web_contents = | 58 WebContents* base_web_contents = |
58 browser->tab_strip_model()->GetActiveWebContents(); | 59 browser->tab_strip_model()->GetActiveWebContents(); |
59 if (base_web_contents) { | 60 if (base_web_contents) { |
60 create_params.initial_size = | 61 create_params.initial_size = |
61 base_web_contents->GetView()->GetContainerSize(); | 62 base_web_contents->GetView()->GetContainerSize(); |
62 } | 63 } |
63 WebContents* web_contents = content::WebContents::CreateWithSessionStorage( | 64 WebContents* web_contents = content::WebContents::CreateWithSessionStorage( |
64 create_params, | 65 create_params, |
65 session_storage_namespace_map); | 66 session_storage_namespace_map); |
66 extensions::TabHelper::CreateForWebContents(web_contents); | 67 extensions::TabHelper::CreateForWebContents(web_contents); |
67 extensions::TabHelper::FromWebContents(web_contents)-> | 68 extensions::TabHelper::FromWebContents(web_contents)-> |
68 SetExtensionAppById(extension_app_id); | 69 SetExtensionAppById(extension_app_id); |
69 std::vector<NavigationEntry*> entries = | 70 std::vector<NavigationEntry*> entries = |
70 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 71 SerializedNavigationEntry::ToNavigationEntries( |
71 navigations, browser->profile()); | 72 navigations, browser->profile()); |
72 web_contents->SetUserAgentOverride(user_agent_override); | 73 web_contents->SetUserAgentOverride(user_agent_override); |
73 web_contents->GetController().Restore( | 74 web_contents->GetController().Restore( |
74 selected_navigation, GetRestoreType(browser, from_last_session), | 75 selected_navigation, GetRestoreType(browser, from_last_session), |
75 &entries); | 76 &entries); |
76 DCHECK_EQ(0u, entries.size()); | 77 DCHECK_EQ(0u, entries.size()); |
77 | 78 |
78 return web_contents; | 79 return web_contents; |
79 } | 80 } |
80 | 81 |
81 } // namespace | 82 } // namespace |
82 | 83 |
83 content::WebContents* AddRestoredTab( | 84 content::WebContents* AddRestoredTab( |
84 Browser* browser, | 85 Browser* browser, |
85 const std::vector<TabNavigation>& navigations, | 86 const std::vector<SerializedNavigationEntry>& navigations, |
86 int tab_index, | 87 int tab_index, |
87 int selected_navigation, | 88 int selected_navigation, |
88 const std::string& extension_app_id, | 89 const std::string& extension_app_id, |
89 bool select, | 90 bool select, |
90 bool pin, | 91 bool pin, |
91 bool from_last_session, | 92 bool from_last_session, |
92 content::SessionStorageNamespace* session_storage_namespace, | 93 content::SessionStorageNamespace* session_storage_namespace, |
93 const std::string& user_agent_override) { | 94 const std::string& user_agent_override) { |
94 WebContents* web_contents = CreateRestoredTab(browser, | 95 WebContents* web_contents = CreateRestoredTab(browser, |
95 navigations, | 96 navigations, |
(...skipping 28 matching lines...) Expand all Loading... |
124 } | 125 } |
125 SessionService* session_service = | 126 SessionService* session_service = |
126 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 127 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
127 if (session_service) | 128 if (session_service) |
128 session_service->TabRestored(web_contents, pin); | 129 session_service->TabRestored(web_contents, pin); |
129 return web_contents; | 130 return web_contents; |
130 } | 131 } |
131 | 132 |
132 void ReplaceRestoredTab( | 133 void ReplaceRestoredTab( |
133 Browser* browser, | 134 Browser* browser, |
134 const std::vector<TabNavigation>& navigations, | 135 const std::vector<SerializedNavigationEntry>& navigations, |
135 int selected_navigation, | 136 int selected_navigation, |
136 bool from_last_session, | 137 bool from_last_session, |
137 const std::string& extension_app_id, | 138 const std::string& extension_app_id, |
138 content::SessionStorageNamespace* session_storage_namespace, | 139 content::SessionStorageNamespace* session_storage_namespace, |
139 const std::string& user_agent_override) { | 140 const std::string& user_agent_override) { |
140 WebContents* web_contents = CreateRestoredTab(browser, | 141 WebContents* web_contents = CreateRestoredTab(browser, |
141 navigations, | 142 navigations, |
142 selected_navigation, | 143 selected_navigation, |
143 extension_app_id, | 144 extension_app_id, |
144 from_last_session, | 145 from_last_session, |
145 session_storage_namespace, | 146 session_storage_namespace, |
146 user_agent_override); | 147 user_agent_override); |
147 | 148 |
148 // ReplaceWebContentsAt won't animate in the restoration, so manually do the | 149 // ReplaceWebContentsAt won't animate in the restoration, so manually do the |
149 // equivalent of ReplaceWebContentsAt. | 150 // equivalent of ReplaceWebContentsAt. |
150 TabStripModel* tab_strip = browser->tab_strip_model(); | 151 TabStripModel* tab_strip = browser->tab_strip_model(); |
151 int insertion_index = tab_strip->active_index(); | 152 int insertion_index = tab_strip->active_index(); |
152 tab_strip->InsertWebContentsAt(insertion_index + 1, | 153 tab_strip->InsertWebContentsAt(insertion_index + 1, |
153 web_contents, | 154 web_contents, |
154 TabStripModel::ADD_ACTIVE | | 155 TabStripModel::ADD_ACTIVE | |
155 TabStripModel::ADD_INHERIT_GROUP); | 156 TabStripModel::ADD_INHERIT_GROUP); |
156 tab_strip->CloseWebContentsAt(insertion_index, TabStripModel::CLOSE_NONE); | 157 tab_strip->CloseWebContentsAt(insertion_index, TabStripModel::CLOSE_NONE); |
157 } | 158 } |
158 | 159 |
159 } // namespace chrome | 160 } // namespace chrome |
OLD | NEW |