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/ui/webui/chromeos/login/network_state_informer.h"
15 #include "net/base/net_errors.h"
18 class ConsumerManagementService;
23 class SigninScreenHandler;
25 // A class that's used to specify the way how Gaia should be loaded.
29 // Forces Gaia to reload.
32 // Whether local verison of Gaia is used.
35 // True if password was changed for the current user.
36 bool password_changed;
38 // True if user pods can be displyed.
41 // Whether Gaia should be loaded in offline mode.
44 // True if user list is non-empty.
47 // Email of current user.
50 // Whether consumer management enrollment is in progress.
51 bool is_enrolling_consumer_management;
53 // True if embedded_signin is enabled.
54 bool embedded_signin_enabled;
57 // A class that handles WebUI hooks in Gaia screen.
58 class GaiaScreenHandler : public BaseScreenHandler {
61 FRAME_STATE_UNKNOWN = 0,
68 CoreOobeActor* core_oobe_actor,
69 const scoped_refptr<NetworkStateInformer>& network_state_informer,
70 policy::ConsumerManagementService* consumer_management);
71 virtual ~GaiaScreenHandler();
73 void LoadGaia(const GaiaContext& context);
74 void UpdateGaia(const GaiaContext& context);
76 // Sends request to reload Gaia. If |force_reload| is true, request
77 // will be sent in any case, otherwise it will be sent only when Gaia is
78 // not loading right now.
79 void ReloadGaia(bool force_reload);
81 // Reload gaia with embedded signin frame.
82 void SwitchToEmbeddedSignin();
84 // Cancel embedded signin for the next load.
85 void CancelEmbeddedSignin();
87 FrameState frame_state() const { return frame_state_; }
88 net::Error frame_error() const { return frame_error_; }
91 // TODO (ygorshenin@): remove this dependency.
92 friend class SigninScreenHandler;
94 // BaseScreenHandler implementation:
95 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) override;
96 virtual void Initialize() override;
98 // WebUIMessageHandler implementation:
99 virtual void RegisterMessages() override;
101 // WebUI message handlers.
102 void HandleFrameLoadingCompleted(int status);
103 void HandleCompleteAuthentication(const std::string& gaia_id,
104 const std::string& email,
105 const std::string& password,
106 const std::string& auth_code);
107 void HandleCompleteLogin(const std::string& gaia_id,
108 const std::string& typed_email,
109 const std::string& password,
112 void HandleUsingSAMLAPI();
113 void HandleScrapedPasswordCount(int password_count);
114 void HandleScrapedPasswordVerificationFailed();
116 void HandleGaiaUIReady();
118 // This is called when ConsumerManagementService::SetOwner() returns.
119 void OnSetOwnerDone(const std::string& gaia_id,
120 const std::string& typed_email,
121 const std::string& password,
125 // Really handles the complete login message.
126 void DoCompleteLogin(const std::string& gaia_id,
127 const std::string& typed_email,
128 const std::string& password,
131 // Fill GAIA user name.
132 void PopulateEmail(const std::string& user_id);
134 // Mark user as having password changed:
135 void PasswordChangedFor(const std::string& user_id);
137 // Kick off cookie / local storage cleanup.
138 void StartClearingCookies(const base::Closure& on_clear_callback);
139 void OnCookiesCleared(const base::Closure& on_clear_callback);
141 // Kick off DNS cache flushing.
142 void StartClearingDnsCache();
145 // Show sign-in screen for the given credentials.
146 virtual void ShowSigninScreenForCreds(const std::string& username,
147 const std::string& password);
148 // Attempts login for test.
149 void SubmitLoginFormForTest();
151 // Updates the member variable and UMA histogram indicating whether the
152 // principals API was used during SAML login.
153 void SetSAMLPrincipalsAPIUsed(bool api_used);
155 void ShowGaia(bool is_enrolling_consumer_management);
157 // Shows signin screen after dns cache and cookie cleanup operations finish.
158 void ShowGaiaScreenIfReady();
160 // Decides whether an auth extension should be pre-loaded. If it should,
162 void MaybePreloadAuthExtension();
164 // Tells webui to load authentication extension. |force| is used to force the
165 // extension reloading, if it has already been loaded. |silent_load| is true
166 // for cases when extension should be loaded in the background and it
167 // shouldn't grab the focus. |offline| is true when offline version of the
168 // extension should be used.
169 void LoadAuthExtension(bool force, bool silent_load, bool offline);
171 // TODO (ygorshenin@): GaiaScreenHandler should implement
172 // NetworkStateInformer::Observer.
173 void UpdateState(ErrorScreenActor::ErrorReason reason);
175 // TODO (ygorshenin@): remove this dependency.
176 void SetSigninScreenHandler(SigninScreenHandler* handler);
178 SigninScreenHandlerDelegate* Delegate();
180 // Current state of Gaia frame.
181 FrameState frame_state_;
183 // Latest Gaia frame error.
184 net::Error frame_error_;
186 // Network state informer used to keep signin screen up.
187 scoped_refptr<NetworkStateInformer> network_state_informer_;
189 // Consumer management service for checking if enrollment is in progress.
190 policy::ConsumerManagementService* consumer_management_;
192 CoreOobeActor* core_oobe_actor_;
194 // Email to pre-populate with.
195 std::string populated_email_;
197 // Emails of the users, whose passwords have recently been changed.
198 std::set<std::string> password_changed_for_;
200 // True if dns cache cleanup is done.
203 // True if DNS cache task is already running.
204 bool dns_clear_task_running_;
206 // True if cookie jar cleanup is done.
207 bool cookies_cleared_;
209 // Is focus still stolen from Gaia page?
212 // Has Gaia page silent load been started for the current sign-in attempt?
213 bool gaia_silent_load_;
215 // The active network at the moment when Gaia page was preloaded.
216 std::string gaia_silent_load_network_;
218 // If the user authenticated via SAML, this indicates whether the principals
220 bool using_saml_api_;
222 // Whether consumer management enrollment is in progress.
223 bool is_enrolling_consumer_management_;
226 std::string test_user_;
227 std::string test_pass_;
228 bool test_expects_complete_login_;
230 // True if user pressed shortcut to enable embedded signin.
231 bool embedded_signin_enabled_by_shortcut_;
233 // Non-owning ptr to SigninScreenHandler instance. Should not be used
235 // TODO (ygorshenin@): GaiaScreenHandler shouldn't communicate with
236 // signin_screen_handler directly.
237 SigninScreenHandler* signin_screen_handler_;
239 base::WeakPtrFactory<GaiaScreenHandler> weak_factory_;
241 DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler);
244 } // namespace chromeos
246 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_