1 // Copyright 2013 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_TOOLBAR_SITE_CHIP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_SITE_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 "chrome/browser/ui/views/toolbar/toolbar_button.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/drag_controller.h"
15 class SiteChipExtensionIcon
;
31 class SiteChipView
: public ToolbarButton
,
32 public views::ButtonListener
,
33 public views::DragController
,
34 public SafeBrowsingUIManager::Observer
{
36 explicit SiteChipView(ToolbarView
* toolbar_view
);
37 virtual ~SiteChipView();
41 // Returns true if the site chip experiment is enabled and thus the site chip
42 // should be shown in the toolbar.
45 // Recalculates the contents of the Site Chip based on the displayed tab.
46 void Update(content::WebContents
* tab
);
48 // Called to signal that the contents of the tab being shown has changed, so
49 // the site chip needs to update itself to the new state.
52 views::ImageView
* location_icon_view() {
53 return location_icon_view_
;
55 const views::ImageView
* location_icon_view() const {
56 return location_icon_view_
;
60 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
61 virtual void Layout() OVERRIDE
;
62 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
64 // views::ButtonListener:
65 virtual void ButtonPressed(views::Button
* sender
,
66 const ui::Event
& event
) OVERRIDE
;
68 // views::DragController:
69 virtual void WriteDragDataForView(View
* sender
,
70 const gfx::Point
& press_pt
,
71 OSExchangeData
* data
) OVERRIDE
;
72 virtual int GetDragOperationsForView(View
* sender
,
73 const gfx::Point
& p
) OVERRIDE
;
74 virtual bool CanStartDragForView(View
* sender
,
75 const gfx::Point
& press_pt
,
76 const gfx::Point
& p
) OVERRIDE
;
78 // SafeBrowsingUIManager::Observer:
79 virtual void OnSafeBrowsingHit(
80 const SafeBrowsingUIManager::UnsafeResource
& resource
) OVERRIDE
;
81 virtual void OnSafeBrowsingMatch(
82 const SafeBrowsingUIManager::UnsafeResource
& resource
) OVERRIDE
;
85 base::string16
SiteLabelFromURL(const GURL
& url
);
87 ToolbarView
* toolbar_view_
;
88 views::Label
* host_label_
;
89 LocationIconView
* location_icon_view_
;
90 scoped_ptr
<views::Painter
> ev_background_painter_
;
91 scoped_ptr
<views::Painter
> broken_ssl_background_painter_
;
92 scoped_ptr
<views::Painter
> malware_background_painter_
;
93 // Will point to one of the background painters, or NULL if the state of the
94 // chip has no background.
95 views::Painter
* painter_
;
96 bool showing_16x16_icon_
;
97 scoped_ptr
<SiteChipExtensionIcon
> extension_icon_
;
99 ToolbarModel::SecurityLevel security_level_
;
102 DISALLOW_COPY_AND_ASSIGN(SiteChipView
);
105 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_SITE_CHIP_VIEW_H_