Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: sync. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #import "base/mac/mac_util.h" 9 #import "base/mac/mac_util.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 keyword_hint_decoration_(new KeywordHintDecoration()), 121 keyword_hint_decoration_(new KeywordHintDecoration()),
122 manage_passwords_decoration_( 122 manage_passwords_decoration_(
123 new ManagePasswordsDecoration(command_updater, this)), 123 new ManagePasswordsDecoration(command_updater, this)),
124 browser_(browser), 124 browser_(browser),
125 location_bar_visible_(true), 125 location_bar_visible_(true),
126 should_show_secure_verbose_(false), 126 should_show_secure_verbose_(false),
127 should_show_nonsecure_verbose_(false), 127 should_show_nonsecure_verbose_(false),
128 should_animate_secure_verbose_(false), 128 should_animate_secure_verbose_(false),
129 should_animate_nonsecure_verbose_(false), 129 should_animate_nonsecure_verbose_(false),
130 is_width_available_for_security_verbose_(false), 130 is_width_available_for_security_verbose_(false),
131 security_level_(security_state::SecurityStateModel::NONE), 131 security_level_(security_state::NONE),
132 weak_ptr_factory_(this) { 132 weak_ptr_factory_(this) {
133 ScopedVector<ContentSettingImageModel> models = 133 ScopedVector<ContentSettingImageModel> models =
134 ContentSettingImageModel::GenerateContentSettingImageModels(); 134 ContentSettingImageModel::GenerateContentSettingImageModels();
135 for (ContentSettingImageModel* model : models.get()) { 135 for (ContentSettingImageModel* model : models.get()) {
136 // ContentSettingDecoration takes ownership of its model. 136 // ContentSettingDecoration takes ownership of its model.
137 content_setting_decorations_.push_back( 137 content_setting_decorations_.push_back(
138 new ContentSettingDecoration(model, this, profile)); 138 new ContentSettingDecoration(model, this, profile));
139 } 139 }
140 models.weak_clear(); 140 models.weak_clear();
141 141
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { 692 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const {
693 return browser_->toolbar_model(); 693 return browser_->toolbar_model();
694 } 694 }
695 695
696 WebContents* LocationBarViewMac::GetWebContents() { 696 WebContents* LocationBarViewMac::GetWebContents() {
697 return browser_->tab_strip_model()->GetActiveWebContents(); 697 return browser_->tab_strip_model()->GetActiveWebContents();
698 } 698 }
699 699
700 bool LocationBarViewMac::ShouldShowEVBubble() const { 700 bool LocationBarViewMac::ShouldShowEVBubble() const {
701 return GetToolbarModel()->GetSecurityLevel(false) == 701 return GetToolbarModel()->GetSecurityLevel(false) ==
702 security_state::SecurityStateModel::EV_SECURE; 702 security_state::EV_SECURE;
703 } 703 }
704 704
705 bool LocationBarViewMac::ShouldShowSecurityState() const { 705 bool LocationBarViewMac::ShouldShowSecurityState() const {
706 if (omnibox_view_->IsEditingOrEmpty() || 706 if (omnibox_view_->IsEditingOrEmpty() ||
707 omnibox_view_->model()->is_keyword_hint()) { 707 omnibox_view_->model()->is_keyword_hint()) {
708 return false; 708 return false;
709 } 709 }
710 710
711 security_state::SecurityStateModel::SecurityLevel security = 711 security_state::SecurityLevel security =
712 GetToolbarModel()->GetSecurityLevel(false); 712 GetToolbarModel()->GetSecurityLevel(false);
713 713
714 if (security == security_state::SecurityStateModel::EV_SECURE) 714 if (security == security_state::EV_SECURE)
715 return true; 715 return true;
716 else if (security == security_state::SecurityStateModel::SECURE) 716 else if (security == security_state::SECURE)
717 return should_show_secure_verbose_; 717 return should_show_secure_verbose_;
718 718
719 return should_show_nonsecure_verbose_ && 719 return should_show_nonsecure_verbose_ &&
720 (security == security_state::SecurityStateModel::DANGEROUS || 720 (security == security_state::DANGEROUS ||
721 security == security_state::SecurityStateModel::HTTP_SHOW_WARNING); 721 security == security_state::HTTP_SHOW_WARNING);
722 } 722 }
723 723
724 bool LocationBarViewMac::IsLocationBarDark() const { 724 bool LocationBarViewMac::IsLocationBarDark() const {
725 return [[field_ window] inIncognitoModeWithSystemTheme]; 725 return [[field_ window] inIncognitoModeWithSystemTheme];
726 } 726 }
727 727
728 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { 728 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
729 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( 729 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
730 profile())->GetTemplateURLForKeyword(keyword); 730 profile())->GetTemplateURLForKeyword(keyword);
731 if (template_url && 731 if (template_url &&
(...skipping 11 matching lines...) Expand all
743 } 743 }
744 744
745 SkColor LocationBarViewMac::GetLocationBarIconColor() const { 745 SkColor LocationBarViewMac::GetLocationBarIconColor() const {
746 bool in_dark_mode = IsLocationBarDark(); 746 bool in_dark_mode = IsLocationBarDark();
747 if (in_dark_mode) 747 if (in_dark_mode)
748 return kMaterialDarkVectorIconColor; 748 return kMaterialDarkVectorIconColor;
749 749
750 if (ShouldShowEVBubble()) 750 if (ShouldShowEVBubble())
751 return gfx::kGoogleGreen700; 751 return gfx::kGoogleGreen700;
752 752
753 security_state::SecurityStateModel::SecurityLevel security_level = 753 security_state::SecurityLevel security_level =
754 GetToolbarModel()->GetSecurityLevel(false); 754 GetToolbarModel()->GetSecurityLevel(false);
755 755
756 if (security_level == security_state::SecurityStateModel::NONE || 756 if (security_level == security_state::NONE ||
757 security_level == security_state::SecurityStateModel::HTTP_SHOW_WARNING) { 757 security_level == security_state::HTTP_SHOW_WARNING) {
758 return gfx::kChromeIconGrey; 758 return gfx::kChromeIconGrey;
759 } 759 }
760 760
761 NSColor* srgb_color = 761 NSColor* srgb_color =
762 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); 762 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode);
763 NSColor* device_color = 763 NSColor* device_color =
764 [srgb_color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; 764 [srgb_color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
765 return skia::NSDeviceColorToSkColor(device_color); 765 return skia::NSDeviceColorToSkColor(device_color);
766 } 766 }
767 767
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 WebContents* web_contents = GetWebContents(); 893 WebContents* web_contents = GetWebContents();
894 if (!web_contents) 894 if (!web_contents)
895 return false; 895 return false;
896 896
897 return zoom_decoration_->UpdateIfNecessary( 897 return zoom_decoration_->UpdateIfNecessary(
898 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, 898 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed,
899 IsLocationBarDark()); 899 IsLocationBarDark());
900 } 900 }
901 901
902 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { 902 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) {
903 using SecurityLevel = security_state::SecurityStateModel::SecurityLevel; 903 using SecurityLevel = security_state::SecurityLevel;
904 SecurityLevel new_security_level = GetToolbarModel()->GetSecurityLevel(false); 904 SecurityLevel new_security_level = GetToolbarModel()->GetSecurityLevel(false);
905 905
906 // If there's enough space, but the secure state decoration had animated 906 // If there's enough space, but the secure state decoration had animated
907 // out, animate it back in. Otherwise, if the security state has changed, 907 // out, animate it back in. Otherwise, if the security state has changed,
908 // animate the decoration if animation is enabled and the state changed is 908 // animate the decoration if animation is enabled and the state changed is
909 // not from a tab switch. 909 // not from a tab switch.
910 if (ShouldShowSecurityState() && is_width_available_for_security_verbose_) { 910 if (ShouldShowSecurityState() && is_width_available_for_security_verbose_) {
911 bool is_secure_to_secure = IsSecureConnection(new_security_level) && 911 bool is_secure_to_secure = IsSecureConnection(new_security_level) &&
912 IsSecureConnection(security_level_); 912 IsSecureConnection(security_level_);
913 bool is_new_security_level = 913 bool is_new_security_level =
914 security_level_ != new_security_level && !is_secure_to_secure; 914 security_level_ != new_security_level && !is_secure_to_secure;
915 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) 915 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut())
916 security_state_bubble_decoration_->AnimateIn(false); 916 security_state_bubble_decoration_->AnimateIn(false);
917 else if (tab_changed || !CanAnimateSecurityLevel(new_security_level)) 917 else if (tab_changed || !CanAnimateSecurityLevel(new_security_level))
918 security_state_bubble_decoration_->ShowWithoutAnimation(); 918 security_state_bubble_decoration_->ShowWithoutAnimation();
919 else if (is_new_security_level) 919 else if (is_new_security_level)
920 security_state_bubble_decoration_->AnimateIn(); 920 security_state_bubble_decoration_->AnimateIn();
921 } else if (!is_width_available_for_security_verbose_ || 921 } else if (!is_width_available_for_security_verbose_ ||
922 CanAnimateSecurityLevel(security_level_)) { 922 CanAnimateSecurityLevel(security_level_)) {
923 security_state_bubble_decoration_->AnimateOut(); 923 security_state_bubble_decoration_->AnimateOut();
924 } 924 }
925 925
926 security_level_ = new_security_level; 926 security_level_ = new_security_level;
927 } 927 }
928 928
929 bool LocationBarViewMac::CanAnimateSecurityLevel( 929 bool LocationBarViewMac::CanAnimateSecurityLevel(
930 security_state::SecurityStateModel::SecurityLevel level) const { 930 security_state::SecurityLevel level) const {
931 using SecurityLevel = security_state::SecurityStateModel::SecurityLevel; 931 using SecurityLevel = security_state::SecurityLevel;
932 if (IsSecureConnection(level)) { 932 if (IsSecureConnection(level)) {
933 return should_animate_secure_verbose_; 933 return should_animate_secure_verbose_;
934 } else if (security_level_ == SecurityLevel::DANGEROUS || 934 } else if (security_level_ == SecurityLevel::DANGEROUS ||
935 security_level_ == SecurityLevel::HTTP_SHOW_WARNING) { 935 security_level_ == SecurityLevel::HTTP_SHOW_WARNING) {
936 return should_animate_nonsecure_verbose_; 936 return should_animate_nonsecure_verbose_;
937 } else { 937 } else {
938 return false; 938 return false;
939 } 939 }
940 } 940 }
941 941
942 bool LocationBarViewMac::IsSecureConnection( 942 bool LocationBarViewMac::IsSecureConnection(
943 security_state::SecurityStateModel::SecurityLevel level) const { 943 security_state::SecurityLevel level) const {
944 return level == security_state::SecurityStateModel::SECURE || 944 return level == security_state::SECURE ||
945 level == security_state::SecurityStateModel::EV_SECURE; 945 level == security_state::EV_SECURE;
946 } 946 }
947 947
948 void LocationBarViewMac::UpdateAccessibilityViewPosition( 948 void LocationBarViewMac::UpdateAccessibilityViewPosition(
949 LocationBarDecoration* decoration) { 949 LocationBarDecoration* decoration) {
950 if (!decoration->IsVisible()) 950 if (!decoration->IsVisible())
951 return; 951 return;
952 NSRect r = 952 NSRect r =
953 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; 953 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]];
954 [decoration->GetAccessibilityView() setFrame:r]; 954 [decoration->GetAccessibilityView() setFrame:r];
955 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; 955 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r];
(...skipping 19 matching lines...) Expand all
975 OnDecorationsChanged(); 975 OnDecorationsChanged();
976 } 976 }
977 977
978 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { 978 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() {
979 std::vector<LocationBarDecoration*> decorations = GetDecorations(); 979 std::vector<LocationBarDecoration*> decorations = GetDecorations();
980 std::vector<NSView*> views; 980 std::vector<NSView*> views;
981 for (auto* decoration : decorations) 981 for (auto* decoration : decorations)
982 views.push_back(decoration->GetAccessibilityView()); 982 views.push_back(decoration->GetAccessibilityView());
983 return views; 983 return views;
984 } 984 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698