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/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
19 #include "chrome/browser/tab_contents/tab_util.h" | 19 #include "chrome/browser/tab_contents/tab_util.h" |
20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/sync/one_click_signin_dialog.h" | 22 #include "chrome/browser/ui/sync/one_click_signin_dialog.h" |
23 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 23 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
24 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 24 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/page_navigator.h" | 29 #include "content/public/browser/page_navigator.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_contents_view.h" | 31 #include "content/public/browser/web_contents_view.h" |
31 #include "content/public/common/frame_navigate_params.h" | 32 #include "content/public/common/frame_navigate_params.h" |
| 33 #include "content/public/common/page_transition_types.h" |
| 34 #include "googleurl/src/gurl.h" |
32 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
34 #include "grit/theme_resources_standard.h" | 37 #include "grit/theme_resources_standard.h" |
35 #include "net/cookies/cookie_monster.h" | 38 #include "net/cookies/cookie_monster.h" |
36 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
37 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
39 #include "webkit/forms/password_form.h" | 42 #include "webkit/forms/password_form.h" |
40 #include "webkit/forms/password_form_dom_manager.h" | 43 #include "webkit/forms/password_form_dom_manager.h" |
41 | 44 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 119 |
117 string16 OneClickLoginInfoBarDelegate::GetButtonLabel( | 120 string16 OneClickLoginInfoBarDelegate::GetButtonLabel( |
118 InfoBarButton button) const { | 121 InfoBarButton button) const { |
119 return l10n_util::GetStringUTF16( | 122 return l10n_util::GetStringUTF16( |
120 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON | 123 (button == BUTTON_OK) ? IDS_ONE_CLICK_SIGNIN_INFOBAR_OK_BUTTON |
121 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); | 124 : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); |
122 } | 125 } |
123 | 126 |
124 namespace { | 127 namespace { |
125 | 128 |
| 129 void OnLearnMore(Browser* browser) { |
| 130 browser->AddSelectedTabWithURL( |
| 131 GURL(chrome::kSyncLearnMoreURL), |
| 132 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 133 } |
| 134 |
| 135 void OnAdvanced(Browser* browser) { |
| 136 browser->AddSelectedTabWithURL( |
| 137 GURL(std::string(chrome::kChromeUISettingsURL) + |
| 138 chrome::kSyncSetupSubPage), |
| 139 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 140 } |
| 141 |
126 // Start syncing with the given user information. | 142 // Start syncing with the given user information. |
127 void StartSync(content::WebContents* web_contents, | 143 void StartSync(content::WebContents* web_contents, |
128 const std::string& session_index, | 144 const std::string& session_index, |
129 const std::string& email, | 145 const std::string& email, |
130 const std::string& password, | 146 const std::string& password, |
131 bool use_default_settings) { | 147 bool use_default_settings) { |
132 // The starter deletes itself once its done. | 148 // The starter deletes itself once its done. |
133 Profile* profile = | 149 Profile* profile = |
134 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 150 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
135 ignore_result( | 151 ignore_result( |
136 new OneClickSigninSyncStarter( | 152 new OneClickSigninSyncStarter( |
137 profile, session_index, email, password, use_default_settings)); | 153 profile, session_index, email, password, use_default_settings)); |
138 | 154 |
139 Browser* browser = BrowserList::FindBrowserWithWebContents(web_contents); | 155 Browser* browser = BrowserList::FindBrowserWithWebContents(web_contents); |
140 browser->window()->ShowOneClickSigninBubble(); | 156 browser->window()->ShowOneClickSigninBubble( |
| 157 base::Bind(&OnLearnMore, base::Unretained(browser)), |
| 158 base::Bind(&OnAdvanced, base::Unretained(browser))); |
141 } | 159 } |
142 | 160 |
143 } // namespace | 161 } // namespace |
144 | 162 |
145 bool OneClickLoginInfoBarDelegate::Accept() { | 163 bool OneClickLoginInfoBarDelegate::Accept() { |
146 DisableOneClickSignIn(); | 164 DisableOneClickSignIn(); |
147 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 165 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
148 ShowOneClickSigninDialog( | 166 ShowOneClickSigninDialog( |
149 owner()->web_contents()->GetView()->GetTopLevelNativeWindow(), | 167 owner()->web_contents()->GetView()->GetTopLevelNativeWindow(), |
150 base::Bind(&StartSync, owner()->web_contents(), session_index_, email_, | 168 base::Bind(&StartSync, owner()->web_contents(), session_index_, email_, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 session_index_ = session_index; | 326 session_index_ = session_index; |
309 email_ = email; | 327 email_ = email; |
310 } | 328 } |
311 | 329 |
312 void OneClickSigninHelper::SavePassword(const std::string& password) { | 330 void OneClickSigninHelper::SavePassword(const std::string& password) { |
313 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of | 331 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of |
314 // challenge, its possible for the user to never complete the signin. | 332 // challenge, its possible for the user to never complete the signin. |
315 // Should have a way to detect this and clear the password member. | 333 // Should have a way to detect this and clear the password member. |
316 password_ = password; | 334 password_ = password; |
317 } | 335 } |
OLD | NEW |