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

Unified Diff: chrome/browser/ui/sync/one_click_signin_helper.cc

Issue 13896009: Remove landing page from history when redirecting to NTP so that the back-button will work as expec… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed test since required modules aren't available on all builds Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/sync/one_click_signin_helper.cc
diff --git a/chrome/browser/ui/sync/one_click_signin_helper.cc b/chrome/browser/ui/sync/one_click_signin_helper.cc
index d215d824594d2622d005cd5ef6d344eeda8efca8..f5b65c0fe218b87c5bb563ad23e91feb557b08c0 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.
@@ -971,6 +1015,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";
@@ -991,6 +1041,7 @@ void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) {
CURRENT_TAB,
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
false);
+ RemoveCurrentHistoryItem(contents);
contents->OpenURL(params);
error_message_.clear();
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698