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