origin_chip_view.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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/views/controls/button/button.h"
12#include "ui/views/controls/button/label_button.h"
13
14class LocationBarView;
15class OriginChipExtensionIcon;
16class Profile;
17
18namespace content {
19class WebContents;
20}
21
22namespace gfx {
23class Canvas;
24class FontList;
25class SlideAnimation;
26}
27
28namespace views {
29class Button;
30class Label;
31}
32
33class OriginChipView : public views::LabelButton,
34                       public views::ButtonListener,
35                       public SafeBrowsingUIManager::Observer {
36 public:
37  OriginChipView(LocationBarView* location_bar_view,
38                 Profile* profile,
39                 const gfx::FontList& font_list);
40  virtual ~OriginChipView();
41
42  // Recalculates the contents of the Origin Chip based on the displayed tab.
43  void Update(content::WebContents* tab);
44
45  // Called to signal that the contents of the tab being shown has changed, so
46  // the origin chip needs to update itself to the new state.
47  void OnChanged();
48
49  views::ImageView* location_icon_view() {
50    return location_icon_view_;
51  }
52  const views::ImageView* location_icon_view() const {
53    return location_icon_view_;
54  }
55
56  // Elides the hostname shown to the indicated width, if needed. Returns the
57  // final width of the origin chip. Note: this may be more than the target
58  // width, since the hostname will not be elided past the TLD+1.
59  int ElideDomainTarget(int target_max_width);
60
61  // Starts an animation that fades in the border.
62  void FadeIn();
63
64  // Returns the current X position of the host label.
65  int host_label_x() const { return host_label_->x(); }
66
67  // views::LabelButton:
68  virtual gfx::Size GetPreferredSize() const OVERRIDE;
69
70 private:
71  // Sets an image grid to represent the current security state.
72  void SetBorderImages(const int images[3][9]);
73
74  // views::LabelButton:
75  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
76  virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
77  virtual void Layout() OVERRIDE;
78  virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE;
79
80  // views::ButtonListener:
81  virtual void ButtonPressed(views::Button* sender,
82                             const ui::Event& event) OVERRIDE;
83
84  // SafeBrowsingUIManager::Observer:
85  virtual void OnSafeBrowsingHit(
86      const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
87  virtual void OnSafeBrowsingMatch(
88      const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
89
90  LocationBarView* location_bar_view_;
91  Profile* profile_;
92  views::Label* host_label_;
93  LocationIconView* location_icon_view_;
94  bool showing_16x16_icon_;
95  scoped_ptr<OriginChipExtensionIcon> extension_icon_;
96  GURL url_displayed_;
97  ToolbarModel::SecurityLevel security_level_;
98  bool url_malware_;
99  scoped_ptr<gfx::SlideAnimation> fade_in_animation_;
100
101  DISALLOW_COPY_AND_ASSIGN(OriginChipView);
102};
103
104#endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
105