ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / gaia_screen_handler.h
blob28c4f577f487db0e78ef2e8005f15fd888777ca0
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 password was changed for the current user.
39 bool password_changed;
41 // True if user pods can be displyed.
42 bool show_users;
44 // Whether Gaia should be loaded in offline mode.
45 bool use_offline;
47 // True if user list is non-empty.
48 bool has_users;
50 // Email of current user.
51 std::string email;
53 // Whether consumer management enrollment is in progress.
54 bool is_enrolling_consumer_management;
56 // True if embedded_signin is enabled.
57 bool embedded_signin_enabled;
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);
77 void UpdateGaia(const GaiaContext& context);
79 // Sends request to reload Gaia. If |force_reload| is true, request
80 // will be sent in any case, otherwise it will be sent only when Gaia is
81 // not loading right now.
82 void ReloadGaia(bool force_reload);
84 // Reload gaia with embedded signin frame.
85 void SwitchToEmbeddedSignin();
87 // Cancel embedded signin for the next load.
88 void CancelEmbeddedSignin();
90 // Decides whether an auth extension should be pre-loaded. If it should,
91 // pre-loads it.
92 void MaybePreloadAuthExtension();
94 FrameState frame_state() const { return frame_state_; }
95 net::Error frame_error() const { return frame_error_; }
97 private:
98 // TODO (antrim@): remove this dependency.
99 friend class SigninScreenHandler;
101 // BaseScreenHandler implementation:
102 void DeclareLocalizedValues(
103 ::login::LocalizedValuesBuilder* builder) override;
104 void GetAdditionalParameters(base::DictionaryValue* dict) override;
105 void Initialize() override;
107 // WebUIMessageHandler implementation:
108 void RegisterMessages() override;
110 // WebUI message handlers.
111 void HandleFrameLoadingCompleted(int status);
112 void HandleCompleteAuthentication(const std::string& gaia_id,
113 const std::string& email,
114 const std::string& password,
115 const std::string& auth_code);
116 void HandleCompleteLogin(const std::string& gaia_id,
117 const std::string& typed_email,
118 const std::string& password,
119 bool using_saml);
121 void HandleUsingSAMLAPI();
122 void HandleScrapedPasswordCount(int password_count);
123 void HandleScrapedPasswordVerificationFailed();
125 void HandleGaiaUIReady();
127 void HandleSwitchToFullTab();
129 void HandleToggleWebviewSignin();
131 // This is called when ConsumerManagementService::SetOwner() returns.
132 void OnSetOwnerDone(const std::string& gaia_id,
133 const std::string& typed_email,
134 const std::string& password,
135 bool using_saml,
136 bool success);
138 // Really handles the complete login message.
139 void DoCompleteLogin(const std::string& gaia_id,
140 const std::string& typed_email,
141 const std::string& password,
142 bool using_saml);
144 // Fill GAIA user name.
145 void PopulateEmail(const std::string& user_id);
147 // Mark user as having password changed:
148 void PasswordChangedFor(const std::string& user_id);
150 // Kick off cookie / local storage cleanup.
151 void StartClearingCookies(const base::Closure& on_clear_callback);
152 void OnCookiesCleared(const base::Closure& on_clear_callback);
154 // Kick off DNS cache flushing.
155 void StartClearingDnsCache();
156 void OnDnsCleared();
158 // Show sign-in screen for the given credentials.
159 virtual void ShowSigninScreenForCreds(const std::string& username,
160 const std::string& password);
161 // Attempts login for test.
162 void SubmitLoginFormForTest();
164 // Updates the member variable and UMA histogram indicating whether the
165 // principals API was used during SAML login.
166 void SetSAMLPrincipalsAPIUsed(bool api_used);
168 // Show the sign-in screen. Depending on internal state, the screen will
169 // either be shown immediately or after an asynchronous clean-up process that
170 // cleans DNS cache and cookies. In the latter case, the request to show the
171 // screen can be canceled by calling CancelShowGaiaAsync() while the clean-up
172 // is in progress.
173 void ShowGaiaAsync(bool is_enrolling_consumer_management);
175 // Cancels the request to show the sign-in screen while the asynchronous
176 // clean-up process that precedes the screen showing is in progress.
177 void CancelShowGaiaAsync();
179 // Shows signin screen after dns cache and cookie cleanup operations finish.
180 void ShowGaiaScreenIfReady();
182 // Tells webui to load authentication extension. |force| is used to force the
183 // extension reloading, if it has already been loaded. |silent_load| is true
184 // for cases when extension should be loaded in the background and it
185 // shouldn't grab the focus. |offline| is true when offline version of the
186 // extension should be used.
187 void LoadAuthExtension(bool force, bool silent_load, bool offline);
189 // TODO (antrim@): GaiaScreenHandler should implement
190 // NetworkStateInformer::Observer.
191 void UpdateState(NetworkError::ErrorReason reason);
193 // TODO (antrim@): remove this dependency.
194 void SetSigninScreenHandler(SigninScreenHandler* handler);
196 SigninScreenHandlerDelegate* Delegate();
198 // Current state of Gaia frame.
199 FrameState frame_state_;
201 // Latest Gaia frame error.
202 net::Error frame_error_;
204 // Network state informer used to keep signin screen up.
205 scoped_refptr<NetworkStateInformer> network_state_informer_;
207 // Consumer management service for checking if enrollment is in progress.
208 policy::ConsumerManagementService* consumer_management_;
210 CoreOobeActor* core_oobe_actor_;
212 // Email to pre-populate with.
213 std::string populated_email_;
215 // Emails of the users, whose passwords have recently been changed.
216 std::set<std::string> password_changed_for_;
218 // True if dns cache cleanup is done.
219 bool dns_cleared_;
221 // True if DNS cache task is already running.
222 bool dns_clear_task_running_;
224 // True if cookie jar cleanup is done.
225 bool cookies_cleared_;
227 // If true, the sign-in screen will be shown when DNS cache and cookie
228 // clean-up finish.
229 bool show_when_dns_and_cookies_cleared_;
231 // Is focus still stolen from Gaia page?
232 bool focus_stolen_;
234 // Has Gaia page silent load been started for the current sign-in attempt?
235 bool gaia_silent_load_;
237 // The active network at the moment when Gaia page was preloaded.
238 std::string gaia_silent_load_network_;
240 // If the user authenticated via SAML, this indicates whether the principals
241 // API was used.
242 bool using_saml_api_;
244 // Whether consumer management enrollment is in progress.
245 bool is_enrolling_consumer_management_;
247 // Test credentials.
248 std::string test_user_;
249 std::string test_pass_;
250 bool test_expects_complete_login_;
252 // True if user pressed shortcut to enable embedded signin.
253 bool embedded_signin_enabled_by_shortcut_;
255 // Non-owning ptr to SigninScreenHandler instance. Should not be used
256 // in dtor.
257 // TODO (antrim@): GaiaScreenHandler shouldn't communicate with
258 // signin_screen_handler directly.
259 SigninScreenHandler* signin_screen_handler_;
261 // GAIA extension loader.
262 scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
264 base::WeakPtrFactory<GaiaScreenHandler> weak_factory_;
266 DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler);
269 } // namespace chromeos
271 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_