Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / login / gaia_screen_handler.h
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   // True if embedded_signin is enabled.
54   bool embedded_signin_enabled;
55 };
56
57 // A class that handles WebUI hooks in Gaia screen.
58 class GaiaScreenHandler : public BaseScreenHandler {
59  public:
60   enum FrameState {
61     FRAME_STATE_UNKNOWN = 0,
62     FRAME_STATE_LOADING,
63     FRAME_STATE_LOADED,
64     FRAME_STATE_ERROR
65   };
66
67   GaiaScreenHandler(
68       CoreOobeActor* core_oobe_actor,
69       const scoped_refptr<NetworkStateInformer>& network_state_informer,
70       policy::ConsumerManagementService* consumer_management);
71   virtual ~GaiaScreenHandler();
72
73   void LoadGaia(const GaiaContext& context);
74   void UpdateGaia(const GaiaContext& context);
75
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);
80
81   // Reload gaia with embedded signin frame.
82   void SwitchToEmbeddedSignin();
83
84   // Cancel embedded signin for the next load.
85   void CancelEmbeddedSignin();
86
87   FrameState frame_state() const { return frame_state_; }
88   net::Error frame_error() const { return frame_error_; }
89
90  private:
91   // TODO (ygorshenin@): remove this dependency.
92   friend class SigninScreenHandler;
93
94   // BaseScreenHandler implementation:
95   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) override;
96   virtual void Initialize() override;
97
98   // WebUIMessageHandler implementation:
99   virtual void RegisterMessages() override;
100
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,
110                            bool using_saml);
111
112   void HandleUsingSAMLAPI();
113   void HandleScrapedPasswordCount(int password_count);
114   void HandleScrapedPasswordVerificationFailed();
115
116   void HandleGaiaUIReady();
117
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,
122                       bool using_saml,
123                       bool success);
124
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,
129                        bool using_saml);
130
131   // Fill GAIA user name.
132   void PopulateEmail(const std::string& user_id);
133
134   // Mark user as having password changed:
135   void PasswordChangedFor(const std::string& user_id);
136
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);
140
141   // Kick off DNS cache flushing.
142   void StartClearingDnsCache();
143   void OnDnsCleared();
144
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();
150
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);
154
155   void ShowGaia(bool is_enrolling_consumer_management);
156
157   // Shows signin screen after dns cache and cookie cleanup operations finish.
158   void ShowGaiaScreenIfReady();
159
160   // Decides whether an auth extension should be pre-loaded. If it should,
161   // pre-loads it.
162   void MaybePreloadAuthExtension();
163
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);
170
171   // TODO (ygorshenin@): GaiaScreenHandler should implement
172   // NetworkStateInformer::Observer.
173   void UpdateState(ErrorScreenActor::ErrorReason reason);
174
175   // TODO (ygorshenin@): remove this dependency.
176   void SetSigninScreenHandler(SigninScreenHandler* handler);
177
178   SigninScreenHandlerDelegate* Delegate();
179
180   // Current state of Gaia frame.
181   FrameState frame_state_;
182
183   // Latest Gaia frame error.
184   net::Error frame_error_;
185
186   // Network state informer used to keep signin screen up.
187   scoped_refptr<NetworkStateInformer> network_state_informer_;
188
189   // Consumer management service for checking if enrollment is in progress.
190   policy::ConsumerManagementService* consumer_management_;
191
192   CoreOobeActor* core_oobe_actor_;
193
194   // Email to pre-populate with.
195   std::string populated_email_;
196
197   // Emails of the users, whose passwords have recently been changed.
198   std::set<std::string> password_changed_for_;
199
200   // True if dns cache cleanup is done.
201   bool dns_cleared_;
202
203   // True if DNS cache task is already running.
204   bool dns_clear_task_running_;
205
206   // True if cookie jar cleanup is done.
207   bool cookies_cleared_;
208
209   // Is focus still stolen from Gaia page?
210   bool focus_stolen_;
211
212   // Has Gaia page silent load been started for the current sign-in attempt?
213   bool gaia_silent_load_;
214
215   // The active network at the moment when Gaia page was preloaded.
216   std::string gaia_silent_load_network_;
217
218   // If the user authenticated via SAML, this indicates whether the principals
219   // API was used.
220   bool using_saml_api_;
221
222   // Whether consumer management enrollment is in progress.
223   bool is_enrolling_consumer_management_;
224
225   // Test credentials.
226   std::string test_user_;
227   std::string test_pass_;
228   bool test_expects_complete_login_;
229
230   // True if user pressed shortcut to enable embedded signin.
231   bool embedded_signin_enabled_by_shortcut_;
232
233   // Non-owning ptr to SigninScreenHandler instance. Should not be used
234   // in dtor.
235   // TODO (ygorshenin@): GaiaScreenHandler shouldn't communicate with
236   // signin_screen_handler directly.
237   SigninScreenHandler* signin_screen_handler_;
238
239   base::WeakPtrFactory<GaiaScreenHandler> weak_factory_;
240
241   DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler);
242 };
243
244 }  // namespace chromeos
245
246 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_