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