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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
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"
14 class LocationBarView
;
15 class OriginChipExtensionIcon
;
33 class OriginChipView
: public views::LabelButton
,
34 public views::ButtonListener
,
35 public SafeBrowsingUIManager::Observer
{
37 OriginChipView(LocationBarView
* location_bar_view
,
39 const gfx::FontList
& font_list
);
40 virtual ~OriginChipView();
42 // Returns true if the origin chip should be visible. This will always be
43 // true if the original origin chip experiment is enabled. If the V2
44 // experiment is enabled this is true if the chip hasn't been hidden by
45 // clicking on it or interacting with the Omnibox.
48 // Recalculates the contents of the Origin Chip based on the displayed tab.
49 void Update(content::WebContents
* tab
);
51 // Called to signal that the contents of the tab being shown has changed, so
52 // the origin chip needs to update itself to the new state.
55 views::ImageView
* location_icon_view() {
56 return location_icon_view_
;
58 const views::ImageView
* location_icon_view() const {
59 return location_icon_view_
;
62 // Elides the hostname shown to the indicated width, if needed. Returns the
63 // final width of the origin chip. Note: this may be more than the target
64 // width, since the hostname will not be elided past the TLD+1.
65 int ElideDomainTarget(int target_max_width
);
67 // Starts an animation that fades in the border.
70 // Returns the current X position of the host label.
71 int host_label_x() const { return host_label_
->x(); }
73 // views::LabelButton:
74 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
77 // Sets an image grid to represent the current security state.
78 void SetBorderImages(const int images
[3][9]);
80 // views::LabelButton:
81 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
82 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
83 virtual void Layout() OVERRIDE
;
84 virtual void OnPaintBorder(gfx::Canvas
* canvas
) OVERRIDE
;
86 // views::ButtonListener:
87 virtual void ButtonPressed(views::Button
* sender
,
88 const ui::Event
& event
) OVERRIDE
;
90 // SafeBrowsingUIManager::Observer:
91 virtual void OnSafeBrowsingHit(
92 const SafeBrowsingUIManager::UnsafeResource
& resource
) OVERRIDE
;
93 virtual void OnSafeBrowsingMatch(
94 const SafeBrowsingUIManager::UnsafeResource
& resource
) OVERRIDE
;
96 LocationBarView
* location_bar_view_
;
98 views::Label
* host_label_
;
99 LocationIconView
* location_icon_view_
;
100 bool showing_16x16_icon_
;
101 scoped_ptr
<OriginChipExtensionIcon
> extension_icon_
;
103 ToolbarModel::SecurityLevel security_level_
;
105 scoped_ptr
<gfx::SlideAnimation
> fade_in_animation_
;
107 DISALLOW_COPY_AND_ASSIGN(OriginChipView
);
110 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_