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/sessions/session_service.h" | 8 #include "chrome/browser/sessions/session_service.h" |
9 #include "chrome/browser/sessions/session_service_factory.h" | 9 #include "chrome/browser/sessions/session_service_factory.h" |
10 #include "chrome/browser/tab_contents/tab_util.h" | 10 #include "chrome/browser/tab_contents/tab_util.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/session_storage_namespace.h" | |
19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
21 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
22 | 21 |
23 using content::WebContents; | 22 using content::WebContents; |
24 using content::NavigationController; | 23 using content::NavigationController; |
25 using content::NavigationEntry; | 24 using content::NavigationEntry; |
26 | 25 |
27 namespace chrome { | 26 namespace chrome { |
28 | 27 |
29 int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index) { | 28 int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index) { |
30 return (browser->tab_strip_model()->insertion_policy() == | 29 return (browser->tab_strip_model()->insertion_policy() == |
31 TabStripModel::INSERT_AFTER) ? browser->tab_count() : relative_index; | 30 TabStripModel::INSERT_AFTER) ? browser->tab_count() : relative_index; |
32 } | 31 } |
33 | 32 |
34 content::WebContents* AddRestoredTab( | 33 content::WebContents* AddRestoredTab( |
35 Browser* browser, | 34 Browser* browser, |
36 const std::vector<TabNavigation>& navigations, | 35 const std::vector<TabNavigation>& navigations, |
37 int tab_index, | 36 int tab_index, |
38 int selected_navigation, | 37 int selected_navigation, |
39 const std::string& extension_app_id, | 38 const std::string& extension_app_id, |
40 bool select, | 39 bool select, |
41 bool pin, | 40 bool pin, |
42 bool from_last_session, | 41 bool from_last_session, |
43 content::SessionStorageNamespace* session_storage_namespace) { | 42 const content::SessionStorageNamespaceMap& storage_namespace_map) { |
44 GURL restore_url = navigations.at(selected_navigation).virtual_url(); | 43 GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
45 // TODO(ajwong): Remove the temporary session_storage_namespace_map when | |
46 // we teach session restore to understand that one tab can have multiple | |
47 // SessionStorageNamespace objects. Also remove the | |
48 // session_storage_namespace.h include since we only need that to assign | |
49 // into the map. | |
50 content::SessionStorageNamespaceMap session_storage_namespace_map; | |
51 session_storage_namespace_map[""] = session_storage_namespace; | |
52 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory( | 44 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory( |
53 browser->profile(), | 45 browser->profile(), |
54 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), | 46 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), |
55 MSG_ROUTING_NONE, | 47 MSG_ROUTING_NONE, |
56 chrome::GetActiveWebContents(browser), | 48 chrome::GetActiveWebContents(browser), |
57 session_storage_namespace_map); | 49 storage_namespace_map); |
58 WebContents* new_tab = tab_contents->web_contents(); | 50 WebContents* new_tab = tab_contents->web_contents(); |
59 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); | 51 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
60 std::vector<NavigationEntry*> entries; | 52 std::vector<NavigationEntry*> entries; |
61 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 53 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
62 browser->profile(), navigations, &entries); | 54 browser->profile(), navigations, &entries); |
63 new_tab->GetController().Restore( | 55 new_tab->GetController().Restore( |
64 selected_navigation, from_last_session, &entries); | 56 selected_navigation, from_last_session, &entries); |
65 DCHECK_EQ(0u, entries.size()); | 57 DCHECK_EQ(0u, entries.size()); |
66 | 58 |
67 int add_types = select ? TabStripModel::ADD_ACTIVE : | 59 int add_types = select ? TabStripModel::ADD_ACTIVE : |
(...skipping 25 matching lines...) Expand all Loading... |
93 session_service->TabRestored(tab_contents, pin); | 85 session_service->TabRestored(tab_contents, pin); |
94 return new_tab; | 86 return new_tab; |
95 } | 87 } |
96 | 88 |
97 void ReplaceRestoredTab( | 89 void ReplaceRestoredTab( |
98 Browser* browser, | 90 Browser* browser, |
99 const std::vector<TabNavigation>& navigations, | 91 const std::vector<TabNavigation>& navigations, |
100 int selected_navigation, | 92 int selected_navigation, |
101 bool from_last_session, | 93 bool from_last_session, |
102 const std::string& extension_app_id, | 94 const std::string& extension_app_id, |
103 content::SessionStorageNamespace* session_storage_namespace) { | 95 const content::SessionStorageNamespaceMap& storage_namespace_map) { |
104 GURL restore_url = navigations.at(selected_navigation).virtual_url(); | 96 GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
105 // TODO(ajwong): Remove the temporary session_storage_namespace_map when | |
106 // we teach session restore to understand that one tab can have multiple | |
107 // SessionStorageNamespace objects. Also remove the | |
108 // session_storage_namespace.h include since we only need that to assign | |
109 // into the map. | |
110 content::SessionStorageNamespaceMap session_storage_namespace_map; | |
111 session_storage_namespace_map[""] = session_storage_namespace; | |
112 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory( | 97 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory( |
113 browser->profile(), | 98 browser->profile(), |
114 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), | 99 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), |
115 MSG_ROUTING_NONE, | 100 MSG_ROUTING_NONE, |
116 GetActiveWebContents(browser), | 101 GetActiveWebContents(browser), |
117 session_storage_namespace_map); | 102 storage_namespace_map); |
118 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); | 103 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
119 WebContents* replacement = tab_contents->web_contents(); | 104 WebContents* replacement = tab_contents->web_contents(); |
120 std::vector<NavigationEntry*> entries; | 105 std::vector<NavigationEntry*> entries; |
121 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 106 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
122 browser->profile(), navigations, &entries); | 107 browser->profile(), navigations, &entries); |
123 replacement->GetController().Restore( | 108 replacement->GetController().Restore( |
124 selected_navigation, from_last_session, &entries); | 109 selected_navigation, from_last_session, &entries); |
125 DCHECK_EQ(0u, entries.size()); | 110 DCHECK_EQ(0u, entries.size()); |
126 | 111 |
127 browser->tab_strip_model()->ReplaceNavigationControllerAt( | 112 browser->tab_strip_model()->ReplaceNavigationControllerAt( |
128 browser->active_index(), | 113 browser->active_index(), |
129 tab_contents); | 114 tab_contents); |
130 } | 115 } |
131 | 116 |
132 } // namespace chrome | 117 } // namespace chrome |
OLD | NEW |