| 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" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_view.h" | 20 #include "content/public/browser/web_contents_view.h" |
| 20 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
| 21 | 22 |
| 22 using content::WebContents; | 23 using content::WebContents; |
| 23 using content::NavigationController; | 24 using content::NavigationController; |
| 24 using content::NavigationEntry; | 25 using content::NavigationEntry; |
| 25 | 26 |
| 26 namespace chrome { | 27 namespace chrome { |
| 27 | 28 |
| 28 int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index) { | 29 int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index) { |
| 29 return (browser->tab_strip_model()->insertion_policy() == | 30 return (browser->tab_strip_model()->insertion_policy() == |
| 30 TabStripModel::INSERT_AFTER) ? browser->tab_count() : relative_index; | 31 TabStripModel::INSERT_AFTER) ? browser->tab_count() : relative_index; |
| 31 } | 32 } |
| 32 | 33 |
| 33 content::WebContents* AddRestoredTab( | 34 content::WebContents* AddRestoredTab( |
| 34 Browser* browser, | 35 Browser* browser, |
| 35 const std::vector<TabNavigation>& navigations, | 36 const std::vector<TabNavigation>& navigations, |
| 36 int tab_index, | 37 int tab_index, |
| 37 int selected_navigation, | 38 int selected_navigation, |
| 38 const std::string& extension_app_id, | 39 const std::string& extension_app_id, |
| 39 bool select, | 40 bool select, |
| 40 bool pin, | 41 bool pin, |
| 41 bool from_last_session, | 42 bool from_last_session, |
| 42 content::SessionStorageNamespace* storage_namespace) { | 43 content::SessionStorageNamespace* session_storage_namespace) { |
| 43 GURL restore_url = navigations.at(selected_navigation).virtual_url(); | 44 GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
| 44 TabContents* tab_contents = chrome::TabContentsFactory( | 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( |
| 45 browser->profile(), | 53 browser->profile(), |
| 46 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), | 54 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), |
| 47 MSG_ROUTING_NONE, | 55 MSG_ROUTING_NONE, |
| 48 chrome::GetActiveWebContents(browser), | 56 chrome::GetActiveWebContents(browser), |
| 49 storage_namespace); | 57 session_storage_namespace_map); |
| 50 WebContents* new_tab = tab_contents->web_contents(); | 58 WebContents* new_tab = tab_contents->web_contents(); |
| 51 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); | 59 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
| 52 std::vector<NavigationEntry*> entries; | 60 std::vector<NavigationEntry*> entries; |
| 53 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 61 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 54 browser->profile(), navigations, &entries); | 62 browser->profile(), navigations, &entries); |
| 55 new_tab->GetController().Restore( | 63 new_tab->GetController().Restore( |
| 56 selected_navigation, from_last_session, &entries); | 64 selected_navigation, from_last_session, &entries); |
| 57 DCHECK_EQ(0u, entries.size()); | 65 DCHECK_EQ(0u, entries.size()); |
| 58 | 66 |
| 59 int add_types = select ? TabStripModel::ADD_ACTIVE : | 67 int add_types = select ? TabStripModel::ADD_ACTIVE : |
| (...skipping 27 matching lines...) Expand all Loading... |
| 87 } | 95 } |
| 88 | 96 |
| 89 void ReplaceRestoredTab( | 97 void ReplaceRestoredTab( |
| 90 Browser* browser, | 98 Browser* browser, |
| 91 const std::vector<TabNavigation>& navigations, | 99 const std::vector<TabNavigation>& navigations, |
| 92 int selected_navigation, | 100 int selected_navigation, |
| 93 bool from_last_session, | 101 bool from_last_session, |
| 94 const std::string& extension_app_id, | 102 const std::string& extension_app_id, |
| 95 content::SessionStorageNamespace* session_storage_namespace) { | 103 content::SessionStorageNamespace* session_storage_namespace) { |
| 96 GURL restore_url = navigations.at(selected_navigation).virtual_url(); | 104 GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
| 97 TabContents* tab_contents = chrome::TabContentsFactory( | 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( |
| 98 browser->profile(), | 113 browser->profile(), |
| 99 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), | 114 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), |
| 100 MSG_ROUTING_NONE, | 115 MSG_ROUTING_NONE, |
| 101 GetActiveWebContents(browser), | 116 GetActiveWebContents(browser), |
| 102 session_storage_namespace); | 117 session_storage_namespace_map); |
| 103 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); | 118 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
| 104 WebContents* replacement = tab_contents->web_contents(); | 119 WebContents* replacement = tab_contents->web_contents(); |
| 105 std::vector<NavigationEntry*> entries; | 120 std::vector<NavigationEntry*> entries; |
| 106 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 121 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 107 browser->profile(), navigations, &entries); | 122 browser->profile(), navigations, &entries); |
| 108 replacement->GetController().Restore( | 123 replacement->GetController().Restore( |
| 109 selected_navigation, from_last_session, &entries); | 124 selected_navigation, from_last_session, &entries); |
| 110 DCHECK_EQ(0u, entries.size()); | 125 DCHECK_EQ(0u, entries.size()); |
| 111 | 126 |
| 112 browser->tab_strip_model()->ReplaceNavigationControllerAt( | 127 browser->tab_strip_model()->ReplaceNavigationControllerAt( |
| 113 browser->active_index(), | 128 browser->active_index(), |
| 114 tab_contents); | 129 tab_contents); |
| 115 } | 130 } |
| 116 | 131 |
| 117 } // namespace chrome | 132 } // namespace chrome |
| OLD | NEW |