| OLD | NEW |
| 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 virtual void DidStopLoading(content::RenderViewHost* render_view_host) | 406 virtual void DidStopLoading(content::RenderViewHost* render_view_host) |
| 407 OVERRIDE; | 407 OVERRIDE; |
| 408 | 408 |
| 409 private: | 409 private: |
| 410 scoped_ptr<content::WebContents> contents_; | 410 scoped_ptr<content::WebContents> contents_; |
| 411 int history_index_to_remove_; | 411 int history_index_to_remove_; |
| 412 | 412 |
| 413 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); | 413 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); |
| 414 }; | 414 }; |
| 415 | 415 |
| 416 | |
| 417 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) | 416 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) |
| 418 : WebContentsObserver(contents) { | 417 : WebContentsObserver(contents) { |
| 419 content::NavigationController& nc = web_contents()->GetController(); | 418 content::NavigationController& nc = web_contents()->GetController(); |
| 420 history_index_to_remove_ = nc.GetLastCommittedEntryIndex(); | 419 history_index_to_remove_ = nc.GetLastCommittedEntryIndex(); |
| 421 } | 420 } |
| 422 | 421 |
| 423 void CurrentHistoryCleaner::DidStopLoading( | 422 void CurrentHistoryCleaner::DidStopLoading( |
| 424 content::RenderViewHost* render_view_host) { | 423 content::RenderViewHost* render_view_host) { |
| 425 content::NavigationController& nc = web_contents()->GetController(); | 424 content::NavigationController& nc = web_contents()->GetController(); |
| 426 // Have to wait until something else gets added to history before removal. | 425 // Have to wait until something else gets added to history before removal. |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 784 |
| 786 if (source != SyncPromoUI::SOURCE_UNKNOWN && | 785 if (source != SyncPromoUI::SOURCE_UNKNOWN && |
| 787 helper->source_ == SyncPromoUI::SOURCE_UNKNOWN) { | 786 helper->source_ == SyncPromoUI::SOURCE_UNKNOWN) { |
| 788 helper->source_ = source; | 787 helper->source_ = source; |
| 789 } | 788 } |
| 790 | 789 |
| 791 CanOfferFor can_offer_for = | 790 CanOfferFor can_offer_for = |
| 792 (auto_accept != AUTO_ACCEPT_EXPLICIT && | 791 (auto_accept != AUTO_ACCEPT_EXPLICIT && |
| 793 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? | 792 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? |
| 794 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; | 793 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; |
| 794 |
| 795 std::string error_message; | 795 std::string error_message; |
| 796 | 796 |
| 797 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, | 797 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, |
| 798 &error_message)) { | 798 &error_message)) { |
| 799 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; | 799 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; |
| 800 if (helper && helper->error_message_.empty() && !error_message.empty()) | 800 if (helper && helper->error_message_.empty() && !error_message.empty()) |
| 801 helper->error_message_ = error_message; | 801 helper->error_message_ = error_message; |
| 802 | 802 |
| 803 return; | 803 return; |
| 804 } | 804 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 825 if (continue_url.is_valid()) | 825 if (continue_url.is_valid()) |
| 826 helper->continue_url_ = continue_url; | 826 helper->continue_url_ = continue_url; |
| 827 } | 827 } |
| 828 | 828 |
| 829 // static | 829 // static |
| 830 void OneClickSigninHelper::RemoveCurrentHistoryItem( | 830 void OneClickSigninHelper::RemoveCurrentHistoryItem( |
| 831 content::WebContents* web_contents) { | 831 content::WebContents* web_contents) { |
| 832 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished | 832 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished |
| 833 } | 833 } |
| 834 | 834 |
| 835 void OneClickSigninHelper::ShowSyncConfirmationBubble(bool show_bubble) { |
| 836 if (show_bubble) { |
| 837 content::WebContents* contents = web_contents(); |
| 838 Profile* profile = |
| 839 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 840 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 841 |
| 842 browser->window()->ShowOneClickSigninBubble( |
| 843 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
| 844 string16(), /* no SAML email */ |
| 845 UTF8ToUTF16(error_message_), |
| 846 base::Bind(&StartSync, |
| 847 StartSyncArgs(profile, browser, AUTO_ACCEPT_ACCEPTED, |
| 848 session_index_, email_, password_, |
| 849 false))); |
| 850 } |
| 851 error_message_.clear(); |
| 852 } |
| 853 |
| 835 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { | 854 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { |
| 836 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; | 855 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; |
| 837 | 856 |
| 838 // Redirect to NTP/Apps page with sign in bubble visible. | 857 // Redirect to NTP/Apps page and display a confirmation bubble |
| 839 content::WebContents* contents = web_contents(); | 858 content::WebContents* contents = web_contents(); |
| 840 Profile* profile = | |
| 841 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
| 842 PrefService* pref_service = profile->GetPrefs(); | |
| 843 if (show_bubble) { | |
| 844 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); | |
| 845 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_); | |
| 846 } | |
| 847 | |
| 848 GURL url(chrome::IsInstantExtendedAPIEnabled() ? | 859 GURL url(chrome::IsInstantExtendedAPIEnabled() ? |
| 849 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | 860 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); |
| 850 content::OpenURLParams params(url, | 861 content::OpenURLParams params(url, |
| 851 content::Referrer(), | 862 content::Referrer(), |
| 852 CURRENT_TAB, | 863 CURRENT_TAB, |
| 853 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 864 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 854 false); | 865 false); |
| 855 contents->OpenURL(params); | 866 contents->OpenURL(params); |
| 856 | 867 |
| 857 error_message_.clear(); | 868 ShowSyncConfirmationBubble(show_bubble); |
| 858 } | 869 } |
| 859 | 870 |
| 860 void OneClickSigninHelper::RedirectToSignin() { | 871 void OneClickSigninHelper::RedirectToSignin() { |
| 861 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; | 872 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; |
| 862 | 873 |
| 863 // Extract the existing sounce=X value. Default to "2" if missing. | 874 // Extract the existing sounce=X value. Default to "2" if missing. |
| 864 SyncPromoUI::Source source = | 875 SyncPromoUI::Source source = |
| 865 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); | 876 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); |
| 866 if (source == SyncPromoUI::SOURCE_UNKNOWN) | 877 if (source == SyncPromoUI::SOURCE_UNKNOWN) |
| 867 source = SyncPromoUI::SOURCE_MENU; | 878 source = SyncPromoUI::SOURCE_MENU; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 if (SyncPromoUI::UseWebBasedSigninFlow() && showing_signin_) | 1091 if (SyncPromoUI::UseWebBasedSigninFlow() && showing_signin_) |
| 1081 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); | 1092 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); |
| 1082 break; | 1093 break; |
| 1083 case AUTO_ACCEPT_ACCEPTED: | 1094 case AUTO_ACCEPT_ACCEPTED: |
| 1084 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1095 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
| 1085 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1096 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
| 1086 SigninManager::DisableOneClickSignIn(profile); | 1097 SigninManager::DisableOneClickSignIn(profile); |
| 1087 browser->window()->ShowOneClickSigninBubble( | 1098 browser->window()->ShowOneClickSigninBubble( |
| 1088 bubble_type, | 1099 bubble_type, |
| 1089 UTF8ToUTF16(email_), | 1100 UTF8ToUTF16(email_), |
| 1101 string16(), /* no error message to display */ |
| 1090 base::Bind(&StartSync, | 1102 base::Bind(&StartSync, |
| 1091 StartSyncArgs(profile, browser, auto_accept_, | 1103 StartSyncArgs(profile, browser, auto_accept_, |
| 1092 session_index_, email_, password_, | 1104 session_index_, email_, password_, |
| 1093 false /* force_same_tab_navigation */))); | 1105 false /* force_same_tab_navigation */))); |
| 1094 break; | 1106 break; |
| 1095 case AUTO_ACCEPT_CONFIGURE: | 1107 case AUTO_ACCEPT_CONFIGURE: |
| 1096 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1108 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
| 1097 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1109 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); |
| 1098 SigninManager::DisableOneClickSignIn(profile); | 1110 SigninManager::DisableOneClickSignIn(profile); |
| 1099 StartSync( | 1111 StartSync( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1118 | 1130 |
| 1119 std::string last_email = | 1131 std::string last_email = |
| 1120 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1132 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 1121 | 1133 |
| 1122 if (!is_trusted_) { | 1134 if (!is_trusted_) { |
| 1123 // The user has navigated away from valid Gaia URLs during sign in, | 1135 // The user has navigated away from valid Gaia URLs during sign in, |
| 1124 // verify this sign in is desired. | 1136 // verify this sign in is desired. |
| 1125 browser->window()->ShowOneClickSigninBubble( | 1137 browser->window()->ShowOneClickSigninBubble( |
| 1126 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, | 1138 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, |
| 1127 UTF8ToUTF16(email_), | 1139 UTF8ToUTF16(email_), |
| 1140 string16(), /* no error message to display */ |
| 1128 base::Bind(&StartSync, | 1141 base::Bind(&StartSync, |
| 1129 StartSyncArgs(profile, browser, auto_accept_, | 1142 StartSyncArgs(profile, browser, auto_accept_, |
| 1130 session_index_, email_, password_, | 1143 session_index_, email_, password_, |
| 1131 force_same_tab_navigation))); | 1144 force_same_tab_navigation))); |
| 1132 } else if (!last_email.empty() && last_email != email_) { | 1145 } else if (!last_email.empty() && last_email != email_) { |
| 1133 // If the new email address is different from the email address that | 1146 // If the new email address is different from the email address that |
| 1134 // just signed in, show a confirmation dialog. | 1147 // just signed in, show a confirmation dialog. |
| 1135 ConfirmEmailDialogDelegate::AskForConfirmation( | 1148 ConfirmEmailDialogDelegate::AskForConfirmation( |
| 1136 contents, | 1149 contents, |
| 1137 last_email, | 1150 last_email, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 // If the user cancelled signin, then no need to display any error | 1247 // If the user cancelled signin, then no need to display any error |
| 1235 // messages or anything - just go back to the NTP. | 1248 // messages or anything - just go back to the NTP. |
| 1236 error_message_.clear(); | 1249 error_message_.clear(); |
| 1237 display_bubble = false; | 1250 display_bubble = false; |
| 1238 break; | 1251 break; |
| 1239 default: | 1252 default: |
| 1240 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_ERROR_SIGNING_IN); | 1253 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_ERROR_SIGNING_IN); |
| 1241 break; | 1254 break; |
| 1242 } | 1255 } |
| 1243 } | 1256 } |
| 1244 RedirectOnSigninComplete(display_bubble); | 1257 ShowSyncConfirmationBubble(display_bubble); |
| 1258 signin_tracker_.reset(); |
| 1245 } | 1259 } |
| 1246 | 1260 |
| 1247 void OneClickSigninHelper::SigninSuccess() { | 1261 void OneClickSigninHelper::SigninSuccess() { |
| 1248 RedirectOnSigninComplete(true); | 1262 ShowSyncConfirmationBubble(true); |
| 1249 } | |
| 1250 | |
| 1251 void OneClickSigninHelper::RedirectOnSigninComplete(bool show_bubble) { | |
| 1252 // Show the result in the sign-in bubble if desired. | |
| 1253 RedirectToNtpOrAppsPage(show_bubble); | |
| 1254 signin_tracker_.reset(); | 1263 signin_tracker_.reset(); |
| 1255 } | 1264 } |
| OLD | NEW |