Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / toolbar / site_chip_view.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_SITE_CHIP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_SITE_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 "chrome/browser/ui/views/toolbar/toolbar_button.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/drag_controller.h"
14
15 class SiteChipExtensionIcon;
16 class ToolbarView;
17
18 namespace content {
19 class WebContents;
20 }
21
22 namespace gfx {
23 class Canvas;
24 }
25
26 namespace views {
27 class Button;
28 class Label;
29 }
30
31 class SiteChipView : public ToolbarButton,
32                      public views::ButtonListener,
33                      public views::DragController,
34                      public SafeBrowsingUIManager::Observer {
35  public:
36   explicit SiteChipView(ToolbarView* toolbar_view);
37   virtual ~SiteChipView();
38
39   void Init();
40
41   // Returns true if the site chip experiment is enabled and thus the site chip
42   // should be shown in the toolbar.
43   bool ShouldShow();
44
45   // Recalculates the contents of the Site Chip based on the displayed tab.
46   void Update(content::WebContents* tab);
47
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.
50   void OnChanged();
51
52   views::ImageView* location_icon_view() {
53     return location_icon_view_;
54   }
55   const views::ImageView* location_icon_view() const {
56     return location_icon_view_;
57   }
58
59   // ToolbarButton:
60   virtual gfx::Size GetPreferredSize() OVERRIDE;
61   virtual void Layout() OVERRIDE;
62   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
63
64   // views::ButtonListener:
65   virtual void ButtonPressed(views::Button* sender,
66                              const ui::Event& event) OVERRIDE;
67
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;
77
78   // SafeBrowsingUIManager::Observer:
79   virtual void OnSafeBrowsingHit(
80       const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
81   virtual void OnSafeBrowsingMatch(
82       const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
83
84  private:
85   base::string16 SiteLabelFromURL(const GURL& url);
86
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_;
98   GURL url_displayed_;
99   ToolbarModel::SecurityLevel security_level_;
100   bool url_malware_;
101
102   DISALLOW_COPY_AND_ASSIGN(SiteChipView);
103 };
104
105 #endif  // CHROME_BROWSER_UI_VIEWS_TOOLBAR_SITE_CHIP_VIEW_H_