background_view.h revision 513209b27ff55e2841eac0e4120199c23acce758
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_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 "views/view.h"
15
16namespace views {
17class Label;
18class TextButton;
19class Widget;
20}
21
22class DOMView;
23class GURL;
24class Profile;
25
26namespace chromeos {
27
28class OobeProgressBar;
29class ShutdownButton;
30class StatusAreaView;
31
32// View used to render the background during login. BackgroundView contains
33// StatusAreaView.
34class BackgroundView : public views::View,
35                       public StatusAreaHost,
36                       public chromeos::LoginHtmlDialog::Delegate {
37 public:
38  enum LoginStep {
39    SELECT_NETWORK,
40#if defined(OFFICIAL_BUILD)
41    EULA,
42#endif
43    SIGNIN,
44#if defined(OFFICIAL_BUILD)
45    REGISTRATION,
46#endif
47    PICTURE
48  };
49
50  BackgroundView();
51
52  // Initializes the background view. It backgroun_url is given (non empty),
53  // it creates a DOMView background area that renders a webpage.
54  void Init(const GURL& background_url);
55
56  // Enable shutdown button.
57  void EnableShutdownButton();
58
59  // Creates a window containing an instance of WizardContentsView as the root
60  // view. The caller is responsible for showing (and closing) the returned
61  // widget. The BackgroundView is set in |view|. If background_url is non
62  // empty, the content page of the url is displayed as a background.
63  static views::Widget* CreateWindowContainingView(
64      const gfx::Rect& bounds,
65      const GURL& background_url,
66      BackgroundView** view);
67
68  // Toggles status area visibility.
69  void SetStatusAreaVisible(bool visible);
70
71  // Toggles OOBE progress bar visibility, the bar is hidden by default.
72  void SetOobeProgressBarVisible(bool visible);
73
74  // Gets progress bar visibility.
75  bool IsOobeProgressBarVisible();
76
77  // Sets current step on OOBE progress bar.
78  void SetOobeProgress(LoginStep step);
79
80  // Shows screen saver.
81  void ShowScreenSaver();
82
83  // Hides screen saver.
84  void HideScreenSaver();
85
86  // Tells if screen saver is visible.
87  bool IsScreenSaverVisible();
88
89  // Tells if screen saver is enabled.
90  bool ScreenSaverEnabled();
91
92 protected:
93  // Overridden from views::View:
94  virtual void Paint(gfx::Canvas* canvas);
95  virtual void Layout();
96  virtual void ChildPreferredSizeChanged(View* child);
97  virtual void OnLocaleChanged();
98
99  // Overridden from StatusAreaHost:
100  virtual Profile* GetProfile() const { return NULL; }
101  virtual gfx::NativeWindow GetNativeWindow() const;
102  virtual void ExecuteBrowserCommand(int id) const {}
103  virtual bool ShouldOpenButtonOptions(
104      const views::View* button_view) const;
105  virtual void OpenButtonOptions(const views::View* button_view);
106  virtual bool IsBrowserMode() const;
107  virtual bool IsScreenLockerMode() const;
108
109  // Overridden from LoginHtmlDialog::Delegate:
110  virtual void OnDialogClosed() {}
111
112 private:
113  // Creates and adds the status_area.
114  void InitStatusArea();
115  // Creates and adds the labels for version and boot time.
116  void InitInfoLabels();
117  // Creates and add OOBE progress bar.
118  void InitProgressBar();
119
120  // Invokes SetWindowType for the window. This is invoked during startup and
121  // after we've painted.
122  void UpdateWindowType();
123
124  // Callback from chromeos::VersionLoader giving the version.
125  void OnVersion(VersionLoader::Handle handle, std::string version);
126  // Callback from chromeos::InfoLoader giving the boot times.
127  void OnBootTimes(
128      BootTimesLoader::Handle handle, BootTimesLoader::BootTimes boot_times);
129
130  // All of these variables could be NULL.
131  StatusAreaView* status_area_;
132  views::Label* os_version_label_;
133  views::Label* boot_times_label_;
134  OobeProgressBar* progress_bar_;
135  ShutdownButton* shutdown_button_;
136
137  // Handles asynchronously loading the version.
138  VersionLoader version_loader_;
139  // Used to request the version.
140  CancelableRequestConsumer version_consumer_;
141
142  // Handles asynchronously loading the boot times.
143  BootTimesLoader boot_times_loader_;
144  // Used to request the boot times.
145  CancelableRequestConsumer boot_times_consumer_;
146
147  // Has Paint been invoked once? The value of this is passed to the window
148  // manager.
149  // TODO(sky): nuke this when the wm knows when chrome has painted.
150  bool did_paint_;
151
152  // True if running official BUILD.
153  bool is_official_build_;
154
155  // DOMView for rendering a webpage as a background.
156  DOMView* background_area_;
157
158  // Proxy settings dialog that can be invoked from network menu.
159  scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_;
160
161  DISALLOW_COPY_AND_ASSIGN(BackgroundView);
162};
163
164}  // namespace chromeos
165
166#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_BACKGROUND_VIEW_H_
167