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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 SyncPromoUI::Source source); | 96 SyncPromoUI::Source source); |
97 | 97 |
98 Profile* profile; | 98 Profile* profile; |
99 Browser* browser; | 99 Browser* browser; |
100 OneClickSigninHelper::AutoAccept auto_accept; | 100 OneClickSigninHelper::AutoAccept auto_accept; |
101 std::string session_index; | 101 std::string session_index; |
102 std::string email; | 102 std::string email; |
103 std::string password; | 103 std::string password; |
104 bool force_same_tab_navigation; | 104 bool force_same_tab_navigation; |
105 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required; | 105 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required; |
106 SyncPromoUI::Source source; | |
106 }; | 107 }; |
107 | 108 |
108 StartSyncArgs::StartSyncArgs( | 109 StartSyncArgs::StartSyncArgs( |
109 Profile* profile, | 110 Profile* profile, |
110 Browser* browser, | 111 Browser* browser, |
111 OneClickSigninHelper::AutoAccept auto_accept, | 112 OneClickSigninHelper::AutoAccept auto_accept, |
112 const std::string& session_index, | 113 const std::string& session_index, |
113 const std::string& email, | 114 const std::string& email, |
114 const std::string& password, | 115 const std::string& password, |
115 bool force_same_tab_navigation, | 116 bool force_same_tab_navigation, |
116 bool untrusted_confirmation_required, | 117 bool untrusted_confirmation_required, |
117 SyncPromoUI::Source source) | 118 SyncPromoUI::Source source) |
118 : profile(profile), | 119 : profile(profile), |
119 browser(browser), | 120 browser(browser), |
120 auto_accept(auto_accept), | 121 auto_accept(auto_accept), |
121 session_index(session_index), | 122 session_index(session_index), |
122 email(email), | 123 email(email), |
123 password(password), | 124 password(password), |
124 force_same_tab_navigation(force_same_tab_navigation) { | 125 force_same_tab_navigation(force_same_tab_navigation), |
126 source(source) { | |
125 if (untrusted_confirmation_required) { | 127 if (untrusted_confirmation_required) { |
126 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; | 128 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; |
127 } else if (source == SyncPromoUI::SOURCE_SETTINGS || | 129 } else if (source == SyncPromoUI::SOURCE_SETTINGS || |
128 source == SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 130 source == SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
129 // Do not display a status confirmation for webstore installs or re-auth. | 131 // Do not display a status confirmation for webstore installs or re-auth. |
130 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; | 132 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; |
131 } else { | 133 } else { |
132 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 134 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
133 } | 135 } |
134 } | 136 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 one_click_signin::HISTOGRAM_MAX); | 190 one_click_signin::HISTOGRAM_MAX); |
189 } | 191 } |
190 | 192 |
191 void LogOneClickHistogramValue(int action) { | 193 void LogOneClickHistogramValue(int action) { |
192 UMA_HISTOGRAM_ENUMERATION("Signin.OneClickActions", action, | 194 UMA_HISTOGRAM_ENUMERATION("Signin.OneClickActions", action, |
193 one_click_signin::HISTOGRAM_MAX); | 195 one_click_signin::HISTOGRAM_MAX); |
194 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | 196 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, |
195 one_click_signin::HISTOGRAM_MAX); | 197 one_click_signin::HISTOGRAM_MAX); |
196 } | 198 } |
197 | 199 |
200 void RedirectToNtpOrAppsPage(content::WebContents* contents, | |
201 SyncPromoUI::Source source) { | |
202 VLOG(1) << "RedirectToNtpOrAppsPage"; | |
203 // Redirect to NTP/Apps page and display a confirmation bubble | |
204 GURL url(source == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? | |
205 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | |
206 content::OpenURLParams params(url, | |
207 content::Referrer(), | |
208 CURRENT_TAB, | |
209 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
210 false); | |
211 contents->OpenURL(params); | |
212 } | |
213 | |
214 // If the |source| is not settings page/webstore, redirects to | |
215 // the NTP/Apps page. | |
216 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents, | |
217 SyncPromoUI::Source source) { | |
218 if (source != SyncPromoUI::SOURCE_SETTINGS && | |
219 source != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | |
220 RedirectToNtpOrAppsPage(contents, source); | |
221 } | |
222 } | |
223 | |
198 // Start syncing with the given user information. | 224 // Start syncing with the given user information. |
199 void StartSync(const StartSyncArgs& args, | 225 void StartSync(const StartSyncArgs& args, |
200 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 226 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
201 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { | 227 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { |
202 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); | 228 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); |
203 return; | 229 return; |
204 } | 230 } |
205 | 231 |
206 // If we are giving the user the option to configure sync, then that will | 232 // If we are giving the user the option to configure sync, then that will |
207 // suffice as a confirmation. | 233 // suffice as a confirmation. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 OneClickSigninSyncStarter::StartSyncMode start_mode, | 273 OneClickSigninSyncStarter::StartSyncMode start_mode, |
248 int button) { | 274 int button) { |
249 if (button == IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON) { | 275 if (button == IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON) { |
250 contents->GetController().LoadURL( | 276 contents->GetController().LoadURL( |
251 GURL(chrome::kChromeUINewTabURL), content::Referrer(), | 277 GURL(chrome::kChromeUINewTabURL), content::Referrer(), |
252 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 278 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
253 chrome::ShowSettingsSubPage(args.browser, | 279 chrome::ShowSettingsSubPage(args.browser, |
254 std::string(chrome::kSearchUsersSubPage)); | 280 std::string(chrome::kSearchUsersSubPage)); |
255 } else { | 281 } else { |
256 StartSync(args, start_mode); | 282 StartSync(args, start_mode); |
283 RedirectToNtpOrAppsPageIfNecessary(contents, args.source); | |
257 } | 284 } |
258 } | 285 } |
259 | 286 |
260 void ClearPendingEmailOnIOThread(content::ResourceContext* context) { | 287 void ClearPendingEmailOnIOThread(content::ResourceContext* context) { |
261 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 288 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
262 DCHECK(io_data); | 289 DCHECK(io_data); |
263 io_data->set_reverse_autologin_pending_email(std::string()); | 290 io_data->set_reverse_autologin_pending_email(std::string()); |
264 } | 291 } |
265 | 292 |
266 // Determines the source of the sign in and the continue URL. Its either one | 293 // Determines the source of the sign in and the continue URL. Its either one |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 browser->window()->ShowOneClickSigninBubble( | 896 browser->window()->ShowOneClickSigninBubble( |
870 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 897 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
871 string16(), /* no SAML email */ | 898 string16(), /* no SAML email */ |
872 UTF8ToUTF16(error), | 899 UTF8ToUTF16(error), |
873 // This callback is never invoked. | 900 // This callback is never invoked. |
874 // TODO(rogerta): Separate out the bubble API so we don't have to pass | 901 // TODO(rogerta): Separate out the bubble API so we don't have to pass |
875 // ignored |email| and |callback| params. | 902 // ignored |email| and |callback| params. |
876 BrowserWindow::StartSyncCallback()); | 903 BrowserWindow::StartSyncCallback()); |
877 } | 904 } |
878 | 905 |
879 void OneClickSigninHelper::RedirectToNtpOrAppsPage() { | |
880 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; | |
881 // Redirect to NTP/Apps page and display a confirmation bubble | |
882 content::WebContents* contents = web_contents(); | |
883 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? | |
884 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | |
885 content::OpenURLParams params(url, | |
886 content::Referrer(), | |
887 CURRENT_TAB, | |
888 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
889 false); | |
890 contents->OpenURL(params); | |
891 } | |
892 | |
893 void OneClickSigninHelper::RedirectToSignin() { | 906 void OneClickSigninHelper::RedirectToSignin() { |
894 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; | 907 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; |
895 | 908 |
896 // Extract the existing sounce=X value. Default to "2" if missing. | 909 // Extract the existing sounce=X value. Default to "2" if missing. |
897 SyncPromoUI::Source source = | 910 SyncPromoUI::Source source = |
898 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); | 911 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); |
899 if (source == SyncPromoUI::SOURCE_UNKNOWN) | 912 if (source == SyncPromoUI::SOURCE_UNKNOWN) |
900 source = SyncPromoUI::SOURCE_MENU; | 913 source = SyncPromoUI::SOURCE_MENU; |
901 GURL page = SyncPromoUI::GetSyncPromoURL(source, false); | 914 GURL page = SyncPromoUI::GetSyncPromoURL(source, false); |
902 | 915 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 // TODO(rogerta): Could we move this code back up to ShowInfoBarUIThread()? | 1015 // TODO(rogerta): Could we move this code back up to ShowInfoBarUIThread()? |
1003 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 1016 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
1004 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 1017 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
1005 RemoveCurrentHistoryItem(contents); | 1018 RemoveCurrentHistoryItem(contents); |
1006 // After we redirect to NTP, our browser pointer gets corrupted because the | 1019 // After we redirect to NTP, our browser pointer gets corrupted because the |
1007 // WebContents have changed, so grab the browser pointer | 1020 // WebContents have changed, so grab the browser pointer |
1008 // before the navigation. | 1021 // before the navigation. |
1009 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1022 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
1010 | 1023 |
1011 // Redirect to the landing page and display an error popup. | 1024 // Redirect to the landing page and display an error popup. |
1012 RedirectToNtpOrAppsPage(); | 1025 RedirectToNtpOrAppsPage(web_contents(), source_); |
1013 ShowSigninErrorBubble(browser, error_message_); | 1026 ShowSigninErrorBubble(browser, error_message_); |
1014 CleanTransientState(); | 1027 CleanTransientState(); |
1015 return; | 1028 return; |
1016 } | 1029 } |
1017 | 1030 |
1018 if (AreWeShowingSignin(url, source_, email_)) { | 1031 if (AreWeShowingSignin(url, source_, email_)) { |
1019 if (!showing_signin_) { | 1032 if (!showing_signin_) { |
1020 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) | 1033 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) |
1021 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); | 1034 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); |
1022 else | 1035 else |
(...skipping 18 matching lines...) Expand all Loading... | |
1041 // If there is no valid email yet, there is nothing to do. As of M26, the | 1054 // If there is no valid email yet, there is nothing to do. As of M26, the |
1042 // password is allowed to be empty, since its no longer required to setup | 1055 // password is allowed to be empty, since its no longer required to setup |
1043 // sync. | 1056 // sync. |
1044 if (email_.empty()) { | 1057 if (email_.empty()) { |
1045 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; | 1058 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; |
1046 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) | 1059 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) |
1047 RedirectToSignin(); | 1060 RedirectToSignin(); |
1048 std::string unused_value; | 1061 std::string unused_value; |
1049 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { | 1062 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { |
1050 SyncPromoUI::SetUserSkippedSyncPromo(profile); | 1063 SyncPromoUI::SetUserSkippedSyncPromo(profile); |
1051 RedirectToNtpOrAppsPage(); | 1064 RedirectToNtpOrAppsPage(web_contents(), source_); |
1052 } | 1065 } |
1053 | 1066 |
1054 if (!continue_url_match && !IsValidGaiaSigninRedirectOrResponseURL(url) && | 1067 if (!continue_url_match && !IsValidGaiaSigninRedirectOrResponseURL(url) && |
1055 ++untrusted_navigations_since_signin_visit_ > kMaxNavigationsSince) { | 1068 ++untrusted_navigations_since_signin_visit_ > kMaxNavigationsSince) { |
1056 CleanTransientState(); | 1069 CleanTransientState(); |
1057 } | 1070 } |
1058 | 1071 |
1059 return; | 1072 return; |
1060 } | 1073 } |
1061 | 1074 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1180 force_same_tab_navigation, | 1193 force_same_tab_navigation, |
1181 false /* confirmation_required */, source_), | 1194 false /* confirmation_required */, source_), |
1182 contents, | 1195 contents, |
1183 start_mode)); | 1196 start_mode)); |
1184 } else { | 1197 } else { |
1185 StartSync( | 1198 StartSync( |
1186 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1199 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
1187 email_, password_, force_same_tab_navigation, | 1200 email_, password_, force_same_tab_navigation, |
1188 untrusted_confirmation_required_, source_), | 1201 untrusted_confirmation_required_, source_), |
1189 start_mode); | 1202 start_mode); |
1203 | |
1204 // If this explicit sign in is not from settings page/webstore, show | |
1205 // the NTP/Apps page after sign in completes. In the case of the | |
1206 // settings page, it will get closed by SyncSetupHandler. In the case | |
1207 // of webstore, it will redirect back to webstore. | |
1208 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); | |
bcwhite
2013/06/11 15:57:02
This is now a conditional call whereas before it i
fdoray
2013/06/11 16:03:35
If we go in the first code block, the StartExplici
| |
1190 } | 1209 } |
1191 | 1210 |
1192 if (source_ == SyncPromoUI::SOURCE_SETTINGS && | 1211 if (source_ == SyncPromoUI::SOURCE_SETTINGS && |
1193 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == | 1212 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == |
1194 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1213 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
1195 redirect_url_ = continue_url_; | 1214 redirect_url_ = continue_url_; |
1196 ProfileSyncService* sync_service = | 1215 ProfileSyncService* sync_service = |
1197 ProfileSyncServiceFactory::GetForProfile(profile); | 1216 ProfileSyncServiceFactory::GetForProfile(profile); |
1198 if (sync_service) | 1217 if (sync_service) |
1199 sync_service->AddObserver(this); | 1218 sync_service->AddObserver(this); |
1200 } | 1219 } |
1201 | |
1202 // If this explicit sign in is not from settings page/webstore, show the | |
1203 // NTP/Apps page after sign in completes. In the case of the settings | |
1204 // page, it will get closed by SyncSetupHandler. In the case of webstore, | |
1205 // it will redirect back to webstore. | |
1206 if (source_ != SyncPromoUI::SOURCE_SETTINGS && | |
1207 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | |
1208 RedirectToNtpOrAppsPage(); | |
1209 } | |
1210 break; | 1220 break; |
1211 } | 1221 } |
1212 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1222 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
1213 AddEmailToOneClickRejectedList(profile, email_); | 1223 AddEmailToOneClickRejectedList(profile, email_); |
1214 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); | 1224 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
1215 break; | 1225 break; |
1216 default: | 1226 default: |
1217 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1227 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
1218 break; | 1228 break; |
1219 } | 1229 } |
(...skipping 21 matching lines...) Expand all Loading... | |
1241 contents->GetController().LoadURL(redirect_url_, | 1251 contents->GetController().LoadURL(redirect_url_, |
1242 content::Referrer(), | 1252 content::Referrer(), |
1243 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1253 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1244 std::string()); | 1254 std::string()); |
1245 } | 1255 } |
1246 | 1256 |
1247 // Clear the redirect URL. | 1257 // Clear the redirect URL. |
1248 redirect_url_ = GURL(); | 1258 redirect_url_ = GURL(); |
1249 sync_service->RemoveObserver(this); | 1259 sync_service->RemoveObserver(this); |
1250 } | 1260 } |
OLD | NEW |