Fix user agent override restoration pipeline

    
There were some disconnects in the pipeline that prevented the user agent override
string from being saved and restored from the temporary tab structions in sessions/,
but couldn't be tested on Android because the pathways weren't being exercised in
the same way.  This CL finishes hooking it up for ChromeOS (and presumably the other
platforms).
    
BUG=140600


Review URL: https://chromiumcodereview.appspot.com/10827168

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152207 0039d316-1c4b-4281-b951-d872f2087c98
parent 44ce9951
...@@ -593,7 +593,8 @@ class SessionRestoreImpl : public content::NotificationObserver { ...@@ -593,7 +593,8 @@ class SessionRestoreImpl : public content::NotificationObserver {
selected_index, selected_index,
true, true,
tab.extension_app_id, tab.extension_app_id,
NULL); NULL,
tab.user_agent_override);
} else { } else {
int tab_index = use_new_window ? 0 : browser->active_index() + 1; int tab_index = use_new_window ? 0 : browser->active_index() + 1;
WebContents* web_contents = chrome::AddRestoredTab( WebContents* web_contents = chrome::AddRestoredTab(
...@@ -605,7 +606,8 @@ class SessionRestoreImpl : public content::NotificationObserver { ...@@ -605,7 +606,8 @@ class SessionRestoreImpl : public content::NotificationObserver {
false, // selected false, // selected
tab.pinned, tab.pinned,
true, true,
NULL); NULL,
tab.user_agent_override);
// Start loading the tab immediately. // Start loading the tab immediately.
web_contents->GetController().LoadIfNecessary(); web_contents->GetController().LoadIfNecessary();
} }
...@@ -904,7 +906,8 @@ class SessionRestoreImpl : public content::NotificationObserver { ...@@ -904,7 +906,8 @@ class SessionRestoreImpl : public content::NotificationObserver {
false, // select false, // select
tab.pinned, tab.pinned,
true, true,
session_storage_namespace.get()); session_storage_namespace.get(),
tab.user_agent_override);
// Regression check: check that the tab didn't start loading right away. The // Regression check: check that the tab didn't start loading right away. The
// focused tab will be loaded by Browser, and TabLoader will load the rest. // focused tab will be loaded by Browser, and TabLoader will load the rest.
DCHECK(web_contents->GetController().NeedsReload()); DCHECK(web_contents->GetController().NeedsReload());
......
...@@ -392,6 +392,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) { ...@@ -392,6 +392,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
tab.pinned = false; tab.pinned = false;
tab.navigations.push_back(nav1); tab.navigations.push_back(nav1);
tab.navigations.push_back(nav2); tab.navigations.push_back(nav2);
tab.user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19"
" (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
ASSERT_EQ(1, browser()->tab_count()); ASSERT_EQ(1, browser()->tab_count());
...@@ -405,8 +407,9 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) { ...@@ -405,8 +407,9 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
observer.Wait(); observer.Wait();
} }
ASSERT_EQ(1, browser()->tab_count()); ASSERT_EQ(1, browser()->tab_count());
VerifyNavigationEntries( content::WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0);
chrome::GetWebContentsAt(browser(), 0)->GetController(), url1, url2); VerifyNavigationEntries(web_contents->GetController(), url1, url2);
ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
// Restore in a new tab. // Restore in a new tab.
{ {
...@@ -419,8 +422,9 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) { ...@@ -419,8 +422,9 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
} }
ASSERT_EQ(2, browser()->tab_count()); ASSERT_EQ(2, browser()->tab_count());
ASSERT_EQ(0, browser()->active_index()); ASSERT_EQ(0, browser()->active_index());
VerifyNavigationEntries( web_contents = chrome::GetWebContentsAt(browser(), 1);
chrome::GetWebContentsAt(browser(), 1)->GetController(), url1, url2); VerifyNavigationEntries(web_contents->GetController(), url1, url2);
ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
// Restore in a new window. // Restore in a new window.
ui_test_utils::BrowserAddedObserver browser_observer; ui_test_utils::BrowserAddedObserver browser_observer;
...@@ -429,8 +433,9 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) { ...@@ -429,8 +433,9 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignTab) {
Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); Browser* new_browser = browser_observer.WaitForSingleNewBrowser();
ASSERT_EQ(1, new_browser->tab_count()); ASSERT_EQ(1, new_browser->tab_count());
VerifyNavigationEntries( web_contents = chrome::GetWebContentsAt(new_browser, 0);
chrome::GetWebContentsAt(new_browser, 0)->GetController(), url1, url2); VerifyNavigationEntries(web_contents->GetController(), url1, url2);
ASSERT_EQ(tab.user_agent_override, web_contents->GetUserAgentOverride());
} }
IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
...@@ -442,6 +447,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { ...@@ -442,6 +447,8 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
std::string(), content::PAGE_TRANSITION_TYPED); std::string(), content::PAGE_TRANSITION_TYPED);
TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"), TabNavigation nav2(0, url2, content::Referrer(), ASCIIToUTF16("two"),
std::string(), content::PAGE_TRANSITION_TYPED); std::string(), content::PAGE_TRANSITION_TYPED);
nav1.set_is_overriding_user_agent(false);
nav2.set_is_overriding_user_agent(true);
// Set up the restore data -- one window with two tabs. // Set up the restore data -- one window with two tabs.
std::vector<const SessionWindow*> session; std::vector<const SessionWindow*> session;
...@@ -451,6 +458,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { ...@@ -451,6 +458,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
tab1.current_navigation_index = 0; tab1.current_navigation_index = 0;
tab1.pinned = true; tab1.pinned = true;
tab1.navigations.push_back(nav1); tab1.navigations.push_back(nav1);
tab1.user_agent_override = "user_agent_override";
window.tabs.push_back(&tab1); window.tabs.push_back(&tab1);
SessionTab tab2; SessionTab tab2;
...@@ -458,6 +466,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { ...@@ -458,6 +466,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
tab2.current_navigation_index = 0; tab2.current_navigation_index = 0;
tab2.pinned = false; tab2.pinned = false;
tab2.navigations.push_back(nav2); tab2.navigations.push_back(nav2);
tab2.user_agent_override = "user_agent_override_2";
window.tabs.push_back(&tab2); window.tabs.push_back(&tab2);
session.push_back(static_cast<const SessionWindow*>(&window)); session.push_back(static_cast<const SessionWindow*>(&window));
...@@ -469,8 +478,25 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { ...@@ -469,8 +478,25 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) {
ASSERT_EQ(2u, BrowserList::size()); ASSERT_EQ(2u, BrowserList::size());
ASSERT_EQ(2, new_browser->tab_count()); ASSERT_EQ(2, new_browser->tab_count());
ASSERT_EQ(url1, chrome::GetWebContentsAt(new_browser, 0)->GetURL()); content::WebContents* web_contents_1 =
ASSERT_EQ(url2, chrome::GetWebContentsAt(new_browser, 1)->GetURL()); chrome::GetWebContentsAt(new_browser, 0);
content::WebContents* web_contents_2 =
chrome::GetWebContentsAt(new_browser, 1);
ASSERT_EQ(url1, web_contents_1->GetURL());
ASSERT_EQ(url2, web_contents_2->GetURL());
// Check user agent override state.
ASSERT_EQ(tab1.user_agent_override, web_contents_1->GetUserAgentOverride());
ASSERT_EQ(tab2.user_agent_override, web_contents_2->GetUserAgentOverride());
content::NavigationEntry* entry =
web_contents_1->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
ASSERT_EQ(nav1.is_overriding_user_agent(), entry->GetIsOverridingUserAgent());
entry = web_contents_2->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
ASSERT_EQ(nav2.is_overriding_user_agent(), entry->GetIsOverridingUserAgent());
// The SessionWindow destructor deletes the tabs, so we have to clear them // The SessionWindow destructor deletes the tabs, so we have to clear them
// here to avoid a crash. // here to avoid a crash.
...@@ -727,6 +753,32 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, ShareProcessesOnRestore) { ...@@ -727,6 +753,32 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreTest, ShareProcessesOnRestore) {
ASSERT_EQ(expected_process_count, RenderProcessHostCount()); ASSERT_EQ(expected_process_count, RenderProcessHostCount());
} }
// Test that changing the user agent override will persist it to disk.
IN_PROC_BROWSER_TEST_F(SessionRestoreTest, PersistAndRestoreUserAgentOverride) {
// Create a tab with an overridden user agent.
ui_test_utils::NavigateToURL(browser(), url1_);
ASSERT_EQ(0, browser()->active_index());
chrome::GetWebContentsAt(browser(), 0)->SetUserAgentOverride("override");
// Create a tab without an overridden user agent.
ui_test_utils::NavigateToURLWithDisposition(
browser(), url2_, NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ASSERT_EQ(1, browser()->active_index());
// Kill the original browser then open a new one to trigger a restore.
Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
ASSERT_EQ(1u, BrowserList::size());
ASSERT_EQ(2, new_browser->tab_count());
ASSERT_EQ(1, new_browser->active_index());
// Confirm that the user agent overrides are properly set.
EXPECT_EQ("override",
chrome::GetWebContentsAt(new_browser, 0)->GetUserAgentOverride());
EXPECT_EQ("",
chrome::GetWebContentsAt(new_browser, 1)->GetUserAgentOverride());
}
// Regression test for crbug.com/125958. When restoring a pinned selected tab in // Regression test for crbug.com/125958. When restoring a pinned selected tab in
// a setting where there are existing tabs, the selected index computation was // a setting where there are existing tabs, the selected index computation was
// wrong, leading to the wrong tab getting selected, DCHECKs firing, and the // wrong, leading to the wrong tab getting selected, DCHECKs firing, and the
......
...@@ -482,6 +482,19 @@ void SessionService::SetSelectedTabInWindow(const SessionID& window_id, ...@@ -482,6 +482,19 @@ void SessionService::SetSelectedTabInWindow(const SessionID& window_id,
ScheduleCommand(CreateSetSelectedTabInWindow(window_id, index)); ScheduleCommand(CreateSetSelectedTabInWindow(window_id, index));
} }
void SessionService::SetTabUserAgentOverride(
const SessionID& window_id,
const SessionID& tab_id,
const std::string& user_agent_override) {
if (!ShouldTrackChangesToWindow(window_id))
return;
ScheduleCommand(CreateSetTabUserAgentOverrideCommand(
kCommandSetTabUserAgentOverride,
tab_id.id(),
user_agent_override));
}
SessionService::Handle SessionService::GetLastSession( SessionService::Handle SessionService::GetLastSession(
CancelableRequestConsumerBase* consumer, CancelableRequestConsumerBase* consumer,
const SessionCallback& callback) { const SessionCallback& callback) {
...@@ -733,19 +746,6 @@ void SessionService::SetTabExtensionAppID( ...@@ -733,19 +746,6 @@ void SessionService::SetTabExtensionAppID(
extension_app_id)); extension_app_id));
} }
void SessionService::SetTabUserAgentOverride(
const SessionID& window_id,
const SessionID& tab_id,
const std::string& user_agent_override) {
if (!ShouldTrackChangesToWindow(window_id))
return;
ScheduleCommand(CreateSetTabUserAgentOverrideCommand(
kCommandSetTabUserAgentOverride,
tab_id.id(),
user_agent_override));
}
SessionCommand* SessionService::CreateSetSelectedTabInWindow( SessionCommand* SessionService::CreateSetSelectedTabInWindow(
const SessionID& window_id, const SessionID& window_id,
int index) { int index) {
......
...@@ -165,6 +165,11 @@ class SessionService : public BaseSessionService, ...@@ -165,6 +165,11 @@ class SessionService : public BaseSessionService,
// Sets the index of the selected tab in the specified window. // Sets the index of the selected tab in the specified window.
void SetSelectedTabInWindow(const SessionID& window_id, int index); void SetSelectedTabInWindow(const SessionID& window_id, int index);
// Sets the user agent override of the specified tab.
void SetTabUserAgentOverride(const SessionID& window_id,
const SessionID& tab_id,
const std::string& user_agent_override);
// Callback from GetSavedSession of GetLastSession. // Callback from GetSavedSession of GetLastSession.
// //
// The contents of the supplied vector are deleted after the callback is // The contents of the supplied vector are deleted after the callback is
...@@ -219,11 +224,6 @@ class SessionService : public BaseSessionService, ...@@ -219,11 +224,6 @@ class SessionService : public BaseSessionService,
const SessionID& tab_id, const SessionID& tab_id,
const std::string& extension_app_id); const std::string& extension_app_id);
// Sets the user agent override of the specified tab.
void SetTabUserAgentOverride(const SessionID& window_id,
const SessionID& tab_id,
const std::string& user_agent_override);
// Methods to create the various commands. It is up to the caller to delete // Methods to create the various commands. It is up to the caller to delete
// the returned the SessionCommand* object. // the returned the SessionCommand* object.
SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id, SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id,
......
...@@ -697,7 +697,9 @@ TEST_F(SessionServiceTest, PersistApplicationExtensionID) { ...@@ -697,7 +697,9 @@ TEST_F(SessionServiceTest, PersistApplicationExtensionID) {
TEST_F(SessionServiceTest, PersistUserAgentOverrides) { TEST_F(SessionServiceTest, PersistUserAgentOverrides) {
SessionID tab_id; SessionID tab_id;
ASSERT_NE(window_id.id(), tab_id.id()); ASSERT_NE(window_id.id(), tab_id.id());
std::string user_agent_override("overridden user agent"); std::string user_agent_override = "Mozilla/5.0 (X11; Linux x86_64) "
"AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 "
"Safari/535.19";
TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(),
ASCIIToUTF16("abc"), std::string(), ASCIIToUTF16("abc"), std::string(),
......
...@@ -379,7 +379,8 @@ void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate, ...@@ -379,7 +379,8 @@ void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate,
static_cast<int>(tab_i) == static_cast<int>(tab_i) ==
window->selected_tab_index, window->selected_tab_index,
tab.pinned, tab.from_last_session, tab.pinned, tab.from_last_session,
tab.session_storage_namespace); tab.session_storage_namespace,
tab.user_agent_override);
if (restored_tab) { if (restored_tab) {
restored_tab->GetController().LoadIfNecessary(); restored_tab->GetController().LoadIfNecessary();
RecordAppLaunch(profile(), tab); RecordAppLaunch(profile(), tab);
...@@ -546,6 +547,9 @@ void TabRestoreService::PopulateTab(Tab* tab, ...@@ -546,6 +547,9 @@ void TabRestoreService::PopulateTab(Tab* tab,
tab->extension_app_id = extension->id(); tab->extension_app_id = extension->id();
} }
tab->user_agent_override =
controller->GetWebContents()->GetUserAgentOverride();
// TODO(ajwong): This does not correctly handle storage for isolated apps. // TODO(ajwong): This does not correctly handle storage for isolated apps.
tab->session_storage_namespace = tab->session_storage_namespace =
controller->GetDefaultSessionStorageNamespace(); controller->GetDefaultSessionStorageNamespace();
...@@ -997,7 +1001,8 @@ TabRestoreServiceDelegate* TabRestoreService::RestoreTab( ...@@ -997,7 +1001,8 @@ TabRestoreServiceDelegate* TabRestoreService::RestoreTab(
tab.current_navigation_index, tab.current_navigation_index,
tab.from_last_session, tab.from_last_session,
tab.extension_app_id, tab.extension_app_id,
tab.session_storage_namespace); tab.session_storage_namespace,
tab.user_agent_override);
} else { } else {
// We only respsect the tab's original browser if there's no disposition. // We only respsect the tab's original browser if there's no disposition.
if (disposition == UNKNOWN && tab.has_browser()) if (disposition == UNKNOWN && tab.has_browser())
...@@ -1031,7 +1036,8 @@ TabRestoreServiceDelegate* TabRestoreService::RestoreTab( ...@@ -1031,7 +1036,8 @@ TabRestoreServiceDelegate* TabRestoreService::RestoreTab(
disposition != NEW_BACKGROUND_TAB, disposition != NEW_BACKGROUND_TAB,
tab.pinned, tab.pinned,
tab.from_last_session, tab.from_last_session,
tab.session_storage_namespace); tab.session_storage_namespace,
tab.user_agent_override);
web_contents->GetController().LoadIfNecessary(); web_contents->GetController().LoadIfNecessary();
} }
RecordAppLaunch(profile(), tab); RecordAppLaunch(profile(), tab);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/render_view_test.h" #include "content/public/test/render_view_test.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
...@@ -57,6 +58,8 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { ...@@ -57,6 +58,8 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness {
url1_ = GURL("http://1"); url1_ = GURL("http://1");
url2_ = GURL("http://2"); url2_ = GURL("http://2");
url3_ = GURL("http://3"); url3_ = GURL("http://3");
user_agent_override_ = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19"
" (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
} }
~TabRestoreServiceTest() { ~TabRestoreServiceTest() {
...@@ -139,6 +142,7 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { ...@@ -139,6 +142,7 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness {
GURL url1_; GURL url1_;
GURL url2_; GURL url2_;
GURL url3_; GURL url3_;
std::string user_agent_override_;
scoped_ptr<TabRestoreService> service_; scoped_ptr<TabRestoreService> service_;
TabRestoreTimeFactory* time_factory_; TabRestoreTimeFactory* time_factory_;
content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox
...@@ -165,19 +169,21 @@ TEST_F(TabRestoreServiceTest, Basic) { ...@@ -165,19 +169,21 @@ TEST_F(TabRestoreServiceTest, Basic) {
EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
EXPECT_EQ("", tab->user_agent_override);
EXPECT_EQ(2, tab->current_navigation_index); EXPECT_EQ(2, tab->current_navigation_index);
EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
tab->timestamp.ToInternalValue()); tab->timestamp.ToInternalValue());
NavigateToIndex(1); NavigateToIndex(1);
// And check again. // And check again, but set the user agent override this time.
contents()->SetUserAgentOverride(user_agent_override_);
service_->CreateHistoricalTab(contents(), -1); service_->CreateHistoricalTab(contents(), -1);
// There should be two entries now. // There should be two entries now.
ASSERT_EQ(2U, service_->entries().size()); ASSERT_EQ(2U, service_->entries().size());
// Make sure the entry matches // Make sure the entry matches.
entry = service_->entries().front(); entry = service_->entries().front();
ASSERT_EQ(TabRestoreService::TAB, entry->type); ASSERT_EQ(TabRestoreService::TAB, entry->type);
tab = static_cast<Tab*>(entry); tab = static_cast<Tab*>(entry);
...@@ -186,6 +192,7 @@ TEST_F(TabRestoreServiceTest, Basic) { ...@@ -186,6 +192,7 @@ TEST_F(TabRestoreServiceTest, Basic) {
EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); EXPECT_EQ(url1_, tab->navigations[0].virtual_url());
EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); EXPECT_EQ(url2_, tab->navigations[1].virtual_url());
EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); EXPECT_EQ(url3_, tab->navigations[2].virtual_url());
EXPECT_EQ(user_agent_override_, tab->user_agent_override);
EXPECT_EQ(1, tab->current_navigation_index); EXPECT_EQ(1, tab->current_navigation_index);
EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
tab->timestamp.ToInternalValue()); tab->timestamp.ToInternalValue());
......
...@@ -51,13 +51,15 @@ class TabRestoreServiceDelegate { ...@@ -51,13 +51,15 @@ class TabRestoreServiceDelegate {
bool select, bool select,
bool pin, bool pin,
bool from_last_session, bool from_last_session,
content::SessionStorageNamespace* storage_namespace) = 0; content::SessionStorageNamespace* storage_namespace,
const std::string& user_agent_override) = 0;
virtual void ReplaceRestoredTab( virtual void ReplaceRestoredTab(
const std::vector<TabNavigation>& navigations, const std::vector<TabNavigation>& navigations,
int selected_navigation, int selected_navigation,
bool from_last_session, bool from_last_session,
const std::string& extension_app_id, const std::string& extension_app_id,
content::SessionStorageNamespace* session_storage_namespace) = 0; content::SessionStorageNamespace* session_storage_namespace,
const std::string& user_agent_override) = 0;
virtual void CloseTab() = 0; virtual void CloseTab() = 0;
// see Browser::Create // see Browser::Create
......
...@@ -58,10 +58,12 @@ WebContents* BrowserTabRestoreServiceDelegate::AddRestoredTab( ...@@ -58,10 +58,12 @@ WebContents* BrowserTabRestoreServiceDelegate::AddRestoredTab(
bool select, bool select,
bool pin, bool pin,
bool from_last_session, bool from_last_session,
SessionStorageNamespace* storage_namespace) { SessionStorageNamespace* storage_namespace,
const std::string& user_agent_override) {
return chrome::AddRestoredTab(browser_, navigations, tab_index, return chrome::AddRestoredTab(browser_, navigations, tab_index,
selected_navigation, extension_app_id, select, selected_navigation, extension_app_id, select,
pin, from_last_session, storage_namespace); pin, from_last_session, storage_namespace,
user_agent_override);
} }
void BrowserTabRestoreServiceDelegate::ReplaceRestoredTab( void BrowserTabRestoreServiceDelegate::ReplaceRestoredTab(
...@@ -69,10 +71,11 @@ void BrowserTabRestoreServiceDelegate::ReplaceRestoredTab( ...@@ -69,10 +71,11 @@ void BrowserTabRestoreServiceDelegate::ReplaceRestoredTab(
int selected_navigation, int selected_navigation,
bool from_last_session, bool from_last_session,
const std::string& extension_app_id, const std::string& extension_app_id,
SessionStorageNamespace* session_storage_namespace) { SessionStorageNamespace* session_storage_namespace,
const std::string& user_agent_override) {
chrome::ReplaceRestoredTab(browser_, navigations, selected_navigation, chrome::ReplaceRestoredTab(browser_, navigations, selected_navigation,
from_last_session, extension_app_id, from_last_session, extension_app_id,
session_storage_namespace); session_storage_namespace, user_agent_override);
} }
void BrowserTabRestoreServiceDelegate::CloseTab() { void BrowserTabRestoreServiceDelegate::CloseTab() {
......
...@@ -38,13 +38,15 @@ class BrowserTabRestoreServiceDelegate : public TabRestoreServiceDelegate { ...@@ -38,13 +38,15 @@ class BrowserTabRestoreServiceDelegate : public TabRestoreServiceDelegate {
bool select, bool select,
bool pin, bool pin,
bool from_last_session, bool from_last_session,
content::SessionStorageNamespace* storage_namespace) OVERRIDE; content::SessionStorageNamespace* storage_namespace,
const std::string& user_agent_override) OVERRIDE;
virtual void ReplaceRestoredTab( virtual void ReplaceRestoredTab(
const std::vector<TabNavigation>& navigations, const std::vector<TabNavigation>& navigations,
int selected_navigation, int selected_navigation,
bool from_last_session, bool from_last_session,
const std::string& extension_app_id, const std::string& extension_app_id,
content::SessionStorageNamespace* session_storage_namespace) OVERRIDE; content::SessionStorageNamespace* session_storage_namespace,
const std::string& user_agent_override) OVERRIDE;
virtual void CloseTab() OVERRIDE; virtual void CloseTab() OVERRIDE;
private: private:
......
...@@ -40,7 +40,8 @@ content::WebContents* AddRestoredTab( ...@@ -40,7 +40,8 @@ content::WebContents* AddRestoredTab(
bool select, bool select,
bool pin, bool pin,
bool from_last_session, bool from_last_session,
content::SessionStorageNamespace* session_storage_namespace) { content::SessionStorageNamespace* session_storage_namespace,
const std::string& user_agent_override) {
GURL restore_url = navigations.at(selected_navigation).virtual_url(); GURL restore_url = navigations.at(selected_navigation).virtual_url();
// TODO(ajwong): Remove the temporary session_storage_namespace_map when // TODO(ajwong): Remove the temporary session_storage_namespace_map when
// we teach session restore to understand that one tab can have multiple // we teach session restore to understand that one tab can have multiple
...@@ -60,6 +61,7 @@ content::WebContents* AddRestoredTab( ...@@ -60,6 +61,7 @@ content::WebContents* AddRestoredTab(
std::vector<NavigationEntry*> entries; std::vector<NavigationEntry*> entries;
TabNavigation::CreateNavigationEntriesFromTabNavigations( TabNavigation::CreateNavigationEntriesFromTabNavigations(
browser->profile(), navigations, &entries); browser->profile(), navigations, &entries);
new_tab->SetUserAgentOverride(user_agent_override);
new_tab->GetController().Restore( new_tab->GetController().Restore(
selected_navigation, from_last_session, &entries); selected_navigation, from_last_session, &entries);
DCHECK_EQ(0u, entries.size()); DCHECK_EQ(0u, entries.size());
...@@ -100,7 +102,8 @@ void ReplaceRestoredTab( ...@@ -100,7 +102,8 @@ void ReplaceRestoredTab(
int selected_navigation, int selected_navigation,
bool from_last_session, bool from_last_session,
const std::string& extension_app_id, const std::string& extension_app_id,
content::SessionStorageNamespace* session_storage_namespace) { content::SessionStorageNamespace* session_storage_namespace,
const std::string& user_agent_override) {
GURL restore_url = navigations.at(selected_navigation).virtual_url(); GURL restore_url = navigations.at(selected_navigation).virtual_url();
// TODO(ajwong): Remove the temporary session_storage_namespace_map when // TODO(ajwong): Remove the temporary session_storage_namespace_map when
// we teach session restore to understand that one tab can have multiple // we teach session restore to understand that one tab can have multiple
...@@ -117,6 +120,7 @@ void ReplaceRestoredTab( ...@@ -117,6 +120,7 @@ void ReplaceRestoredTab(
session_storage_namespace_map); session_storage_namespace_map);
tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id); tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
WebContents* replacement = tab_contents->web_contents(); WebContents* replacement = tab_contents->web_contents();
replacement->SetUserAgentOverride(user_agent_override);
std::vector<NavigationEntry*> entries; std::vector<NavigationEntry*> entries;
TabNavigation::CreateNavigationEntriesFromTabNavigations( TabNavigation::CreateNavigationEntriesFromTabNavigations(
browser->profile(), navigations, &entries); browser->profile(), navigations, &entries);
......
...@@ -31,7 +31,9 @@ int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index); ...@@ -31,7 +31,9 @@ int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index);
// non-empty the tab is an app tab and |extension_app_id| is the id of the // non-empty the tab is an app tab and |extension_app_id| is the id of the
// extension. If |pin| is true and |tab_index|/ is the last pinned tab, then // extension. If |pin| is true and |tab_index|/ is the last pinned tab, then
// the newly created tab is pinned. If |from_last_session| is true, // the newly created tab is pinned. If |from_last_session| is true,
// |navigations| are from the previous session. // |navigations| are from the previous session. |user_agent_override| contains
// the string being used as the user agent for all of the tab's navigations when
// the regular user agent is overridden.
content::WebContents* AddRestoredTab( content::WebContents* AddRestoredTab(
Browser* browser, Browser* browser,
const std::vector<TabNavigation>& navigations, const std::vector<TabNavigation>& navigations,
...@@ -41,7 +43,8 @@ content::WebContents* AddRestoredTab( ...@@ -41,7 +43,8 @@ content::WebContents* AddRestoredTab(
bool select, bool select,
bool pin, bool pin,
bool from_last_session, bool from_last_session,
content::SessionStorageNamespace* storage_namespace); content::SessionStorageNamespace* storage_namespace,
const std::string& user_agent_override);
// Replaces the state of the currently selected tab with the session // Replaces the state of the currently selected tab with the session
// history restored from the SessionRestore system. // history restored from the SessionRestore system.
...@@ -51,7 +54,8 @@ void ReplaceRestoredTab( ...@@ -51,7 +54,8 @@ void ReplaceRestoredTab(
int selected_navigation, int selected_navigation,
bool from_last_session, bool from_last_session,
const std::string& extension_app_id, const std::string& extension_app_id,
content::SessionStorageNamespace* session_storage_namespace); content::SessionStorageNamespace* session_storage_namespace,
const std::string& user_agent_override);
} // namespace chrome } // namespace chrome
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/printing/print_view_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
#include "chrome/browser/sessions/restore_tab_helper.h" #include "chrome/browser/sessions/restore_tab_helper.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/tab_contents/navigation_metrics_recorder.h" #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
#include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/tab_contents/thumbnail_generator.h"
...@@ -251,3 +253,15 @@ void TabContents::WebContentsDestroyed(WebContents* tab) { ...@@ -251,3 +253,15 @@ void TabContents::WebContentsDestroyed(WebContents* tab) {
// will attempt to access the WebContents and we'll crash. // will attempt to access the WebContents and we'll crash.
DCHECK(in_destructor_); DCHECK(in_destructor_);
} }
void TabContents::UserAgentOverrideSet(const std::string& user_agent) {
#if defined(ENABLE_SESSION_SERVICE)
SessionService* session =
SessionServiceFactory::GetForProfile(profile());
if (session) {
session->SetTabUserAgentOverride(restore_tab_helper()->window_id(),
restore_tab_helper()->session_id(),
user_agent);
}
#endif
}
...@@ -255,6 +255,7 @@ class TabContents : public content::WebContentsObserver { ...@@ -255,6 +255,7 @@ class TabContents : public content::WebContentsObserver {
// content::WebContentsObserver overrides: // content::WebContentsObserver overrides:
virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE; virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE;
virtual void UserAgentOverrideSet(const std::string& user_agent) OVERRIDE;
private: private:
// Used to retrieve this object from |web_contents_|, which is placed in // Used to retrieve this object from |web_contents_|, which is placed in
......
...@@ -808,6 +808,9 @@ void WebContentsImpl::SetUserAgentOverride(const std::string& override) { ...@@ -808,6 +808,9 @@ void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
NavigationEntry* entry = controller_.GetActiveEntry(); NavigationEntry* entry = controller_.GetActiveEntry();
if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
controller_.ReloadIgnoringCache(true); controller_.ReloadIgnoringCache(true);
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
UserAgentOverrideSet(override));
} }
const std::string& WebContentsImpl::GetUserAgentOverride() const { const std::string& WebContentsImpl::GetUserAgentOverride() const {
......
...@@ -126,6 +126,9 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener, ...@@ -126,6 +126,9 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
// It is safe to delete 'this' from here. // It is safe to delete 'this' from here.
virtual void WebContentsDestroyed(WebContents* web_contents) {} virtual void WebContentsDestroyed(WebContents* web_contents) {}
// Called when the user agent override for a WebContents has been changed.
virtual void UserAgentOverrideSet(const std::string& user_agent) {}
// IPC::Listener implementation. // IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment