NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / origin_chip_view.h
blob559f4cf0e0c3d1b918b3f0f19d4c2f58e7eed2c4
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_TOOLBAR_ORIGIN_CHIP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_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 "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 OriginChipExtensionIcon;
16 class ToolbarView;
18 namespace content {
19 class WebContents;
22 namespace gfx {
23 class Canvas;
26 namespace views {
27 class Button;
28 class Label;
31 class OriginChipView : public ToolbarButton,
32 public views::ButtonListener,
33 public views::DragController,
34 public SafeBrowsingUIManager::Observer {
35 public:
36 explicit OriginChipView(ToolbarView* toolbar_view);
37 virtual ~OriginChipView();
39 void Init();
41 // Returns true if the origin chip should be visible. This will always be
42 // true if the original origin chip experiment is enabled. If the V2
43 // experiment is enabled this is true if the chip hasn't been hidden by
44 // clicking on it or interacting with the Omnibox.
45 bool ShouldShow();
47 // Recalculates the contents of the Origin Chip based on the displayed tab.
48 void Update(content::WebContents* tab);
50 // Called to signal that the contents of the tab being shown has changed, so
51 // the origin chip needs to update itself to the new state.
52 void OnChanged();
54 views::ImageView* location_icon_view() {
55 return location_icon_view_;
57 const views::ImageView* location_icon_view() const {
58 return location_icon_view_;
61 // Elides the hostname shown to the indicated width, if needed. Returns the
62 // final width of the origin chip. Note: this may be more than the target
63 // width, since the hostname will not be elided past the TLD+1.
64 int ElideDomainTarget(int target_max_width);
66 // ToolbarButton:
67 virtual gfx::Size GetPreferredSize() OVERRIDE;
68 virtual void Layout() OVERRIDE;
69 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
71 // views::ButtonListener:
72 virtual void ButtonPressed(views::Button* sender,
73 const ui::Event& event) OVERRIDE;
75 // views::DragController:
76 virtual void WriteDragDataForView(View* sender,
77 const gfx::Point& press_pt,
78 OSExchangeData* data) OVERRIDE;
79 virtual int GetDragOperationsForView(View* sender,
80 const gfx::Point& p) OVERRIDE;
81 virtual bool CanStartDragForView(View* sender,
82 const gfx::Point& press_pt,
83 const gfx::Point& p) OVERRIDE;
85 // SafeBrowsingUIManager::Observer:
86 virtual void OnSafeBrowsingHit(
87 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
88 virtual void OnSafeBrowsingMatch(
89 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE;
91 private:
92 ToolbarView* toolbar_view_;
93 views::Label* host_label_;
94 LocationIconView* location_icon_view_;
95 scoped_ptr<views::Painter> ev_background_painter_;
96 scoped_ptr<views::Painter> broken_ssl_background_painter_;
97 scoped_ptr<views::Painter> malware_background_painter_;
98 // Will point to one of the background painters, or NULL if the state of the
99 // chip has no background.
100 views::Painter* painter_;
101 bool showing_16x16_icon_;
102 scoped_ptr<OriginChipExtensionIcon> extension_icon_;
103 GURL url_displayed_;
104 ToolbarModel::SecurityLevel security_level_;
105 bool url_malware_;
107 DISALLOW_COPY_AND_ASSIGN(OriginChipView);
110 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_ORIGIN_CHIP_VIEW_H_