| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/safe_browsing/ui_manager.h" | 8 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 9 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 9 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 10 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 10 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 11 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
| 12 #include "ui/views/controls/button/label_button.h" | 12 #include "ui/views/controls/button/label_button.h" |
| 13 | 13 |
| 14 class LocationBarView; | 14 class LocationBarView; |
| 15 class OriginChipExtensionIcon; | 15 class OriginChipExtensionIcon; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class WebContents; | 19 class WebContents; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace gfx { | 22 namespace gfx { |
| 23 class Canvas; | 23 class Canvas; |
| 24 class FontList; | 24 class FontList; |
| 25 class SlideAnimation; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace views { | 28 namespace views { |
| 28 class Button; | 29 class Button; |
| 29 class Label; | 30 class Label; |
| 30 } | 31 } |
| 31 | 32 |
| 32 class OriginChipView : public views::LabelButton, | 33 class OriginChipView : public views::LabelButton, |
| 33 public views::ButtonListener, | 34 public views::ButtonListener, |
| 34 public SafeBrowsingUIManager::Observer { | 35 public SafeBrowsingUIManager::Observer { |
| 35 public: | 36 public: |
| 36 OriginChipView(LocationBarView* location_bar_view, | 37 OriginChipView(LocationBarView* location_bar_view, |
| 37 Profile* profile, | 38 Profile* profile, |
| 38 const gfx::FontList& font_list); | 39 const gfx::FontList& font_list); |
| 39 virtual ~OriginChipView(); | 40 virtual ~OriginChipView(); |
| 40 | 41 |
| 41 void Init(); | |
| 42 | |
| 43 // Returns true if the origin chip should be visible. This will always be | 42 // 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 | 43 // 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 | 44 // experiment is enabled this is true if the chip hasn't been hidden by |
| 46 // clicking on it or interacting with the Omnibox. | 45 // clicking on it or interacting with the Omnibox. |
| 47 bool ShouldShow(); | 46 bool ShouldShow(); |
| 48 | 47 |
| 49 // Recalculates the contents of the Origin Chip based on the displayed tab. | 48 // Recalculates the contents of the Origin Chip based on the displayed tab. |
| 50 void Update(content::WebContents* tab); | 49 void Update(content::WebContents* tab); |
| 51 | 50 |
| 52 // Called to signal that the contents of the tab being shown has changed, so | 51 // 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. | 52 // the origin chip needs to update itself to the new state. |
| 54 void OnChanged(); | 53 void OnChanged(); |
| 55 | 54 |
| 56 views::ImageView* location_icon_view() { | 55 views::ImageView* location_icon_view() { |
| 57 return location_icon_view_; | 56 return location_icon_view_; |
| 58 } | 57 } |
| 59 const views::ImageView* location_icon_view() const { | 58 const views::ImageView* location_icon_view() const { |
| 60 return location_icon_view_; | 59 return location_icon_view_; |
| 61 } | 60 } |
| 62 | 61 |
| 63 // Elides the hostname shown to the indicated width, if needed. Returns the | 62 // 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 | 63 // 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. | 64 // width, since the hostname will not be elided past the TLD+1. |
| 66 int ElideDomainTarget(int target_max_width); | 65 int ElideDomainTarget(int target_max_width); |
| 67 | 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 |
| 68 // views::LabelButton: | 73 // views::LabelButton: |
| 74 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 75 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
| 69 virtual gfx::Size GetPreferredSize() OVERRIDE; | 76 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 70 virtual void Layout() OVERRIDE; | 77 virtual void Layout() OVERRIDE; |
| 78 virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE; |
| 71 | 79 |
| 72 // views::ButtonListener: | 80 // views::ButtonListener: |
| 73 virtual void ButtonPressed(views::Button* sender, | 81 virtual void ButtonPressed(views::Button* sender, |
| 74 const ui::Event& event) OVERRIDE; | 82 const ui::Event& event) OVERRIDE; |
| 75 | 83 |
| 76 // SafeBrowsingUIManager::Observer: | 84 // SafeBrowsingUIManager::Observer: |
| 77 virtual void OnSafeBrowsingHit( | 85 virtual void OnSafeBrowsingHit( |
| 78 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; | 86 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; |
| 79 virtual void OnSafeBrowsingMatch( | 87 virtual void OnSafeBrowsingMatch( |
| 80 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; | 88 const SafeBrowsingUIManager::UnsafeResource& resource) OVERRIDE; |
| 81 | 89 |
| 82 private: | 90 private: |
| 83 // Sets an image grid to represent the current security state. | 91 // Sets an image grid to represent the current security state. |
| 84 void SetBorderImages(const int images[3][9]); | 92 void SetBorderImages(const int images[3][9]); |
| 85 | 93 |
| 86 LocationBarView* location_bar_view_; | 94 LocationBarView* location_bar_view_; |
| 87 Profile* profile_; | 95 Profile* profile_; |
| 88 views::Label* host_label_; | 96 views::Label* host_label_; |
| 89 LocationIconView* location_icon_view_; | 97 LocationIconView* location_icon_view_; |
| 90 bool showing_16x16_icon_; | 98 bool showing_16x16_icon_; |
| 91 scoped_ptr<OriginChipExtensionIcon> extension_icon_; | 99 scoped_ptr<OriginChipExtensionIcon> extension_icon_; |
| 92 GURL url_displayed_; | 100 GURL url_displayed_; |
| 93 ToolbarModel::SecurityLevel security_level_; | 101 ToolbarModel::SecurityLevel security_level_; |
| 94 bool url_malware_; | 102 bool url_malware_; |
| 103 scoped_ptr<gfx::SlideAnimation> fade_in_animation_; |
| 95 | 104 |
| 96 DISALLOW_COPY_AND_ASSIGN(OriginChipView); | 105 DISALLOW_COPY_AND_ASSIGN(OriginChipView); |
| 97 }; | 106 }; |
| 98 | 107 |
| 99 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ | 108 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_ |
| OLD | NEW |