1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
10 #include "base/basictypes.h"
11 #include "base/command_line.h"
12 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h"
14 #include "chrome/browser/extensions/signin/scoped_gaia_auth_extension.h"
15 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
16 #include "net/base/net_errors.h"
19 class ConsumerManagementService
;
24 class SigninScreenHandler
;
26 // A class that's used to specify the way how Gaia should be loaded.
30 // Forces Gaia to reload.
33 // Whether local verison of Gaia is used.
36 // True if password was changed for the current user.
37 bool password_changed
;
39 // True if user pods can be displyed.
42 // Whether Gaia should be loaded in offline mode.
45 // True if user list is non-empty.
48 // Email of current user.
51 // Whether consumer management enrollment is in progress.
52 bool is_enrolling_consumer_management
;
54 // True if embedded_signin is enabled.
55 bool embedded_signin_enabled
;
58 // A class that handles WebUI hooks in Gaia screen.
59 class GaiaScreenHandler
: public BaseScreenHandler
{
62 FRAME_STATE_UNKNOWN
= 0,
69 CoreOobeActor
* core_oobe_actor
,
70 const scoped_refptr
<NetworkStateInformer
>& network_state_informer
,
71 policy::ConsumerManagementService
* consumer_management
);
72 virtual ~GaiaScreenHandler();
74 void LoadGaia(const GaiaContext
& context
);
75 void UpdateGaia(const GaiaContext
& context
);
77 // Sends request to reload Gaia. If |force_reload| is true, request
78 // will be sent in any case, otherwise it will be sent only when Gaia is
79 // not loading right now.
80 void ReloadGaia(bool force_reload
);
82 // Reload gaia with embedded signin frame.
83 void SwitchToEmbeddedSignin();
85 // Cancel embedded signin for the next load.
86 void CancelEmbeddedSignin();
88 FrameState
frame_state() const { return frame_state_
; }
89 net::Error
frame_error() const { return frame_error_
; }
92 // TODO (ygorshenin@): remove this dependency.
93 friend class SigninScreenHandler
;
95 // BaseScreenHandler implementation:
96 virtual void DeclareLocalizedValues(LocalizedValuesBuilder
* builder
) override
;
97 virtual void Initialize() override
;
99 // WebUIMessageHandler implementation:
100 virtual void RegisterMessages() override
;
102 // WebUI message handlers.
103 void HandleFrameLoadingCompleted(int status
);
104 void HandleCompleteAuthentication(const std::string
& gaia_id
,
105 const std::string
& email
,
106 const std::string
& password
,
107 const std::string
& auth_code
);
108 void HandleCompleteLogin(const std::string
& gaia_id
,
109 const std::string
& typed_email
,
110 const std::string
& password
,
113 void HandleUsingSAMLAPI();
114 void HandleScrapedPasswordCount(int password_count
);
115 void HandleScrapedPasswordVerificationFailed();
117 void HandleGaiaUIReady();
119 // This is called when ConsumerManagementService::SetOwner() returns.
120 void OnSetOwnerDone(const std::string
& gaia_id
,
121 const std::string
& typed_email
,
122 const std::string
& password
,
126 // Really handles the complete login message.
127 void DoCompleteLogin(const std::string
& gaia_id
,
128 const std::string
& typed_email
,
129 const std::string
& password
,
132 // Fill GAIA user name.
133 void PopulateEmail(const std::string
& user_id
);
135 // Mark user as having password changed:
136 void PasswordChangedFor(const std::string
& user_id
);
138 // Kick off cookie / local storage cleanup.
139 void StartClearingCookies(const base::Closure
& on_clear_callback
);
140 void OnCookiesCleared(const base::Closure
& on_clear_callback
);
142 // Kick off DNS cache flushing.
143 void StartClearingDnsCache();
146 // Show sign-in screen for the given credentials.
147 virtual void ShowSigninScreenForCreds(const std::string
& username
,
148 const std::string
& password
);
149 // Attempts login for test.
150 void SubmitLoginFormForTest();
152 // Updates the member variable and UMA histogram indicating whether the
153 // principals API was used during SAML login.
154 void SetSAMLPrincipalsAPIUsed(bool api_used
);
156 // Show the sign-in screen. Depending on internal state, the screen will
157 // either be shown immediately or after an asynchronous clean-up process that
158 // cleans DNS cache and cookies. In the latter case, the request to show the
159 // screen can be canceled by calling CancelShowGaiaAsync() while the clean-up
161 void ShowGaiaAsync(bool is_enrolling_consumer_management
);
163 // Cancels the request to show the sign-in screen while the asynchronous
164 // clean-up process that precedes the screen showing is in progress.
165 void CancelShowGaiaAsync();
167 // Shows signin screen after dns cache and cookie cleanup operations finish.
168 void ShowGaiaScreenIfReady();
170 // Decides whether an auth extension should be pre-loaded. If it should,
172 void MaybePreloadAuthExtension();
174 // Tells webui to load authentication extension. |force| is used to force the
175 // extension reloading, if it has already been loaded. |silent_load| is true
176 // for cases when extension should be loaded in the background and it
177 // shouldn't grab the focus. |offline| is true when offline version of the
178 // extension should be used.
179 void LoadAuthExtension(bool force
, bool silent_load
, bool offline
);
181 // TODO (ygorshenin@): GaiaScreenHandler should implement
182 // NetworkStateInformer::Observer.
183 void UpdateState(ErrorScreenActor::ErrorReason reason
);
185 // TODO (ygorshenin@): remove this dependency.
186 void SetSigninScreenHandler(SigninScreenHandler
* handler
);
188 SigninScreenHandlerDelegate
* Delegate();
190 // Current state of Gaia frame.
191 FrameState frame_state_
;
193 // Latest Gaia frame error.
194 net::Error frame_error_
;
196 // Network state informer used to keep signin screen up.
197 scoped_refptr
<NetworkStateInformer
> network_state_informer_
;
199 // Consumer management service for checking if enrollment is in progress.
200 policy::ConsumerManagementService
* consumer_management_
;
202 CoreOobeActor
* core_oobe_actor_
;
204 // Email to pre-populate with.
205 std::string populated_email_
;
207 // Emails of the users, whose passwords have recently been changed.
208 std::set
<std::string
> password_changed_for_
;
210 // True if dns cache cleanup is done.
213 // True if DNS cache task is already running.
214 bool dns_clear_task_running_
;
216 // True if cookie jar cleanup is done.
217 bool cookies_cleared_
;
219 // If true, the sign-in screen will be shown when DNS cache and cookie
221 bool show_when_dns_and_cookies_cleared_
;
223 // Is focus still stolen from Gaia page?
226 // Has Gaia page silent load been started for the current sign-in attempt?
227 bool gaia_silent_load_
;
229 // The active network at the moment when Gaia page was preloaded.
230 std::string gaia_silent_load_network_
;
232 // If the user authenticated via SAML, this indicates whether the principals
234 bool using_saml_api_
;
236 // Whether consumer management enrollment is in progress.
237 bool is_enrolling_consumer_management_
;
240 std::string test_user_
;
241 std::string test_pass_
;
242 bool test_expects_complete_login_
;
244 // True if user pressed shortcut to enable embedded signin.
245 bool embedded_signin_enabled_by_shortcut_
;
247 // Non-owning ptr to SigninScreenHandler instance. Should not be used
249 // TODO (ygorshenin@): GaiaScreenHandler shouldn't communicate with
250 // signin_screen_handler directly.
251 SigninScreenHandler
* signin_screen_handler_
;
253 // GAIA extension loader.
254 scoped_ptr
<ScopedGaiaAuthExtension
> auth_extension_
;
256 base::WeakPtrFactory
<GaiaScreenHandler
> weak_factory_
;
258 DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler
);
261 } // namespace chromeos
263 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_