origin_chip_view.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_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 "ui/views/controls/button/button.h" 12#include "ui/views/controls/button/label_button.h" 13 14class LocationBarView; 15class OriginChipExtensionIcon; 16class Profile; 17 18namespace content { 19class WebContents; 20} 21 22namespace gfx { 23class Canvas; 24class FontList; 25} 26 27namespace views { 28class Button; 29class Label; 30} 31 32class OriginChipView : public views::LabelButton, 33 public views::ButtonListener, 34 public SafeBrowsingUIManager::Observer { 35 public: 36 OriginChipView(LocationBarView* location_bar_view, 37 Profile* profile, 38 const gfx::FontList& font_list); 39 virtual ~OriginChipView(); 40 41 void Init(); 42 43 // Returns true if the origin chip should be visible. This will always be 44 // true if the original origin chip experiment is enabled. If the V2 45 // experiment is enabled this is true if the chip hasn't been hidden by 46 // clicking on it or interacting with the Omnibox. 47 bool ShouldShow(); 48 49 // Recalculates the contents of the Origin Chip based on the displayed tab. 50 void Update(content::WebContents* tab); 51 52 // Called to signal that the contents of the tab being shown has changed, so 53 // the origin chip needs to update itself to the new state. 54 void OnChanged(); 55 56 views::ImageView* location_icon_view() { 57 return location_icon_view_; 58 } 59 const views::ImageView* location_icon_view() const { 60 return location_icon_view_; 61 } 62 63 // Elides the hostname shown to the indicated width, if needed. Returns the 64 // final width of the origin chip. Note: this may be more than the target 65 // width, since the hostname will not be elided past the TLD+1. 66 int ElideDomainTarget(int target_max_width); 67 68 // views::LabelButton: 69 virtual gfx::Size GetPreferredSize() OVERRIDE; 70 virtual void Layout() OVERRIDE; 71 72 // views::ButtonListener: 73 virtual void ButtonPressed(views::Button* sender, 74 const ui::Event& event) OVERRIDE; 75 76 // SafeBrowsingUIManager::Observer: 77 virtual void OnSafeBrowsingHit( 78 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; 79 virtual void OnSafeBrowsingMatch( 80 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; 81 82 private: 83 // Sets an image grid to represent the current security state. 84 void SetBorderImages(const int images[3][9]); 85 86 LocationBarView* location_bar_view_; 87 Profile* profile_; 88 views::Label* host_label_; 89 LocationIconView* location_icon_view_; 90 bool showing_16x16_icon_; 91 scoped_ptr<OriginChipExtensionIcon> extension_icon_; 92 GURL url_displayed_; 93 ToolbarModel::SecurityLevel security_level_; 94 bool url_malware_; 95 96 DISALLOW_COPY_AND_ASSIGN(OriginChipView); 97}; 98 99#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ 100