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