| 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/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_info_cache.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/signin/signin_manager.h" | 18 #include "chrome/browser/signin/signin_manager.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 22 #include "chrome/browser/tab_contents/tab_util.h" | 22 #include "chrome/browser/tab_contents/tab_util.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/browser/ui/sync/one_click_signin_dialog.h" | |
| 26 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 25 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
| 27 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 26 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/page_navigator.h" | 31 #include "content/public/browser/page_navigator.h" |
| 33 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/browser/web_contents_view.h" | 33 #include "content/public/browser/web_contents_view.h" |
| 35 #include "content/public/common/frame_navigate_params.h" | 34 #include "content/public/common/frame_navigate_params.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 // ConfirmInfoBarDelegate overrides. | 57 // ConfirmInfoBarDelegate overrides. |
| 59 virtual void InfoBarDismissed() OVERRIDE; | 58 virtual void InfoBarDismissed() OVERRIDE; |
| 60 virtual gfx::Image* GetIcon() const OVERRIDE; | 59 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 61 virtual Type GetInfoBarType() const OVERRIDE; | 60 virtual Type GetInfoBarType() const OVERRIDE; |
| 62 virtual string16 GetMessageText() const OVERRIDE; | 61 virtual string16 GetMessageText() const OVERRIDE; |
| 63 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 62 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 64 virtual bool Accept() OVERRIDE; | 63 virtual bool Accept() OVERRIDE; |
| 65 virtual bool Cancel() OVERRIDE; | 64 virtual bool Cancel() OVERRIDE; |
| 65 virtual string16 GetLinkText() const OVERRIDE; |
| 66 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 66 | 67 |
| 67 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; | 68 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; |
| 68 | 69 |
| 69 // Set the profile preference to turn off one-click sign in so that it won't | 70 // Set the profile preference to turn off one-click sign in so that it won't |
| 70 // show again in this profile. | 71 // show again in this profile. |
| 71 void DisableOneClickSignIn(); | 72 void DisableOneClickSignIn(); |
| 72 | 73 |
| 73 // Record the specified action in the histogram for one-click sign in. | 74 // Record the specified action in the histogram for one-click sign in. |
| 74 void RecordHistogramAction(int action); | 75 void RecordHistogramAction(int action); |
| 75 | 76 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 123 |
| 123 string16 OneClickLoginInfoBarDelegate::GetButtonLabel( | 124 string16 OneClickLoginInfoBarDelegate::GetButtonLabel( |
| 124 InfoBarButton button) const { | 125 InfoBarButton button) const { |
| 125 return l10n_util::GetStringUTF16( | 126 return l10n_util::GetStringUTF16( |
| 126 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON | 127 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON |
| 127 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); | 128 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); |
| 128 } | 129 } |
| 129 | 130 |
| 130 namespace { | 131 namespace { |
| 131 | 132 |
| 132 void OnLearnMore(Browser* browser) { | |
| 133 browser->AddSelectedTabWithURL( | |
| 134 GURL(chrome::kSyncLearnMoreURL), | |
| 135 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 136 } | |
| 137 | |
| 138 void OnAdvanced(Browser* browser) { | |
| 139 browser->AddSelectedTabWithURL( | |
| 140 GURL(std::string(chrome::kChromeUISettingsURL) + | |
| 141 chrome::kSyncSetupSubPage), | |
| 142 content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 143 } | |
| 144 | |
| 145 // Start syncing with the given user information. | 133 // Start syncing with the given user information. |
| 146 void StartSync(content::WebContents* web_contents, | 134 void StartSync(content::WebContents* web_contents, |
| 147 const std::string& session_index, | 135 const std::string& session_index, |
| 148 const std::string& email, | 136 const std::string& email, |
| 149 const std::string& password, | 137 const std::string& password, |
| 150 bool use_default_settings) { | 138 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 151 // The starter deletes itself once its done. | 139 // The starter deletes itself once its done. |
| 152 Profile* profile = | 140 Profile* profile = |
| 153 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 141 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 154 ignore_result( | 142 ignore_result( |
| 155 new OneClickSigninSyncStarter( | 143 new OneClickSigninSyncStarter( |
| 156 profile, session_index, email, password, use_default_settings)); | 144 profile, session_index, email, password, start_mode)); |
| 157 | |
| 158 Browser* browser = browser::FindBrowserWithWebContents(web_contents); | |
| 159 browser->window()->ShowOneClickSigninBubble( | |
| 160 base::Bind(&OnLearnMore, base::Unretained(browser)), | |
| 161 base::Bind(&OnAdvanced, base::Unretained(browser))); | |
| 162 } | 145 } |
| 163 | 146 |
| 164 } // namespace | 147 } // namespace |
| 165 | 148 |
| 166 bool OneClickLoginInfoBarDelegate::Accept() { | 149 bool OneClickLoginInfoBarDelegate::Accept() { |
| 167 DisableOneClickSignIn(); | 150 DisableOneClickSignIn(); |
| 151 content::WebContents* web_contents = owner()->web_contents(); |
| 168 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 152 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
| 169 ShowOneClickSigninDialog( | 153 Browser* browser = browser::FindBrowserWithWebContents(web_contents); |
| 170 owner()->web_contents()->GetView()->GetTopLevelNativeWindow(), | 154 browser->window()->ShowOneClickSigninBubble( |
| 171 base::Bind(&StartSync, owner()->web_contents(), session_index_, email_, | 155 base::Bind(&StartSync, web_contents, session_index_, email_, |
| 172 password_)); | 156 password_)); |
| 173 button_pressed_ = true; | 157 button_pressed_ = true; |
| 174 return true; | 158 return true; |
| 175 } | 159 } |
| 176 | 160 |
| 177 bool OneClickLoginInfoBarDelegate::Cancel() { | 161 bool OneClickLoginInfoBarDelegate::Cancel() { |
| 178 DisableOneClickSignIn(); | 162 DisableOneClickSignIn(); |
| 179 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 163 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
| 180 button_pressed_ = true; | 164 button_pressed_ = true; |
| 181 return true; | 165 return true; |
| 182 } | 166 } |
| 183 | 167 |
| 168 string16 OneClickLoginInfoBarDelegate::GetLinkText() const { |
| 169 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 170 } |
| 171 |
| 172 bool OneClickLoginInfoBarDelegate::LinkClicked( |
| 173 WindowOpenDisposition disposition) { |
| 174 RecordHistogramAction(one_click_signin::HISTOGRAM_LEARN_MORE); |
| 175 content::OpenURLParams params( |
| 176 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), disposition, |
| 177 // Pretend the user typed this URL, so that navigating to |
| 178 // it will be the default action when it's typed again in |
| 179 // the future. |
| 180 content::PAGE_TRANSITION_TYPED, |
| 181 false); |
| 182 owner()->web_contents()->OpenURL(params); |
| 183 |
| 184 // We should always close, even if the navigation did not occur within this |
| 185 // WebContents. |
| 186 return true; |
| 187 } |
| 188 |
| 189 |
| 184 InfoBarDelegate::InfoBarAutomationType | 190 InfoBarDelegate::InfoBarAutomationType |
| 185 OneClickLoginInfoBarDelegate::GetInfoBarAutomationType() const { | 191 OneClickLoginInfoBarDelegate::GetInfoBarAutomationType() const { |
| 186 return ONE_CLICK_LOGIN_INFOBAR; | 192 return ONE_CLICK_LOGIN_INFOBAR; |
| 187 } | 193 } |
| 188 | 194 |
| 189 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { | 195 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { |
| 190 PrefService* pref_service = | 196 PrefService* pref_service = |
| 191 TabContentsWrapper::GetCurrentWrapperForContents( | 197 TabContentsWrapper::GetCurrentWrapperForContents( |
| 192 owner()->web_contents())->profile()->GetPrefs(); | 198 owner()->web_contents())->profile()->GetPrefs(); |
| 193 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); | 199 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 session_index_ = session_index; | 351 session_index_ = session_index; |
| 346 email_ = email; | 352 email_ = email; |
| 347 } | 353 } |
| 348 | 354 |
| 349 void OneClickSigninHelper::SavePassword(const std::string& password) { | 355 void OneClickSigninHelper::SavePassword(const std::string& password) { |
| 350 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of | 356 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of |
| 351 // challenge, its possible for the user to never complete the signin. | 357 // challenge, its possible for the user to never complete the signin. |
| 352 // Should have a way to detect this and clear the password member. | 358 // Should have a way to detect this and clear the password member. |
| 353 password_ = password; | 359 password_ = password; |
| 354 } | 360 } |
| OLD | NEW |