OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webui/signin/inline_login_handler_impl.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | |
11 #include "base/metrics/histogram.h" | |
12 #include "base/prefs/pref_service.h" | |
13 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 13 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | |
18 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_window.h" | 15 #include "chrome/browser/profiles/profile_window.h" |
20 #include "chrome/browser/signin/about_signin_internals_factory.h" | 16 #include "chrome/browser/signin/about_signin_internals_factory.h" |
21 #include "chrome/browser/signin/account_tracker_service_factory.h" | 17 #include "chrome/browser/signin/account_tracker_service_factory.h" |
22 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 18 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
23 #include "chrome/browser/signin/local_auth.h" | 19 #include "chrome/browser/signin/local_auth.h" |
24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
25 #include "chrome/browser/signin/signin_error_controller_factory.h" | 21 #include "chrome/browser/signin/signin_error_controller_factory.h" |
26 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
27 #include "chrome/browser/signin/signin_promo.h" | 23 #include "chrome/browser/signin/signin_promo.h" |
28 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
30 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
31 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
32 #include "chrome/browser/ui/chrome_pages.h" | 28 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
33 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | |
34 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | |
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
36 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 30 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
37 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 31 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
38 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
39 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
40 #include "chrome/grit/chromium_strings.h" | |
41 #include "chrome/grit/generated_resources.h" | |
42 #include "components/signin/core/browser/about_signin_internals.h" | 34 #include "components/signin/core/browser/about_signin_internals.h" |
43 #include "components/signin/core/browser/account_tracker_service.h" | 35 #include "components/signin/core/browser/account_tracker_service.h" |
44 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 36 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
45 #include "components/signin/core/browser/signin_error_controller.h" | 37 #include "components/signin/core/browser/signin_error_controller.h" |
46 #include "components/signin/core/browser/signin_metrics.h" | 38 #include "components/signin/core/browser/signin_metrics.h" |
47 #include "components/signin/core/common/profile_management_switches.h" | 39 #include "components/signin/core/common/profile_management_switches.h" |
48 #include "components/signin/core/common/signin_pref_names.h" | |
49 #include "content/public/browser/storage_partition.h" | 40 #include "content/public/browser/storage_partition.h" |
50 #include "content/public/browser/web_ui.h" | 41 #include "content/public/browser/web_ui.h" |
51 #include "google_apis/gaia/gaia_auth_consumer.h" | 42 #include "google_apis/gaia/gaia_auth_consumer.h" |
52 #include "google_apis/gaia/gaia_auth_fetcher.h" | 43 #include "google_apis/gaia/gaia_auth_fetcher.h" |
53 #include "google_apis/gaia/gaia_auth_util.h" | 44 #include "google_apis/gaia/gaia_auth_util.h" |
54 #include "google_apis/gaia/gaia_constants.h" | 45 #include "google_apis/gaia/gaia_constants.h" |
55 #include "google_apis/gaia/gaia_urls.h" | 46 #include "google_apis/gaia/gaia_urls.h" |
56 #include "grit/components_strings.h" | |
57 #include "net/base/url_util.h" | 47 #include "net/base/url_util.h" |
58 #include "ui/base/l10n/l10n_util.h" | |
59 | 48 |
60 namespace { | 49 namespace { |
61 | 50 |
62 void LogHistogramValue(int action) { | |
63 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | |
64 signin_metrics::HISTOGRAM_MAX); | |
65 } | |
66 | |
67 void RedirectToNtpOrAppsPage(content::WebContents* contents, | |
68 signin_metrics::Source source) { | |
69 // Do nothing if a navigation is pending, since this call can be triggered | |
70 // from DidStartLoading. This avoids deleting the pending entry while we are | |
71 // still navigating to it. See crbug/346632. | |
72 if (contents->GetController().GetPendingEntry()) | |
73 return; | |
74 | |
75 VLOG(1) << "RedirectToNtpOrAppsPage"; | |
76 // Redirect to NTP/Apps page and display a confirmation bubble | |
77 GURL url(source == signin_metrics::SOURCE_APPS_PAGE_LINK ? | |
78 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | |
79 content::OpenURLParams params(url, | |
80 content::Referrer(), | |
81 CURRENT_TAB, | |
82 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
83 false); | |
84 contents->OpenURL(params); | |
85 } | |
86 | |
87 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents, | |
88 signin_metrics::Source source) { | |
89 if (source != signin_metrics::SOURCE_SETTINGS) | |
90 RedirectToNtpOrAppsPage(contents, source); | |
91 } | |
92 | |
93 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { | |
94 public: | |
95 enum Action { | |
96 CREATE_NEW_USER, | |
97 START_SYNC, | |
98 CLOSE | |
99 }; | |
100 | |
101 // Callback indicating action performed by the user. | |
102 typedef base::Callback<void(Action)> Callback; | |
103 | |
104 // Ask the user for confirmation before starting to sync. | |
105 static void AskForConfirmation(content::WebContents* contents, | |
106 const std::string& last_email, | |
107 const std::string& email, | |
108 Callback callback); | |
109 | |
110 private: | |
111 ConfirmEmailDialogDelegate(content::WebContents* contents, | |
112 const std::string& last_email, | |
113 const std::string& email, | |
114 Callback callback); | |
115 ~ConfirmEmailDialogDelegate() override; | |
116 | |
117 // TabModalConfirmDialogDelegate: | |
118 base::string16 GetTitle() override; | |
119 base::string16 GetDialogMessage() override; | |
120 base::string16 GetAcceptButtonTitle() override; | |
121 base::string16 GetCancelButtonTitle() override; | |
122 base::string16 GetLinkText() const override; | |
123 void OnAccepted() override; | |
124 void OnCanceled() override; | |
125 void OnClosed() override; | |
126 void OnLinkClicked(WindowOpenDisposition disposition) override; | |
127 | |
128 std::string last_email_; | |
129 std::string email_; | |
130 Callback callback_; | |
131 | |
132 // Web contents from which the "Learn more" link should be opened. | |
133 content::WebContents* web_contents_; | |
134 | |
135 DISALLOW_COPY_AND_ASSIGN(ConfirmEmailDialogDelegate); | |
136 }; | |
137 | |
138 // static | |
139 void ConfirmEmailDialogDelegate::AskForConfirmation( | |
140 content::WebContents* contents, | |
141 const std::string& last_email, | |
142 const std::string& email, | |
143 Callback callback) { | |
144 TabModalConfirmDialog::Create( | |
145 new ConfirmEmailDialogDelegate(contents, last_email, email, callback), | |
146 contents); | |
147 } | |
148 | |
149 ConfirmEmailDialogDelegate::ConfirmEmailDialogDelegate( | |
150 content::WebContents* contents, | |
151 const std::string& last_email, | |
152 const std::string& email, | |
153 Callback callback) | |
154 : TabModalConfirmDialogDelegate(contents), | |
155 last_email_(last_email), | |
156 email_(email), | |
157 callback_(callback), | |
158 web_contents_(contents) { | |
159 } | |
160 | |
161 ConfirmEmailDialogDelegate::~ConfirmEmailDialogDelegate() { | |
162 } | |
163 | |
164 base::string16 ConfirmEmailDialogDelegate::GetTitle() { | |
165 return l10n_util::GetStringUTF16( | |
166 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_TITLE); | |
167 } | |
168 | |
169 base::string16 ConfirmEmailDialogDelegate::GetDialogMessage() { | |
170 return l10n_util::GetStringFUTF16( | |
171 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_MESSAGE, | |
172 base::UTF8ToUTF16(last_email_), base::UTF8ToUTF16(email_)); | |
173 } | |
174 | |
175 base::string16 ConfirmEmailDialogDelegate::GetAcceptButtonTitle() { | |
176 return l10n_util::GetStringUTF16( | |
177 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON); | |
178 } | |
179 | |
180 base::string16 ConfirmEmailDialogDelegate::GetCancelButtonTitle() { | |
181 return l10n_util::GetStringUTF16( | |
182 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | |
183 } | |
184 | |
185 base::string16 ConfirmEmailDialogDelegate::GetLinkText() const { | |
186 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
187 } | |
188 | |
189 void ConfirmEmailDialogDelegate::OnAccepted() { | |
190 base::ResetAndReturn(&callback_).Run(CREATE_NEW_USER); | |
191 } | |
192 | |
193 void ConfirmEmailDialogDelegate::OnCanceled() { | |
194 base::ResetAndReturn(&callback_).Run(START_SYNC); | |
195 } | |
196 | |
197 void ConfirmEmailDialogDelegate::OnClosed() { | |
198 base::ResetAndReturn(&callback_).Run(CLOSE); | |
199 } | |
200 | |
201 void ConfirmEmailDialogDelegate::OnLinkClicked( | |
202 WindowOpenDisposition disposition) { | |
203 content::OpenURLParams params( | |
204 GURL(chrome::kChromeSyncMergeTroubleshootingURL), | |
205 content::Referrer(), | |
206 NEW_POPUP, | |
207 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
208 false); | |
209 // It is guaranteed that |web_contents_| is valid here because when it's | |
210 // deleted, the dialog is immediately closed and no further action can be | |
211 // performed. | |
212 web_contents_->OpenURL(params); | |
213 } | |
214 | |
215 class InlineSigninHelper : public GaiaAuthConsumer { | 51 class InlineSigninHelper : public GaiaAuthConsumer { |
216 public: | 52 public: |
217 InlineSigninHelper( | 53 InlineSigninHelper( |
218 base::WeakPtr<InlineLoginHandlerImpl> handler, | 54 base::WeakPtr<InlineLoginHandlerImpl> handler, |
219 net::URLRequestContextGetter* getter, | 55 net::URLRequestContextGetter* getter, |
220 Profile* profile, | 56 Profile* profile, |
221 const GURL& current_url, | 57 const GURL& current_url, |
222 const std::string& email, | 58 const std::string& email, |
223 const std::string& gaia_id, | 59 const std::string& gaia_id, |
224 const std::string& password, | 60 const std::string& password, |
225 const std::string& session_index, | 61 const std::string& session_index, |
226 const std::string& signin_scoped_device_id, | 62 const std::string& signin_scoped_device_id, |
227 bool choose_what_to_sync, | 63 bool choose_what_to_sync, |
228 bool confirm_untrusted_signin); | 64 bool confirm_untrusted_signin); |
229 | 65 |
230 private: | 66 private: |
231 // Handles cross account sign in error. If the supplied |email| does not match | |
232 // the last signed in email of the current profile, then Chrome will show a | |
233 // confirmation dialog before starting sync. It returns true if there is a | |
234 // cross account error, and false otherwise. | |
235 bool HandleCrossAccountError( | |
236 const std::string& refresh_token, | |
237 signin_metrics::Source source, | |
238 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | |
239 OneClickSigninSyncStarter::StartSyncMode start_mode); | |
240 | |
241 // Callback used with ConfirmEmailDialogDelegate. | |
242 void ConfirmEmailAction( | |
243 content::WebContents* web_contents, | |
244 const std::string& refresh_token, | |
245 signin_metrics::Source source, | |
246 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | |
247 OneClickSigninSyncStarter::StartSyncMode start_mode, | |
248 ConfirmEmailDialogDelegate::Action action); | |
249 | |
250 // Overridden from GaiaAuthConsumer. | 67 // Overridden from GaiaAuthConsumer. |
251 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; | 68 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; |
252 void OnClientOAuthFailure(const GoogleServiceAuthError& error) | 69 void OnClientOAuthFailure(const GoogleServiceAuthError& error) |
253 override; | 70 override; |
254 | 71 |
255 GaiaAuthFetcher gaia_auth_fetcher_; | 72 GaiaAuthFetcher gaia_auth_fetcher_; |
256 base::WeakPtr<InlineLoginHandlerImpl> handler_; | 73 base::WeakPtr<InlineLoginHandlerImpl> handler_; |
257 Profile* profile_; | 74 Profile* profile_; |
258 GURL current_url_; | 75 GURL current_url_; |
259 std::string email_; | 76 std::string email_; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } else if (is_new_avatar_menu) { | 190 } else if (is_new_avatar_menu) { |
374 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 191 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
375 } else { | 192 } else { |
376 confirmation_required = | 193 confirmation_required = |
377 source == signin_metrics::SOURCE_SETTINGS || | 194 source == signin_metrics::SOURCE_SETTINGS || |
378 choose_what_to_sync_ ? | 195 choose_what_to_sync_ ? |
379 OneClickSigninSyncStarter::NO_CONFIRMATION : | 196 OneClickSigninSyncStarter::NO_CONFIRMATION : |
380 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 197 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
381 } | 198 } |
382 | 199 |
383 bool start_signin = !HandleCrossAccountError(result.refresh_token, source, | 200 bool start_signin = |
384 confirmation_required, start_mode); | 201 !OneClickSigninHelper::HandleCrossAccountError( |
| 202 profile_, "", |
| 203 email_, password_, result.refresh_token, |
| 204 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, |
| 205 source, start_mode, |
| 206 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, |
| 207 handler_)); |
385 if (start_signin) { | 208 if (start_signin) { |
386 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. | 209 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. |
387 // OneClickSigninSyncStarter will delete itself once the job is done. | 210 // OneClickSigninSyncStarter will delete itself once the job is done. |
388 new OneClickSigninSyncStarter( | 211 new OneClickSigninSyncStarter( |
389 profile_, browser, | 212 profile_, browser, |
390 email_, password_, result.refresh_token, | 213 email_, password_, result.refresh_token, |
391 start_mode, | 214 start_mode, |
392 contents, | 215 contents, |
393 confirmation_required, | 216 confirmation_required, |
394 signin::GetNextPageURLForPromoURL(current_url_), | 217 signin::GetNextPageURLForPromoURL(current_url_), |
395 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | 218 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); |
396 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
397 } | 219 } |
398 } | 220 } |
399 } | |
400 | 221 |
401 bool InlineSigninHelper::HandleCrossAccountError( | |
402 const std::string& refresh_token, | |
403 signin_metrics::Source source, | |
404 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | |
405 OneClickSigninSyncStarter::StartSyncMode start_mode) { | |
406 std::string last_email = | |
407 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | |
408 | |
409 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_)) | |
410 return false; | |
411 | |
412 Browser* browser = chrome::FindLastActiveWithProfile( | |
413 profile_, chrome::GetActiveDesktop()); | |
414 content::WebContents* web_contents = | |
415 browser->tab_strip_model()->GetActiveWebContents(); | |
416 | |
417 ConfirmEmailDialogDelegate::AskForConfirmation( | |
418 web_contents, | |
419 last_email, | |
420 email_, | |
421 base::Bind(&InlineSigninHelper::ConfirmEmailAction, | |
422 base::Unretained(this), | |
423 web_contents, | |
424 refresh_token, | |
425 source, | |
426 confirmation_required, | |
427 start_mode)); | |
428 return true; | |
429 } | |
430 | |
431 void InlineSigninHelper::ConfirmEmailAction( | |
432 content::WebContents* web_contents, | |
433 const std::string& refresh_token, | |
434 signin_metrics::Source source, | |
435 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | |
436 OneClickSigninSyncStarter::StartSyncMode start_mode, | |
437 ConfirmEmailDialogDelegate::Action action) { | |
438 Browser* browser = chrome::FindLastActiveWithProfile( | |
439 profile_, chrome::GetActiveDesktop()); | |
440 switch (action) { | |
441 case ConfirmEmailDialogDelegate::CREATE_NEW_USER: | |
442 if (handler_) { | |
443 handler_->SyncStarterCallback( | |
444 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | |
445 } | |
446 chrome::ShowSettingsSubPage(browser, | |
447 std::string(chrome::kCreateProfileSubPage)); | |
448 break; | |
449 case ConfirmEmailDialogDelegate::START_SYNC: | |
450 new OneClickSigninSyncStarter( | |
451 profile_, browser, email_, password_, refresh_token, | |
452 start_mode, web_contents, confirmation_required, GURL(), | |
453 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | |
454 break; | |
455 case ConfirmEmailDialogDelegate::CLOSE: | |
456 if (handler_) { | |
457 handler_->SyncStarterCallback( | |
458 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | |
459 } | |
460 break; | |
461 default: | |
462 DCHECK(false) << "Invalid action"; | |
463 } | |
464 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 222 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
465 } | 223 } |
466 | 224 |
467 void InlineSigninHelper::OnClientOAuthFailure( | 225 void InlineSigninHelper::OnClientOAuthFailure( |
468 const GoogleServiceAuthError& error) { | 226 const GoogleServiceAuthError& error) { |
469 if (handler_) | 227 if (handler_) |
470 handler_->HandleLoginError(error.ToString()); | 228 handler_->HandleLoginError(error.ToString()); |
471 | 229 |
472 AboutSigninInternals* about_signin_internals = | 230 AboutSigninInternals* about_signin_internals = |
473 AboutSigninInternalsFactory::GetForProfile(profile_); | 231 AboutSigninInternalsFactory::GetForProfile(profile_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 if (!url.is_empty()) { | 264 if (!url.is_empty()) { |
507 GURL origin(url.GetOrigin()); | 265 GURL origin(url.GetOrigin()); |
508 if (url.spec() != url::kAboutBlankURL && | 266 if (url.spec() != url::kAboutBlankURL && |
509 origin != kGaiaExtOrigin && | 267 origin != kGaiaExtOrigin && |
510 !gaia::IsGaiaSignonRealm(origin)) { | 268 !gaia::IsGaiaSignonRealm(origin)) { |
511 confirm_untrusted_signin_ = true; | 269 confirm_untrusted_signin_ = true; |
512 } | 270 } |
513 } | 271 } |
514 } | 272 } |
515 | 273 |
516 // static | |
517 bool InlineLoginHandlerImpl::CanOffer(Profile* profile, | |
518 CanOfferFor can_offer_for, | |
519 const std::string& email, | |
520 std::string* error_message) { | |
521 if (error_message) | |
522 error_message->clear(); | |
523 | |
524 if (!profile) | |
525 return false; | |
526 | |
527 SigninManager* manager = SigninManagerFactory::GetForProfile(profile); | |
528 if (manager && !manager->IsSigninAllowed()) | |
529 return false; | |
530 | |
531 if (!ChromeSigninClient::ProfileAllowsSigninCookies(profile)) | |
532 return false; | |
533 | |
534 if (!email.empty()) { | |
535 if (!manager) | |
536 return false; | |
537 | |
538 // Make sure this username is not prohibited by policy. | |
539 if (!manager->IsAllowedUsername(email)) { | |
540 if (error_message) { | |
541 error_message->assign( | |
542 l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED)); | |
543 } | |
544 return false; | |
545 } | |
546 | |
547 if (can_offer_for == CAN_OFFER_FOR_SECONDARY_ACCOUNT) | |
548 return true; | |
549 | |
550 // If the signin manager already has an authenticated name, then this is a | |
551 // re-auth scenario. Make sure the email just signed in corresponds to | |
552 // the one sign in manager expects. | |
553 std::string current_email = manager->GetAuthenticatedUsername(); | |
554 const bool same_email = gaia::AreEmailsSame(current_email, email); | |
555 if (!current_email.empty() && !same_email) { | |
556 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", | |
557 signin_metrics::HISTOGRAM_ACCOUNT_MISSMATCH, | |
558 signin_metrics::HISTOGRAM_MAX); | |
559 if (error_message) { | |
560 error_message->assign( | |
561 l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL, | |
562 base::UTF8ToUTF16(current_email))); | |
563 } | |
564 return false; | |
565 } | |
566 | |
567 // If some profile, not just the current one, is already connected to this | |
568 // account, don't show the infobar. | |
569 if (g_browser_process && !same_email) { | |
570 ProfileManager* manager = g_browser_process->profile_manager(); | |
571 if (manager) { | |
572 ProfileInfoCache& cache = manager->GetProfileInfoCache(); | |
573 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | |
574 std::string current_email = | |
575 base::UTF16ToUTF8(cache.GetUserNameOfProfileAtIndex(i)); | |
576 if (gaia::AreEmailsSame(email, current_email)) { | |
577 if (error_message) { | |
578 error_message->assign( | |
579 l10n_util::GetStringUTF8(IDS_SYNC_USER_NAME_IN_USE_ERROR)); | |
580 } | |
581 return false; | |
582 } | |
583 } | |
584 } | |
585 } | |
586 } | |
587 | |
588 return true; | |
589 } | |
590 | |
591 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { | 274 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { |
592 params.SetString("service", "chromiumsync"); | 275 params.SetString("service", "chromiumsync"); |
593 | 276 |
594 content::WebContents* contents = web_ui()->GetWebContents(); | 277 content::WebContents* contents = web_ui()->GetWebContents(); |
595 const GURL& current_url = contents->GetURL(); | 278 const GURL& current_url = contents->GetURL(); |
596 std::string is_constrained; | 279 std::string is_constrained; |
597 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | 280 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); |
598 | 281 |
599 content::WebContentsObserver::Observe(contents); | 282 content::WebContentsObserver::Observe(contents); |
600 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); | 283 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); |
601 } | 284 } |
602 | 285 |
603 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { | 286 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
604 content::WebContents* contents = web_ui()->GetWebContents(); | 287 content::WebContents* contents = web_ui()->GetWebContents(); |
605 const GURL& current_url = contents->GetURL(); | 288 const GURL& current_url = contents->GetURL(); |
606 | 289 |
607 const base::DictionaryValue* dict = NULL; | 290 const base::DictionaryValue* dict = NULL; |
608 args->GetDictionary(0, &dict); | 291 args->GetDictionary(0, &dict); |
609 | 292 |
610 bool skip_for_now = false; | 293 bool skip_for_now = false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 335 |
653 base::string16 session_index_string16; | 336 base::string16 session_index_string16; |
654 dict->GetString("sessionIndex", &session_index_string16); | 337 dict->GetString("sessionIndex", &session_index_string16); |
655 std::string session_index = base::UTF16ToASCII(session_index_string16); | 338 std::string session_index = base::UTF16ToASCII(session_index_string16); |
656 DCHECK(!session_index.empty()); | 339 DCHECK(!session_index.empty()); |
657 | 340 |
658 bool choose_what_to_sync = false; | 341 bool choose_what_to_sync = false; |
659 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); | 342 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); |
660 | 343 |
661 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); | 344 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); |
662 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); | 345 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); |
663 bool switch_to_advanced = | 346 bool switch_to_advanced = |
664 choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS); | 347 choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS); |
665 LogHistogramValue( | 348 OneClickSigninHelper::LogHistogramValue( |
666 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED : | 349 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED : |
667 signin_metrics::HISTOGRAM_WITH_DEFAULTS); | 350 signin_metrics::HISTOGRAM_WITH_DEFAULTS); |
668 | 351 |
669 CanOfferFor can_offer_for = CAN_OFFER_FOR_ALL; | 352 OneClickSigninHelper::CanOfferFor can_offer_for = |
| 353 OneClickSigninHelper::CAN_OFFER_FOR_ALL; |
670 switch (source) { | 354 switch (source) { |
671 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: | 355 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: |
672 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; | 356 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT; |
673 break; | 357 break; |
674 case signin_metrics::SOURCE_REAUTH: { | 358 case signin_metrics::SOURCE_REAUTH: { |
675 std::string primary_username = | 359 std::string primary_username = |
676 SigninManagerFactory::GetForProfile( | 360 SigninManagerFactory::GetForProfile( |
677 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername(); | 361 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername(); |
678 if (!gaia::AreEmailsSame(default_email, primary_username)) | 362 if (!gaia::AreEmailsSame(default_email, primary_username)) |
679 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; | 363 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT; |
680 break; | 364 break; |
681 } | 365 } |
682 default: | 366 default: |
683 // No need to change |can_offer_for|. | 367 // No need to change |can_offer_for|. |
684 break; | 368 break; |
685 } | 369 } |
686 | 370 |
687 std::string error_msg; | 371 std::string error_msg; |
688 bool can_offer = CanOffer(Profile::FromWebUI(web_ui()), can_offer_for, | 372 bool can_offer = OneClickSigninHelper::CanOffer( |
689 email, &error_msg); | 373 contents, can_offer_for, email, &error_msg); |
690 if (!can_offer) { | 374 if (!can_offer) { |
691 HandleLoginError(error_msg); | 375 HandleLoginError(error_msg); |
692 return; | 376 return; |
693 } | 377 } |
694 | 378 |
695 AboutSigninInternals* about_signin_internals = | 379 AboutSigninInternals* about_signin_internals = |
696 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 380 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
697 about_signin_internals->OnAuthenticationResultReceived( | 381 about_signin_internals->OnAuthenticationResultReceived( |
698 "GAIA Auth Successful"); | 382 "GAIA Auth Successful"); |
699 | 383 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 // from DidStartLoading. This avoids deleting the pending entry while we are | 428 // from DidStartLoading. This avoids deleting the pending entry while we are |
745 // still navigating to it. See crbug/346632. | 429 // still navigating to it. See crbug/346632. |
746 return; | 430 return; |
747 } | 431 } |
748 | 432 |
749 const GURL& current_url = contents->GetLastCommittedURL(); | 433 const GURL& current_url = contents->GetLastCommittedURL(); |
750 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); | 434 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); |
751 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); | 435 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); |
752 | 436 |
753 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { | 437 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { |
754 RedirectToNtpOrAppsPage(contents, source); | 438 OneClickSigninHelper::RedirectToNtpOrAppsPage(contents, source); |
755 } else if (auto_close) { | 439 } else if (auto_close) { |
756 base::MessageLoop::current()->PostTask( | 440 base::MessageLoop::current()->PostTask( |
757 FROM_HERE, | 441 FROM_HERE, |
758 base::Bind(&InlineLoginHandlerImpl::CloseTab, | 442 base::Bind(&InlineLoginHandlerImpl::CloseTab, |
759 weak_factory_.GetWeakPtr(), | 443 weak_factory_.GetWeakPtr(), |
760 signin::ShouldShowAccountManagement(current_url))); | 444 signin::ShouldShowAccountManagement(current_url))); |
761 } else { | 445 } else { |
762 RedirectToNtpOrAppsPageIfNecessary(contents, source); | 446 OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(contents, source); |
763 } | 447 } |
764 } | 448 } |
765 | 449 |
766 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) { | 450 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) { |
767 content::WebContents* tab = web_ui()->GetWebContents(); | 451 content::WebContents* tab = web_ui()->GetWebContents(); |
768 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 452 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
769 if (browser) { | 453 if (browser) { |
770 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 454 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
771 if (tab_strip_model) { | 455 if (tab_strip_model) { |
772 int index = tab_strip_model->GetIndexOfWebContents(tab); | 456 int index = tab_strip_model->GetIndexOfWebContents(tab); |
773 if (index != TabStripModel::kNoTab) { | 457 if (index != TabStripModel::kNoTab) { |
774 tab_strip_model->ExecuteContextMenuCommand( | 458 tab_strip_model->ExecuteContextMenuCommand( |
775 index, TabStripModel::CommandCloseTab); | 459 index, TabStripModel::CommandCloseTab); |
776 } | 460 } |
777 } | 461 } |
778 | 462 |
779 if (show_account_management) { | 463 if (show_account_management) { |
780 browser->window()->ShowAvatarBubbleFromAvatarButton( | 464 browser->window()->ShowAvatarBubbleFromAvatarButton( |
781 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 465 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
782 signin::ManageAccountsParams()); | 466 signin::ManageAccountsParams()); |
783 } | 467 } |
784 } | 468 } |
785 } | 469 } |
OLD | NEW |