diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 03:36:47 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 03:36:47 +0000 |
commit | 6c6b02dcf61fa8d344a3b1768b5e9610c17468c1 (patch) | |
tree | 1d62f8bc14264eace0e5bf489edb3634142d7df4 /content | |
parent | 2bf646e71e7f103b1e761a68284462849cba7bcb (diff) | |
download | chromium_src-6c6b02dcf61fa8d344a3b1768b5e9610c17468c1.zip chromium_src-6c6b02dcf61fa8d344a3b1768b5e9610c17468c1.tar.gz chromium_src-6c6b02dcf61fa8d344a3b1768b5e9610c17468c1.tar.bz2 |
When the user navigates to the home page, make sure to set the RLZ string
if needed.
John: can you plase look at the content\... changes?
Scott: can you plase look at the chrome\... changes?
BUG=0
TEST=Install an official chrome build (not a chromium build) with a non
organic brand code. During the install, make sure to choose google as the
home page. When google is running, pressing the home page button should
cause the request to include the RLZ http header. Pressed Alt-Home should
do the samer thing.
When starting chrome, the RLZ header should also be present since the startup
page is the home page, and the home page is set to google.
Navigating to the google.com manually by typing the URL or by clicking on
a link should not cause the hrrp header to be added.
Not choosing google as the home during install, or changing the home page
to be something other than google should stop the http header from being
added. This is true is even if the user subsequently set his home page to
google again.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=99283
Review URL: http://codereview.chromium.org/7791029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
10 files changed, 67 insertions, 27 deletions
diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc index 85780cd..1ee7492 100644 --- a/content/browser/tab_contents/navigation_controller.cc +++ b/content/browser/tab_contents/navigation_controller.cc @@ -221,6 +221,7 @@ bool NavigationController::IsInitialNavigation() { // static NavigationEntry* NavigationController::CreateNavigationEntry( const GURL& url, const GURL& referrer, PageTransition::Type transition, + const std::string& extra_headers, content::BrowserContext* browser_context) { // Allow the browser URL handler to rewrite the URL. This will, for example, // remove "view-source:" from the beginning of the URL to get the URL that @@ -242,6 +243,7 @@ NavigationEntry* NavigationController::CreateNavigationEntry( entry->set_virtual_url(url); entry->set_user_typed_url(url); entry->set_update_virtual_url_with_url(reverse_on_redirect); + entry->set_extra_headers(extra_headers); return entry; } @@ -273,7 +275,7 @@ void NavigationController::LoadEntry(NavigationEntry* entry) { NotificationService::current()->Notify( content::NOTIFICATION_NAV_ENTRY_PENDING, Source<NavigationController>(this), - NotificationService::NoDetails()); + Details<NavigationEntry>(entry)); NavigateToPendingEntry(NO_RELOAD); } @@ -483,10 +485,21 @@ void NavigationController::AddTransientEntry(NavigationEntry* entry) { void NavigationController::LoadURL(const GURL& url, const GURL& referrer, PageTransition::Type transition) { + LoadURLWithHeaders(url, referrer, transition, std::string()); +} + +// TODO(rogerta): Remove this call and put the extra_headers argument directly +// in LoadURL(). +void NavigationController::LoadURLWithHeaders( + const GURL& url, + const GURL& referrer, + PageTransition::Type transition, + const std::string& extra_headers) { // The user initiated a load, we don't need to reload anymore. needs_reload_ = false; NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, + extra_headers, browser_context_); LoadEntry(entry); diff --git a/content/browser/tab_contents/navigation_controller.h b/content/browser/tab_contents/navigation_controller.h index c7d9d03..a410c4d 100644 --- a/content/browser/tab_contents/navigation_controller.h +++ b/content/browser/tab_contents/navigation_controller.h @@ -176,6 +176,13 @@ class NavigationController { void LoadURL(const GURL& url, const GURL& referrer, PageTransition::Type type); + // Loads the specified URL, specifying extra http headers to add to the + // request. Extra headers are separated by \n. + void LoadURLWithHeaders(const GURL& url, + const GURL& referrer, + PageTransition::Type type, + const std::string& extra_headers); + // Loads the current page if this NavigationController was restored from // history and the current page has not loaded yet. void LoadIfNecessary(); @@ -327,11 +334,13 @@ class NavigationController { bool IsInitialNavigation(); // Creates navigation entry and translates the virtual url to a real one. - // Used when navigating to a new URL using LoadURL. + // Used when navigating to a new URL using LoadURL. Extra headers are + // separated by \n. static NavigationEntry* CreateNavigationEntry( const GURL& url, const GURL& referrer, PageTransition::Type transition, + const std::string& extra_headers, content::BrowserContext* browser_context); private: diff --git a/content/browser/tab_contents/navigation_controller_unittest.cc b/content/browser/tab_contents/navigation_controller_unittest.cc index 0830650..fbb9b01 100644 --- a/content/browser/tab_contents/navigation_controller_unittest.cc +++ b/content/browser/tab_contents/navigation_controller_unittest.cc @@ -1438,7 +1438,7 @@ TEST_F(NavigationControllerTest, RestoreNavigate) { GURL url("http://foo"); std::vector<NavigationEntry*> entries; NavigationEntry* entry = NavigationController::CreateNavigationEntry( - url, GURL(), PageTransition::RELOAD, profile()); + url, GURL(), PageTransition::RELOAD, std::string(), profile()); entry->set_page_id(0); entry->set_title(ASCIIToUTF16("Title")); entry->set_content_state("state"); @@ -1496,7 +1496,7 @@ TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { GURL url("http://foo"); std::vector<NavigationEntry*> entries; NavigationEntry* entry = NavigationController::CreateNavigationEntry( - url, GURL(), PageTransition::RELOAD, profile()); + url, GURL(), PageTransition::RELOAD, std::string(), profile()); entry->set_page_id(0); entry->set_title(ASCIIToUTF16("Title")); entry->set_content_state("state"); diff --git a/content/browser/tab_contents/navigation_entry.h b/content/browser/tab_contents/navigation_entry.h index a43eba9..c86e75d 100644 --- a/content/browser/tab_contents/navigation_entry.h +++ b/content/browser/tab_contents/navigation_entry.h @@ -318,6 +318,14 @@ class NavigationEntry { return ssl_; } + // Extra headers (separated by \n) to send during the request. + void set_extra_headers(const std::string& extra_headers) { + extra_headers_ = extra_headers; + } + const std::string& extra_headers() const { + return extra_headers_; + } + // Page-related helpers ------------------------------------------------------ // Returns the title to be displayed on the tab. This could be the title of @@ -417,8 +425,11 @@ class NavigationEntry { bool has_post_data_; RestoreType restore_type_; + // This member is not persisted with sesssion restore. + std::string extra_headers_; + // This is a cached version of the result of GetTitleForDisplay. It prevents - // us from having to do URL formatting on the URL evey time the title is + // us from having to do URL formatting on the URL every time the title is // displayed. When the URL, virtual URL, or title is set, this should be // cleared to force a refresh. mutable string16 cached_display_title_; diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 9271d1b..f87c69e 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -140,6 +140,7 @@ ViewMsg_Navigate_Type::Value GetNavigationType( void MakeNavigateParams(const NavigationEntry& entry, const NavigationController& controller, + TabContentsDelegate* delegate, NavigationController::ReloadType reload_type, ViewMsg_Navigate_Params* params) { params->page_id = entry.page_id(); @@ -153,6 +154,10 @@ void MakeNavigateParams(const NavigationEntry& entry, params->navigation_type = GetNavigationType(controller.browser_context(), entry, reload_type); params->request_time = base::Time::Now(); + params->extra_headers = entry.extra_headers(); + + if (delegate) + delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); } } // namespace @@ -587,11 +592,8 @@ bool TabContents::NavigateToEntry( // Navigate in the desired RenderViewHost. ViewMsg_Navigate_Params navigate_params; - MakeNavigateParams(entry, controller_, reload_type, &navigate_params); - if (delegate_) { - navigate_params.extra_headers = - delegate_->GetNavigationHeaders(navigate_params.url); - } + MakeNavigateParams(entry, controller_, delegate_, reload_type, + &navigate_params); dest_render_view_host->Navigate(navigate_params); if (entry.page_id() == -1) { diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index a6bdb98..7247a7a 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -34,8 +34,8 @@ void TabContentsDelegate::NavigationStateChanged(const TabContents* source, unsigned changed_flags) { } -std::string TabContentsDelegate::GetNavigationHeaders(const GURL& url) { - return std::string(); +void TabContentsDelegate::AddNavigationHeaders(const GURL& url, + std::string* headers) { } void TabContentsDelegate::AddNewContents(TabContents* source, diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index 9638775..b1f0d52 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -75,9 +75,9 @@ class TabContentsDelegate { virtual void NavigationStateChanged(const TabContents* source, unsigned changed_flags); - // Returns the set of headers to add to the navigation request. Use + // Adds the navigation request headers to |headers|. Use // net::HttpUtil::AppendHeaderIfMissing to build the set of headers. - virtual std::string GetNavigationHeaders(const GURL& url); + virtual void AddNavigationHeaders(const GURL& url, std::string* headers); // Creates a new tab with the already-created TabContents 'new_contents'. // The window for the added contents should be reparented correctly when this diff --git a/content/browser/tab_contents/tab_contents_delegate_unittest.cc b/content/browser/tab_contents/tab_contents_delegate_unittest.cc index 55a25b8..fab9edb 100644 --- a/content/browser/tab_contents/tab_contents_delegate_unittest.cc +++ b/content/browser/tab_contents/tab_contents_delegate_unittest.cc @@ -33,31 +33,33 @@ class MockTabContentsDelegate : public TabContentsDelegate { } virtual void NavigationStateChanged(const TabContents* source, - unsigned changed_flags) {} + unsigned changed_flags) OVERRIDE {} - virtual std::string GetNavigationHeaders(const GURL& url) { - return ""; + virtual void AddNavigationHeaders( + const GURL& url, std::string* headers) OVERRIDE { } virtual void AddNewContents(TabContents* source, TabContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, - bool user_gesture) {} + bool user_gesture) OVERRIDE {} - virtual void ActivateContents(TabContents* contents) {} + virtual void ActivateContents(TabContents* contents) OVERRIDE {} - virtual void DeactivateContents(TabContents* contents) {} + virtual void DeactivateContents(TabContents* contents) OVERRIDE {} - virtual void LoadingStateChanged(TabContents* source) {} + virtual void LoadingStateChanged(TabContents* source) OVERRIDE {} - virtual void LoadProgressChanged(double progress) {} + virtual void LoadProgressChanged(double progress) OVERRIDE {} - virtual void CloseContents(TabContents* source) {} + virtual void CloseContents(TabContents* source) OVERRIDE {} - virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} + virtual void MoveContents(TabContents* source, + const gfx::Rect& pos) OVERRIDE { + } - virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} + virtual void UpdateTargetURL(TabContents* source, const GURL& url) OVERRIDE {} }; TEST(TabContentsDelegateTest, UnregisterInDestructor) { diff --git a/content/common/content_notification_types.h b/content/common/content_notification_types.h index 14e72f7..144ebb7 100644 --- a/content/common/content_notification_types.h +++ b/content/common/content_notification_types.h @@ -43,8 +43,8 @@ enum NotificationType { // // This notification is called after the pending entry is created, but // before we actually try to navigate. The source will be the - // NavigationController that owns the pending entry, and there are no - // details. + // NavigationController that owns the pending entry, and the details + // will be a NavigationEntry. NOTIFICATION_NAV_ENTRY_PENDING, // A new non-pending navigation entry has been created. This will diff --git a/content/common/page_transition_types.h b/content/common/page_transition_types.h index 357b433..1bd6ec9 100644 --- a/content/common/page_transition_types.h +++ b/content/common/page_transition_types.h @@ -108,6 +108,9 @@ class PageTransition { // User used the address bar to trigger this navigation. FROM_ADDRESS_BAR = 0x02000000, + // User is navigating to the home page. + HOME_PAGE = 0x04000000, + // The beginning of a navigation chain. CHAIN_START = 0x10000000, |