• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
7 
8 #include "chrome/browser/safe_browsing/ui_manager.h"
9 #include "chrome/browser/ui/toolbar/toolbar_model.h"
10 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
11 #include "ui/gfx/animation/slide_animation.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/button/label_button.h"
14 
15 class LocationBarView;
16 class OriginChipExtensionIcon;
17 class Profile;
18 
19 namespace content {
20 class WebContents;
21 }
22 
23 namespace gfx {
24 class FontList;
25 }
26 
27 namespace views {
28 class Label;
29 }
30 
31 // A button visible at the beginning of the omnibox which contains the location
32 // icon, an optional EV cert name, and a hostname.  The hostname is normally the
33 // hostname for the current page with any leading "www." removed, though for
34 // special built-in pages (e.g. chrome://settings), it can be a descriptive
35 // string.  The EV cert name is the organization name of the EV cert holder and
36 // is only present when the current page's security status is EV_SECURE.
37 class OriginChipView : public views::LabelButton,
38                        public views::ButtonListener,
39                        public SafeBrowsingUIManager::Observer {
40  public:
41   OriginChipView(LocationBarView* location_bar_view,
42                  Profile* profile,
43                  const gfx::FontList& font_list);
44   virtual ~OriginChipView();
45 
pressed_text_color()46   SkColor pressed_text_color() const { return pressed_text_color_; }
pressed_background_color()47   SkColor pressed_background_color() const {
48     return background_colors_[Button::STATE_PRESSED];
49   }
host_label_text()50   const base::string16& host_label_text() const { return host_label_->text(); }
51 
52   // Called to signal that the contents of the tab being shown has changed, so
53   // the origin chip needs to update itself to the new state.
54   void OnChanged();
55 
56   // Starts/stops a fade-in animation for the border.
57   void FadeIn();
58   void CancelFade();
59 
60   // Returns the offset of the host label, relative to where the first label
61   // starts.  When the EV cert name is not visible, this will always be 0;
62   // otherwise, it's a positive value equal to the width of the cert name plus
63   // the space between the labels.
64   int HostLabelOffset() const;
65 
66   // Returns the width of the origin chip from the start of the first label to
67   // the trailing edge of the chip.
68   int WidthFromStartOfLabels() const;
69 
70   // views::LabelButton:
71   virtual gfx::Size GetPreferredSize() const OVERRIDE;
72   virtual void Layout() OVERRIDE;
73 
74  private:
75   // Returns the X coordinate the first label should be placed at.
76   int GetLabelX() const;
77 
78   // Sets an image grid to represent the current security state.
79   void SetBorderImages(const int images[3][9]);
80 
81   // views::LabelButton:
82   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
83   virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
84   virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE;
85   virtual void StateChanged() OVERRIDE;
86 
87   // views::ButtonListener:
88   virtual void ButtonPressed(views::Button* sender,
89                              const ui::Event& event) OVERRIDE;
90 
91   // SafeBrowsingUIManager::Observer:
92   virtual void OnSafeBrowsingHit(
93       const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
94   virtual void OnSafeBrowsingMatch(
95       const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
96 
97   LocationBarView* location_bar_view_;
98   Profile* profile_;
99   SkColor pressed_text_color_;
100   SkColor background_colors_[3];
101   views::Label* ev_label_;
102   views::Label* host_label_;
103   LocationIconView* location_icon_view_;
104   bool showing_16x16_icon_;
105   scoped_ptr<OriginChipExtensionIcon> extension_icon_;
106   gfx::SlideAnimation fade_in_animation_;
107   GURL url_displayed_;
108   ToolbarModel::SecurityLevel security_level_;
109   bool url_malware_;
110 
111   DISALLOW_COPY_AND_ASSIGN(OriginChipView);
112 };
113 
114 #endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
115