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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper.cc

Issue 22510004: Show sync setup in same tab as sign in instead of active tab. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add web_contents parameter to ShowSyncSettingsPageInWebContents Created 7 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/ui/sync/one_click_signin_sync_starter.h » ('j') | 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 return; 1140 return;
1137 } 1141 }
1138 1142
1139 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have 1143 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have
1140 // the option of checking the the box "Let me choose what to sync". When the 1144 // the option of checking the the box "Let me choose what to sync". When the
1141 // sign in process started, the source parameter in the continue URL may have 1145 // sign in process started, the source parameter in the continue URL may have
1142 // indicated one of the three options above. However, once this box is 1146 // indicated one of the three options above. However, once this box is
1143 // checked, the source parameter will indicate settings. This will only be 1147 // checked, the source parameter will indicate settings. This will only be
1144 // communicated back to chrome when Gaia redirects to the continue URL, and 1148 // communicated back to chrome when Gaia redirects to the continue URL, and
1145 // this is considered here a last minute change to the source. See a little 1149 // this is considered here a last minute change to the source. See a little
1146 // further below for when this variable is set to true. 1150 // further below for when this variable is set to a web contents that must be
1147 bool force_same_tab_navigation = false; 1151 // used to show the sync setup page.
1152 content::WebContents* sync_setup_contents = NULL;
1148 1153
1149 if (!continue_url_match && IsValidGaiaSigninRedirectOrResponseURL(url)) 1154 if (!continue_url_match && IsValidGaiaSigninRedirectOrResponseURL(url))
1150 return; 1155 return;
1151 1156
1152 // During an explicit sign in, if the user has not yet reached the final 1157 // During an explicit sign in, if the user has not yet reached the final
1153 // continue URL, wait for it to arrive. Note that Gaia will add some extra 1158 // continue URL, wait for it to arrive. Note that Gaia will add some extra
1154 // query parameters to the continue URL. Ignore them when checking to 1159 // query parameters to the continue URL. Ignore them when checking to
1155 // see if the user has continued. 1160 // see if the user has continued.
1156 // 1161 //
1157 // If this is not an explicit sign in, we don't need to check if we landed 1162 // If this is not an explicit sign in, we don't need to check if we landed
(...skipping 15 matching lines...) Expand all
1173 // source of the continue URL. Make one last check of the current URL 1178 // source of the continue URL. Make one last check of the current URL
1174 // to see if there is a valid source. If so, it overrides the 1179 // to see if there is a valid source. If so, it overrides the
1175 // current source. 1180 // current source.
1176 // 1181 //
1177 // If the source was changed to SOURCE_SETTINGS, we want 1182 // If the source was changed to SOURCE_SETTINGS, we want
1178 // OneClickSigninSyncStarter to reuse the current tab to display the 1183 // OneClickSigninSyncStarter to reuse the current tab to display the
1179 // advanced configuration. 1184 // advanced configuration.
1180 signin::Source source = signin::GetSourceForPromoURL(url); 1185 signin::Source source = signin::GetSourceForPromoURL(url);
1181 if (source != source_) { 1186 if (source != source_) {
1182 source_ = source; 1187 source_ = source;
1183 force_same_tab_navigation = source == signin::SOURCE_SETTINGS; 1188 if (source == signin::SOURCE_SETTINGS) {
1184 switched_to_advanced_ = source == signin::SOURCE_SETTINGS; 1189 sync_setup_contents = web_contents();
1190 switched_to_advanced_ = true;
1191 }
1185 } 1192 }
1186 } 1193 }
1187 1194
1188 Browser* browser = chrome::FindBrowserWithWebContents(contents); 1195 Browser* browser = chrome::FindBrowserWithWebContents(contents);
1189 1196
1190 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." 1197 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go."
1191 << " auto_accept=" << auto_accept_ 1198 << " auto_accept=" << auto_accept_
1192 << " source=" << source_; 1199 << " source=" << source_;
1193 1200
1194 switch (auto_accept_) { 1201 switch (auto_accept_) {
1195 case AUTO_ACCEPT_NONE: 1202 case AUTO_ACCEPT_NONE:
1196 if (showing_signin_) 1203 if (showing_signin_)
1197 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); 1204 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED);
1198 break; 1205 break;
1199 case AUTO_ACCEPT_ACCEPTED: 1206 case AUTO_ACCEPT_ACCEPTED:
1200 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); 1207 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED);
1201 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); 1208 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS);
1202 SigninManager::DisableOneClickSignIn(profile); 1209 SigninManager::DisableOneClickSignIn(profile);
1203 // Start syncing with the default settings - prompt the user to sign in 1210 // Start syncing with the default settings - prompt the user to sign in
1204 // first. 1211 // first.
1205 StartSync(StartSyncArgs(profile, browser, auto_accept_, 1212 StartSync(
1206 session_index_, email_, password_, 1213 StartSyncArgs(profile, browser, auto_accept_,
1207 false /* force_same_tab_navigation */, 1214 session_index_, email_, password_,
1208 true /* confirmation_required */, source_, 1215 NULL /* don't force to show sync setup in same tab */,
1209 CreateSyncStarterCallback()), 1216 true /* confirmation_required */, source_,
1210 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); 1217 CreateSyncStarterCallback()),
1218 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS);
1211 break; 1219 break;
1212 case AUTO_ACCEPT_CONFIGURE: 1220 case AUTO_ACCEPT_CONFIGURE:
1213 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); 1221 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED);
1214 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); 1222 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED);
1215 SigninManager::DisableOneClickSignIn(profile); 1223 SigninManager::DisableOneClickSignIn(profile);
1216 // Display the extra confirmation (even in the SAML case) in case this 1224 // Display the extra confirmation (even in the SAML case) in case this
1217 // was an untrusted renderer. 1225 // was an untrusted renderer.
1218 StartSync( 1226 StartSync(
1219 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, 1227 StartSyncArgs(profile, browser, auto_accept_,
1220 password_, false /* force_same_tab_navigation */, 1228 session_index_, email_, password_,
1229 NULL /* don't force to show sync setup in same tab */,
1221 true /* confirmation_required */, source_, 1230 true /* confirmation_required */, source_,
1222 CreateSyncStarterCallback()), 1231 CreateSyncStarterCallback()),
1223 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); 1232 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST);
1224 break; 1233 break;
1225 case AUTO_ACCEPT_EXPLICIT: { 1234 case AUTO_ACCEPT_EXPLICIT: {
1226 signin::Source original_source = 1235 signin::Source original_source =
1227 signin::GetSourceForPromoURL(original_continue_url_); 1236 signin::GetSourceForPromoURL(original_continue_url_);
1228 if (switched_to_advanced_) { 1237 if (switched_to_advanced_) {
1229 LogHistogramValue(original_source, 1238 LogHistogramValue(original_source,
1230 one_click_signin::HISTOGRAM_WITH_ADVANCED); 1239 one_click_signin::HISTOGRAM_WITH_ADVANCED);
(...skipping 19 matching lines...) Expand all
1250 1259
1251 std::string last_email = 1260 std::string last_email =
1252 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); 1261 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername);
1253 1262
1254 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email_)) { 1263 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email_)) {
1255 // If the new email address is different from the email address that 1264 // If the new email address is different from the email address that
1256 // just signed in, show a confirmation dialog. 1265 // just signed in, show a confirmation dialog.
1257 1266
1258 // No need to display a second confirmation so pass false below. 1267 // No need to display a second confirmation so pass false below.
1259 // TODO(atwilson): Move this into OneClickSigninSyncStarter. 1268 // TODO(atwilson): Move this into OneClickSigninSyncStarter.
1269 // If |sync_setup_contents| is deleted before the callback execution,
1270 // the tab modal dialog is closed and the callback is never executed.
1260 ConfirmEmailDialogDelegate::AskForConfirmation( 1271 ConfirmEmailDialogDelegate::AskForConfirmation(
1261 contents, 1272 contents,
1262 last_email, 1273 last_email,
1263 email_, 1274 email_,
1264 base::Bind( 1275 base::Bind(
1265 &StartExplicitSync, 1276 &StartExplicitSync,
1266 StartSyncArgs(profile, browser, auto_accept_, 1277 StartSyncArgs(profile, browser, auto_accept_,
1267 session_index_, email_, password_, 1278 session_index_, email_, password_,
1268 force_same_tab_navigation, 1279 sync_setup_contents,
1269 false /* confirmation_required */, source_, 1280 false /* confirmation_required */, source_,
1270 CreateSyncStarterCallback()), 1281 CreateSyncStarterCallback()),
1271 contents, 1282 contents,
1272 start_mode)); 1283 start_mode));
1273 } else { 1284 } else {
1274 StartSync( 1285 StartSync(
1275 StartSyncArgs(profile, browser, auto_accept_, session_index_, 1286 StartSyncArgs(profile, browser, auto_accept_, session_index_,
1276 email_, password_, force_same_tab_navigation, 1287 email_, password_, sync_setup_contents,
1277 untrusted_confirmation_required_, source_, 1288 untrusted_confirmation_required_, source_,
1278 CreateSyncStarterCallback()), 1289 CreateSyncStarterCallback()),
1279 start_mode); 1290 start_mode);
1280 1291
1281 // If this explicit sign in is not from settings page/webstore, show 1292 // If this explicit sign in is not from settings page/webstore, show
1282 // the NTP/Apps page after sign in completes. In the case of the 1293 // the NTP/Apps page after sign in completes. In the case of the
1283 // settings page, it will get auto-closed after sync setup. In the case 1294 // settings page, it will get auto-closed after sync setup. In the case
1284 // of webstore, it will redirect back to webstore. 1295 // of webstore, it will redirect back to webstore.
1285 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); 1296 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_);
1286 } 1297 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 // If the web contents is showing a blank page and not about to be closed, 1381 // If the web contents is showing a blank page and not about to be closed,
1371 // redirect to the NTP or apps page. 1382 // redirect to the NTP or apps page.
1372 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && 1383 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) &&
1373 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { 1384 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) {
1374 RedirectToNtpOrAppsPage( 1385 RedirectToNtpOrAppsPage(
1375 web_contents(), 1386 web_contents(),
1376 signin::GetSourceForPromoURL(original_continue_url_)); 1387 signin::GetSourceForPromoURL(original_continue_url_));
1377 } 1388 }
1378 } 1389 }
1379 } 1390 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/sync/one_click_signin_sync_starter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698