1// Copyright (c) 2011 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_BACKGROUND_VIEW_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_BACKGROUND_VIEW_H_
7#pragma once
8
9#include "chrome/browser/chromeos/boot_times_loader.h"
10#include "chrome/browser/chromeos/cros/cros_library.h"
11#include "chrome/browser/chromeos/login/login_html_dialog.h"
12#include "chrome/browser/chromeos/status/status_area_host.h"
13#include "chrome/browser/chromeos/version_loader.h"
14#include "chrome/browser/policy/cloud_policy_subsystem.h"
15#include "views/view.h"
16
17namespace views {
18class Label;
19class TextButton;
20class Widget;
21class WindowDelegate;
22}
23
24class DOMView;
25class GURL;
26class Profile;
27
28namespace chromeos {
29
30class OobeProgressBar;
31class ShutdownButton;
32class StatusAreaView;
33
34// View used to render the background during login. BackgroundView contains
35// StatusAreaView.
36class BackgroundView : public views::View,
37                       public StatusAreaHost,
38                       public chromeos::LoginHtmlDialog::Delegate,
39                       public policy::CloudPolicySubsystem::Observer {
40 public:
41  enum LoginStep {
42    SELECT_NETWORK,
43    EULA,
44    SIGNIN,
45    REGISTRATION,
46    PICTURE,
47
48    // Steps count, must be the last in the enum.
49    STEPS_COUNT
50  };
51
52  BackgroundView();
53
54  // Initializes the background view. It backgroun_url is given (non empty),
55  // it creates a DOMView background area that renders a webpage.
56  void Init(const GURL& background_url);
57
58  // Enable/disable shutdown button.
59  void EnableShutdownButton(bool enable);
60
61  // Creates a window containing an instance of WizardContentsView as the root
62  // view. The caller is responsible for showing (and closing) the returned
63  // widget. The BackgroundView is set in |view|. If background_url is non
64  // empty, the content page of the url is displayed as a background.
65  static views::Widget* CreateWindowContainingView(
66      const gfx::Rect& bounds,
67      const GURL& background_url,
68      BackgroundView** view);
69
70  // Create a modal popup view.
71  void CreateModalPopup(views::WindowDelegate* view);
72
73  // Overridden from StatusAreaHost:
74  virtual gfx::NativeWindow GetNativeWindow() const;
75
76  // Toggles status area visibility.
77  void SetStatusAreaVisible(bool visible);
78
79  // Toggles whether status area is enabled.
80  void SetStatusAreaEnabled(bool enable);
81
82  // Toggles OOBE progress bar visibility, the bar is hidden by default.
83  void SetOobeProgressBarVisible(bool visible);
84
85  // Gets progress bar visibility.
86  bool IsOobeProgressBarVisible();
87
88  // Sets current step on OOBE progress bar.
89  void SetOobeProgress(LoginStep step);
90
91  // Shows screen saver.
92  void ShowScreenSaver();
93
94  // Hides screen saver.
95  void HideScreenSaver();
96
97  // Tells if screen saver is visible.
98  bool IsScreenSaverVisible();
99
100  // Tells if screen saver is enabled.
101  bool ScreenSaverEnabled();
102
103 protected:
104  // Overridden from views::View:
105  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
106  virtual void Layout() OVERRIDE;
107  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
108  virtual void OnLocaleChanged() OVERRIDE;
109
110  // Overridden from StatusAreaHost:
111  virtual Profile* GetProfile() const OVERRIDE { return NULL; }
112  virtual void ExecuteBrowserCommand(int id) const OVERRIDE {}
113  virtual bool ShouldOpenButtonOptions(
114      const views::View* button_view) const OVERRIDE;
115  virtual void OpenButtonOptions(const views::View* button_view) OVERRIDE;
116  virtual ScreenMode GetScreenMode() const OVERRIDE;
117  virtual TextStyle GetTextStyle() const OVERRIDE;
118
119  // Overridden from LoginHtmlDialog::Delegate:
120  virtual void OnDialogClosed() OVERRIDE {}
121
122 private:
123  // Creates and adds the status_area.
124  void InitStatusArea();
125  // Creates and adds the labels for version and boot time.
126  void InitInfoLabels();
127  // Creates and add OOBE progress bar.
128  void InitProgressBar();
129
130  // Invokes SetWindowType for the window. This is invoked during startup and
131  // after we've painted.
132  void UpdateWindowType();
133
134  // Update the version label.
135  void UpdateVersionLabel();
136
137  // Check and update enterprise domain.
138  void UpdateEnterpriseInfo();
139
140  // Set enterprise domain name.
141  void SetEnterpriseInfo(const std::string& domain_name,
142                         const std::string& status_text);
143
144  // Callback from chromeos::VersionLoader giving the version.
145  void OnVersion(VersionLoader::Handle handle, std::string version);
146  // Callback from chromeos::InfoLoader giving the boot times.
147  void OnBootTimes(
148      BootTimesLoader::Handle handle, BootTimesLoader::BootTimes boot_times);
149
150  // policy::CloudPolicySubsystem::Observer methods:
151  void OnPolicyStateChanged(
152      policy::CloudPolicySubsystem::PolicySubsystemState state,
153      policy::CloudPolicySubsystem::ErrorDetails error_details);
154
155  // All of these variables could be NULL.
156  StatusAreaView* status_area_;
157  views::Label* os_version_label_;
158  views::Label* boot_times_label_;
159  OobeProgressBar* progress_bar_;
160  ShutdownButton* shutdown_button_;
161
162  // Handles asynchronously loading the version.
163  VersionLoader version_loader_;
164  // Used to request the version.
165  CancelableRequestConsumer version_consumer_;
166
167  // Handles asynchronously loading the boot times.
168  BootTimesLoader boot_times_loader_;
169  // Used to request the boot times.
170  CancelableRequestConsumer boot_times_consumer_;
171
172  // Has Paint been invoked once? The value of this is passed to the window
173  // manager.
174  // TODO(sky): nuke this when the wm knows when chrome has painted.
175  bool did_paint_;
176
177  // True if running official BUILD.
178  bool is_official_build_;
179
180  // DOMView for rendering a webpage as a background.
181  DOMView* background_area_;
182
183  // Information pieces for version label.
184  std::string version_text_;
185  std::string enterprise_domain_text_;
186  std::string enterprise_status_text_;
187
188  // Proxy settings dialog that can be invoked from network menu.
189  scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_;
190
191  // CloudPolicySubsysterm observer registrar
192  scoped_ptr<policy::CloudPolicySubsystem::ObserverRegistrar>
193      cloud_policy_registrar_;
194
195  DISALLOW_COPY_AND_ASSIGN(BackgroundView);
196};
197
198}  // namespace chromeos
199
200#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_BACKGROUND_VIEW_H_
201