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 #ifndef CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
6 #define CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 6 #define CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "chrome/browser/signin/signin_tracker.h" | 11 #include "chrome/browser/sync/profile_sync_service_observer.h" |
12 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 12 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
13 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
16 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
17 | 17 |
18 class GURL; | 18 class GURL; |
19 class ProfileIOData; | 19 class ProfileIOData; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 class WebContents; | 22 class WebContents; |
23 struct PasswordForm; | 23 struct PasswordForm; |
24 } | 24 } |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 class URLRequest; | 27 class URLRequest; |
28 } | 28 } |
29 | 29 |
30 // Per-tab one-click signin helper. When a user signs in to a Google service | 30 // Per-tab one-click signin helper. When a user signs in to a Google service |
31 // and the profile is not yet connected to a Google account, will start the | 31 // and the profile is not yet connected to a Google account, will start the |
32 // process of helping the user connect his profile with one click. The process | 32 // process of helping the user connect his profile with one click. The process |
33 // begins with an infobar and is followed with a confirmation dialog explaining | 33 // begins with an infobar and is followed with a confirmation dialog explaining |
34 // more about what this means. | 34 // more about what this means. |
35 class OneClickSigninHelper | 35 class OneClickSigninHelper |
36 : public content::WebContentsObserver, | 36 : public content::WebContentsObserver, |
37 public content::WebContentsUserData<OneClickSigninHelper>, | 37 public content::WebContentsUserData<OneClickSigninHelper>, |
38 public SigninTracker::Observer, | |
39 public ProfileSyncServiceObserver { | 38 public ProfileSyncServiceObserver { |
40 public: | 39 public: |
41 // Represents user's decision about sign in process. | 40 // Represents user's decision about sign in process. |
42 enum AutoAccept { | 41 enum AutoAccept { |
43 // User decision not yet known. Assume cancel. | 42 // User decision not yet known. Assume cancel. |
44 AUTO_ACCEPT_NONE, | 43 AUTO_ACCEPT_NONE, |
45 | 44 |
46 // User has explicitly accepted to sign in. A bubble is shown with the | 45 // User has explicitly accepted to sign in. A bubble is shown with the |
47 // option to start sync, configure it first, or abort. | 46 // option to start sync, configure it first, or abort. |
48 AUTO_ACCEPT_ACCEPTED, | 47 AUTO_ACCEPT_ACCEPTED, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // when the sign process is over and to collect infomation from the user | 181 // when the sign process is over and to collect infomation from the user |
183 // entered on the Gaia sign in page (for explicit sign ins). | 182 // entered on the Gaia sign in page (for explicit sign ins). |
184 static void ShowInfoBarUIThread(const std::string& session_index, | 183 static void ShowInfoBarUIThread(const std::string& session_index, |
185 const std::string& email, | 184 const std::string& email, |
186 AutoAccept auto_accept, | 185 AutoAccept auto_accept, |
187 SyncPromoUI::Source source, | 186 SyncPromoUI::Source source, |
188 const GURL& continue_url, | 187 const GURL& continue_url, |
189 int child_id, | 188 int child_id, |
190 int route_id); | 189 int route_id); |
191 | 190 |
192 void RedirectToNtpOrAppsPage(bool show_bubble); | 191 void RedirectToNtpOrAppsPage(); |
193 void RedirectToSignin(); | 192 void RedirectToSignin(); |
194 void ShowSyncConfirmationBubble(bool show_bubble); | 193 void ShowSigninErrorBubble(const std::string& error); |
195 | 194 |
196 // Clear all data member of the helper, except for the error. | 195 // Clear all data member of the helper, except for the error. |
197 void CleanTransientState(); | 196 void CleanTransientState(); |
198 | 197 |
199 // Grab Gaia password if available. | 198 // Grab Gaia password if available. |
200 bool OnFormSubmitted(const content::PasswordForm& form); | 199 bool OnFormSubmitted(const content::PasswordForm& form); |
201 | 200 |
202 // content::WebContentsObserver overrides. | 201 // content::WebContentsObserver overrides. |
203 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 202 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
204 virtual void NavigateToPendingEntry( | 203 virtual void NavigateToPendingEntry( |
205 const GURL& url, | 204 const GURL& url, |
206 content::NavigationController::ReloadType reload_type) OVERRIDE; | 205 content::NavigationController::ReloadType reload_type) OVERRIDE; |
207 virtual void DidStopLoading( | 206 virtual void DidStopLoading( |
208 content::RenderViewHost* render_view_host) OVERRIDE; | 207 content::RenderViewHost* render_view_host) OVERRIDE; |
209 | 208 |
210 // SigninTracker::Observer override. | |
211 virtual void GaiaCredentialsValid() OVERRIDE; | |
212 virtual void SigninFailed(const GoogleServiceAuthError& error) OVERRIDE; | |
213 virtual void SigninSuccess() OVERRIDE; | |
214 | |
215 // ProfileSyncServiceObserver. | 209 // ProfileSyncServiceObserver. |
216 virtual void OnStateChanged() OVERRIDE; | 210 virtual void OnStateChanged() OVERRIDE; |
217 | 211 |
218 // Tracks if we are in the process of showing the signin or one click | 212 // Tracks if we are in the process of showing the signin or one click |
219 // interstitial page. It's set to true the first time we load one of those | 213 // interstitial page. It's set to true the first time we load one of those |
220 // pages and set to false when transient state is cleaned. | 214 // pages and set to false when transient state is cleaned. |
221 // Note: This should only be used for logging purposes. | 215 // Note: This should only be used for logging purposes. |
222 bool showing_signin_; | 216 bool showing_signin_; |
223 | 217 |
224 // Information about the account that has just logged in. | 218 // Information about the account that has just logged in. |
225 std::string session_index_; | 219 std::string session_index_; |
226 std::string email_; | 220 std::string email_; |
227 std::string password_; | 221 std::string password_; |
228 AutoAccept auto_accept_; | 222 AutoAccept auto_accept_; |
229 SyncPromoUI::Source source_; | 223 SyncPromoUI::Source source_; |
230 bool switched_to_advanced_; | 224 bool switched_to_advanced_; |
231 // When switching to advanced settings, we want to track the original source. | 225 // When switching to advanced settings, we want to track the original source. |
232 SyncPromoUI::Source original_source_; | 226 SyncPromoUI::Source original_source_; |
233 GURL continue_url_; | 227 GURL continue_url_; |
234 // Redirect URL after sync setup is complete. | 228 // Redirect URL after sync setup is complete. |
235 GURL redirect_url_; | 229 GURL redirect_url_; |
236 std::string error_message_; | 230 std::string error_message_; |
237 scoped_ptr<SigninTracker> signin_tracker_; | |
238 | 231 |
239 // Number of navigations since starting a sign in that is outside the | 232 // Number of navigations since starting a sign in that is outside the |
240 // the set of trusted Gaia URLs. Sign in attempts that include visits to | 233 // the set of trusted Gaia URLs. Sign in attempts that include visits to |
241 // one more untrusted will cause a modal dialog to appear asking the user | 234 // one more untrusted will cause a modal dialog to appear asking the user |
242 // to confirm, similar to the interstitial flow. | 235 // to confirm, similar to the interstitial flow. |
243 int untrusted_navigations_since_signin_visit_; | 236 int untrusted_navigations_since_signin_visit_; |
244 | 237 |
245 // Whether a Gaia URL during the sign in process was not handled by the | 238 // Whether a Gaia URL during the sign in process was not handled by the |
246 // dedicated sign in process (e.g. SAML login, which redirects to a | 239 // dedicated sign in process (e.g. SAML login, which redirects to a |
247 // non-google-controlled domain). | 240 // non-google-controlled domain). |
248 // This is set to true if at least one such URL is detected. | 241 // This is set to true if at least one such URL is detected. |
249 bool confirmation_required_; | 242 bool untrusted_confirmation_required_; |
250 | 243 |
251 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); | 244 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); |
252 }; | 245 }; |
253 | 246 |
254 #endif // CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 247 #endif // CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
OLD | NEW |