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