• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_ENROLLMENT_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
16 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
17 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
18 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
19 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
20 
21 namespace policy {
22 class PolicyOAuth2TokenFetcher;
23 }
24 
25 namespace chromeos {
26 
27 class AuthenticatedUserEmailRetriever;
28 
29 // WebUIMessageHandler implementation which handles events occurring on the
30 // page, such as the user pressing the signin button.
31 class EnrollmentScreenHandler
32     : public BaseScreenHandler,
33       public EnrollmentScreenActor,
34       public BrowsingDataRemover::Observer,
35       public NetworkStateInformer::NetworkStateInformerObserver,
36       public WebUILoginView::FrameObserver {
37  public:
38   EnrollmentScreenHandler(
39       const scoped_refptr<NetworkStateInformer>& network_state_informer,
40       ErrorScreenActor* error_screen_actor);
41   virtual ~EnrollmentScreenHandler();
42 
43   // Implements WebUIMessageHandler:
44   virtual void RegisterMessages() OVERRIDE;
45 
46   // Implements EnrollmentScreenActor:
47   virtual void SetParameters(Controller* controller,
48                              EnrollmentMode enrollment_mode,
49                              const std::string& management_domain) OVERRIDE;
50   virtual void PrepareToShow() OVERRIDE;
51   virtual void Show() OVERRIDE;
52   virtual void Hide() OVERRIDE;
53   virtual void FetchOAuthToken() OVERRIDE;
54   virtual void ResetAuth(const base::Closure& callback) OVERRIDE;
55   virtual void ShowSigninScreen() OVERRIDE;
56   virtual void ShowEnrollmentSpinnerScreen() OVERRIDE;
57   virtual void ShowLoginSpinnerScreen() OVERRIDE;
58   virtual void ShowAuthError(const GoogleServiceAuthError& error) OVERRIDE;
59   virtual void ShowEnrollmentStatus(policy::EnrollmentStatus status) OVERRIDE;
60   virtual void ShowUIError(UIError error_code) OVERRIDE;
61 
62   // Implements BaseScreenHandler:
63   virtual void Initialize() OVERRIDE;
64   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
65 
66   // Implements BrowsingDataRemover::Observer:
67   virtual void OnBrowsingDataRemoverDone() OVERRIDE;
68 
69   // Implements NetworkStateInformer::NetworkStateInformerObserver
70   virtual void UpdateState(ErrorScreenActor::ErrorReason reason) OVERRIDE;
71 
72   // Implements WebUILoginView::FrameObserver
73   virtual void OnFrameError(const std::string& frame_unique_name) OVERRIDE;
74 
75  private:
76   // Handlers for WebUI messages.
77   void HandleRetrieveAuthenticatedUserEmail(double attempt_token);
78   void HandleClose(const std::string& reason);
79   void HandleCompleteLogin(const std::string& user);
80   void HandleRetry();
81   void HandleFrameLoadingCompleted(int status);
82 
83   void SetupAndShowOfflineMessage(NetworkStateInformer::State state,
84                                   ErrorScreenActor::ErrorReason reason);
85   void HideOfflineMessage(NetworkStateInformer::State state,
86                           ErrorScreenActor::ErrorReason reason);
87 
frame_error()88   net::Error frame_error() const { return frame_error_; }
89   // Shows a given enrollment step.
90   void ShowStep(const char* step);
91 
92   // Display the given i18n resource as error message.
93   void ShowError(int message_id, bool retry);
94 
95   // Display the given string as error message.
96   void ShowErrorMessage(const std::string& message, bool retry);
97 
98   // Display the given i18n string as a progress message.
99   void ShowWorking(int message_id);
100 
101   // Handles completion of the OAuth2 token fetch attempt.
102   void OnTokenFetched(const std::string& token,
103                       const GoogleServiceAuthError& error);
104 
105   // Shows the screen.
106   void DoShow();
107 
108   // Returns current visible screen.
109   OobeUI::Screen GetCurrentScreen() const;
110 
111   // Returns true if current visible screen is the enrollment sign-in page.
112   bool IsOnEnrollmentScreen() const;
113 
114   // Returns true if current visible screen is the error screen over
115   // enrollment sign-in page.
116   bool IsEnrollmentScreenHiddenByError() const;
117 
118   // Keeps the controller for this actor.
119   Controller* controller_;
120 
121   bool show_on_init_;
122 
123   // The enrollment mode.
124   EnrollmentMode enrollment_mode_;
125 
126   // The management domain, if applicable.
127   std::string management_domain_;
128 
129   // Whether an enrollment attempt has failed.
130   bool enrollment_failed_once_;
131 
132   // This intentionally lives here and not in the controller, since it needs to
133   // execute requests in the context of the profile that displays the webui.
134   scoped_ptr<policy::PolicyOAuth2TokenFetcher> oauth_fetcher_;
135 
136   // The browsing data remover instance currently active, if any.
137   BrowsingDataRemover* browsing_data_remover_;
138 
139   // The callbacks to invoke after browsing data has been cleared.
140   std::vector<base::Closure> auth_reset_callbacks_;
141 
142   // Helper that retrieves the authenticated user's e-mail address.
143   scoped_ptr<AuthenticatedUserEmailRetriever> email_retriever_;
144 
145   // Latest enrollment frame error.
146   net::Error frame_error_;
147 
148   // Network state informer used to keep signin screen up.
149   scoped_refptr<NetworkStateInformer> network_state_informer_;
150 
151   ErrorScreenActor* error_screen_actor_;
152 
153   base::WeakPtrFactory<EnrollmentScreenHandler> weak_ptr_factory_;
154 
155   DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenHandler);
156 };
157 
158 }  // namespace chromeos
159 
160 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_ENROLLMENT_SCREEN_HANDLER_H_
161