| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" |
| 13 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/api/infobars/one_click_signin_infobar_delegate.h" | 16 #include "chrome/browser/api/infobars/one_click_signin_infobar_delegate.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
| 19 #include "chrome/browser/google/google_util.h" |
| 18 #include "chrome/browser/infobars/infobar_tab_helper.h" | 20 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_info_cache.h" | 24 #include "chrome/browser/profiles/profile_info_cache.h" |
| 23 #include "chrome/browser/profiles/profile_io_data.h" | 25 #include "chrome/browser/profiles/profile_io_data.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/signin/signin_manager.h" | 27 #include "chrome/browser/signin/signin_manager.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 27 #include "chrome/browser/signin/signin_names_io_thread.h" | 29 #include "chrome/browser/signin/signin_names_io_thread.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 #include "content/public/browser/web_contents_view.h" | 46 #include "content/public/browser/web_contents_view.h" |
| 45 #include "content/public/common/frame_navigate_params.h" | 47 #include "content/public/common/frame_navigate_params.h" |
| 46 #include "content/public/common/page_transition_types.h" | 48 #include "content/public/common/page_transition_types.h" |
| 47 #include "content/public/common/password_form.h" | 49 #include "content/public/common/password_form.h" |
| 48 #include "google_apis/gaia/gaia_auth_util.h" | 50 #include "google_apis/gaia/gaia_auth_util.h" |
| 49 #include "google_apis/gaia/gaia_urls.h" | 51 #include "google_apis/gaia/gaia_urls.h" |
| 50 #include "googleurl/src/gurl.h" | 52 #include "googleurl/src/gurl.h" |
| 51 #include "grit/chromium_strings.h" | 53 #include "grit/chromium_strings.h" |
| 52 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
| 53 #include "grit/theme_resources.h" | 55 #include "grit/theme_resources.h" |
| 54 #include "net/base/escape.h" | |
| 55 #include "net/cookies/cookie_monster.h" | 56 #include "net/cookies/cookie_monster.h" |
| 56 #include "net/url_request/url_request.h" | 57 #include "net/url_request/url_request.h" |
| 57 #include "ui/base/l10n/l10n_util.h" | 58 #include "ui/base/l10n/l10n_util.h" |
| 58 #include "ui/base/resource/resource_bundle.h" | 59 #include "ui/base/resource/resource_bundle.h" |
| 59 | 60 |
| 60 #include <functional> | 61 #include <functional> |
| 61 | 62 |
| 62 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper) | 63 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper) |
| 63 | 64 |
| 64 namespace { | 65 namespace { |
| 65 | 66 |
| 66 // Set to true if this chrome instance is in the blue-button-on-white-bar | 67 // Set to true if this chrome instance is in the blue-button-on-white-bar |
| 67 // experimental group. | 68 // experimental group. |
| 68 bool use_blue_on_white = false; | 69 bool use_blue_on_white = false; |
| 69 | 70 |
| 71 // Add a specific email to the list of emails rejected for one-click |
| 72 // sign-in, for this profile. |
| 73 void AddEmailToOneClickRejectedList(Profile* profile, |
| 74 const std::string& email) { |
| 75 PrefService* pref_service = profile->GetPrefs(); |
| 76 ListPrefUpdate updater(pref_service, |
| 77 prefs::kReverseAutologinRejectedEmailList); |
| 78 updater->AppendIfNotPresent(new base::StringValue(email)); |
| 79 } |
| 80 |
| 70 // Start syncing with the given user information. | 81 // Start syncing with the given user information. |
| 71 void StartSync(Browser* browser, | 82 void StartSync(Browser* browser, |
| 72 OneClickSigninHelper::AutoAccept auto_accept, | 83 OneClickSigninHelper::AutoAccept auto_accept, |
| 73 const std::string& session_index, | 84 const std::string& session_index, |
| 74 const std::string& email, | 85 const std::string& email, |
| 75 const std::string& password, | 86 const std::string& password, |
| 76 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 87 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 77 // The starter deletes itself once its done. | 88 // The starter deletes itself once its done. |
| 78 new OneClickSigninSyncStarter(browser, session_index, email, password, | 89 new OneClickSigninSyncStarter(browser, session_index, email, password, |
| 79 start_mode); | 90 start_mode); |
| 80 | 91 |
| 81 int action = one_click_signin::HISTOGRAM_MAX; | 92 int action = one_click_signin::HISTOGRAM_MAX; |
| 82 switch (auto_accept) { | 93 switch (auto_accept) { |
| 83 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: | 94 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: |
| 84 action = one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS; | 95 action = one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS; |
| 85 break; | 96 break; |
| 86 case OneClickSigninHelper::AUTO_ACCEPT: | 97 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: |
| 87 action = | 98 action = |
| 88 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? | 99 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? |
| 89 one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS : | 100 one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS : |
| 90 one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; | 101 one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; |
| 91 break; | 102 break; |
| 92 case OneClickSigninHelper::NO_AUTO_ACCEPT: | 103 case OneClickSigninHelper::AUTO_ACCEPT_NONE: |
| 93 action = | 104 action = |
| 94 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? | 105 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? |
| 95 one_click_signin::HISTOGRAM_WITH_DEFAULTS : | 106 one_click_signin::HISTOGRAM_WITH_DEFAULTS : |
| 96 one_click_signin::HISTOGRAM_WITH_ADVANCED; | 107 one_click_signin::HISTOGRAM_WITH_ADVANCED; |
| 97 break; | 108 break; |
| 98 case OneClickSigninHelper::AUTO_ACCEPT_CONFIGURE: | 109 case OneClickSigninHelper::AUTO_ACCEPT_CONFIGURE: |
| 99 DCHECK(start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 110 DCHECK(start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 100 action = one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; | 111 action = one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; |
| 101 break; | 112 break; |
| 102 default: | 113 default: |
| 103 NOTREACHED() << "Invalid auto_accept: " << auto_accept; | 114 NOTREACHED() << "Invalid auto_accept: " << auto_accept; |
| 104 break; | 115 break; |
| 105 } | 116 } |
| 106 | 117 |
| 107 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 118 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
| 108 one_click_signin::HISTOGRAM_MAX); | 119 one_click_signin::HISTOGRAM_MAX); |
| 109 } | 120 } |
| 110 | 121 |
| 111 // Determines the source of the sign in. Its either one of the known sign in | 122 // Determines the source of the sign in and the continue URL. Its either one |
| 112 // access point (first run, NTP, menu, settings) or its an implicit sign in | 123 // of the known sign in access point (first run, NTP, menu, settings) or its |
| 113 // via another Google property. In the former case, "service" is also | 124 // an implicit sign in via another Google property. In the former case, |
| 114 // checked to make sure its "chromiumsync". | 125 // "service" is also checked to make sure its "chromiumsync". |
| 115 SyncPromoUI::Source GetSigninSource(const GURL& url) { | 126 SyncPromoUI::Source GetSigninSource(const GURL& url, GURL* continue_url) { |
| 116 std::string value; | 127 std::string value; |
| 117 chrome_common_net::GetValueForKeyInQuery(url, "service", &value); | 128 chrome_common_net::GetValueForKeyInQuery(url, "service", &value); |
| 118 bool is_explicit_signin = value == "chromiumsync"; | 129 bool possibly_an_explicit_signin = value == "chromiumsync"; |
| 119 | 130 |
| 120 chrome_common_net::GetValueForKeyInQuery(url, "continue", &value); | 131 // Find the final continue URL for this sign in. In some cases, Gaia can |
| 121 SyncPromoUI::Source source = | 132 // continue to itself, with the original continue URL buried under a couple |
| 122 SyncPromoUI::GetSourceForSyncPromoURL(GURL( | 133 // of layers of indirection. Peel those layers away. |
| 123 net::UnescapeURLComponent(value, | 134 GURL local_continue_url = url; |
| 124 net::UnescapeRule::URL_SPECIAL_CHARS))); | 135 do { |
| 136 local_continue_url = |
| 137 SyncPromoUI::GetNextPageURLForSyncPromoURL(local_continue_url); |
| 138 } while (gaia::IsGaiaSignonRealm(local_continue_url.GetOrigin())); |
| 125 | 139 |
| 126 if (!is_explicit_signin) | 140 if (continue_url && local_continue_url.is_valid()) { |
| 127 source = SyncPromoUI::SOURCE_UNKNOWN; | 141 DCHECK(!continue_url->is_valid() || *continue_url == local_continue_url); |
| 142 *continue_url = local_continue_url; |
| 143 } |
| 128 | 144 |
| 129 return source; | 145 return possibly_an_explicit_signin ? |
| 146 SyncPromoUI::GetSourceForSyncPromoURL(local_continue_url) : |
| 147 SyncPromoUI::SOURCE_UNKNOWN; |
| 148 } |
| 149 |
| 150 // Returns true if |url| is a valid URL that can occur during the sign in |
| 151 // process. Valid URLs are of the form: |
| 152 // |
| 153 // https://accounts.google.{TLD}/... |
| 154 // https://accounts.youtube.com/... |
| 155 // https://accounts.blogger.com/... |
| 156 // |
| 157 // All special headers used by one click sign in occur on |
| 158 // https://accounts.google.com URLs. However, the sign in process may redirect |
| 159 // to intermediate Gaia URLs that do not end with .com. For example, an account |
| 160 // that uses SMS 2-factor outside the US may redirect to country specific URLs. |
| 161 // |
| 162 // The sign in process may also redirect to youtube and blogger account URLs |
| 163 // so that Gaia acts as a single signon service. |
| 164 bool IsValidGaiaSigninRedirectOrResponseURL(const GURL& url) { |
| 165 std::string hostname = url.host(); |
| 166 if (google_util::IsGoogleHostname(hostname, google_util::ALLOW_SUBDOMAIN)) { |
| 167 // Also using IsGaiaSignonRealm() to handle overriding with command line. |
| 168 return gaia::IsGaiaSignonRealm(url.GetOrigin()) || |
| 169 StartsWithASCII(hostname, "accounts.", false); |
| 170 } |
| 171 |
| 172 GURL origin = url.GetOrigin(); |
| 173 if (origin == GURL("https://accounts.youtube.com") || |
| 174 origin == GURL("https://accounts.blogger.com")) |
| 175 return true; |
| 176 |
| 177 return false; |
| 130 } | 178 } |
| 131 | 179 |
| 132 // This class is associated as user data with a given URLRequest object, in | 180 // This class is associated as user data with a given URLRequest object, in |
| 133 // order to pass information from one response to another during the process | 181 // order to pass information from one response to another during the process |
| 134 // of signing the user into their Gaia account. This class is only meant | 182 // of signing the user into their Gaia account. This class is only meant |
| 135 // to be used from the IO thread. | 183 // to be used from the IO thread. |
| 136 class OneClickSigninRequestUserData : public base::SupportsUserData::Data { | 184 class OneClickSigninRequestUserData : public base::SupportsUserData::Data { |
| 137 public: | 185 public: |
| 138 const std::string& email() const { return email_; } | 186 const std::string& email() const { return email_; } |
| 139 | 187 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // ConfirmInfoBarDelegate overrides. | 249 // ConfirmInfoBarDelegate overrides. |
| 202 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 250 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 203 virtual bool Accept() OVERRIDE; | 251 virtual bool Accept() OVERRIDE; |
| 204 virtual bool Cancel() OVERRIDE; | 252 virtual bool Cancel() OVERRIDE; |
| 205 virtual string16 GetLinkText() const OVERRIDE; | 253 virtual string16 GetLinkText() const OVERRIDE; |
| 206 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | 254 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 207 | 255 |
| 208 // OneClickSigninInfoBarDelegate overrides. | 256 // OneClickSigninInfoBarDelegate overrides. |
| 209 virtual void GetAlternateColors(AlternateColors* alt_colors) OVERRIDE; | 257 virtual void GetAlternateColors(AlternateColors* alt_colors) OVERRIDE; |
| 210 | 258 |
| 211 // Add a specific email to the list of emails rejected for one-click | |
| 212 // sign-in, for this profile. | |
| 213 void AddEmailToOneClickRejectedList(const std::string& email); | |
| 214 | |
| 215 // Record the specified action in the histogram for one-click sign in. | 259 // Record the specified action in the histogram for one-click sign in. |
| 216 void RecordHistogramAction(int action); | 260 void RecordHistogramAction(int action); |
| 217 | 261 |
| 218 // Information about the account that has just logged in. | 262 // Information about the account that has just logged in. |
| 219 std::string session_index_; | 263 std::string session_index_; |
| 220 std::string email_; | 264 std::string email_; |
| 221 std::string password_; | 265 std::string password_; |
| 222 | 266 |
| 223 // Whether any UI controls in the infobar were pressed or not. | 267 // Whether any UI controls in the infobar were pressed or not. |
| 224 bool button_pressed_; | 268 bool button_pressed_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 312 } |
| 269 | 313 |
| 270 string16 OneClickInfoBarDelegateImpl::GetButtonLabel( | 314 string16 OneClickInfoBarDelegateImpl::GetButtonLabel( |
| 271 InfoBarButton button) const { | 315 InfoBarButton button) const { |
| 272 return l10n_util::GetStringUTF16( | 316 return l10n_util::GetStringUTF16( |
| 273 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON | 317 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON |
| 274 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); | 318 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); |
| 275 } | 319 } |
| 276 | 320 |
| 277 bool OneClickInfoBarDelegateImpl::Accept() { | 321 bool OneClickInfoBarDelegateImpl::Accept() { |
| 322 content::WebContents* web_contents = owner()->GetWebContents(); |
| 323 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 324 Profile* profile = Profile::FromBrowserContext( |
| 325 web_contents->GetBrowserContext()); |
| 326 |
| 278 // User has accepted one-click sign-in for this account. Never ask again for | 327 // User has accepted one-click sign-in for this account. Never ask again for |
| 279 // this profile. | 328 // this profile. |
| 280 Profile* profile = Profile::FromBrowserContext( | |
| 281 owner()->GetWebContents()->GetBrowserContext()); | |
| 282 SigninManager::DisableOneClickSignIn(profile); | 329 SigninManager::DisableOneClickSignIn(profile); |
| 283 | |
| 284 content::WebContents* web_contents = owner()->GetWebContents(); | |
| 285 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 286 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 330 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
| 287 chrome::FindBrowserWithWebContents(web_contents)->window()-> | 331 chrome::FindBrowserWithWebContents(web_contents)->window()-> |
| 288 ShowOneClickSigninBubble(base::Bind(&StartSync, browser, | 332 ShowOneClickSigninBubble( |
| 289 OneClickSigninHelper::NO_AUTO_ACCEPT, | 333 base::Bind(&StartSync, browser, |
| 290 session_index_, email_, password_)); | 334 OneClickSigninHelper::AUTO_ACCEPT_NONE, session_index_, |
| 335 email_, password_)); |
| 291 button_pressed_ = true; | 336 button_pressed_ = true; |
| 292 return true; | 337 return true; |
| 293 } | 338 } |
| 294 | 339 |
| 295 bool OneClickInfoBarDelegateImpl::Cancel() { | 340 bool OneClickInfoBarDelegateImpl::Cancel() { |
| 296 AddEmailToOneClickRejectedList(email_); | 341 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( |
| 342 owner()->GetWebContents()->GetBrowserContext()), email_); |
| 297 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 343 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
| 298 button_pressed_ = true; | 344 button_pressed_ = true; |
| 299 return true; | 345 return true; |
| 300 } | 346 } |
| 301 | 347 |
| 302 string16 OneClickInfoBarDelegateImpl::GetLinkText() const { | 348 string16 OneClickInfoBarDelegateImpl::GetLinkText() const { |
| 303 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 349 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 304 } | 350 } |
| 305 | 351 |
| 306 bool OneClickInfoBarDelegateImpl::LinkClicked( | 352 bool OneClickInfoBarDelegateImpl::LinkClicked( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 321 alt_colors->infobar_top_color = SK_ColorWHITE; | 367 alt_colors->infobar_top_color = SK_ColorWHITE; |
| 322 alt_colors->button_text_color = SK_ColorWHITE; | 368 alt_colors->button_text_color = SK_ColorWHITE; |
| 323 alt_colors->button_background_color = SkColorSetRGB(71, 135, 237); | 369 alt_colors->button_background_color = SkColorSetRGB(71, 135, 237); |
| 324 alt_colors->button_border_color = SkColorSetRGB(48, 121, 237); | 370 alt_colors->button_border_color = SkColorSetRGB(48, 121, 237); |
| 325 return; | 371 return; |
| 326 } | 372 } |
| 327 | 373 |
| 328 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); | 374 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); |
| 329 } | 375 } |
| 330 | 376 |
| 331 void OneClickInfoBarDelegateImpl::AddEmailToOneClickRejectedList( | |
| 332 const std::string& email) { | |
| 333 Profile* profile = Profile::FromBrowserContext( | |
| 334 owner()->GetWebContents()->GetBrowserContext()); | |
| 335 PrefService* pref_service = profile->GetPrefs(); | |
| 336 ListPrefUpdate updater(pref_service, | |
| 337 prefs::kReverseAutologinRejectedEmailList); | |
| 338 updater->AppendIfNotPresent(new base::StringValue(email)); | |
| 339 } | |
| 340 | |
| 341 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { | 377 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { |
| 342 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 378 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
| 343 one_click_signin::HISTOGRAM_MAX); | 379 one_click_signin::HISTOGRAM_MAX); |
| 344 } | 380 } |
| 345 | 381 |
| 346 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 382 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
| 347 : content::WebContentsObserver(web_contents), | 383 : content::WebContentsObserver(web_contents), |
| 348 auto_accept_(NO_AUTO_ACCEPT), | 384 auto_accept_(AUTO_ACCEPT_NONE), |
| 349 source_(SyncPromoUI::SOURCE_UNKNOWN) { | 385 source_(SyncPromoUI::SOURCE_UNKNOWN) { |
| 350 } | 386 } |
| 351 | 387 |
| 352 OneClickSigninHelper::~OneClickSigninHelper() { | 388 OneClickSigninHelper::~OneClickSigninHelper() { |
| 353 } | 389 } |
| 354 | 390 |
| 355 // static | 391 // static |
| 356 void OneClickSigninHelper::AssociateWithRequestForTesting( | 392 void OneClickSigninHelper::AssociateWithRequestForTesting( |
| 357 base::SupportsUserData* request, | 393 base::SupportsUserData* request, |
| 358 const std::string& email) { | 394 const std::string& email) { |
| 359 OneClickSigninRequestUserData::AssociateWithRequest(request, email); | 395 OneClickSigninRequestUserData::AssociateWithRequest(request, email); |
| 360 } | 396 } |
| 361 | 397 |
| 362 // static | 398 // static |
| 363 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 399 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
| 364 CanOfferFor can_offer_for, | 400 CanOfferFor can_offer_for, |
| 365 const std::string& email, | 401 const std::string& email, |
| 366 int* error_message_id) { | 402 int* error_message_id) { |
| 367 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 403 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 404 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
| 368 | 405 |
| 369 if (error_message_id) | 406 if (error_message_id) |
| 370 *error_message_id = 0; | 407 *error_message_id = 0; |
| 371 | 408 |
| 372 if (!web_contents) | 409 if (!web_contents) |
| 373 return false; | 410 return false; |
| 374 | 411 |
| 375 if (web_contents->GetBrowserContext()->IsOffTheRecord()) | 412 if (web_contents->GetBrowserContext()->IsOffTheRecord()) |
| 376 return false; | 413 return false; |
| 377 | 414 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 ProfileSyncService* service = | 487 ProfileSyncService* service = |
| 451 ProfileSyncServiceFactory::GetForProfile(profile); | 488 ProfileSyncServiceFactory::GetForProfile(profile); |
| 452 if (!service) | 489 if (!service) |
| 453 return false; | 490 return false; |
| 454 | 491 |
| 455 if (service->FirstSetupInProgress()) | 492 if (service->FirstSetupInProgress()) |
| 456 return false; | 493 return false; |
| 457 } | 494 } |
| 458 } | 495 } |
| 459 | 496 |
| 497 VLOG(1) << "OneClickSigninHelper::CanOffer: yes we can"; |
| 460 return true; | 498 return true; |
| 461 } | 499 } |
| 462 | 500 |
| 463 // static | 501 // static |
| 464 OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThread( | 502 OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThread( |
| 465 net::URLRequest* request, | 503 net::URLRequest* request, |
| 466 ProfileIOData* io_data) { | 504 ProfileIOData* io_data) { |
| 467 return CanOfferOnIOThreadImpl(request->url(), request->referrer(), | 505 return CanOfferOnIOThreadImpl(request->url(), request->referrer(), |
| 468 request, io_data); | 506 request, io_data); |
| 469 } | 507 } |
| 470 | 508 |
| 471 // static | 509 // static |
| 472 OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThreadImpl( | 510 OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThreadImpl( |
| 473 const GURL& url, | 511 const GURL& url, |
| 474 const std::string& referrer, | 512 const std::string& referrer, |
| 475 base::SupportsUserData* request, | 513 base::SupportsUserData* request, |
| 476 ProfileIOData* io_data) { | 514 ProfileIOData* io_data) { |
| 477 if (!gaia::IsGaiaSignonRealm(url.GetOrigin())) | 515 if (!gaia::IsGaiaSignonRealm(url.GetOrigin())) |
| 478 return IGNORE_REQUEST; | 516 return IGNORE_REQUEST; |
| 479 | 517 |
| 480 if (!io_data) | 518 if (!io_data) |
| 481 return DONT_OFFER; | 519 return DONT_OFFER; |
| 482 | 520 |
| 483 if (!SyncPromoUI::UseWebBasedSigninFlow()) | 521 if (!SyncPromoUI::UseWebBasedSigninFlow()) |
| 484 return DONT_OFFER; | 522 return DONT_OFFER; |
| 485 | 523 |
| 486 // Don't offer if the source is known, as that means it's an explicit sign | |
| 487 // in request. | |
| 488 if (GetSigninSource(url) != SyncPromoUI::SOURCE_UNKNOWN || | |
| 489 GetSigninSource(GURL(referrer)) != SyncPromoUI::SOURCE_UNKNOWN) { | |
| 490 return DONT_OFFER; | |
| 491 } | |
| 492 | |
| 493 if (!ProfileSyncService::IsSyncEnabled()) | 524 if (!ProfileSyncService::IsSyncEnabled()) |
| 494 return DONT_OFFER; | 525 return DONT_OFFER; |
| 495 | 526 |
| 496 // Check for incognito before other parts of the io_data, since those | 527 // Check for incognito before other parts of the io_data, since those |
| 497 // members may not be initalized. | 528 // members may not be initalized. |
| 498 if (io_data->is_incognito()) | 529 if (io_data->is_incognito()) |
| 499 return DONT_OFFER; | 530 return DONT_OFFER; |
| 500 | 531 |
| 501 if (!io_data->reverse_autologin_enabled()->GetValue()) | 532 if (!io_data->reverse_autologin_enabled()->GetValue()) |
| 502 return DONT_OFFER; | 533 return DONT_OFFER; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request, | 591 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request, |
| 561 int child_id, | 592 int child_id, |
| 562 int route_id) { | 593 int route_id) { |
| 563 std::string google_chrome_signin_value; | 594 std::string google_chrome_signin_value; |
| 564 std::string google_accounts_signin_value; | 595 std::string google_accounts_signin_value; |
| 565 request->GetResponseHeaderByName("Google-Chrome-SignIn", | 596 request->GetResponseHeaderByName("Google-Chrome-SignIn", |
| 566 &google_chrome_signin_value); | 597 &google_chrome_signin_value); |
| 567 request->GetResponseHeaderByName("Google-Accounts-SignIn", | 598 request->GetResponseHeaderByName("Google-Accounts-SignIn", |
| 568 &google_accounts_signin_value); | 599 &google_accounts_signin_value); |
| 569 | 600 |
| 570 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" | 601 if (!google_accounts_signin_value.empty() || |
| 571 << " g-a-s='" << google_accounts_signin_value << "'" | 602 !google_chrome_signin_value.empty()) { |
| 572 << " g-c-s='" << google_chrome_signin_value << "'"; | 603 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" |
| 604 << " g-a-s='" << google_accounts_signin_value << "'" |
| 605 << " g-c-s='" << google_chrome_signin_value << "'"; |
| 606 } |
| 573 | 607 |
| 574 if (!SyncPromoUI::UseWebBasedSigninFlow() && | 608 if (!SyncPromoUI::UseWebBasedSigninFlow() && |
| 575 google_accounts_signin_value.empty()) { | 609 google_accounts_signin_value.empty()) { |
| 576 return; | 610 return; |
| 577 } | 611 } |
| 578 | 612 |
| 579 if (!gaia::IsGaiaSignonRealm(request->original_url().GetOrigin())) | 613 if (!gaia::IsGaiaSignonRealm(request->original_url().GetOrigin())) |
| 580 return; | 614 return; |
| 581 | 615 |
| 582 // Parse Google-Accounts-SignIn. | 616 // Parse Google-Accounts-SignIn. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 595 session_index = value; | 629 session_index = value; |
| 596 } | 630 } |
| 597 } | 631 } |
| 598 | 632 |
| 599 // Later in the chain of this request, we'll need to check the email address | 633 // Later in the chain of this request, we'll need to check the email address |
| 600 // in the IO thread (see CanOfferOnIOThread). So save the email address as | 634 // in the IO thread (see CanOfferOnIOThread). So save the email address as |
| 601 // user data on the request (only for web-based flow). | 635 // user data on the request (only for web-based flow). |
| 602 if (SyncPromoUI::UseWebBasedSigninFlow() && !email.empty()) | 636 if (SyncPromoUI::UseWebBasedSigninFlow() && !email.empty()) |
| 603 OneClickSigninRequestUserData::AssociateWithRequest(request, email); | 637 OneClickSigninRequestUserData::AssociateWithRequest(request, email); |
| 604 | 638 |
| 605 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" | 639 if (!email.empty() || !session_index.empty()) { |
| 606 << " email=" << email | 640 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" |
| 607 << " sessionindex=" << session_index; | 641 << " email=" << email |
| 642 << " sessionindex=" << session_index; |
| 643 } |
| 608 | 644 |
| 609 // Parse Google-Chrome-SignIn. | 645 // Parse Google-Chrome-SignIn. |
| 610 AutoAccept auto_accept = NO_AUTO_ACCEPT; | 646 AutoAccept auto_accept = AUTO_ACCEPT_NONE; |
| 611 SyncPromoUI::Source source = SyncPromoUI::SOURCE_UNKNOWN; | 647 SyncPromoUI::Source source = SyncPromoUI::SOURCE_UNKNOWN; |
| 648 GURL continue_url; |
| 612 if (SyncPromoUI::UseWebBasedSigninFlow()) { | 649 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 613 std::vector<std::string> tokens; | 650 std::vector<std::string> tokens; |
| 614 base::SplitString(google_chrome_signin_value, ',', &tokens); | 651 base::SplitString(google_chrome_signin_value, ',', &tokens); |
| 615 for (size_t i = 0; i < tokens.size(); ++i) { | 652 for (size_t i = 0; i < tokens.size(); ++i) { |
| 616 const std::string& token = tokens[i]; | 653 const std::string& token = tokens[i]; |
| 617 if (token == "accepted") { | 654 if (token == "accepted") { |
| 618 auto_accept = AUTO_ACCEPT; | 655 auto_accept = AUTO_ACCEPT_ACCEPTED; |
| 619 } else if (token == "configure") { | 656 } else if (token == "configure") { |
| 620 auto_accept = AUTO_ACCEPT_CONFIGURE; | 657 auto_accept = AUTO_ACCEPT_CONFIGURE; |
| 621 } else if (token == "rejected-for-profile") { | 658 } else if (token == "rejected-for-profile") { |
| 622 auto_accept = REJECTED_FOR_PROFILE; | 659 auto_accept = AUTO_ACCEPT_REJECTED_FOR_PROFILE; |
| 623 } | 660 } |
| 624 } | 661 } |
| 625 | 662 |
| 626 // If this is an explicit sign in (i.e., first run, NTP, menu,settings) | 663 // If this is an explicit sign in (i.e., first run, NTP, menu,settings) |
| 627 // then force the auto accept type to explicit. | 664 // then force the auto accept type to explicit. |
| 628 source = GetSigninSource(request->original_url()); | 665 source = GetSigninSource(request->original_url(), &continue_url); |
| 629 if (source == SyncPromoUI::SOURCE_UNKNOWN) | |
| 630 source = GetSigninSource(GURL(request->referrer())); | |
| 631 | |
| 632 if (source != SyncPromoUI::SOURCE_UNKNOWN) | 666 if (source != SyncPromoUI::SOURCE_UNKNOWN) |
| 633 auto_accept = AUTO_ACCEPT_EXPLICIT; | 667 auto_accept = AUTO_ACCEPT_EXPLICIT; |
| 634 } | 668 } |
| 635 | 669 |
| 636 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" | 670 if (auto_accept != AUTO_ACCEPT_NONE) { |
| 637 << " auto_accept=" << auto_accept; | 671 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" |
| 672 << " auto_accept=" << auto_accept; |
| 673 } |
| 638 | 674 |
| 639 // If |session_index|, |email|, and |auto_accept| all have their default | 675 // If |session_index|, |email|, |auto_accept|, and |continue_url| all have |
| 640 // value, don't bother posting a task to the UI thread. It will be a noop | 676 // their default value, don't bother posting a task to the UI thread. |
| 641 // anyway. | 677 // It will be a noop anyway. |
| 642 // | 678 // |
| 643 // The two headers above may (but not always) come in different http requests | 679 // The two headers above may (but not always) come in different http requests |
| 644 // so a post to the UI thread is still needed if |auto_accept| is not its | 680 // so a post to the UI thread is still needed if |auto_accept| is not its |
| 645 // default value, but |email| and |session_index| are. | 681 // default value, but |email| and |session_index| are. |
| 646 if (session_index.empty() && email.empty() && auto_accept == NO_AUTO_ACCEPT) | 682 if (session_index.empty() && email.empty() && |
| 683 auto_accept == AUTO_ACCEPT_NONE && !continue_url.is_valid()) { |
| 647 return; | 684 return; |
| 685 } |
| 648 | 686 |
| 649 content::BrowserThread::PostTask( | 687 content::BrowserThread::PostTask( |
| 650 content::BrowserThread::UI, FROM_HERE, | 688 content::BrowserThread::UI, FROM_HERE, |
| 651 base::Bind(&OneClickSigninHelper::ShowInfoBarUIThread, session_index, | 689 base::Bind(&OneClickSigninHelper::ShowInfoBarUIThread, session_index, |
| 652 email, auto_accept, source, child_id, route_id)); | 690 email, auto_accept, source, continue_url, child_id, route_id)); |
| 653 } | 691 } |
| 654 | 692 |
| 655 // static | 693 // static |
| 656 void OneClickSigninHelper::ShowInfoBarUIThread( | 694 void OneClickSigninHelper::ShowInfoBarUIThread( |
| 657 const std::string& session_index, | 695 const std::string& session_index, |
| 658 const std::string& email, | 696 const std::string& email, |
| 659 AutoAccept auto_accept, | 697 AutoAccept auto_accept, |
| 660 SyncPromoUI::Source source, | 698 SyncPromoUI::Source source, |
| 699 const GURL& continue_url, |
| 661 int child_id, | 700 int child_id, |
| 662 int route_id) { | 701 int route_id) { |
| 663 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 702 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 664 | 703 |
| 665 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, | 704 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, |
| 666 route_id); | 705 route_id); |
| 667 | 706 |
| 668 // TODO(mathp): The appearance of this infobar should be tested using a | 707 // TODO(mathp): The appearance of this infobar should be tested using a |
| 669 // browser_test. | 708 // browser_test. |
| 670 OneClickSigninHelper* helper = | 709 OneClickSigninHelper* helper = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 690 | 729 |
| 691 // Save the email in the one-click signin manager. The manager may | 730 // Save the email in the one-click signin manager. The manager may |
| 692 // not exist if the contents is incognito or if the profile is already | 731 // not exist if the contents is incognito or if the profile is already |
| 693 // connected to a Google account. | 732 // connected to a Google account. |
| 694 if (!session_index.empty()) | 733 if (!session_index.empty()) |
| 695 helper->session_index_ = session_index; | 734 helper->session_index_ = session_index; |
| 696 | 735 |
| 697 if (!email.empty()) | 736 if (!email.empty()) |
| 698 helper->email_ = email; | 737 helper->email_ = email; |
| 699 | 738 |
| 700 if (auto_accept != NO_AUTO_ACCEPT) { | 739 if (auto_accept != AUTO_ACCEPT_NONE) { |
| 701 helper->auto_accept_ = auto_accept; | 740 helper->auto_accept_ = auto_accept; |
| 702 helper->source_ = source; | 741 helper->source_ = source; |
| 703 } | 742 } |
| 743 |
| 744 if (continue_url.is_valid()) { |
| 745 // When Gaia finally redirects to the continue URL, Gaia will add some |
| 746 // extra query parameters. So ignore the parameters when checking to see |
| 747 // if the user has continued. |
| 748 GURL::Replacements replacements; |
| 749 replacements.ClearQuery(); |
| 750 helper->continue_url_ = continue_url.ReplaceComponents(replacements); |
| 751 } |
| 704 } | 752 } |
| 705 | 753 |
| 706 void OneClickSigninHelper::RedirectToNTP() { | 754 void OneClickSigninHelper::RedirectToNTP() { |
| 755 VLOG(1) << "OneClickSigninHelper::RedirectToNTP"; |
| 756 |
| 707 // Redirect to NTP with sign in bubble visible. | 757 // Redirect to NTP with sign in bubble visible. |
| 708 content::WebContents* contents = web_contents(); | 758 content::WebContents* contents = web_contents(); |
| 709 Profile* profile = | 759 Profile* profile = |
| 710 Profile::FromBrowserContext(contents->GetBrowserContext()); | 760 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 711 PrefService* pref_service = profile->GetPrefs(); | 761 PrefService* pref_service = profile->GetPrefs(); |
| 712 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); | 762 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); |
| 713 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_); | 763 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_); |
| 714 | 764 |
| 715 contents->GetController().LoadURL(GURL(chrome::kChromeUINewTabURL), | 765 contents->GetController().LoadURL(GURL(chrome::kChromeUINewTabURL), |
| 716 content::Referrer(), | 766 content::Referrer(), |
| 717 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 767 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 718 std::string()); | 768 std::string()); |
| 719 | 769 |
| 720 error_message_.clear(); | 770 error_message_.clear(); |
| 721 signin_tracker_.reset(); | 771 signin_tracker_.reset(); |
| 722 } | 772 } |
| 723 | 773 |
| 724 void OneClickSigninHelper::CleanTransientState() { | 774 void OneClickSigninHelper::CleanTransientState() { |
| 775 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
| 725 email_.clear(); | 776 email_.clear(); |
| 726 password_.clear(); | 777 password_.clear(); |
| 727 auto_accept_ = NO_AUTO_ACCEPT; | 778 auto_accept_ = AUTO_ACCEPT_NONE; |
| 728 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 779 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
| 780 continue_url_ = GURL(); |
| 729 } | 781 } |
| 730 | 782 |
| 731 void OneClickSigninHelper::DidNavigateAnyFrame( | 783 void OneClickSigninHelper::DidNavigateAnyFrame( |
| 732 const content::LoadCommittedDetails& details, | 784 const content::LoadCommittedDetails& details, |
| 733 const content::FrameNavigateParams& params) { | 785 const content::FrameNavigateParams& params) { |
| 734 // We only need to scrape the password for Gaia logins. | 786 // We only need to scrape the password for Gaia logins. |
| 735 const content::PasswordForm& form = params.password_form; | 787 const content::PasswordForm& form = params.password_form; |
| 736 if (form.origin.is_valid() && | 788 if (form.origin.is_valid() && |
| 737 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { | 789 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { |
| 738 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; | 790 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; |
| 739 password_ = UTF16ToUTF8(params.password_form.password_value); | 791 password_ = UTF16ToUTF8(params.password_form.password_value); |
| 740 } | 792 } |
| 741 } | 793 } |
| 742 | 794 |
| 743 void OneClickSigninHelper::DidStopLoading( | 795 void OneClickSigninHelper::DidStopLoading( |
| 744 content::RenderViewHost* render_view_host) { | 796 content::RenderViewHost* render_view_host) { |
| 745 // If the user left the sign in process, clear all members. | 797 // If the user left the sign in process, clear all members. |
| 746 // TODO(rogerta): might need to allow some youtube URLs. | 798 // TODO(rogerta): might need to allow some youtube URLs. |
| 747 content::WebContents* contents = web_contents(); | 799 content::WebContents* contents = web_contents(); |
| 748 if (!gaia::IsGaiaSignonRealm(contents->GetURL().GetOrigin())) { | 800 const GURL url = contents->GetURL(); |
| 749 CleanTransientState(); | 801 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); |
| 750 return; | |
| 751 } | |
| 752 | 802 |
| 753 if (!error_message_.empty()) { | 803 // If an error has already occured during the sign in flow, make sure to |
| 804 // display it to the user and abort the process. Do this only for |
| 805 // explicit sign ins. |
| 806 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
| 807 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
| 754 RedirectToNTP(); | 808 RedirectToNTP(); |
| 755 return; | 809 return; |
| 756 } | 810 } |
| 757 | 811 |
| 812 // If there is no valid email or password yet, there is nothing to do. |
| 758 if (email_.empty() || password_.empty()) | 813 if (email_.empty() || password_.empty()) |
| 759 return; | 814 return; |
| 760 | 815 |
| 816 // When the user use the firt-run, ntp, or hotdog menu to sign in, then have |
| 817 // the option of checking the the box "Let me choose what to sync". When the |
| 818 // sign in process started, the source parameter in the continue URL may have |
| 819 // indicated one of the three options above. However, once this box is |
| 820 // checked, the source parameter will indicate settings. This will only be |
| 821 // comminucated back to chrome when Gaia redirects to the continue URL, and |
| 822 // this is considered here a last minute change to the source. See a little |
| 823 // further below for when this variable is set to true. |
| 824 bool last_minute_source_change = false; |
| 825 |
| 826 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 827 if (IsValidGaiaSigninRedirectOrResponseURL(url)) |
| 828 return; |
| 829 |
| 830 // During an explicit sign in, if the user has not yet reached the final |
| 831 // continue URL, wait for it to arrive. Note that Gaia will add some extra |
| 832 // query parameters to the continue URL. Ignore them when checking to |
| 833 // see if the user has continued. |
| 834 // |
| 835 // If this is not an explicit sign in, we don't need to check if we landed |
| 836 // on the right continue URL. This is important because the continue URL |
| 837 // may itself lead to a redirect, which means this function will never see |
| 838 // the continue URL go by. |
| 839 if (auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
| 840 DCHECK(source_ != SyncPromoUI::SOURCE_UNKNOWN); |
| 841 GURL::Replacements replacements; |
| 842 replacements.ClearQuery(); |
| 843 const bool continue_url_match = |
| 844 url.ReplaceComponents(replacements) == continue_url_; |
| 845 if (!continue_url_match) { |
| 846 VLOG(1) << "OneClickSigninHelper::DidStopLoading: invalid url='" |
| 847 << url.spec() |
| 848 << "' expected continue url=" << continue_url_; |
| 849 CleanTransientState(); |
| 850 return; |
| 851 } |
| 852 |
| 853 // In explicit sign ins, the user may have checked the box |
| 854 // "Let me choose what to sync". This is reflected as a change in the |
| 855 // source of the continue URL. Make one last check of the current URL |
| 856 // to see if there is a valid source and its set to settings. If so, |
| 857 // it overrides the current source. |
| 858 SyncPromoUI::Source source = |
| 859 SyncPromoUI::GetSourceForSyncPromoURL(url); |
| 860 if (source == SyncPromoUI::SOURCE_SETTINGS) { |
| 861 source_ = SyncPromoUI::SOURCE_SETTINGS; |
| 862 last_minute_source_change = true; |
| 863 } |
| 864 } |
| 865 } |
| 866 |
| 761 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 867 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 868 Profile* profile = |
| 869 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 762 InfoBarTabHelper* infobar_tab_helper = | 870 InfoBarTabHelper* infobar_tab_helper = |
| 763 InfoBarTabHelper::FromWebContents(contents); | 871 InfoBarTabHelper::FromWebContents(contents); |
| 764 | 872 |
| 873 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." |
| 874 << " auto_accept=" << auto_accept_ |
| 875 << " source=" << source_; |
| 876 |
| 765 switch (auto_accept_) { | 877 switch (auto_accept_) { |
| 766 case AUTO_ACCEPT: | 878 case AUTO_ACCEPT_NONE: |
| 879 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 880 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", |
| 881 one_click_signin::HISTOGRAM_DISMISSED, |
| 882 one_click_signin::HISTOGRAM_MAX); |
| 883 } else { |
| 884 infobar_tab_helper->AddInfoBar( |
| 885 new OneClickInfoBarDelegateImpl(infobar_tab_helper, session_index_, |
| 886 email_, password_)); |
| 887 } |
| 888 break; |
| 889 case AUTO_ACCEPT_ACCEPTED: |
| 890 SigninManager::DisableOneClickSignIn(profile); |
| 767 browser->window()->ShowOneClickSigninBubble( | 891 browser->window()->ShowOneClickSigninBubble( |
| 768 base::Bind(&StartSync, browser, auto_accept_, session_index_, | 892 base::Bind(&StartSync, browser, auto_accept_, session_index_, |
| 769 email_, password_)); | 893 email_, password_)); |
| 770 break; | 894 break; |
| 771 case NO_AUTO_ACCEPT: | |
| 772 infobar_tab_helper->AddInfoBar( | |
| 773 new OneClickInfoBarDelegateImpl(infobar_tab_helper, session_index_, | |
| 774 email_, password_)); | |
| 775 break; | |
| 776 case AUTO_ACCEPT_CONFIGURE: | 895 case AUTO_ACCEPT_CONFIGURE: |
| 896 SigninManager::DisableOneClickSignIn(profile); |
| 777 StartSync(browser, auto_accept_, session_index_, email_, password_, | 897 StartSync(browser, auto_accept_, session_index_, email_, password_, |
| 778 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 898 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 779 break; | 899 break; |
| 780 case AUTO_ACCEPT_EXPLICIT: | 900 case AUTO_ACCEPT_EXPLICIT: |
| 781 StartSync(browser, auto_accept_, session_index_, email_, password_, | 901 StartSync(browser, auto_accept_, session_index_, email_, password_, |
| 782 source_ == SyncPromoUI::SOURCE_SETTINGS ? | 902 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
| 783 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 903 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
| 784 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 904 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 905 |
| 906 // If this was a last minute switch to the settings page, this means the |
| 907 // started with first-run/NTP/wrench menu, and checked the "configure |
| 908 // first" checkbox. Replace the default blank continue page with an |
| 909 // about:blank page, so that when the settings page is displayed, it |
| 910 // reuses the tab. |
| 911 if (last_minute_source_change) { |
| 912 contents->GetController().LoadURL( |
| 913 GURL("about:blank"), content::Referrer(), |
| 914 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 915 } |
| 785 break; | 916 break; |
| 786 case REJECTED_FOR_PROFILE: | 917 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
| 918 AddEmailToOneClickRejectedList(profile, email_); |
| 787 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", | 919 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", |
| 788 one_click_signin::HISTOGRAM_REJECTED, | 920 one_click_signin::HISTOGRAM_REJECTED, |
| 789 one_click_signin::HISTOGRAM_MAX); | 921 one_click_signin::HISTOGRAM_MAX); |
| 790 break; | 922 break; |
| 791 default: | 923 default: |
| 792 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 924 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
| 793 break; | 925 break; |
| 794 } | 926 } |
| 795 | 927 |
| 796 // If this explicit sign in is not from settings page, show the NTP after | 928 // If this explicit sign in is not from settings page, show the NTP after |
| 797 // sign in completes. In the case of the settings page, it will get closed | 929 // sign in completes. In the case of the settings page, it will get closed |
| 798 // by SyncSetupHandler. | 930 // by SyncSetupHandler. |
| 799 if (auto_accept_ == AUTO_ACCEPT_EXPLICIT && | 931 if (auto_accept_ == AUTO_ACCEPT_EXPLICIT && |
| 800 source_ != SyncPromoUI::SOURCE_SETTINGS) { | 932 source_ != SyncPromoUI::SOURCE_SETTINGS) { |
| 801 Profile* profile = | |
| 802 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
| 803 signin_tracker_.reset(new SigninTracker(profile, this)); | 933 signin_tracker_.reset(new SigninTracker(profile, this)); |
| 804 } | 934 } |
| 805 | 935 |
| 806 CleanTransientState(); | 936 CleanTransientState(); |
| 807 } | 937 } |
| 808 | 938 |
| 809 void OneClickSigninHelper::GaiaCredentialsValid() { | 939 void OneClickSigninHelper::GaiaCredentialsValid() { |
| 810 } | 940 } |
| 811 | 941 |
| 812 void OneClickSigninHelper::SigninFailed(const GoogleServiceAuthError& error) { | 942 void OneClickSigninHelper::SigninFailed(const GoogleServiceAuthError& error) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 826 break; | 956 break; |
| 827 } | 957 } |
| 828 } | 958 } |
| 829 | 959 |
| 830 RedirectToNTP(); | 960 RedirectToNTP(); |
| 831 } | 961 } |
| 832 | 962 |
| 833 void OneClickSigninHelper::SigninSuccess() { | 963 void OneClickSigninHelper::SigninSuccess() { |
| 834 RedirectToNTP(); | 964 RedirectToNTP(); |
| 835 } | 965 } |
| OLD | NEW |