Home | History | Annotate | Download | only in login
      1 // Copyright 2014 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_SUPERVISED_USER_CREATION_SCREEN_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SUPERVISED_USER_CREATION_SCREEN_HANDLER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/strings/string16.h"
     12 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
     13 #include "components/user_manager/user_image/default_user_images.h"
     14 #include "content/public/browser/web_ui.h"
     15 
     16 namespace base {
     17 class ListValue;
     18 }
     19 
     20 namespace chromeos {
     21 
     22 class SupervisedUserCreationScreenHandler : public BaseScreenHandler {
     23  public:
     24   class Delegate {
     25    public:
     26     virtual ~Delegate() {}
     27 
     28     // This method is called, when actor is being destroyed. Note, if Delegate
     29     // is destroyed earlier then it has to call SetDelegate(NULL).
     30     virtual void OnActorDestroyed(
     31         SupervisedUserCreationScreenHandler* actor) = 0;
     32 
     33     // Starts supervised user creation flow, with manager identified by
     34     // |manager_id| and |manager_password|.
     35     virtual void AuthenticateManager(const std::string& manager_id,
     36                                      const std::string& manager_password) = 0;
     37 
     38     // Starts supervised user creation flow, with supervised user that would
     39     // have |display_name| and authenticated by the |supervised_user_password|.
     40     virtual void CreateSupervisedUser(
     41         const base::string16& display_name,
     42         const std::string& supervised_user_password) = 0;
     43 
     44     // Look up if user with name |display_name| already exist and can be
     45     // imported. Returns user ID in |out_id|. Returns true if user was found,
     46     // false otherwise.
     47     virtual bool FindUserByDisplayName(const base::string16& display_name,
     48                                        std::string *out_id) const = 0;
     49 
     50     // Starts supervised user import flow for user identified with |user_id|.
     51     virtual void ImportSupervisedUser(const std::string& user_id) = 0;
     52     // Starts supervised user import flow for user identified with |user_id| and
     53     // additional |password|.
     54     virtual void ImportSupervisedUserWithPassword(
     55         const std::string& user_id, const std::string& password) = 0;
     56 
     57     virtual void AbortFlow() = 0;
     58     virtual void FinishFlow() = 0;
     59 
     60     virtual void OnPhotoTaken(const std::string& raw_data) = 0;
     61     virtual void OnImageSelected(const std::string& image_url,
     62                                  const std::string& image_type) = 0;
     63     virtual void OnImageAccepted() = 0;
     64     virtual void OnPageSelected(const std::string& page) = 0;
     65   };
     66 
     67   SupervisedUserCreationScreenHandler();
     68   virtual ~SupervisedUserCreationScreenHandler();
     69 
     70   virtual void PrepareToShow();
     71   virtual void Show();
     72   virtual void Hide();
     73   virtual void SetDelegate(Delegate* delegate);
     74 
     75   void ShowManagerPasswordError();
     76 
     77   void ShowIntroPage();
     78   void ShowManagerSelectionPage();
     79   void ShowUsernamePage();
     80 
     81   // Shows progress or error message close in the button area. |is_progress| is
     82   // true for progress messages and false for error messages.
     83   void ShowStatusMessage(bool is_progress, const base::string16& message);
     84   void ShowTutorialPage();
     85 
     86   void ShowErrorPage(const base::string16& title,
     87                      const base::string16& message,
     88                      const base::string16& button_text);
     89 
     90   // Navigates to specified page.
     91   void ShowPage(const std::string& page);
     92 
     93   void SetCameraPresent(bool enabled);
     94 
     95   void ShowExistingSupervisedUsers(const base::ListValue* users);
     96 
     97   // BaseScreenHandler implementation:
     98   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
     99   virtual void Initialize() OVERRIDE;
    100 
    101   // WebUIMessageHandler implementation:
    102   virtual void RegisterMessages() OVERRIDE;
    103 
    104  private:
    105   // WebUI message handlers.
    106   void HandleCheckSupervisedUserName(const base::string16& name);
    107 
    108   void HandleManagerSelected(const std::string& manager_id);
    109   void HandleImportUserSelected(const std::string& user_id);
    110 
    111   void HandleFinishLocalSupervisedUserCreation();
    112   void HandleAbortLocalSupervisedUserCreation();
    113   void HandleRetryLocalSupervisedUserCreation(const base::ListValue* args);
    114   void HandleCurrentSupervisedUserPage(const std::string& current_page);
    115 
    116   void HandleAuthenticateManager(const std::string& raw_manager_username,
    117                                  const std::string& manager_password);
    118   void HandleCreateSupervisedUser(const base::string16& new_raw_user_name,
    119                                const std::string& new_user_password);
    120   void HandleImportSupervisedUser(const std::string& user_id);
    121   void HandleImportSupervisedUserWithPassword(const std::string& user_id,
    122                                               const std::string& password);
    123 
    124   void HandleGetImages();
    125   void HandlePhotoTaken(const std::string& image_url);
    126   void HandleTakePhoto();
    127   void HandleDiscardPhoto();
    128   void HandleSelectImage(const std::string& image_url,
    129                          const std::string& image_type);
    130 
    131   void UpdateText(const std::string& element_id, const base::string16& text);
    132 
    133   Delegate* delegate_;
    134 
    135   DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationScreenHandler);
    136 };
    137 
    138 }  // namespace chromeos
    139 
    140 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SUPERVISED_USER_CREATION_SCREEN_HANDLER_H_
    141