about_chrome_view.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2006-2008 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_VIEWS_ABOUT_CHROME_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_ABOUT_CHROME_VIEW_H_
7#pragma once
8
9#include "views/controls/image_view.h"
10#include "views/controls/label.h"
11#include "views/controls/link.h"
12#include "views/view.h"
13#include "views/window/dialog_delegate.h"
14
15#if defined(OS_WIN) || defined(OS_CHROMEOS)
16#include "chrome/browser/google/google_update.h"
17#endif
18#if defined(OS_CHROMEOS)
19#include "chrome/browser/chromeos/version_loader.h"
20#endif
21
22namespace views {
23class Textfield;
24class Throbber;
25class Window;
26}
27
28class AccessibleViewHelper;
29class Profile;
30
31////////////////////////////////////////////////////////////////////////////////
32//
33// The AboutChromeView class is responsible for drawing the UI controls of the
34// About Chrome dialog that allows the user to see what version is installed
35// and check for updates.
36//
37////////////////////////////////////////////////////////////////////////////////
38class AboutChromeView : public views::View,
39                        public views::DialogDelegate,
40                        public views::LinkController
41#if defined(OS_WIN) || defined(OS_CHROMEOS)
42                        , public GoogleUpdateStatusListener
43#endif
44                        {
45 public:
46  explicit AboutChromeView(Profile* profile);
47  virtual ~AboutChromeView();
48
49  // Initialize the controls on the dialog.
50  void Init();
51
52  // Overridden from views::View:
53  virtual gfx::Size GetPreferredSize();
54  virtual void Layout();
55  virtual void Paint(gfx::Canvas* canvas);
56  virtual void ViewHierarchyChanged(bool is_add,
57                                    views::View* parent,
58                                    views::View* child);
59
60  // Overridden from views::DialogDelegate:
61  virtual std::wstring GetDialogButtonLabel(
62      MessageBoxFlags::DialogButton button) const;
63  virtual bool IsDialogButtonEnabled(
64      MessageBoxFlags::DialogButton button) const;
65  virtual bool IsDialogButtonVisible(
66      MessageBoxFlags::DialogButton button) const;
67  virtual int GetDefaultDialogButton() const;
68  virtual bool CanResize() const;
69  virtual bool CanMaximize() const;
70  virtual bool IsAlwaysOnTop() const;
71  virtual bool HasAlwaysOnTopMenu() const;
72  virtual bool IsModal() const;
73  virtual std::wstring GetWindowTitle() const;
74  virtual bool Accept();
75  virtual views::View* GetContentsView();
76
77  // Overridden from views::LinkController:
78  virtual void LinkActivated(views::Link* source, int event_flags);
79#if defined(OS_WIN) || defined(OS_CHROMEOS)
80  // Overridden from GoogleUpdateStatusListener:
81  virtual void OnReportResults(GoogleUpdateUpgradeResult result,
82                               GoogleUpdateErrorCode error_code,
83                               const std::wstring& version);
84#endif
85
86 private:
87#if defined(OS_WIN) || defined(OS_CHROMEOS)
88  // Update the UI to show the status of the upgrade.
89  void UpdateStatus(GoogleUpdateUpgradeResult result,
90                    GoogleUpdateErrorCode error_code);
91#endif
92
93#if defined(OS_CHROMEOS)
94  // Callback from chromeos::VersionLoader giving the version.
95  void OnOSVersion(chromeos::VersionLoader::Handle handle,
96                   std::string version);
97#endif
98
99
100  Profile* profile_;
101
102  // UI elements on the dialog.
103  views::ImageView* about_dlg_background_logo_;
104  views::Label* about_title_label_;
105  views::Textfield* version_label_;
106#if defined(OS_CHROMEOS)
107  views::Textfield* os_version_label_;
108#endif
109  views::Label* copyright_label_;
110  views::Label* main_text_label_;
111  int main_text_label_height_;
112  views::Link* chromium_url_;
113  gfx::Rect chromium_url_rect_;
114  views::Link* open_source_url_;
115  gfx::Rect open_source_url_rect_;
116  views::Link* terms_of_service_url_;
117  gfx::Rect terms_of_service_url_rect_;
118  // UI elements we add to the parent view.
119  scoped_ptr<views::Throbber> throbber_;
120  views::ImageView success_indicator_;
121  views::ImageView update_available_indicator_;
122  views::ImageView timeout_indicator_;
123  views::Label update_label_;
124
125  // The dialog dimensions.
126  gfx::Size dialog_dimensions_;
127
128  // Keeps track of the visible state of the Restart Now button.
129  bool restart_button_visible_;
130
131  // The text to display as the main label of the About box. We draw this text
132  // word for word with the help of the WordIterator, and make room for URLs
133  // which are drawn using views::Link. See also |url_offsets_|.
134  std::wstring main_label_chunk1_;
135  std::wstring main_label_chunk2_;
136  std::wstring main_label_chunk3_;
137  std::wstring main_label_chunk4_;
138  std::wstring main_label_chunk5_;
139  // Determines the order of the two links we draw in the main label.
140  bool chromium_url_appears_first_;
141
142#if defined(OS_WIN) || defined(OS_CHROMEOS)
143  // The class that communicates with Google Update to find out if an update is
144  // available and asks it to start an upgrade.
145  scoped_refptr<GoogleUpdate> google_updater_;
146#endif
147
148  // Our current version.
149  std::string current_version_;
150
151  // Additional information about the version (channel and build number).
152  std::string version_details_;
153
154  // The version Google Update reports is available to us.
155  std::wstring new_version_available_;
156
157  // Whether text direction is left-to-right or right-to-left.
158  bool text_direction_is_rtl_;
159
160#if defined(OS_CHROMEOS)
161  // Handles asynchronously loading the version.
162  chromeos::VersionLoader loader_;
163
164  // Used to request the version.
165  CancelableRequestConsumer consumer_;
166#endif
167
168  scoped_ptr<AccessibleViewHelper> accessible_view_helper_;
169
170  DISALLOW_COPY_AND_ASSIGN(AboutChromeView);
171};
172
173#endif  // CHROME_BROWSER_UI_VIEWS_ABOUT_CHROME_VIEW_H_
174