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 "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "chrome/browser/signin/signin_promo.h" | 12 #include "chrome/browser/signin/signin_promo.h" |
13 #include "chrome/browser/sync/profile_sync_service_observer.h" | 13 #include "chrome/browser/sync/profile_sync_service_observer.h" |
14 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 14 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
17 #include "content/public/browser/web_contents_user_data.h" | 17 #include "content/public/browser/web_contents_user_data.h" |
18 #include "google_apis/gaia/google_service_auth_error.h" | 18 #include "google_apis/gaia/google_service_auth_error.h" |
19 | 19 |
20 class Browser; | 20 class Browser; |
21 class GURL; | 21 class GURL; |
| 22 class PasswordManager; |
22 class ProfileIOData; | 23 class ProfileIOData; |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 class WebContents; | 26 class WebContents; |
26 struct FrameNavigateParams; | 27 struct FrameNavigateParams; |
27 struct LoadCommittedDetails; | 28 struct LoadCommittedDetails; |
28 struct PasswordForm; | 29 struct PasswordForm; |
29 } | 30 } |
30 | 31 |
31 namespace net { | 32 namespace net { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 DONT_OFFER, | 72 DONT_OFFER, |
72 IGNORE_REQUEST | 73 IGNORE_REQUEST |
73 }; | 74 }; |
74 | 75 |
75 // Argument to CanOffer(). | 76 // Argument to CanOffer(). |
76 enum CanOfferFor { | 77 enum CanOfferFor { |
77 CAN_OFFER_FOR_ALL, | 78 CAN_OFFER_FOR_ALL, |
78 CAN_OFFER_FOR_INTERSTITAL_ONLY | 79 CAN_OFFER_FOR_INTERSTITAL_ONLY |
79 }; | 80 }; |
80 | 81 |
| 82 static void CreateForWebContentsWithPasswordManager( |
| 83 content::WebContents* contents, |
| 84 PasswordManager* password_manager); |
| 85 |
81 virtual ~OneClickSigninHelper(); | 86 virtual ~OneClickSigninHelper(); |
82 | 87 |
83 // Returns true if the one-click signin feature can be offered at this time. | 88 // Returns true if the one-click signin feature can be offered at this time. |
84 // If |email| is not empty, then the profile is checked to see if it's | 89 // If |email| is not empty, then the profile is checked to see if it's |
85 // already connected to a google account or if the user has already rejected | 90 // already connected to a google account or if the user has already rejected |
86 // one-click sign-in with this email, in which cases a one click signin | 91 // one-click sign-in with this email, in which cases a one click signin |
87 // should not be offered. | 92 // should not be offered. |
88 // | 93 // |
89 // If |can_offer_for| is |CAN_OFFER_FOR_INTERSTITAL_ONLY|, then only do the | 94 // If |can_offer_for| is |CAN_OFFER_FOR_INTERSTITAL_ONLY|, then only do the |
90 // checks that would affect the interstitial page. Otherwise, do the checks | 95 // checks that would affect the interstitial page. Otherwise, do the checks |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 FRIEND_TEST_ALL_PREFIXES(OneClickSigninHelperIOTest, | 164 FRIEND_TEST_ALL_PREFIXES(OneClickSigninHelperIOTest, |
160 CanOfferOnIOThreadNoSigninCookies); | 165 CanOfferOnIOThreadNoSigninCookies); |
161 FRIEND_TEST_ALL_PREFIXES(OneClickSigninHelperIOTest, | 166 FRIEND_TEST_ALL_PREFIXES(OneClickSigninHelperIOTest, |
162 CanOfferOnIOThreadDisabledByPolicy); | 167 CanOfferOnIOThreadDisabledByPolicy); |
163 | 168 |
164 // Maximum number of navigations away from the set of valid Gaia URLs before | 169 // Maximum number of navigations away from the set of valid Gaia URLs before |
165 // clearing the internal state of the helper. This is necessary to support | 170 // clearing the internal state of the helper. This is necessary to support |
166 // SAML-based accounts, but causes bug crbug.com/181163. | 171 // SAML-based accounts, but causes bug crbug.com/181163. |
167 static const int kMaxNavigationsSince; | 172 static const int kMaxNavigationsSince; |
168 | 173 |
169 explicit OneClickSigninHelper(content::WebContents* web_contents); | 174 OneClickSigninHelper(content::WebContents* web_contents, |
| 175 PasswordManager* password_manager); |
170 | 176 |
171 // Returns true if the one-click signin feature can be offered at this time. | 177 // Returns true if the one-click signin feature can be offered at this time. |
172 // It can be offered if the io_data is not in an incognito window and if the | 178 // It can be offered if the io_data is not in an incognito window and if the |
173 // origin of |url| is a valid Gaia sign in origin. This function is meant | 179 // origin of |url| is a valid Gaia sign in origin. This function is meant |
174 // to called only from the IO thread. | 180 // to called only from the IO thread. |
175 static Offer CanOfferOnIOThreadImpl(const GURL& url, | 181 static Offer CanOfferOnIOThreadImpl(const GURL& url, |
176 const std::string& referrer, | 182 const std::string& referrer, |
177 base::SupportsUserData* request, | 183 base::SupportsUserData* request, |
178 ProfileIOData* io_data); | 184 ProfileIOData* io_data); |
179 | 185 |
(...skipping 21 matching lines...) Expand all Loading... |
201 | 207 |
202 // Clear all data member of the helper, except for the error. | 208 // Clear all data member of the helper, except for the error. |
203 void CleanTransientState(); | 209 void CleanTransientState(); |
204 | 210 |
205 // Unitests that use a TestingProfile should call this. | 211 // Unitests that use a TestingProfile should call this. |
206 // Otherwise, clearing the pending e-mail crashes because the code expects | 212 // Otherwise, clearing the pending e-mail crashes because the code expects |
207 // a real ResourceContext rather than the MockResourceContext a | 213 // a real ResourceContext rather than the MockResourceContext a |
208 // TestingProfile provides. | 214 // TestingProfile provides. |
209 void SetDoNotClearPendingEmailForTesting(); | 215 void SetDoNotClearPendingEmailForTesting(); |
210 | 216 |
211 // Grab Gaia password if available. | 217 // Called when password has been submitted. |
212 bool OnFormSubmitted(const content::PasswordForm& form); | 218 void PasswordSubmitted(const content::PasswordForm& form); |
213 | 219 |
214 // content::WebContentsObserver overrides. | 220 // content::WebContentsObserver overrides. |
215 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
216 virtual void NavigateToPendingEntry( | 221 virtual void NavigateToPendingEntry( |
217 const GURL& url, | 222 const GURL& url, |
218 content::NavigationController::ReloadType reload_type) OVERRIDE; | 223 content::NavigationController::ReloadType reload_type) OVERRIDE; |
219 virtual void DidNavigateMainFrame( | 224 virtual void DidNavigateMainFrame( |
220 const content::LoadCommittedDetails& details, | 225 const content::LoadCommittedDetails& details, |
221 const content::FrameNavigateParams& params) OVERRIDE; | 226 const content::FrameNavigateParams& params) OVERRIDE; |
222 virtual void DidStopLoading( | 227 virtual void DidStopLoading( |
223 content::RenderViewHost* render_view_host) OVERRIDE; | 228 content::RenderViewHost* render_view_host) OVERRIDE; |
224 | 229 |
225 // ProfileSyncServiceObserver. | 230 // ProfileSyncServiceObserver. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // Allows unittests to avoid accessing the ResourceContext for clearing a | 269 // Allows unittests to avoid accessing the ResourceContext for clearing a |
265 // pending e-mail. | 270 // pending e-mail. |
266 bool do_not_clear_pending_email_; | 271 bool do_not_clear_pending_email_; |
267 | 272 |
268 base::WeakPtrFactory<OneClickSigninHelper> weak_pointer_factory_; | 273 base::WeakPtrFactory<OneClickSigninHelper> weak_pointer_factory_; |
269 | 274 |
270 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); | 275 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); |
271 }; | 276 }; |
272 | 277 |
273 #endif // CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 278 #endif // CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
OLD | NEW |