wizard_controller.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 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_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
7#pragma once
8
9#include <string>
10
11#include "base/gtest_prod_util.h"
12#include "base/scoped_ptr.h"
13#include "chrome/browser/chromeos/login/screen_observer.h"
14#include "chrome/browser/chromeos/login/view_screen.h"
15#include "chrome/browser/chromeos/login/wizard_screen.h"
16#include "gfx/rect.h"
17#include "googleurl/src/gurl.h"
18#include "testing/gtest/include/gtest/gtest_prod.h"
19
20class PrefService;
21class WizardContentsView;
22class WizardScreen;
23
24namespace chromeos {
25class AccountScreen;
26class BackgroundView;
27class EulaScreen;
28class ExistingUserController;
29class HTMLPageScreen;
30class LoginScreen;
31class NetworkScreen;
32class RegistrationScreen;
33class StartupCustomizationDocument;
34class UpdateScreen;
35class UserImageScreen;
36}
37
38namespace gfx {
39class Rect;
40}
41
42namespace views {
43class Views;
44class Widget;
45class WidgetGtk;
46}
47
48// Class that manages control flow between wizard screens. Wizard controller
49// interacts with screen controllers to move the user between screens.
50class WizardController : public chromeos::ScreenObserver,
51                         public WizardScreenDelegate {
52 public:
53  WizardController();
54  ~WizardController();
55
56  // Returns the default wizard controller if it has been created.
57  static WizardController* default_controller() {
58    return default_controller_;
59  }
60
61  // Returns OOBE completion status.
62  static bool IsOobeCompleted();
63
64  // Marks OOBE process as completed.
65  static void MarkOobeCompleted();
66
67  // Returns device registration completion status, i.e. second part of OOBE.
68  static bool IsDeviceRegistered();
69
70  // Marks device registered. i.e. second part of OOBE is completed.
71  static void MarkDeviceRegistered();
72
73  // Shows the first screen defined by |first_screen_name| or by default
74  // if the parameter is empty. |screen_bounds| are used to calculate position
75  // of the wizard screen.
76  void Init(const std::string& first_screen_name,
77            const gfx::Rect& screen_bounds);
78
79  // Returns the view that contains all the other views.
80  views::View* contents() { return contents_; }
81
82  // Shows the wizard controller in a window.
83  void Show();
84
85  // Creates and shows a background window.
86  void ShowBackground(const gfx::Rect& bounds);
87
88  // Takes ownership of the specified background widget and view.
89  void OwnBackground(views::Widget* background_widget,
90                     chromeos::BackgroundView* background_view);
91
92  // Lazy initializers and getters for screens.
93  chromeos::NetworkScreen* GetNetworkScreen();
94  chromeos::LoginScreen* GetLoginScreen();
95  chromeos::AccountScreen* GetAccountScreen();
96  chromeos::UpdateScreen* GetUpdateScreen();
97  chromeos::UserImageScreen* GetUserImageScreen();
98  chromeos::EulaScreen* GetEulaScreen();
99  chromeos::RegistrationScreen* GetRegistrationScreen();
100  chromeos::HTMLPageScreen* GetHTMLPageScreen();
101
102  // Show specific screen.
103  void ShowNetworkScreen();
104  void ShowAccountScreen();
105  void ShowUpdateScreen();
106  void ShowUserImageScreen();
107  void ShowEulaScreen();
108  void ShowRegistrationScreen();
109  void ShowHTMLPageScreen();
110  // Shows the default login screen and returns NULL or shows images login
111  // screen and returns the corresponding controller instance for optional
112  // tweaking.
113  chromeos::ExistingUserController* ShowLoginScreen();
114
115  // Returns a pointer to the current screen or NULL if there's no such
116  // screen.
117  WizardScreen* current_screen() const { return current_screen_; }
118
119  // Overrides observer for testing.
120  void set_observer(ScreenObserver* observer) { observer_ = observer; }
121
122  // Set URL to open on browser launch.
123  void set_start_url(const GURL& start_url) { start_url_ = start_url; }
124
125  // Sets partner startup customization. WizardController takes ownership
126  // of the document object.
127  void SetCustomization(
128      const chromeos::StartupCustomizationDocument* customization);
129
130  // Returns partner startup customization document owned by WizardController.
131  const chromeos::StartupCustomizationDocument* GetCustomization() const;
132
133  // If being at register screen proceeds to the next one.
134  void SkipRegistration();
135
136  // Registers OOBE preferences.
137  static void RegisterPrefs(PrefService* local_state);
138
139  static const char kNetworkScreenName[];
140  static const char kLoginScreenName[];
141  static const char kAccountScreenName[];
142  static const char kUpdateScreenName[];
143  static const char kUserImageScreenName[];
144  static const char kRegistrationScreenName[];
145  static const char kOutOfBoxScreenName[];
146  static const char kTestNoScreenName[];
147  static const char kEulaScreenName[];
148  static const char kHTMLPageScreenName[];
149
150 private:
151  // Exit handlers:
152  void OnLoginSignInSelected();
153  void OnLoginGuestUser();
154  void OnLoginCreateAccount();
155  void OnNetworkConnected();
156  void OnNetworkOffline();
157  void OnAccountCreateBack();
158  void OnAccountCreated();
159  void OnConnectionFailed();
160  void OnUpdateCompleted();
161  void OnEulaAccepted();
162  void OnUpdateErrorCheckingForUpdate();
163  void OnUpdateErrorUpdating();
164  void OnUserImageSelected();
165  void OnUserImageSkipped();
166  void OnRegistrationSuccess();
167  void OnRegistrationSkipped();
168  void OnOOBECompleted();
169
170  // Creates wizard screen window with the specified |bounds|.
171  // If |initial_show| initial animation (window & background) is shown.
172  // Otherwise only window is animated.
173  views::WidgetGtk* CreateScreenWindow(const gfx::Rect& bounds,
174                                       bool initial_show);
175
176  // Returns bounds for the wizard screen host window in screen coordinates.
177  // Calculates bounds using screen_bounds_.
178  gfx::Rect GetWizardScreenBounds(int screen_width, int screen_height) const;
179
180  // Switches from one screen to another.
181  void SetCurrentScreen(WizardScreen* screen);
182
183  // Changes status area visibility.
184  void SetStatusAreaVisible(bool visible);
185
186  // Overridden from chromeos::ScreenObserver:
187  virtual void OnExit(ExitCodes exit_code);
188  virtual void OnSetUserNamePassword(const std::string& username,
189                                     const std::string& password);
190
191  // Overridden from WizardScreenDelegate:
192  virtual views::View* GetWizardView();
193  virtual chromeos::ScreenObserver* GetObserver(WizardScreen* screen);
194
195  // Determines which screen to show first by the parameter, shows it and
196  // sets it as the current one.
197  void ShowFirstScreen(const std::string& first_screen_name);
198
199  // Logs in the specified user via default login screen.
200  void Login(const std::string& username, const std::string& password);
201
202  // Widget we're showing in.
203  views::Widget* widget_;
204
205  // Used to render the background.
206  views::Widget* background_widget_;
207  chromeos::BackgroundView* background_view_;
208
209  // Contents view.
210  views::View* contents_;
211
212  // Used to calculate position of the wizard screen.
213  gfx::Rect screen_bounds_;
214
215  // Screens.
216  scoped_ptr<chromeos::NetworkScreen> network_screen_;
217  scoped_ptr<chromeos::LoginScreen> login_screen_;
218  scoped_ptr<chromeos::AccountScreen> account_screen_;
219  scoped_ptr<chromeos::UpdateScreen> update_screen_;
220  scoped_ptr<chromeos::UserImageScreen> user_image_screen_;
221  scoped_ptr<chromeos::EulaScreen> eula_screen_;
222  scoped_ptr<chromeos::RegistrationScreen> registration_screen_;
223  scoped_ptr<chromeos::HTMLPageScreen> html_page_screen_;
224
225  // Screen that's currently active.
226  WizardScreen* current_screen_;
227
228  std::string username_;
229  std::string password_;
230
231  // True if running official BUILD.
232  bool is_official_build_;
233
234  // True if full OOBE flow should be shown.
235  bool is_out_of_box_;
236
237  // True if this is run under automation test and we need to show only
238  // login screen.
239  bool is_test_mode_;
240
241  // Value of the screen name that WizardController was started with.
242  std::string first_screen_name_;
243
244  // NULL by default - controller itself is observer. Mock could be assigned.
245  ScreenObserver* observer_;
246
247  // Default WizardController.
248  static WizardController* default_controller_;
249
250  // Partner startup customizations.
251  scoped_ptr<const chromeos::StartupCustomizationDocument> customization_;
252
253  // URL to open on browser launch.
254  GURL start_url_;
255
256  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, ControlFlowErrorNetwork);
257  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, ControlFlowErrorUpdate);
258  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, ControlFlowEulaDeclined);
259  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest,
260                           ControlFlowLanguageOnLogin);
261  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest,
262                           ControlFlowLanguageOnNetwork);
263  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, ControlFlowMain);
264  FRIEND_TEST_ALL_PREFIXES(WizardControllerTest, SwitchLanguage);
265  friend class WizardControllerFlowTest;
266
267  DISALLOW_COPY_AND_ASSIGN(WizardController);
268};
269
270#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
271