diff options
author | bcwhite@chromium.org <bcwhite@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 03:18:21 +0000 |
---|---|---|
committer | bcwhite@chromium.org <bcwhite@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 03:18:21 +0000 |
commit | 845c845346d94adbc76473a8daf8367d416d48dd (patch) | |
tree | 67004cea5eeec96937572c8bdd892cb3401510d3 /chrome/browser/ui/sync | |
parent | 9fccd8ed1148092154d8a5d60b3a567b8ecca658 (diff) | |
download | chromium_src-845c845346d94adbc76473a8daf8367d416d48dd.zip chromium_src-845c845346d94adbc76473a8daf8367d416d48dd.tar.gz chromium_src-845c845346d94adbc76473a8daf8367d416d48dd.tar.bz2 |
Remove landing page from history when redirecting to NTP so that the back-button will work as expected.
BUG=180145
Review URL: https://chromiumcodereview.appspot.com/13896009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195061 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/sync')
-rw-r--r-- | chrome/browser/ui/sync/one_click_signin_helper.cc | 51 | ||||
-rw-r--r-- | chrome/browser/ui/sync/one_click_signin_helper.h | 5 |
2 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/ui/sync/one_click_signin_helper.cc b/chrome/browser/ui/sync/one_click_signin_helper.cc index 1b08df9..678a1c2 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper.cc +++ b/chrome/browser/ui/sync/one_click_signin_helper.cc @@ -398,6 +398,50 @@ bool AreWeShowingSignin(GURL url, SyncPromoUI::Source source, !email.empty()); } + +// Watch a webcontents and remove URL from the history once loading is complete. +// We have to delay the cleaning until the new URL has finished loading because +// we're not allowed to remove the last-loaded URL from the history. Objects +// of this type automatically self-destruct once they're finished their work. +class CurrentHistoryCleaner : public content::WebContentsObserver { + public: + explicit CurrentHistoryCleaner(content::WebContents* contents); + + virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE; + virtual void DidStopLoading(content::RenderViewHost* render_view_host) + OVERRIDE; + + private: + scoped_ptr<content::WebContents> contents_; + int history_index_to_remove_; + + DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); +}; + + +CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) + : WebContentsObserver(contents) { + content::NavigationController& nc = web_contents()->GetController(); + history_index_to_remove_ = nc.GetLastCommittedEntryIndex(); +} + +void CurrentHistoryCleaner::DidStopLoading( + content::RenderViewHost* render_view_host) { + content::NavigationController& nc = web_contents()->GetController(); + // Have to wait until something else gets added to history before removal. + if (history_index_to_remove_ != nc.GetLastCommittedEntryIndex()) { + nc.RemoveEntryAtIndex(history_index_to_remove_); + Observe(NULL); + delete this; /* success */ + } +} + +void CurrentHistoryCleaner::WebContentsDestroyed( + content::WebContents* contents) { + Observe(NULL); + delete this; /* failure */ +} + } // namespace // The infobar asking the user if they want to use one-click sign in. @@ -972,6 +1016,12 @@ void OneClickSigninHelper::ShowInfoBarUIThread( helper->continue_url_ = continue_url; } +// static +void OneClickSigninHelper::RemoveCurrentHistoryItem( + content::WebContents* web_contents) { + new CurrentHistoryCleaner(web_contents); // will self-destruct when finished +} + void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; @@ -992,6 +1042,7 @@ void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { CURRENT_TAB, content::PAGE_TRANSITION_AUTO_TOPLEVEL, false); + RemoveCurrentHistoryItem(contents); contents->OpenURL(params); error_message_.clear(); diff --git a/chrome/browser/ui/sync/one_click_signin_helper.h b/chrome/browser/ui/sync/one_click_signin_helper.h index e4da000..33507c9 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper.h +++ b/chrome/browser/ui/sync/one_click_signin_helper.h @@ -113,6 +113,11 @@ class OneClickSigninHelper int child_id, int route_id); + // Remove the item currently at the top of the history list. Due to + // limitations of the NavigationController, this cannot be done until + // a new page becomes "current". + static void RemoveCurrentHistoryItem(content::WebContents* web_contents); + private: explicit OneClickSigninHelper(content::WebContents* web_contents); friend class content::WebContentsUserData<OneClickSigninHelper>; |