[cleanup] Removed online password check on Chrome OS login.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / gaia_screen_handler.h
blobbd7e4c9d5cd07922199d93b1dd0e1c0fba79cec1
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_
8 #include <string>
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/base_screen_handler.h"
16 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
17 #include "net/base/net_errors.h"
19 namespace policy {
20 class ConsumerManagementService;
23 namespace chromeos {
25 class SigninScreenHandler;
26 class SigninScreenHandlerDelegate;
28 // A class that's used to specify the way how Gaia should be loaded.
29 struct GaiaContext {
30 GaiaContext();
32 // Forces Gaia to reload.
33 bool force_reload;
35 // Whether local verison of Gaia is used.
36 bool is_local;
38 // True if user pods can be displayed.
39 bool show_users;
41 // Whether Gaia should be loaded in offline mode.
42 bool use_offline;
44 // True if user list is non-empty.
45 bool has_users;
47 // Email of the current user.
48 std::string email;
50 // GAIA ID of the current user.
51 std::string gaia_id;
53 // GAPS cookie.
54 std::string gaps_cookie;
56 // Whether consumer management enrollment is in progress.
57 bool is_enrolling_consumer_management;
60 // A class that handles WebUI hooks in Gaia screen.
61 class GaiaScreenHandler : public BaseScreenHandler {
62 public:
63 enum FrameState {
64 FRAME_STATE_UNKNOWN = 0,
65 FRAME_STATE_LOADING,
66 FRAME_STATE_LOADED,
67 FRAME_STATE_ERROR
70 GaiaScreenHandler(
71 CoreOobeActor* core_oobe_actor,
72 const scoped_refptr<NetworkStateInformer>& network_state_informer,
73 policy::ConsumerManagementService* consumer_management);
74 ~GaiaScreenHandler() override;
76 void LoadGaia(const GaiaContext& context);
78 // Callback that loads GAIA after version information has been retrieved.
79 void LoadGaiaWithVersion(const GaiaContext& context,
80 const std::string& platform_version);
81 void UpdateGaia(const GaiaContext& context);
83 // Sends request to reload Gaia. If |force_reload| is true, request
84 // will be sent in any case, otherwise it will be sent only when Gaia is
85 // not loading right now.
86 void ReloadGaia(bool force_reload);
88 // Turns offline idle detection on or off. Idle detection should only be on if
89 // we're using the offline login page but the device is online.
90 void MonitorOfflineIdle(bool is_online);
92 // Decides whether an auth extension should be pre-loaded. If it should,
93 // pre-loads it.
94 void MaybePreloadAuthExtension();
96 // Show error UI at the end of GAIA flow when user is not whitelisted.
97 void ShowWhitelistCheckFailedError();
99 FrameState frame_state() const { return frame_state_; }
100 net::Error frame_error() const { return frame_error_; }
102 private:
103 // TODO (antrim@): remove this dependency.
104 friend class SigninScreenHandler;
106 // BaseScreenHandler implementation:
107 void DeclareLocalizedValues(
108 ::login::LocalizedValuesBuilder* builder) override;
109 void GetAdditionalParameters(base::DictionaryValue* dict) override;
110 void Initialize() override;
112 // WebUIMessageHandler implementation:
113 void RegisterMessages() override;
115 // WebUI message handlers.
116 void HandleFrameLoadingCompleted(int status);
117 void HandleWebviewLoadAborted(const std::string& error_reason_str);
118 void HandleCompleteAuthentication(const std::string& gaia_id,
119 const std::string& email,
120 const std::string& password,
121 const std::string& auth_code,
122 bool using_saml,
123 const std::string& gaps_cookie);
124 void HandleCompleteAuthenticationAuthCodeOnly(const std::string& auth_code);
125 void HandleCompleteLogin(const std::string& gaia_id,
126 const std::string& typed_email,
127 const std::string& password,
128 bool using_saml);
130 void HandleUsingSAMLAPI();
131 void HandleScrapedPasswordCount(int password_count);
132 void HandleScrapedPasswordVerificationFailed();
134 void HandleGaiaUIReady();
136 void HandleToggleEasyBootstrap();
138 void HandleIdentifierEntered(const std::string& account_identifier);
140 // This is called when ConsumerManagementService::SetOwner() returns.
141 void OnSetOwnerDone(const std::string& gaia_id,
142 const std::string& typed_email,
143 const std::string& password,
144 bool using_saml,
145 bool success);
147 // Really handles the complete login message.
148 void DoCompleteLogin(const std::string& gaia_id,
149 const std::string& typed_email,
150 const std::string& password,
151 bool using_saml);
153 // Fill GAIA user name.
154 void PopulateEmail(const std::string& user_id);
156 // Kick off cookie / local storage cleanup.
157 void StartClearingCookies(const base::Closure& on_clear_callback);
158 void OnCookiesCleared(const base::Closure& on_clear_callback);
160 // Kick off DNS cache flushing.
161 void StartClearingDnsCache();
162 void OnDnsCleared();
164 // Show sign-in screen for the given credentials.
165 virtual void ShowSigninScreenForCreds(const std::string& username,
166 const std::string& password);
167 // Attempts login for test.
168 void SubmitLoginFormForTest();
170 // Updates the member variable and UMA histogram indicating whether the
171 // principals API was used during SAML login.
172 void SetSAMLPrincipalsAPIUsed(bool api_used);
174 // Show the sign-in screen. Depending on internal state, the screen will
175 // either be shown immediately or after an asynchronous clean-up process that
176 // cleans DNS cache and cookies. In the latter case, the request to show the
177 // screen can be canceled by calling CancelShowGaiaAsync() while the clean-up
178 // is in progress.
179 void ShowGaiaAsync(bool is_enrolling_consumer_management);
181 // Cancels the request to show the sign-in screen while the asynchronous
182 // clean-up process that precedes the screen showing is in progress.
183 void CancelShowGaiaAsync();
185 // Shows signin screen after dns cache and cookie cleanup operations finish.
186 void ShowGaiaScreenIfReady();
188 // Tells webui to load authentication extension. |force| is used to force the
189 // extension reloading, if it has already been loaded. |silent_load| is true
190 // for cases when extension should be loaded in the background and it
191 // shouldn't grab the focus. |offline| is true when offline version of the
192 // extension should be used.
193 void LoadAuthExtension(bool force, bool silent_load, bool offline);
195 // TODO (antrim@): GaiaScreenHandler should implement
196 // NetworkStateInformer::Observer.
197 void UpdateState(NetworkError::ErrorReason reason);
199 // TODO (antrim@): remove this dependency.
200 void SetSigninScreenHandler(SigninScreenHandler* handler);
202 SigninScreenHandlerDelegate* Delegate();
204 // Returns temporary unused device Id.
205 std::string GetTemporaryDeviceId();
207 // Current state of Gaia frame.
208 FrameState frame_state_;
210 // Latest Gaia frame error.
211 net::Error frame_error_;
213 // Network state informer used to keep signin screen up.
214 scoped_refptr<NetworkStateInformer> network_state_informer_;
216 // Consumer management service for checking if enrollment is in progress.
217 policy::ConsumerManagementService* consumer_management_;
219 CoreOobeActor* core_oobe_actor_;
221 // Email to pre-populate with.
222 std::string populated_email_;
224 // True if dns cache cleanup is done.
225 bool dns_cleared_;
227 // True if DNS cache task is already running.
228 bool dns_clear_task_running_;
230 // True if cookie jar cleanup is done.
231 bool cookies_cleared_;
233 // If true, the sign-in screen will be shown when DNS cache and cookie
234 // clean-up finish.
235 bool show_when_dns_and_cookies_cleared_;
237 // Has Gaia page silent load been started for the current sign-in attempt?
238 bool gaia_silent_load_;
240 // The active network at the moment when Gaia page was preloaded.
241 std::string gaia_silent_load_network_;
243 // If the user authenticated via SAML, this indicates whether the principals
244 // API was used.
245 bool using_saml_api_;
247 // Whether consumer management enrollment is in progress.
248 bool is_enrolling_consumer_management_;
250 // Test credentials.
251 std::string test_user_;
252 std::string test_pass_;
253 bool test_expects_complete_login_;
255 // True if Easy bootstrap is enabled.
256 bool use_easy_bootstrap_;
258 // Non-owning ptr to SigninScreenHandler instance. Should not be used
259 // in dtor.
260 // TODO (antrim@): GaiaScreenHandler shouldn't communicate with
261 // signin_screen_handler directly.
262 SigninScreenHandler* signin_screen_handler_;
264 // GAIA extension loader.
265 scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
267 base::WeakPtrFactory<GaiaScreenHandler> weak_factory_;
269 DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler);
272 } // namespace chromeos
274 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_