• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
7 
8 #include <string>
9 
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"
16 
17 namespace policy {
18 class ConsumerManagementService;
19 }
20 
21 namespace chromeos {
22 
23 class SigninScreenHandler;
24 
25 // A class that's used to specify the way how Gaia should be loaded.
26 struct GaiaContext {
27   GaiaContext();
28 
29   // Forces Gaia to reload.
30   bool force_reload;
31 
32   // Whether local verison of Gaia is used.
33   bool is_local;
34 
35   // True if password was changed for the current user.
36   bool password_changed;
37 
38   // True if user pods can be displyed.
39   bool show_users;
40 
41   // Whether Gaia should be loaded in offline mode.
42   bool use_offline;
43 
44   // True if user list is non-empty.
45   bool has_users;
46 
47   // Email of current user.
48   std::string email;
49 
50   // Whether consumer management enrollment is in progress.
51   bool is_enrolling_consumer_management;
52 };
53 
54 // A class that handles WebUI hooks in Gaia screen.
55 class GaiaScreenHandler : public BaseScreenHandler {
56  public:
57   enum FrameState {
58     FRAME_STATE_UNKNOWN = 0,
59     FRAME_STATE_LOADING,
60     FRAME_STATE_LOADED,
61     FRAME_STATE_ERROR
62   };
63 
64   GaiaScreenHandler(
65       CoreOobeActor* core_oobe_actor,
66       const scoped_refptr<NetworkStateInformer>& network_state_informer,
67       policy::ConsumerManagementService* consumer_management);
68   virtual ~GaiaScreenHandler();
69 
70   void LoadGaia(const GaiaContext& context);
71   void UpdateGaia(const GaiaContext& context);
72 
73   // Sends request to reload Gaia. If |force_reload| is true, request
74   // will be sent in any case, otherwise it will be sent only when Gaia is
75   // not loading right now.
76   void ReloadGaia(bool force_reload);
77 
frame_state()78   FrameState frame_state() const { return frame_state_; }
frame_error()79   net::Error frame_error() const { return frame_error_; }
80 
81  private:
82   // TODO (ygorshenin@): remove this dependency.
83   friend class SigninScreenHandler;
84 
85   // BaseScreenHandler implementation:
86   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
87   virtual void Initialize() OVERRIDE;
88 
89   // WebUIMessageHandler implementation:
90   virtual void RegisterMessages() OVERRIDE;
91 
92   // WebUI message handlers.
93   void HandleFrameLoadingCompleted(int status);
94   void HandleCompleteAuthentication(const std::string& email,
95                                     const std::string& password,
96                                     const std::string& auth_code);
97   void HandleCompleteLogin(const std::string& typed_email,
98                            const std::string& password,
99                            bool using_saml);
100 
101   void HandleUsingSAMLAPI();
102   void HandleScrapedPasswordCount(int password_count);
103   void HandleScrapedPasswordVerificationFailed();
104 
105   void HandleGaiaUIReady();
106 
107   // This is called when ConsumerManagementService::SetOwner() returns.
108   void OnSetOwnerDone(const std::string& typed_email,
109                       const std::string& password,
110                       bool using_saml,
111                       bool success);
112 
113   // Really handles the complete login message.
114   void DoCompleteLogin(const std::string& typed_email,
115                        const std::string& password,
116                        bool using_saml);
117 
118   // Fill GAIA user name.
119   void PopulateEmail(const std::string& user_id);
120 
121   // Mark user as having password changed:
122   void PasswordChangedFor(const std::string& user_id);
123 
124   // Kick off cookie / local storage cleanup.
125   void StartClearingCookies(const base::Closure& on_clear_callback);
126   void OnCookiesCleared(const base::Closure& on_clear_callback);
127 
128   // Kick off DNS cache flushing.
129   void StartClearingDnsCache();
130   void OnDnsCleared();
131 
132   // Show sign-in screen for the given credentials.
133   virtual void ShowSigninScreenForCreds(const std::string& username,
134                                         const std::string& password);
135   // Attempts login for test.
136   void SubmitLoginFormForTest();
137 
138   // Updates the member variable and UMA histogram indicating whether the
139   // principals API was used during SAML login.
140   void SetSAMLPrincipalsAPIUsed(bool api_used);
141 
142   void ShowGaia(bool is_enrolling_consumer_management);
143 
144   // Shows signin screen after dns cache and cookie cleanup operations finish.
145   void ShowGaiaScreenIfReady();
146 
147   // Decides whether an auth extension should be pre-loaded. If it should,
148   // pre-loads it.
149   void MaybePreloadAuthExtension();
150 
151   // Tells webui to load authentication extension. |force| is used to force the
152   // extension reloading, if it has already been loaded. |silent_load| is true
153   // for cases when extension should be loaded in the background and it
154   // shouldn't grab the focus. |offline| is true when offline version of the
155   // extension should be used.
156   void LoadAuthExtension(bool force, bool silent_load, bool offline);
157 
158   // TODO (ygorshenin@): GaiaScreenHandler should implement
159   // NetworkStateInformer::Observer.
160   void UpdateState(ErrorScreenActor::ErrorReason reason);
161 
162   // TODO (ygorshenin@): remove this dependency.
163   void SetSigninScreenHandler(SigninScreenHandler* handler);
164 
165   SigninScreenHandlerDelegate* Delegate();
166 
167   // Current state of Gaia frame.
168   FrameState frame_state_;
169 
170   // Latest Gaia frame error.
171   net::Error frame_error_;
172 
173   // Network state informer used to keep signin screen up.
174   scoped_refptr<NetworkStateInformer> network_state_informer_;
175 
176   // Consumer management service for checking if enrollment is in progress.
177   policy::ConsumerManagementService* consumer_management_;
178 
179   CoreOobeActor* core_oobe_actor_;
180 
181   // Email to pre-populate with.
182   std::string populated_email_;
183 
184   // Emails of the users, whose passwords have recently been changed.
185   std::set<std::string> password_changed_for_;
186 
187   // True if dns cache cleanup is done.
188   bool dns_cleared_;
189 
190   // True if DNS cache task is already running.
191   bool dns_clear_task_running_;
192 
193   // True if cookie jar cleanup is done.
194   bool cookies_cleared_;
195 
196   // Is focus still stolen from Gaia page?
197   bool focus_stolen_;
198 
199   // Has Gaia page silent load been started for the current sign-in attempt?
200   bool gaia_silent_load_;
201 
202   // The active network at the moment when Gaia page was preloaded.
203   std::string gaia_silent_load_network_;
204 
205   // If the user authenticated via SAML, this indicates whether the principals
206   // API was used.
207   bool using_saml_api_;
208 
209   // Whether consumer management enrollment is in progress.
210   bool is_enrolling_consumer_management_;
211 
212   // Test credentials.
213   std::string test_user_;
214   std::string test_pass_;
215   bool test_expects_complete_login_;
216 
217   // Non-owning ptr to SigninScreenHandler instance. Should not be used
218   // in dtor.
219   // TODO (ygorshenin@): GaiaScreenHandler shouldn't communicate with
220   // signin_screen_handler directly.
221   SigninScreenHandler* signin_screen_handler_;
222 
223   base::WeakPtrFactory<GaiaScreenHandler> weak_factory_;
224 
225   DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler);
226 };
227 
228 }  // namespace chromeos
229 
230 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
231