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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sync/one_click_signin_helper.h" 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 GURL clean_one_click_url = 391 GURL clean_one_click_url =
392 GURL(GaiaUrls::GetInstance()->gaia_login_form_realm() + 392 GURL(GaiaUrls::GetInstance()->gaia_login_form_realm() +
393 "ChromeLoginPrompt").ReplaceComponents(replacements); 393 "ChromeLoginPrompt").ReplaceComponents(replacements);
394 394
395 return (url.ReplaceComponents(replacements) == clean_login_url && 395 return (url.ReplaceComponents(replacements) == clean_login_url &&
396 source != SyncPromoUI::SOURCE_UNKNOWN) || 396 source != SyncPromoUI::SOURCE_UNKNOWN) ||
397 (url.ReplaceComponents(replacements) == clean_one_click_url && 397 (url.ReplaceComponents(replacements) == clean_one_click_url &&
398 !email.empty()); 398 !email.empty());
399 } 399 }
400 400
401
402 // Watch a webcontents and remove URL from the history once loading is complete.
403 // We have to delay the cleaning until the new URL has finished loading because
404 // we're not allowed to remove the last-loaded URL from the history. Objects
405 // of this type automatically self-destruct once they're finished their work.
406 class CurrentHistoryCleaner : public content::WebContentsObserver {
407 public:
408 explicit CurrentHistoryCleaner(content::WebContents* contents);
409
410 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE;
411 virtual void DidStopLoading(content::RenderViewHost* render_view_host)
412 OVERRIDE;
413
414 private:
415 scoped_ptr<content::WebContents> contents_;
416 int history_index_to_remove_;
417
418 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner);
419 };
420
421
422 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents)
423 : WebContentsObserver(contents) {
424 content::NavigationController& nc = web_contents()->GetController();
425 history_index_to_remove_ = nc.GetLastCommittedEntryIndex();
426 }
427
428 void CurrentHistoryCleaner::DidStopLoading(
429 content::RenderViewHost* render_view_host) {
430 content::NavigationController& nc = web_contents()->GetController();
431 // Have to wait until something else gets added to history before removal.
432 if (history_index_to_remove_ != nc.GetLastCommittedEntryIndex()) {
433 nc.RemoveEntryAtIndex(history_index_to_remove_);
434 Observe(NULL);
435 delete this; /* success */
436 }
437 }
438
439 void CurrentHistoryCleaner::WebContentsDestroyed(
440 content::WebContents* contents) {
441 Observe(NULL);
442 delete this; /* failure */
443 }
444
401 } // namespace 445 } // namespace
402 446
403 // The infobar asking the user if they want to use one-click sign in. 447 // The infobar asking the user if they want to use one-click sign in.
404 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid 448 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid
405 // of this infobar. 449 // of this infobar.
406 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { 450 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate {
407 public: 451 public:
408 // Creates a one click signin delegate and adds it to |infobar_service|. 452 // Creates a one click signin delegate and adds it to |infobar_service|.
409 static void Create(InfoBarService* infobar_service, 453 static void Create(InfoBarService* infobar_service,
410 const std::string& session_index, 454 const std::string& session_index,
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 if (!session_index.empty()) 1008 if (!session_index.empty())
965 helper->session_index_ = session_index; 1009 helper->session_index_ = session_index;
966 1010
967 if (!email.empty()) 1011 if (!email.empty())
968 helper->email_ = email; 1012 helper->email_ = email;
969 1013
970 if (continue_url.is_valid()) 1014 if (continue_url.is_valid())
971 helper->continue_url_ = continue_url; 1015 helper->continue_url_ = continue_url;
972 } 1016 }
973 1017
1018 // static
1019 void OneClickSigninHelper::RemoveCurrentHistoryItem(
1020 content::WebContents* web_contents) {
1021 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished
1022 }
1023
974 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { 1024 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) {
975 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; 1025 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage";
976 1026
977 // Redirect to NTP/Apps page with sign in bubble visible. 1027 // Redirect to NTP/Apps page with sign in bubble visible.
978 content::WebContents* contents = web_contents(); 1028 content::WebContents* contents = web_contents();
979 Profile* profile = 1029 Profile* profile =
980 Profile::FromBrowserContext(contents->GetBrowserContext()); 1030 Profile::FromBrowserContext(contents->GetBrowserContext());
981 PrefService* pref_service = profile->GetPrefs(); 1031 PrefService* pref_service = profile->GetPrefs();
982 if (show_bubble) { 1032 if (show_bubble) {
983 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); 1033 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true);
984 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_); 1034 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_);
985 } 1035 }
986 1036
987 GURL url(chrome::IsInstantExtendedAPIEnabled() ? 1037 GURL url(chrome::IsInstantExtendedAPIEnabled() ?
988 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); 1038 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
989 content::OpenURLParams params(url, 1039 content::OpenURLParams params(url,
990 content::Referrer(), 1040 content::Referrer(),
991 CURRENT_TAB, 1041 CURRENT_TAB,
992 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1042 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
993 false); 1043 false);
1044 RemoveCurrentHistoryItem(contents);
994 contents->OpenURL(params); 1045 contents->OpenURL(params);
995 1046
996 error_message_.clear(); 1047 error_message_.clear();
997 } 1048 }
998 1049
999 void OneClickSigninHelper::RedirectToSignin() { 1050 void OneClickSigninHelper::RedirectToSignin() {
1000 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; 1051 VLOG(1) << "OneClickSigninHelper::RedirectToSignin";
1001 1052
1002 // Extract the existing sounce=X value. Default to "2" if missing. 1053 // Extract the existing sounce=X value. Default to "2" if missing.
1003 SyncPromoUI::Source source = 1054 SyncPromoUI::Source source =
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 1439
1389 void OneClickSigninHelper::SigninSuccess() { 1440 void OneClickSigninHelper::SigninSuccess() {
1390 RedirectOnSigninComplete(true); 1441 RedirectOnSigninComplete(true);
1391 } 1442 }
1392 1443
1393 void OneClickSigninHelper::RedirectOnSigninComplete(bool show_bubble) { 1444 void OneClickSigninHelper::RedirectOnSigninComplete(bool show_bubble) {
1394 // Show the result in the sign-in bubble if desired. 1445 // Show the result in the sign-in bubble if desired.
1395 RedirectToNtpOrAppsPage(show_bubble); 1446 RedirectToNtpOrAppsPage(show_bubble);
1396 signin_tracker_.reset(); 1447 signin_tracker_.reset();
1397 } 1448 }
OLDNEW
« 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