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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 86 |
87 // Arguments used with StartSync function. base::Bind() cannot support too | 87 // Arguments used with StartSync function. base::Bind() cannot support too |
88 // many args for performance reasons, so they are packaged up into a struct. | 88 // many args for performance reasons, so they are packaged up into a struct. |
89 struct StartSyncArgs { | 89 struct StartSyncArgs { |
90 StartSyncArgs(Profile* profile, | 90 StartSyncArgs(Profile* profile, |
91 Browser* browser, | 91 Browser* browser, |
92 OneClickSigninHelper::AutoAccept auto_accept, | 92 OneClickSigninHelper::AutoAccept auto_accept, |
93 const std::string& session_index, | 93 const std::string& session_index, |
94 const std::string& email, | 94 const std::string& email, |
95 const std::string& password, | 95 const std::string& password, |
96 bool force_same_tab_navigation, | 96 content::WebContents* web_contents, |
97 bool untrusted_confirmation_required, | 97 bool untrusted_confirmation_required, |
98 signin::Source source, | 98 signin::Source source, |
99 OneClickSigninSyncStarter::Callback callback); | 99 OneClickSigninSyncStarter::Callback callback); |
100 | 100 |
101 Profile* profile; | 101 Profile* profile; |
102 Browser* browser; | 102 Browser* browser; |
103 OneClickSigninHelper::AutoAccept auto_accept; | 103 OneClickSigninHelper::AutoAccept auto_accept; |
104 std::string session_index; | 104 std::string session_index; |
105 std::string email; | 105 std::string email; |
106 std::string password; | 106 std::string password; |
107 bool force_same_tab_navigation; | 107 |
108 // Web contents in which the sync setup page should be displayed, | |
109 // if necessary. Can be NULL. | |
110 content::WebContents* web_contents; | |
111 | |
108 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required; | 112 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required; |
109 signin::Source source; | 113 signin::Source source; |
110 OneClickSigninSyncStarter::Callback callback; | 114 OneClickSigninSyncStarter::Callback callback; |
111 }; | 115 }; |
112 | 116 |
113 StartSyncArgs::StartSyncArgs(Profile* profile, | 117 StartSyncArgs::StartSyncArgs(Profile* profile, |
114 Browser* browser, | 118 Browser* browser, |
115 OneClickSigninHelper::AutoAccept auto_accept, | 119 OneClickSigninHelper::AutoAccept auto_accept, |
116 const std::string& session_index, | 120 const std::string& session_index, |
117 const std::string& email, | 121 const std::string& email, |
118 const std::string& password, | 122 const std::string& password, |
119 bool force_same_tab_navigation, | 123 content::WebContents* web_contents, |
120 bool untrusted_confirmation_required, | 124 bool untrusted_confirmation_required, |
121 signin::Source source, | 125 signin::Source source, |
122 OneClickSigninSyncStarter::Callback callback) | 126 OneClickSigninSyncStarter::Callback callback) |
123 : profile(profile), | 127 : profile(profile), |
124 browser(browser), | 128 browser(browser), |
125 auto_accept(auto_accept), | 129 auto_accept(auto_accept), |
126 session_index(session_index), | 130 session_index(session_index), |
127 email(email), | 131 email(email), |
128 password(password), | 132 password(password), |
129 force_same_tab_navigation(force_same_tab_navigation), | 133 web_contents(web_contents), |
130 source(source), | 134 source(source), |
131 callback(callback) { | 135 callback(callback) { |
132 if (untrusted_confirmation_required) { | 136 if (untrusted_confirmation_required) { |
133 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; | 137 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; |
134 } else if (source == signin::SOURCE_SETTINGS || | 138 } else if (source == signin::SOURCE_SETTINGS || |
135 source == signin::SOURCE_WEBSTORE_INSTALL) { | 139 source == signin::SOURCE_WEBSTORE_INSTALL) { |
136 // Do not display a status confirmation for webstore installs or re-auth. | 140 // Do not display a status confirmation for webstore installs or re-auth. |
137 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; | 141 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; |
138 } else { | 142 } else { |
139 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 143 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 void StartSync(const StartSyncArgs& args, | 240 void StartSync(const StartSyncArgs& args, |
237 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 241 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
238 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { | 242 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { |
239 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); | 243 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); |
240 return; | 244 return; |
241 } | 245 } |
242 | 246 |
243 // The starter deletes itself once its done. | 247 // The starter deletes itself once its done. |
244 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, | 248 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, |
245 args.email, args.password, start_mode, | 249 args.email, args.password, start_mode, |
246 args.force_same_tab_navigation, | 250 args.web_contents, |
247 args.confirmation_required, | 251 args.confirmation_required, |
248 args.source, | 252 args.source, |
249 args.callback); | 253 args.callback); |
250 | 254 |
251 int action = one_click_signin::HISTOGRAM_MAX; | 255 int action = one_click_signin::HISTOGRAM_MAX; |
252 switch (args.auto_accept) { | 256 switch (args.auto_accept) { |
253 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: | 257 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: |
254 break; | 258 break; |
255 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: | 259 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: |
256 action = | 260 action = |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 return; | 1142 return; |
1139 } | 1143 } |
1140 | 1144 |
1141 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have | 1145 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have |
1142 // the option of checking the the box "Let me choose what to sync". When the | 1146 // the option of checking the the box "Let me choose what to sync". When the |
1143 // sign in process started, the source parameter in the continue URL may have | 1147 // sign in process started, the source parameter in the continue URL may have |
1144 // indicated one of the three options above. However, once this box is | 1148 // indicated one of the three options above. However, once this box is |
1145 // checked, the source parameter will indicate settings. This will only be | 1149 // checked, the source parameter will indicate settings. This will only be |
1146 // communicated back to chrome when Gaia redirects to the continue URL, and | 1150 // communicated back to chrome when Gaia redirects to the continue URL, and |
1147 // this is considered here a last minute change to the source. See a little | 1151 // this is considered here a last minute change to the source. See a little |
1148 // further below for when this variable is set to true. | 1152 // further below for when this variable is set to a web contents that must be |
1149 bool force_same_tab_navigation = false; | 1153 // used to show the sync setup page. |
1154 content::WebContents* sync_setup_contents = NULL; | |
1150 | 1155 |
1151 if (!continue_url_match && IsValidGaiaSigninRedirectOrResponseURL(url)) | 1156 if (!continue_url_match && IsValidGaiaSigninRedirectOrResponseURL(url)) |
1152 return; | 1157 return; |
1153 | 1158 |
1154 // During an explicit sign in, if the user has not yet reached the final | 1159 // During an explicit sign in, if the user has not yet reached the final |
1155 // continue URL, wait for it to arrive. Note that Gaia will add some extra | 1160 // continue URL, wait for it to arrive. Note that Gaia will add some extra |
1156 // query parameters to the continue URL. Ignore them when checking to | 1161 // query parameters to the continue URL. Ignore them when checking to |
1157 // see if the user has continued. | 1162 // see if the user has continued. |
1158 // | 1163 // |
1159 // If this is not an explicit sign in, we don't need to check if we landed | 1164 // If this is not an explicit sign in, we don't need to check if we landed |
(...skipping 15 matching lines...) Expand all Loading... | |
1175 // source of the continue URL. Make one last check of the current URL | 1180 // source of the continue URL. Make one last check of the current URL |
1176 // to see if there is a valid source. If so, it overrides the | 1181 // to see if there is a valid source. If so, it overrides the |
1177 // current source. | 1182 // current source. |
1178 // | 1183 // |
1179 // If the source was changed to SOURCE_SETTINGS, we want | 1184 // If the source was changed to SOURCE_SETTINGS, we want |
1180 // OneClickSigninSyncStarter to reuse the current tab to display the | 1185 // OneClickSigninSyncStarter to reuse the current tab to display the |
1181 // advanced configuration. | 1186 // advanced configuration. |
1182 signin::Source source = signin::GetSourceForPromoURL(url); | 1187 signin::Source source = signin::GetSourceForPromoURL(url); |
1183 if (source != source_) { | 1188 if (source != source_) { |
1184 source_ = source; | 1189 source_ = source; |
1185 force_same_tab_navigation = source == signin::SOURCE_SETTINGS; | 1190 if (source == signin::SOURCE_SETTINGS) { |
1186 switched_to_advanced_ = source == signin::SOURCE_SETTINGS; | 1191 sync_setup_contents = web_contents(); |
noms
2013/08/08 20:19:24
What's the difference between web_contents() here
Roger Tawa OOO till Jul 10th
2013/08/08 20:49:54
They are the same. See line 1076 above.
fdoray
2013/08/09 15:31:13
Should I use |contents|?
On 2013/08/08 20:49:54,
| |
1192 switched_to_advanced_ = true; | |
1193 } | |
1187 } | 1194 } |
1188 } | 1195 } |
1189 | 1196 |
1190 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1197 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
1191 | 1198 |
1192 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." | 1199 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." |
1193 << " auto_accept=" << auto_accept_ | 1200 << " auto_accept=" << auto_accept_ |
1194 << " source=" << source_; | 1201 << " source=" << source_; |
1195 | 1202 |
1196 switch (auto_accept_) { | 1203 switch (auto_accept_) { |
1197 case AUTO_ACCEPT_NONE: | 1204 case AUTO_ACCEPT_NONE: |
1198 if (showing_signin_) | 1205 if (showing_signin_) |
1199 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); | 1206 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); |
1200 break; | 1207 break; |
1201 case AUTO_ACCEPT_ACCEPTED: | 1208 case AUTO_ACCEPT_ACCEPTED: |
1202 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1209 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1203 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1210 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
1204 SigninManager::DisableOneClickSignIn(profile); | 1211 SigninManager::DisableOneClickSignIn(profile); |
1205 // Start syncing with the default settings - prompt the user to sign in | 1212 // Start syncing with the default settings - prompt the user to sign in |
1206 // first. | 1213 // first. |
1207 StartSync(StartSyncArgs(profile, browser, auto_accept_, | 1214 StartSync( |
1208 session_index_, email_, password_, | 1215 StartSyncArgs(profile, browser, auto_accept_, |
1209 false /* force_same_tab_navigation */, | 1216 session_index_, email_, password_, |
1210 true /* confirmation_required */, source_, | 1217 NULL /* don't force to show sync setup in same tab */, |
1211 CreateSyncStarterCallback()), | 1218 true /* confirmation_required */, source_, |
1212 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 1219 CreateSyncStarterCallback()), |
1220 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
1213 break; | 1221 break; |
1214 case AUTO_ACCEPT_CONFIGURE: | 1222 case AUTO_ACCEPT_CONFIGURE: |
1215 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1223 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1216 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1224 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); |
1217 SigninManager::DisableOneClickSignIn(profile); | 1225 SigninManager::DisableOneClickSignIn(profile); |
1218 // Display the extra confirmation (even in the SAML case) in case this | 1226 // Display the extra confirmation (even in the SAML case) in case this |
1219 // was an untrusted renderer. | 1227 // was an untrusted renderer. |
1220 StartSync( | 1228 StartSync( |
1221 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, | 1229 StartSyncArgs(profile, browser, auto_accept_, |
1222 password_, false /* force_same_tab_navigation */, | 1230 session_index_, email_, password_, |
1231 NULL /* don't force to show sync setup in same tab */, | |
1223 true /* confirmation_required */, source_, | 1232 true /* confirmation_required */, source_, |
1224 CreateSyncStarterCallback()), | 1233 CreateSyncStarterCallback()), |
1225 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1234 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
1226 break; | 1235 break; |
1227 case AUTO_ACCEPT_EXPLICIT: { | 1236 case AUTO_ACCEPT_EXPLICIT: { |
1228 signin::Source original_source = | 1237 signin::Source original_source = |
1229 signin::GetSourceForPromoURL(original_continue_url_); | 1238 signin::GetSourceForPromoURL(original_continue_url_); |
1230 if (switched_to_advanced_) { | 1239 if (switched_to_advanced_) { |
1231 LogHistogramValue(original_source, | 1240 LogHistogramValue(original_source, |
1232 one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1241 one_click_signin::HISTOGRAM_WITH_ADVANCED); |
(...skipping 19 matching lines...) Expand all Loading... | |
1252 | 1261 |
1253 std::string last_email = | 1262 std::string last_email = |
1254 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1263 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
1255 | 1264 |
1256 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email_)) { | 1265 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email_)) { |
1257 // If the new email address is different from the email address that | 1266 // If the new email address is different from the email address that |
1258 // just signed in, show a confirmation dialog. | 1267 // just signed in, show a confirmation dialog. |
1259 | 1268 |
1260 // No need to display a second confirmation so pass false below. | 1269 // No need to display a second confirmation so pass false below. |
1261 // TODO(atwilson): Move this into OneClickSigninSyncStarter. | 1270 // TODO(atwilson): Move this into OneClickSigninSyncStarter. |
1271 // If |sync_setup_contents| is deleted before the callback execution, | |
1272 // the tab modal dialog is closed and the callback is never executed. | |
1262 ConfirmEmailDialogDelegate::AskForConfirmation( | 1273 ConfirmEmailDialogDelegate::AskForConfirmation( |
1263 contents, | 1274 contents, |
1264 last_email, | 1275 last_email, |
1265 email_, | 1276 email_, |
1266 base::Bind( | 1277 base::Bind( |
1267 &StartExplicitSync, | 1278 &StartExplicitSync, |
1268 StartSyncArgs(profile, browser, auto_accept_, | 1279 StartSyncArgs(profile, browser, auto_accept_, |
1269 session_index_, email_, password_, | 1280 session_index_, email_, password_, |
1270 force_same_tab_navigation, | 1281 sync_setup_contents, |
1271 false /* confirmation_required */, source_, | 1282 false /* confirmation_required */, source_, |
1272 CreateSyncStarterCallback()), | 1283 CreateSyncStarterCallback()), |
1273 contents, | 1284 contents, |
1274 start_mode)); | 1285 start_mode)); |
1275 } else { | 1286 } else { |
1276 StartSync( | 1287 StartSync( |
1277 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1288 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
1278 email_, password_, force_same_tab_navigation, | 1289 email_, password_, sync_setup_contents, |
1279 untrusted_confirmation_required_, source_, | 1290 untrusted_confirmation_required_, source_, |
1280 CreateSyncStarterCallback()), | 1291 CreateSyncStarterCallback()), |
1281 start_mode); | 1292 start_mode); |
1282 | 1293 |
1283 // If this explicit sign in is not from settings page/webstore, show | 1294 // If this explicit sign in is not from settings page/webstore, show |
1284 // the NTP/Apps page after sign in completes. In the case of the | 1295 // the NTP/Apps page after sign in completes. In the case of the |
1285 // settings page, it will get auto-closed after sync setup. In the case | 1296 // settings page, it will get auto-closed after sync setup. In the case |
1286 // of webstore, it will redirect back to webstore. | 1297 // of webstore, it will redirect back to webstore. |
1287 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); | 1298 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); |
1288 } | 1299 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1372 // If the web contents is showing a blank page and not about to be closed, | 1383 // If the web contents is showing a blank page and not about to be closed, |
1373 // redirect to the NTP or apps page. | 1384 // redirect to the NTP or apps page. |
1374 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1385 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1375 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1386 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1376 RedirectToNtpOrAppsPage( | 1387 RedirectToNtpOrAppsPage( |
1377 web_contents(), | 1388 web_contents(), |
1378 signin::GetSourceForPromoURL(original_continue_url_)); | 1389 signin::GetSourceForPromoURL(original_continue_url_)); |
1379 } | 1390 } |
1380 } | 1391 } |
1381 } | 1392 } |
OLD | NEW |