Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/signin/signin_manager.h" | 19 #include "chrome/browser/signin/signin_manager.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
| 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 22 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 22 #include "chrome/browser/tab_contents/tab_util.h" | 23 #include "chrome/browser/tab_contents/tab_util.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 virtual bool Cancel() OVERRIDE; | 65 virtual bool Cancel() OVERRIDE; |
| 65 virtual string16 GetLinkText() const OVERRIDE; | 66 virtual string16 GetLinkText() const OVERRIDE; |
| 66 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | 67 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 67 | 68 |
| 68 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; | 69 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; |
| 69 | 70 |
| 70 // Set the profile preference to turn off one-click sign in so that it won't | 71 // Set the profile preference to turn off one-click sign in so that it won't |
| 71 // show again in this profile. | 72 // show again in this profile. |
| 72 void DisableOneClickSignIn(); | 73 void DisableOneClickSignIn(); |
| 73 | 74 |
| 75 // Add a specific email to the list of emails rejected for one-click | |
| 76 // sign-in, for this profile. | |
| 77 void AddEmailToOneClickRejectedList(const std::string& email); | |
| 78 | |
| 74 // Record the specified action in the histogram for one-click sign in. | 79 // Record the specified action in the histogram for one-click sign in. |
| 75 void RecordHistogramAction(int action); | 80 void RecordHistogramAction(int action); |
| 76 | 81 |
| 77 // Information about the account that has just logged in. | 82 // Information about the account that has just logged in. |
| 78 std::string session_index_; | 83 std::string session_index_; |
| 79 std::string email_; | 84 std::string email_; |
| 80 std::string password_; | 85 std::string password_; |
| 81 | 86 |
| 82 // Whether any UI controls in the infobar were pressed or not. | 87 // Whether any UI controls in the infobar were pressed or not. |
| 83 bool button_pressed_; | 88 bool button_pressed_; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 // The starter deletes itself once its done. | 144 // The starter deletes itself once its done. |
| 140 Profile* profile = | 145 Profile* profile = |
| 141 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 146 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 142 new OneClickSigninSyncStarter(profile, session_index, email, password, | 147 new OneClickSigninSyncStarter(profile, session_index, email, password, |
| 143 start_mode); | 148 start_mode); |
| 144 } | 149 } |
| 145 | 150 |
| 146 } // namespace | 151 } // namespace |
| 147 | 152 |
| 148 bool OneClickLoginInfoBarDelegate::Accept() { | 153 bool OneClickLoginInfoBarDelegate::Accept() { |
| 154 // User has accepted one-click sign-in for this account. Never ask again for | |
| 155 // this profile. | |
| 149 DisableOneClickSignIn(); | 156 DisableOneClickSignIn(); |
| 150 content::WebContents* web_contents = owner()->web_contents(); | 157 content::WebContents* web_contents = owner()->web_contents(); |
| 151 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 158 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
| 152 browser::FindBrowserWithWebContents(web_contents)->window()-> | 159 browser::FindBrowserWithWebContents(web_contents)->window()-> |
| 153 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents, | 160 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents, |
| 154 session_index_, email_, password_)); | 161 session_index_, email_, password_)); |
| 155 button_pressed_ = true; | 162 button_pressed_ = true; |
| 156 return true; | 163 return true; |
| 157 } | 164 } |
| 158 | 165 |
| 159 bool OneClickLoginInfoBarDelegate::Cancel() { | 166 bool OneClickLoginInfoBarDelegate::Cancel() { |
| 160 DisableOneClickSignIn(); | 167 AddEmailToOneClickRejectedList(email_); |
| 161 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 168 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
| 162 button_pressed_ = true; | 169 button_pressed_ = true; |
| 163 return true; | 170 return true; |
| 164 } | 171 } |
| 165 | 172 |
| 166 string16 OneClickLoginInfoBarDelegate::GetLinkText() const { | 173 string16 OneClickLoginInfoBarDelegate::GetLinkText() const { |
| 167 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 174 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 168 } | 175 } |
| 169 | 176 |
| 170 bool OneClickLoginInfoBarDelegate::LinkClicked( | 177 bool OneClickLoginInfoBarDelegate::LinkClicked( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 183 return ONE_CLICK_LOGIN_INFOBAR; | 190 return ONE_CLICK_LOGIN_INFOBAR; |
| 184 } | 191 } |
| 185 | 192 |
| 186 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { | 193 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { |
| 187 PrefService* pref_service = | 194 PrefService* pref_service = |
| 188 TabContents::FromWebContents(owner()->web_contents())-> | 195 TabContents::FromWebContents(owner()->web_contents())-> |
| 189 profile()->GetPrefs(); | 196 profile()->GetPrefs(); |
| 190 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); | 197 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); |
| 191 } | 198 } |
| 192 | 199 |
| 200 void OneClickLoginInfoBarDelegate::AddEmailToOneClickRejectedList( | |
| 201 const std::string& email) { | |
| 202 PrefService* pref_service = | |
| 203 TabContents::FromWebContents(owner()->web_contents())-> | |
| 204 profile()->GetPrefs(); | |
| 205 ListPrefUpdate updater(pref_service, | |
| 206 prefs::kReverseAutologinRejectedEmailList); | |
| 207 updater->AppendIfNotPresent(base::Value::CreateStringValue(email)); | |
| 208 } | |
| 209 | |
| 193 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) { | 210 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) { |
| 194 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 211 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
| 195 one_click_signin::HISTOGRAM_MAX); | 212 one_click_signin::HISTOGRAM_MAX); |
| 196 } | 213 } |
| 197 | 214 |
| 198 // static | 215 // static |
| 199 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 216 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
| 217 const std::string& email, | |
| 200 bool check_connected) { | 218 bool check_connected) { |
| 201 if (!web_contents) | 219 if (!web_contents) |
| 202 return false; | 220 return false; |
| 203 | 221 |
| 204 if (web_contents->GetBrowserContext()->IsOffTheRecord()) | 222 if (web_contents->GetBrowserContext()->IsOffTheRecord()) |
| 205 return false; | 223 return false; |
| 206 | 224 |
| 207 if (!ProfileSyncService::IsSyncEnabled()) | 225 if (!ProfileSyncService::IsSyncEnabled()) |
| 208 return false; | 226 return false; |
| 209 | 227 |
| 210 Profile* profile = | 228 Profile* profile = |
| 211 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 229 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 212 if (!profile) | 230 if (!profile) |
| 213 return false; | 231 return false; |
| 214 | 232 |
| 215 if (!profile->GetPrefs()->GetBoolean(prefs::kReverseAutologinEnabled)) | 233 if (!profile->GetPrefs()->GetBoolean(prefs::kReverseAutologinEnabled)) |
| 216 return false; | 234 return false; |
| 217 | 235 |
| 236 // If email was already rejected by this profile for one-click sign-in. | |
| 237 if (!email.empty()) { | |
| 238 const ListValue* rejected_emails = profile->GetPrefs()->GetList( | |
| 239 prefs::kReverseAutologinRejectedEmailList); | |
| 240 if (!rejected_emails->empty()) { | |
| 241 const Value* email_value = Value::CreateStringValue(email); | |
| 242 ListValue::const_iterator iter = rejected_emails->Find( | |
| 243 *email_value); | |
| 244 if (iter != rejected_emails->end()) | |
| 245 return false; | |
| 246 } | |
| 247 } | |
|
Roger Tawa OOO till Jul 10th
2012/06/15 17:56:00
i think it would be better to move this to the if
Mathieu
2012/06/21 13:13:00
Done.
| |
| 248 | |
| 218 if (!SigninManager::AreSigninCookiesAllowed(profile)) | 249 if (!SigninManager::AreSigninCookiesAllowed(profile)) |
| 219 return false; | 250 return false; |
| 220 | 251 |
| 221 if (check_connected) { | 252 if (check_connected) { |
| 222 SigninManager* manager = | 253 SigninManager* manager = |
| 223 SigninManagerFactory::GetForProfile(profile); | 254 SigninManagerFactory::GetForProfile(profile); |
| 224 if (!manager) | 255 if (!manager) |
| 225 return false; | 256 return false; |
| 226 | 257 |
| 227 if (!manager->GetAuthenticatedUsername().empty()) | 258 if (!manager->GetAuthenticatedUsername().empty()) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 // static | 307 // static |
| 277 void OneClickSigninHelper::ShowInfoBarUIThread( | 308 void OneClickSigninHelper::ShowInfoBarUIThread( |
| 278 const std::string& session_index, | 309 const std::string& session_index, |
| 279 const std::string& email, | 310 const std::string& email, |
| 280 int child_id, | 311 int child_id, |
| 281 int route_id) { | 312 int route_id) { |
| 282 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 313 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 283 | 314 |
| 284 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, | 315 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, |
| 285 route_id); | 316 route_id); |
| 286 if (!web_contents || !CanOffer(web_contents, true)) | 317 if (!web_contents || !CanOffer(web_contents, email, true)) |
| 287 return; | 318 return; |
| 288 | 319 |
| 289 // If some profile, not just the current one, is already connected to this | 320 // If some profile, not just the current one, is already connected to this |
| 290 // account, don't show the infobar. | 321 // account, don't show the infobar. |
| 291 if (g_browser_process) { | 322 if (g_browser_process) { |
| 292 ProfileManager* manager = g_browser_process->profile_manager(); | 323 ProfileManager* manager = g_browser_process->profile_manager(); |
| 293 if (manager) { | 324 if (manager) { |
| 294 string16 email16 = UTF8ToUTF16(email); | 325 string16 email16 = UTF8ToUTF16(email); |
| 295 ProfileInfoCache& cache = manager->GetProfileInfoCache(); | 326 ProfileInfoCache& cache = manager->GetProfileInfoCache(); |
| 296 | 327 |
| 297 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 328 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 298 if (email16 == cache.GetUserNameOfProfileAtIndex(i)) | 329 if (email16 == cache.GetUserNameOfProfileAtIndex(i)) |
| 299 return; | 330 return; |
| 300 } | 331 } |
| 301 } | 332 } |
| 302 } | 333 } |
|
Roger Tawa OOO till Jul 10th
2012/06/15 17:56:00
this if block should now be moved into CanOffer()
| |
| 303 | 334 |
| 304 // Make sure this username is not prohibited by policy. | 335 // Make sure this username is not prohibited by policy. |
| 305 Profile* profile = | 336 Profile* profile = |
| 306 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 337 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 307 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); | 338 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); |
| 308 if (!signin->IsAllowedUsername(email)) | 339 if (!signin->IsAllowedUsername(email)) |
| 309 return; | 340 return; |
|
Roger Tawa OOO till Jul 10th
2012/06/15 17:56:00
this check should also be moved inside the if (che
| |
| 310 | 341 |
| 311 TabContents* tab_contents = TabContents::FromWebContents(web_contents); | 342 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
| 312 if (!tab_contents) | 343 if (!tab_contents) |
| 313 return; | 344 return; |
| 314 | 345 |
| 315 // Save the email in the one-click signin manager. The manager may | 346 // Save the email in the one-click signin manager. The manager may |
| 316 // not exist if the contents is incognito or if the profile is already | 347 // not exist if the contents is incognito or if the profile is already |
| 317 // connected to a Google account. | 348 // connected to a Google account. |
| 318 OneClickSigninHelper* helper = tab_contents->one_click_signin_helper(); | 349 OneClickSigninHelper* helper = tab_contents->one_click_signin_helper(); |
| 319 if (helper) | 350 if (helper) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 347 session_index_ = session_index; | 378 session_index_ = session_index; |
| 348 email_ = email; | 379 email_ = email; |
| 349 } | 380 } |
| 350 | 381 |
| 351 void OneClickSigninHelper::SavePassword(const std::string& password) { | 382 void OneClickSigninHelper::SavePassword(const std::string& password) { |
| 352 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of | 383 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of |
| 353 // challenge, its possible for the user to never complete the signin. | 384 // challenge, its possible for the user to never complete the signin. |
| 354 // Should have a way to detect this and clear the password member. | 385 // Should have a way to detect this and clear the password member. |
| 355 password_ = password; | 386 password_ = password; |
| 356 } | 387 } |
| OLD | NEW |