Move gaia component extension initialization closer to where it is really needed
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / gaia_screen_handler.h
blob0c5b838c50f5e6ea58e6ca1ac9dbcab9723e294f
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/network_state_informer.h"
16 #include "net/base/net_errors.h"
18 namespace policy {
19 class ConsumerManagementService;
22 namespace chromeos {
24 class SigninScreenHandler;
26 // A class that's used to specify the way how Gaia should be loaded.
27 struct GaiaContext {
28 GaiaContext();
30 // Forces Gaia to reload.
31 bool force_reload;
33 // Whether local verison of Gaia is used.
34 bool is_local;
36 // True if password was changed for the current user.
37 bool password_changed;
39 // True if user pods can be displyed.
40 bool show_users;
42 // Whether Gaia should be loaded in offline mode.
43 bool use_offline;
45 // True if user list is non-empty.
46 bool has_users;
48 // Email of current user.
49 std::string email;
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 {
60 public:
61 enum FrameState {
62 FRAME_STATE_UNKNOWN = 0,
63 FRAME_STATE_LOADING,
64 FRAME_STATE_LOADED,
65 FRAME_STATE_ERROR
68 GaiaScreenHandler(
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_; }
91 private:
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,
111 bool using_saml);
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,
123 bool using_saml,
124 bool success);
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,
130 bool using_saml);
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();
144 void OnDnsCleared();
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
160 // is in progress.
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,
171 // pre-loads it.
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.
211 bool dns_cleared_;
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
220 // clean-up finish.
221 bool show_when_dns_and_cookies_cleared_;
223 // Is focus still stolen from Gaia page?
224 bool focus_stolen_;
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
233 // API was used.
234 bool using_saml_api_;
236 // Whether consumer management enrollment is in progress.
237 bool is_enrolling_consumer_management_;
239 // Test credentials.
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
248 // in dtor.
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_