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