| 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/metrics/field_trial.h" |
| 10 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/api/infobars/one_click_signin_infobar_delegate.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/defaults.h" |
| 14 #include "chrome/browser/infobars/infobar_tab_helper.h" | 16 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_info_cache.h" | 20 #include "chrome/browser/profiles/profile_info_cache.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/signin/signin_manager.h" | 22 #include "chrome/browser/signin/signin_manager.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
| 23 #include "chrome/browser/tab_contents/tab_util.h" | 25 #include "chrome/browser/tab_contents/tab_util.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 28 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
| 27 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 29 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 28 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 31 #include "chrome/common/chrome_version_info.h" |
| 29 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 31 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/page_navigator.h" | 35 #include "content/public/browser/page_navigator.h" |
| 33 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/browser/web_contents_view.h" | 37 #include "content/public/browser/web_contents_view.h" |
| 35 #include "content/public/common/frame_navigate_params.h" | 38 #include "content/public/common/frame_navigate_params.h" |
| 36 #include "content/public/common/page_transition_types.h" | 39 #include "content/public/common/page_transition_types.h" |
| 37 #include "googleurl/src/gurl.h" | 40 #include "googleurl/src/gurl.h" |
| 38 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
| 39 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| 40 #include "grit/theme_resources.h" | 43 #include "grit/theme_resources.h" |
| 41 #include "net/cookies/cookie_monster.h" | 44 #include "net/cookies/cookie_monster.h" |
| 42 #include "net/url_request/url_request.h" | 45 #include "net/url_request/url_request.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "webkit/forms/password_form.h" | 48 #include "webkit/forms/password_form.h" |
| 46 #include "webkit/forms/password_form_dom_manager.h" | 49 #include "webkit/forms/password_form_dom_manager.h" |
| 47 | 50 |
| 51 namespace { |
| 52 |
| 53 // Set to true if this chrome instance is in the blue-button-on-white-bar |
| 54 // experimental group. |
| 55 bool use_blue_on_white = false; |
| 56 |
| 57 // Start syncing with the given user information. |
| 58 void StartSync(content::WebContents* web_contents, |
| 59 const std::string& session_index, |
| 60 const std::string& email, |
| 61 const std::string& password, |
| 62 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 63 // The starter deletes itself once its done. |
| 64 Browser* browser = browser::FindBrowserWithWebContents(web_contents); |
| 65 new OneClickSigninSyncStarter(browser, session_index, email, password, |
| 66 start_mode); |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
| 48 // The infobar asking the user if they want to use one-click sign in. | 71 // The infobar asking the user if they want to use one-click sign in. |
| 49 class OneClickLoginInfoBarDelegate : public ConfirmInfoBarDelegate { | 72 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { |
| 50 public: | 73 public: |
| 51 OneClickLoginInfoBarDelegate(InfoBarTabHelper* owner, | 74 OneClickInfoBarDelegateImpl(InfoBarTabHelper* owner, |
| 52 const std::string& session_index, | 75 const std::string& session_index, |
| 53 const std::string& email, | 76 const std::string& email, |
| 54 const std::string& password); | 77 const std::string& password); |
| 55 virtual ~OneClickLoginInfoBarDelegate(); | 78 virtual ~OneClickInfoBarDelegateImpl(); |
| 56 | 79 |
| 57 private: | 80 private: |
| 58 // ConfirmInfoBarDelegate overrides. | 81 // InfoBarDelegate overrides. |
| 82 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; |
| 59 virtual void InfoBarDismissed() OVERRIDE; | 83 virtual void InfoBarDismissed() OVERRIDE; |
| 60 virtual gfx::Image* GetIcon() const OVERRIDE; | 84 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 61 virtual Type GetInfoBarType() const OVERRIDE; | 85 virtual Type GetInfoBarType() const OVERRIDE; |
| 62 virtual string16 GetMessageText() const OVERRIDE; | 86 virtual string16 GetMessageText() const OVERRIDE; |
| 87 |
| 88 // ConfirmInfoBarDelegate overrides. |
| 63 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 89 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 64 virtual bool Accept() OVERRIDE; | 90 virtual bool Accept() OVERRIDE; |
| 65 virtual bool Cancel() OVERRIDE; | 91 virtual bool Cancel() OVERRIDE; |
| 66 virtual string16 GetLinkText() const OVERRIDE; | 92 virtual string16 GetLinkText() const OVERRIDE; |
| 67 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | 93 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 68 | 94 |
| 69 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; | 95 // OneClickSigninInfoBarDelegate overrides. |
| 96 virtual void GetAlternateColors(AlternateColors* alt_colors) OVERRIDE; |
| 70 | 97 |
| 71 // Set the profile preference to turn off one-click sign in so that it won't | 98 // Set the profile preference to turn off one-click sign in so that it won't |
| 72 // show again in this profile. | 99 // show again in this profile. |
| 73 void DisableOneClickSignIn(); | 100 void DisableOneClickSignIn(); |
| 74 | 101 |
| 75 // Add a specific email to the list of emails rejected for one-click | 102 // Add a specific email to the list of emails rejected for one-click |
| 76 // sign-in, for this profile. | 103 // sign-in, for this profile. |
| 77 void AddEmailToOneClickRejectedList(const std::string& email); | 104 void AddEmailToOneClickRejectedList(const std::string& email); |
| 78 | 105 |
| 79 // Record the specified action in the histogram for one-click sign in. | 106 // Record the specified action in the histogram for one-click sign in. |
| 80 void RecordHistogramAction(int action); | 107 void RecordHistogramAction(int action); |
| 81 | 108 |
| 82 // Information about the account that has just logged in. | 109 // Information about the account that has just logged in. |
| 83 std::string session_index_; | 110 std::string session_index_; |
| 84 std::string email_; | 111 std::string email_; |
| 85 std::string password_; | 112 std::string password_; |
| 86 | 113 |
| 87 // Whether any UI controls in the infobar were pressed or not. | 114 // Whether any UI controls in the infobar were pressed or not. |
| 88 bool button_pressed_; | 115 bool button_pressed_; |
| 89 | 116 |
| 90 DISALLOW_COPY_AND_ASSIGN(OneClickLoginInfoBarDelegate); | 117 DISALLOW_COPY_AND_ASSIGN(OneClickInfoBarDelegateImpl); |
| 91 }; | 118 }; |
| 92 | 119 |
| 93 OneClickLoginInfoBarDelegate::OneClickLoginInfoBarDelegate( | 120 OneClickInfoBarDelegateImpl::OneClickInfoBarDelegateImpl( |
| 94 InfoBarTabHelper* owner, | 121 InfoBarTabHelper* owner, |
| 95 const std::string& session_index, | 122 const std::string& session_index, |
| 96 const std::string& email, | 123 const std::string& email, |
| 97 const std::string& password) | 124 const std::string& password) |
| 98 : ConfirmInfoBarDelegate(owner), | 125 : OneClickSigninInfoBarDelegate(owner), |
| 99 session_index_(session_index), | 126 session_index_(session_index), |
| 100 email_(email), | 127 email_(email), |
| 101 password_(password), | 128 password_(password), |
| 102 button_pressed_(false) { | 129 button_pressed_(false) { |
| 103 RecordHistogramAction(one_click_signin::HISTOGRAM_SHOWN); | 130 RecordHistogramAction(one_click_signin::HISTOGRAM_SHOWN); |
| 104 } | 131 } |
| 105 | 132 |
| 106 OneClickLoginInfoBarDelegate::~OneClickLoginInfoBarDelegate() { | 133 OneClickInfoBarDelegateImpl::~OneClickInfoBarDelegateImpl() { |
| 107 if (!button_pressed_) | 134 if (!button_pressed_) |
| 108 RecordHistogramAction(one_click_signin::HISTOGRAM_IGNORED); | 135 RecordHistogramAction(one_click_signin::HISTOGRAM_IGNORED); |
| 109 } | 136 } |
| 110 | 137 |
| 111 void OneClickLoginInfoBarDelegate::InfoBarDismissed() { | 138 InfoBarDelegate::InfoBarAutomationType |
| 139 OneClickInfoBarDelegateImpl::GetInfoBarAutomationType() const { |
| 140 return ONE_CLICK_LOGIN_INFOBAR; |
| 141 } |
| 142 |
| 143 void OneClickInfoBarDelegateImpl::InfoBarDismissed() { |
| 112 RecordHistogramAction(one_click_signin::HISTOGRAM_DISMISSED); | 144 RecordHistogramAction(one_click_signin::HISTOGRAM_DISMISSED); |
| 113 button_pressed_ = true; | 145 button_pressed_ = true; |
| 114 } | 146 } |
| 115 | 147 |
| 116 gfx::Image* OneClickLoginInfoBarDelegate::GetIcon() const { | 148 gfx::Image* OneClickInfoBarDelegateImpl::GetIcon() const { |
| 117 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 149 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 118 IDR_INFOBAR_SYNC); | 150 IDR_INFOBAR_SYNC); |
| 119 } | 151 } |
| 120 | 152 |
| 121 InfoBarDelegate::Type OneClickLoginInfoBarDelegate::GetInfoBarType() const { | 153 InfoBarDelegate::Type OneClickInfoBarDelegateImpl::GetInfoBarType() const { |
| 122 return PAGE_ACTION_TYPE; | 154 return PAGE_ACTION_TYPE; |
| 123 } | 155 } |
| 124 | 156 |
| 125 string16 OneClickLoginInfoBarDelegate::GetMessageText() const { | 157 string16 OneClickInfoBarDelegateImpl::GetMessageText() const { |
| 126 return l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_INFOBAR_MESSAGE); | 158 return l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_INFOBAR_MESSAGE); |
| 127 } | 159 } |
| 128 | 160 |
| 129 string16 OneClickLoginInfoBarDelegate::GetButtonLabel( | 161 string16 OneClickInfoBarDelegateImpl::GetButtonLabel( |
| 130 InfoBarButton button) const { | 162 InfoBarButton button) const { |
| 131 return l10n_util::GetStringUTF16( | 163 return l10n_util::GetStringUTF16( |
| 132 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON | 164 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON |
| 133 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); | 165 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); |
| 134 } | 166 } |
| 135 | 167 |
| 136 namespace { | 168 bool OneClickInfoBarDelegateImpl::Accept() { |
| 137 | |
| 138 // Start syncing with the given user information. | |
| 139 void StartSync(content::WebContents* web_contents, | |
| 140 const std::string& session_index, | |
| 141 const std::string& email, | |
| 142 const std::string& password, | |
| 143 OneClickSigninSyncStarter::StartSyncMode start_mode) { | |
| 144 // The starter deletes itself once its done. | |
| 145 Browser* browser = browser::FindBrowserWithWebContents(web_contents); | |
| 146 new OneClickSigninSyncStarter(browser, session_index, email, password, | |
| 147 start_mode); | |
| 148 } | |
| 149 | |
| 150 } // namespace | |
| 151 | |
| 152 bool OneClickLoginInfoBarDelegate::Accept() { | |
| 153 // User has accepted one-click sign-in for this account. Never ask again for | 169 // User has accepted one-click sign-in for this account. Never ask again for |
| 154 // this profile. | 170 // this profile. |
| 155 DisableOneClickSignIn(); | 171 DisableOneClickSignIn(); |
| 156 content::WebContents* web_contents = owner()->GetWebContents(); | 172 content::WebContents* web_contents = owner()->GetWebContents(); |
| 157 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 173 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
| 158 browser::FindBrowserWithWebContents(web_contents)->window()-> | 174 browser::FindBrowserWithWebContents(web_contents)->window()-> |
| 159 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents, | 175 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents, |
| 160 session_index_, email_, password_)); | 176 session_index_, email_, password_)); |
| 161 button_pressed_ = true; | 177 button_pressed_ = true; |
| 162 return true; | 178 return true; |
| 163 } | 179 } |
| 164 | 180 |
| 165 bool OneClickLoginInfoBarDelegate::Cancel() { | 181 bool OneClickInfoBarDelegateImpl::Cancel() { |
| 166 AddEmailToOneClickRejectedList(email_); | 182 AddEmailToOneClickRejectedList(email_); |
| 167 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 183 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
| 168 button_pressed_ = true; | 184 button_pressed_ = true; |
| 169 return true; | 185 return true; |
| 170 } | 186 } |
| 171 | 187 |
| 172 string16 OneClickLoginInfoBarDelegate::GetLinkText() const { | 188 string16 OneClickInfoBarDelegateImpl::GetLinkText() const { |
| 173 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 189 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 174 } | 190 } |
| 175 | 191 |
| 176 bool OneClickLoginInfoBarDelegate::LinkClicked( | 192 bool OneClickInfoBarDelegateImpl::LinkClicked( |
| 177 WindowOpenDisposition disposition) { | 193 WindowOpenDisposition disposition) { |
| 178 RecordHistogramAction(one_click_signin::HISTOGRAM_LEARN_MORE); | 194 RecordHistogramAction(one_click_signin::HISTOGRAM_LEARN_MORE); |
| 179 content::OpenURLParams params( | 195 content::OpenURLParams params( |
| 180 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), disposition, | 196 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), disposition, |
| 181 content::PAGE_TRANSITION_LINK, false); | 197 content::PAGE_TRANSITION_LINK, false); |
| 182 owner()->GetWebContents()->OpenURL(params); | 198 owner()->GetWebContents()->OpenURL(params); |
| 183 return false; | 199 return false; |
| 184 } | 200 } |
| 185 | 201 |
| 202 void OneClickInfoBarDelegateImpl::GetAlternateColors( |
| 203 AlternateColors* alt_colors) { |
| 204 if (use_blue_on_white) { |
| 205 alt_colors->enabled = true; |
| 206 alt_colors->infobar_bottom_color = SK_ColorWHITE; |
| 207 alt_colors->infobar_top_color = SK_ColorWHITE; |
| 208 alt_colors->button_text_color = SK_ColorWHITE; |
| 209 alt_colors->button_background_color = SkColorSetRGB(71, 135, 237); |
| 210 alt_colors->button_border_color = SkColorSetRGB(48, 121, 237); |
| 211 return; |
| 212 } |
| 186 | 213 |
| 187 InfoBarDelegate::InfoBarAutomationType | 214 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); |
| 188 OneClickLoginInfoBarDelegate::GetInfoBarAutomationType() const { | |
| 189 return ONE_CLICK_LOGIN_INFOBAR; | |
| 190 } | 215 } |
| 191 | 216 |
| 192 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { | 217 void OneClickInfoBarDelegateImpl::DisableOneClickSignIn() { |
| 193 PrefService* pref_service = | 218 PrefService* pref_service = |
| 194 TabContents::FromWebContents(owner()->GetWebContents())-> | 219 TabContents::FromWebContents(owner()->GetWebContents())-> |
| 195 profile()->GetPrefs(); | 220 profile()->GetPrefs(); |
| 196 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); | 221 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); |
| 197 } | 222 } |
| 198 | 223 |
| 199 void OneClickLoginInfoBarDelegate::AddEmailToOneClickRejectedList( | 224 void OneClickInfoBarDelegateImpl::AddEmailToOneClickRejectedList( |
| 200 const std::string& email) { | 225 const std::string& email) { |
| 201 PrefService* pref_service = | 226 PrefService* pref_service = |
| 202 TabContents::FromWebContents(owner()->GetWebContents())-> | 227 TabContents::FromWebContents(owner()->GetWebContents())-> |
| 203 profile()->GetPrefs(); | 228 profile()->GetPrefs(); |
| 204 ListPrefUpdate updater(pref_service, | 229 ListPrefUpdate updater(pref_service, |
| 205 prefs::kReverseAutologinRejectedEmailList); | 230 prefs::kReverseAutologinRejectedEmailList); |
| 206 updater->AppendIfNotPresent(base::Value::CreateStringValue(email)); | 231 updater->AppendIfNotPresent(base::Value::CreateStringValue(email)); |
| 207 } | 232 } |
| 208 | 233 |
| 209 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) { | 234 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { |
| 210 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 235 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
| 211 one_click_signin::HISTOGRAM_MAX); | 236 one_click_signin::HISTOGRAM_MAX); |
| 212 } | 237 } |
| 213 | 238 |
| 239 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
| 240 : content::WebContentsObserver(web_contents) { |
| 241 } |
| 242 |
| 243 OneClickSigninHelper::~OneClickSigninHelper() { |
| 244 } |
| 245 |
| 214 // static | 246 // static |
| 215 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 247 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
| 216 const std::string& email, | 248 const std::string& email, |
| 217 bool check_connected) { | 249 bool check_connected) { |
| 218 if (!web_contents) | 250 if (!web_contents) |
| 219 return false; | 251 return false; |
| 220 | 252 |
| 221 if (web_contents->GetBrowserContext()->IsOffTheRecord()) | 253 if (web_contents->GetBrowserContext()->IsOffTheRecord()) |
| 222 return false; | 254 return false; |
| 223 | 255 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 if (iter != rejected_emails->end()) | 306 if (iter != rejected_emails->end()) |
| 275 return false; | 307 return false; |
| 276 } | 308 } |
| 277 } | 309 } |
| 278 } | 310 } |
| 279 | 311 |
| 280 return true; | 312 return true; |
| 281 } | 313 } |
| 282 | 314 |
| 283 // static | 315 // static |
| 316 void OneClickSigninHelper::InitializeFieldTrial() { |
| 317 scoped_refptr<base::FieldTrial> trial( |
| 318 base::FieldTrialList::FactoryGetFieldTrial("OneClickSignIn", 100, |
| 319 "Standard", 2013, 9, 1, NULL)); |
| 320 |
| 321 // For dev and beta, we'll give half the people the new experience. For |
| 322 // stable, only 1%. These numbers are overridable on the server. |
| 323 const bool kIsStableChannel = |
| 324 chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_STABLE; |
| 325 const int kBlueOnWhiteGroup = trial->AppendGroup("BlueOnWhite", |
| 326 kIsStableChannel ? 1 : 50); |
| 327 use_blue_on_white = trial->group() == kBlueOnWhiteGroup; |
| 328 } |
| 329 |
| 330 // static |
| 284 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request, | 331 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request, |
| 285 int child_id, | 332 int child_id, |
| 286 int route_id) { | 333 int route_id) { |
| 287 // See if the response contains the Google-Accounts-SignIn header. | 334 // See if the response contains the Google-Accounts-SignIn header. |
| 288 std::string value; | 335 std::string value; |
| 289 request->GetResponseHeaderByName("Google-Accounts-SignIn", &value); | 336 request->GetResponseHeaderByName("Google-Accounts-SignIn", &value); |
| 290 if (value.empty()) | 337 if (value.empty()) |
| 291 return; | 338 return; |
| 292 | 339 |
| 293 std::vector<std::pair<std::string, std::string> > pairs; | 340 std::vector<std::pair<std::string, std::string> > pairs; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 308 | 355 |
| 309 if (email.empty() || session_index.empty()) | 356 if (email.empty() || session_index.empty()) |
| 310 return; | 357 return; |
| 311 | 358 |
| 312 content::BrowserThread::PostTask( | 359 content::BrowserThread::PostTask( |
| 313 content::BrowserThread::UI, FROM_HERE, | 360 content::BrowserThread::UI, FROM_HERE, |
| 314 base::Bind(&OneClickSigninHelper::ShowInfoBarUIThread, session_index, | 361 base::Bind(&OneClickSigninHelper::ShowInfoBarUIThread, session_index, |
| 315 email, child_id, route_id)); | 362 email, child_id, route_id)); |
| 316 } | 363 } |
| 317 | 364 |
| 318 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | |
| 319 : content::WebContentsObserver(web_contents) { | |
| 320 } | |
| 321 | |
| 322 OneClickSigninHelper::~OneClickSigninHelper() { | |
| 323 } | |
| 324 | |
| 325 // static | 365 // static |
| 326 void OneClickSigninHelper::ShowInfoBarUIThread( | 366 void OneClickSigninHelper::ShowInfoBarUIThread( |
| 327 const std::string& session_index, | 367 const std::string& session_index, |
| 328 const std::string& email, | 368 const std::string& email, |
| 329 int child_id, | 369 int child_id, |
| 330 int route_id) { | 370 int route_id) { |
| 331 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 371 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 332 | 372 |
| 333 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, | 373 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, |
| 334 route_id); | 374 route_id); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 358 } | 398 } |
| 359 | 399 |
| 360 void OneClickSigninHelper::DidStopLoading( | 400 void OneClickSigninHelper::DidStopLoading( |
| 361 content::RenderViewHost* render_view_host) { | 401 content::RenderViewHost* render_view_host) { |
| 362 if (email_.empty() || password_.empty()) | 402 if (email_.empty() || password_.empty()) |
| 363 return; | 403 return; |
| 364 | 404 |
| 365 TabContents* tab_contents = TabContents::FromWebContents(web_contents()); | 405 TabContents* tab_contents = TabContents::FromWebContents(web_contents()); |
| 366 | 406 |
| 367 tab_contents->infobar_tab_helper()->AddInfoBar( | 407 tab_contents->infobar_tab_helper()->AddInfoBar( |
| 368 new OneClickLoginInfoBarDelegate(tab_contents->infobar_tab_helper(), | 408 new OneClickInfoBarDelegateImpl(tab_contents->infobar_tab_helper(), |
| 369 session_index_, email_, password_)); | 409 session_index_, email_, password_)); |
| 370 | 410 |
| 371 email_.clear(); | 411 email_.clear(); |
| 372 password_.clear(); | 412 password_.clear(); |
| 373 } | 413 } |
| 374 | 414 |
| 375 void OneClickSigninHelper::SaveSessionIndexAndEmail( | 415 void OneClickSigninHelper::SaveSessionIndexAndEmail( |
| 376 const std::string& session_index, | 416 const std::string& session_index, |
| 377 const std::string& email) { | 417 const std::string& email) { |
| 378 session_index_ = session_index; | 418 session_index_ = session_index; |
| 379 email_ = email; | 419 email_ = email; |
| 380 } | 420 } |
| 381 | 421 |
| 382 void OneClickSigninHelper::SavePassword(const std::string& password) { | 422 void OneClickSigninHelper::SavePassword(const std::string& password) { |
| 383 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of | 423 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of |
| 384 // challenge, its possible for the user to never complete the signin. | 424 // challenge, its possible for the user to never complete the signin. |
| 385 // Should have a way to detect this and clear the password member. | 425 // Should have a way to detect this and clear the password member. |
| 386 password_ = password; | 426 password_ = password; |
| 387 } | 427 } |
| OLD | NEW |