Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/ui/browser_tabrestore.cc

Issue 10827168: Fix user agent override restore pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nit addressing Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 33
34 content::WebContents* AddRestoredTab( 34 content::WebContents* AddRestoredTab(
35 Browser* browser, 35 Browser* browser,
36 const std::vector<TabNavigation>& navigations, 36 const std::vector<TabNavigation>& navigations,
37 int tab_index, 37 int tab_index,
38 int selected_navigation, 38 int selected_navigation,
39 const std::string& extension_app_id, 39 const std::string& extension_app_id,
40 bool select, 40 bool select,
41 bool pin, 41 bool pin,
42 bool from_last_session, 42 bool from_last_session,
43 content::SessionStorageNamespace* session_storage_namespace) { 43 content::SessionStorageNamespace* session_storage_namespace,
44 const std::string& user_agent_override) {
44 GURL restore_url = navigations.at(selected_navigation).virtual_url(); 45 GURL restore_url = navigations.at(selected_navigation).virtual_url();
45 // TODO(ajwong): Remove the temporary session_storage_namespace_map when 46 // TODO(ajwong): Remove the temporary session_storage_namespace_map when
46 // we teach session restore to understand that one tab can have multiple 47 // we teach session restore to understand that one tab can have multiple
47 // SessionStorageNamespace objects. Also remove the 48 // SessionStorageNamespace objects. Also remove the
48 // session_storage_namespace.h include since we only need that to assign 49 // session_storage_namespace.h include since we only need that to assign
49 // into the map. 50 // into the map.
50 content::SessionStorageNamespaceMap session_storage_namespace_map; 51 content::SessionStorageNamespaceMap session_storage_namespace_map;
51 session_storage_namespace_map[""] = session_storage_namespace; 52 session_storage_namespace_map[""] = session_storage_namespace;
52 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory( 53 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory(
53 browser->profile(), 54 browser->profile(),
54 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), 55 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url),
55 MSG_ROUTING_NONE, 56 MSG_ROUTING_NONE,
56 chrome::GetActiveWebContents(browser), 57 chrome::GetActiveWebContents(browser),
57 session_storage_namespace_map); 58 session_storage_namespace_map);
58 WebContents* new_tab = tab_contents->web_contents(); 59 WebContents* new_tab = tab_contents->web_contents();
59 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); 60 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
60 std::vector<NavigationEntry*> entries; 61 std::vector<NavigationEntry*> entries;
61 TabNavigation::CreateNavigationEntriesFromTabNavigations( 62 TabNavigation::CreateNavigationEntriesFromTabNavigations(
62 browser->profile(), navigations, &entries); 63 browser->profile(), navigations, &entries);
64 new_tab->SetUserAgentOverride(user_agent_override);
63 new_tab->GetController().Restore( 65 new_tab->GetController().Restore(
64 selected_navigation, from_last_session, &entries); 66 selected_navigation, from_last_session, &entries);
65 DCHECK_EQ(0u, entries.size()); 67 DCHECK_EQ(0u, entries.size());
66 68
67 int add_types = select ? TabStripModel::ADD_ACTIVE : 69 int add_types = select ? TabStripModel::ADD_ACTIVE :
68 TabStripModel::ADD_NONE; 70 TabStripModel::ADD_NONE;
69 if (pin) { 71 if (pin) {
70 int first_mini_tab_idx = 72 int first_mini_tab_idx =
71 browser->tab_strip_model()->IndexOfFirstNonMiniTab(); 73 browser->tab_strip_model()->IndexOfFirstNonMiniTab();
72 tab_index = std::min(tab_index, first_mini_tab_idx); 74 tab_index = std::min(tab_index, first_mini_tab_idx);
(...skipping 20 matching lines...) Expand all
93 session_service->TabRestored(tab_contents, pin); 95 session_service->TabRestored(tab_contents, pin);
94 return new_tab; 96 return new_tab;
95 } 97 }
96 98
97 void ReplaceRestoredTab( 99 void ReplaceRestoredTab(
98 Browser* browser, 100 Browser* browser,
99 const std::vector<TabNavigation>& navigations, 101 const std::vector<TabNavigation>& navigations,
100 int selected_navigation, 102 int selected_navigation,
101 bool from_last_session, 103 bool from_last_session,
102 const std::string& extension_app_id, 104 const std::string& extension_app_id,
103 content::SessionStorageNamespace* session_storage_namespace) { 105 content::SessionStorageNamespace* session_storage_namespace,
106 const std::string& user_agent_override) {
104 GURL restore_url = navigations.at(selected_navigation).virtual_url(); 107 GURL restore_url = navigations.at(selected_navigation).virtual_url();
105 // TODO(ajwong): Remove the temporary session_storage_namespace_map when 108 // TODO(ajwong): Remove the temporary session_storage_namespace_map when
106 // we teach session restore to understand that one tab can have multiple 109 // we teach session restore to understand that one tab can have multiple
107 // SessionStorageNamespace objects. Also remove the 110 // SessionStorageNamespace objects. Also remove the
108 // session_storage_namespace.h include since we only need that to assign 111 // session_storage_namespace.h include since we only need that to assign
109 // into the map. 112 // into the map.
110 content::SessionStorageNamespaceMap session_storage_namespace_map; 113 content::SessionStorageNamespaceMap session_storage_namespace_map;
111 session_storage_namespace_map[""] = session_storage_namespace; 114 session_storage_namespace_map[""] = session_storage_namespace;
112 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory( 115 TabContents* tab_contents = chrome::TabContentsWithSessionStorageFactory(
113 browser->profile(), 116 browser->profile(),
114 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url), 117 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url),
115 MSG_ROUTING_NONE, 118 MSG_ROUTING_NONE,
116 GetActiveWebContents(browser), 119 GetActiveWebContents(browser),
117 session_storage_namespace_map); 120 session_storage_namespace_map);
118 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); 121 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
119 WebContents* replacement = tab_contents->web_contents(); 122 WebContents* replacement = tab_contents->web_contents();
123 replacement->SetUserAgentOverride(user_agent_override);
120 std::vector<NavigationEntry*> entries; 124 std::vector<NavigationEntry*> entries;
121 TabNavigation::CreateNavigationEntriesFromTabNavigations( 125 TabNavigation::CreateNavigationEntriesFromTabNavigations(
122 browser->profile(), navigations, &entries); 126 browser->profile(), navigations, &entries);
123 replacement->GetController().Restore( 127 replacement->GetController().Restore(
124 selected_navigation, from_last_session, &entries); 128 selected_navigation, from_last_session, &entries);
125 DCHECK_EQ(0u, entries.size()); 129 DCHECK_EQ(0u, entries.size());
126 130
127 browser->tab_strip_model()->ReplaceNavigationControllerAt( 131 browser->tab_strip_model()->ReplaceNavigationControllerAt(
128 browser->active_index(), 132 browser->active_index(),
129 tab_contents); 133 tab_contents);
130 } 134 }
131 135
132 } // namespace chrome 136 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698