OLD | NEW |
| (Empty) |
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_TOOLBAR_TOOLBAR_ORIGIN_CHIP_VIEW_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_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 "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 ToolbarOriginChipExtensionIcon; | |
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 ToolbarOriginChipView : public ToolbarButton, | |
32 public views::ButtonListener, | |
33 public views::DragController, | |
34 public SafeBrowsingUIManager::Observer { | |
35 public: | |
36 explicit ToolbarOriginChipView(ToolbarView* toolbar_view); | |
37 virtual ~ToolbarOriginChipView(); | |
38 | |
39 void Init(); | |
40 | |
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(); | |
46 | |
47 // Recalculates the contents of the Origin Chip based on the displayed tab. | |
48 void Update(content::WebContents* tab); | |
49 | |
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(); | |
53 | |
54 views::ImageView* location_icon_view() { | |
55 return location_icon_view_; | |
56 } | |
57 const views::ImageView* location_icon_view() const { | |
58 return location_icon_view_; | |
59 } | |
60 | |
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); | |
65 | |
66 // ToolbarButton: | |
67 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
68 virtual void Layout() OVERRIDE; | |
69 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
70 | |
71 // views::ButtonListener: | |
72 virtual void ButtonPressed(views::Button* sender, | |
73 const ui::Event& event) OVERRIDE; | |
74 | |
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; | |
84 | |
85 // SafeBrowsingUIManager::Observer: | |
86 virtual void OnSafeBrowsingHit( | |
87 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; | |
88 virtual void OnSafeBrowsingMatch( | |
89 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; | |
90 | |
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<ToolbarOriginChipExtensionIcon> extension_icon_; | |
103 GURL url_displayed_; | |
104 ToolbarModel::SecurityLevel security_level_; | |
105 bool url_malware_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(ToolbarOriginChipView); | |
108 }; | |
109 | |
110 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ORIGIN_CHIP_VIEW_H_ | |
OLD | NEW |