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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 content::WebContents* AddRestoredTab( | 33 content::WebContents* AddRestoredTab( |
34 Browser* browser, | 34 Browser* browser, |
35 const std::vector<TabNavigation>& navigations, | 35 const std::vector<TabNavigation>& navigations, |
36 int tab_index, | 36 int tab_index, |
37 int selected_navigation, | 37 int selected_navigation, |
38 const std::string& extension_app_id, | 38 const std::string& extension_app_id, |
39 bool select, | 39 bool select, |
40 bool pin, | 40 bool pin, |
41 bool from_last_session, | 41 bool from_last_session, |
42 content::SessionStorageNamespace* storage_namespace) { | 42 content::SessionStorageNamespace* storage_namespace, |
| 43 const std::string& user_agent_override) { |
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 TabContents* tab_contents = chrome::TabContentsFactory( |
45 browser->profile(), | 46 browser->profile(), |
46 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), | 47 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), |
47 MSG_ROUTING_NONE, | 48 MSG_ROUTING_NONE, |
48 chrome::GetActiveWebContents(browser), | 49 chrome::GetActiveWebContents(browser), |
49 storage_namespace); | 50 storage_namespace); |
50 WebContents* new_tab = tab_contents->web_contents(); | 51 WebContents* new_tab = tab_contents->web_contents(); |
51 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); | 52 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
52 std::vector<NavigationEntry*> entries; | 53 std::vector<NavigationEntry*> entries; |
53 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 54 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
54 browser->profile(), navigations, &entries); | 55 browser->profile(), navigations, &entries); |
| 56 new_tab->SetUserAgentOverride(user_agent_override); |
55 new_tab->GetController().Restore( | 57 new_tab->GetController().Restore( |
56 selected_navigation, from_last_session, &entries); | 58 selected_navigation, from_last_session, &entries); |
57 DCHECK_EQ(0u, entries.size()); | 59 DCHECK_EQ(0u, entries.size()); |
58 | 60 |
59 int add_types = select ? TabStripModel::ADD_ACTIVE : | 61 int add_types = select ? TabStripModel::ADD_ACTIVE : |
60 TabStripModel::ADD_NONE; | 62 TabStripModel::ADD_NONE; |
61 if (pin) { | 63 if (pin) { |
62 int first_mini_tab_idx = | 64 int first_mini_tab_idx = |
63 browser->tab_strip_model()->IndexOfFirstNonMiniTab(); | 65 browser->tab_strip_model()->IndexOfFirstNonMiniTab(); |
64 tab_index = std::min(tab_index, first_mini_tab_idx); | 66 tab_index = std::min(tab_index, first_mini_tab_idx); |
(...skipping 20 matching lines...) Expand all Loading... |
85 session_service->TabRestored(tab_contents, pin); | 87 session_service->TabRestored(tab_contents, pin); |
86 return new_tab; | 88 return new_tab; |
87 } | 89 } |
88 | 90 |
89 void ReplaceRestoredTab( | 91 void ReplaceRestoredTab( |
90 Browser* browser, | 92 Browser* browser, |
91 const std::vector<TabNavigation>& navigations, | 93 const std::vector<TabNavigation>& navigations, |
92 int selected_navigation, | 94 int selected_navigation, |
93 bool from_last_session, | 95 bool from_last_session, |
94 const std::string& extension_app_id, | 96 const std::string& extension_app_id, |
95 content::SessionStorageNamespace* session_storage_namespace) { | 97 content::SessionStorageNamespace* session_storage_namespace, |
| 98 const std::string& user_agent_override) { |
96 GURL restore_url = navigations.at(selected_navigation).virtual_url(); | 99 GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
97 TabContents* tab_contents = chrome::TabContentsFactory( | 100 TabContents* tab_contents = chrome::TabContentsFactory( |
98 browser->profile(), | 101 browser->profile(), |
99 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), | 102 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), |
100 MSG_ROUTING_NONE, | 103 MSG_ROUTING_NONE, |
101 GetActiveWebContents(browser), | 104 GetActiveWebContents(browser), |
102 session_storage_namespace); | 105 session_storage_namespace); |
103 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); | 106 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
104 WebContents* replacement = tab_contents->web_contents(); | 107 WebContents* replacement = tab_contents->web_contents(); |
| 108 replacement->SetUserAgentOverride(user_agent_override); |
105 std::vector<NavigationEntry*> entries; | 109 std::vector<NavigationEntry*> entries; |
106 TabNavigation::CreateNavigationEntriesFromTabNavigations( | 110 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
107 browser->profile(), navigations, &entries); | 111 browser->profile(), navigations, &entries); |
108 replacement->GetController().Restore( | 112 replacement->GetController().Restore( |
109 selected_navigation, from_last_session, &entries); | 113 selected_navigation, from_last_session, &entries); |
110 DCHECK_EQ(0u, entries.size()); | 114 DCHECK_EQ(0u, entries.size()); |
111 | 115 |
112 browser->tab_strip_model()->ReplaceNavigationControllerAt( | 116 browser->tab_strip_model()->ReplaceNavigationControllerAt( |
113 browser->active_index(), | 117 browser->active_index(), |
114 tab_contents); | 118 tab_contents); |
115 } | 119 } |
116 | 120 |
117 } // namespace chrome | 121 } // namespace chrome |
OLD | NEW |