| OLD | NEW |
| 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 Loading... |
| 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { | 690 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { |
| 691 return browser_->toolbar_model(); | 691 return browser_->toolbar_model(); |
| 692 } | 692 } |
| 693 | 693 |
| 694 WebContents* LocationBarViewMac::GetWebContents() { | 694 WebContents* LocationBarViewMac::GetWebContents() { |
| 695 return browser_->tab_strip_model()->GetActiveWebContents(); | 695 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 696 } | 696 } |
| 697 | 697 |
| 698 bool LocationBarViewMac::ShouldShowEVBubble() const { | 698 bool LocationBarViewMac::ShouldShowEVBubble() const { |
| 699 return GetToolbarModel()->GetSecurityLevel(false) == | 699 return GetToolbarModel()->GetSecurityLevel(false) == |
| 700 security_state::SecurityStateModel::EV_SECURE; | 700 security_state::EV_SECURE; |
| 701 } | 701 } |
| 702 | 702 |
| 703 bool LocationBarViewMac::ShouldShowSecurityState() const { | 703 bool LocationBarViewMac::ShouldShowSecurityState() const { |
| 704 if (omnibox_view_->IsEditingOrEmpty() || | 704 if (omnibox_view_->IsEditingOrEmpty() || |
| 705 omnibox_view_->model()->is_keyword_hint()) { | 705 omnibox_view_->model()->is_keyword_hint()) { |
| 706 return false; | 706 return false; |
| 707 } | 707 } |
| 708 | 708 |
| 709 security_state::SecurityStateModel::SecurityLevel security = | 709 security_state::SecurityLevel security = |
| 710 GetToolbarModel()->GetSecurityLevel(false); | 710 GetToolbarModel()->GetSecurityLevel(false); |
| 711 | 711 |
| 712 if (security == security_state::SecurityStateModel::EV_SECURE) | 712 if (security == security_state::EV_SECURE) |
| 713 return true; | 713 return true; |
| 714 else if (security == security_state::SecurityStateModel::SECURE) | 714 else if (security == security_state::SECURE) |
| 715 return should_show_secure_verbose_; | 715 return should_show_secure_verbose_; |
| 716 | 716 |
| 717 return should_show_nonsecure_verbose_ && | 717 return should_show_nonsecure_verbose_ && |
| 718 (security == security_state::SecurityStateModel::DANGEROUS || | 718 (security == security_state::DANGEROUS || |
| 719 security == security_state::SecurityStateModel::HTTP_SHOW_WARNING); | 719 security == security_state::HTTP_SHOW_WARNING); |
| 720 } | 720 } |
| 721 | 721 |
| 722 bool LocationBarViewMac::IsLocationBarDark() const { | 722 bool LocationBarViewMac::IsLocationBarDark() const { |
| 723 return [[field_ window] inIncognitoModeWithSystemTheme]; | 723 return [[field_ window] inIncognitoModeWithSystemTheme]; |
| 724 } | 724 } |
| 725 | 725 |
| 726 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { | 726 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { |
| 727 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( | 727 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
| 728 profile())->GetTemplateURLForKeyword(keyword); | 728 profile())->GetTemplateURLForKeyword(keyword); |
| 729 if (template_url && | 729 if (template_url && |
| (...skipping 11 matching lines...) Expand all Loading... |
| 741 } | 741 } |
| 742 | 742 |
| 743 SkColor LocationBarViewMac::GetLocationBarIconColor() const { | 743 SkColor LocationBarViewMac::GetLocationBarIconColor() const { |
| 744 bool in_dark_mode = IsLocationBarDark(); | 744 bool in_dark_mode = IsLocationBarDark(); |
| 745 if (in_dark_mode) | 745 if (in_dark_mode) |
| 746 return kMaterialDarkVectorIconColor; | 746 return kMaterialDarkVectorIconColor; |
| 747 | 747 |
| 748 if (ShouldShowEVBubble()) | 748 if (ShouldShowEVBubble()) |
| 749 return gfx::kGoogleGreen700; | 749 return gfx::kGoogleGreen700; |
| 750 | 750 |
| 751 security_state::SecurityStateModel::SecurityLevel security_level = | 751 security_state::SecurityLevel security_level = |
| 752 GetToolbarModel()->GetSecurityLevel(false); | 752 GetToolbarModel()->GetSecurityLevel(false); |
| 753 | 753 |
| 754 if (security_level == security_state::SecurityStateModel::NONE || | 754 if (security_level == security_state::NONE || |
| 755 security_level == security_state::SecurityStateModel::HTTP_SHOW_WARNING) { | 755 security_level == security_state::HTTP_SHOW_WARNING) { |
| 756 return gfx::kChromeIconGrey; | 756 return gfx::kChromeIconGrey; |
| 757 } | 757 } |
| 758 | 758 |
| 759 NSColor* srgb_color = | 759 NSColor* srgb_color = |
| 760 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); | 760 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); |
| 761 NSColor* device_color = | 761 NSColor* device_color = |
| 762 [srgb_color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; | 762 [srgb_color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; |
| 763 return skia::NSDeviceColorToSkColor(device_color); | 763 return skia::NSDeviceColorToSkColor(device_color); |
| 764 } | 764 } |
| 765 | 765 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 | 894 |
| 895 return zoom_decoration_->UpdateIfNecessary( | 895 return zoom_decoration_->UpdateIfNecessary( |
| 896 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, | 896 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, |
| 897 IsLocationBarDark()); | 897 IsLocationBarDark()); |
| 898 } | 898 } |
| 899 | 899 |
| 900 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { | 900 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { |
| 901 if (!ShouldShowSecurityState()) | 901 if (!ShouldShowSecurityState()) |
| 902 return; | 902 return; |
| 903 | 903 |
| 904 security_state::SecurityStateModel::SecurityLevel new_security_level = | 904 security_state::SecurityLevel new_security_level = |
| 905 GetToolbarModel()->GetSecurityLevel(false); | 905 GetToolbarModel()->GetSecurityLevel(false); |
| 906 bool is_new_level_secure = IsSecureConnection(new_security_level); | 906 bool is_new_level_secure = IsSecureConnection(new_security_level); |
| 907 bool is_secure_to_secure = | 907 bool is_secure_to_secure = |
| 908 is_new_level_secure && IsSecureConnection(security_level_); | 908 is_new_level_secure && IsSecureConnection(security_level_); |
| 909 bool is_new_security_level = | 909 bool is_new_security_level = |
| 910 security_level_ != new_security_level && !is_secure_to_secure; | 910 security_level_ != new_security_level && !is_secure_to_secure; |
| 911 security_level_ = new_security_level; | 911 security_level_ = new_security_level; |
| 912 | 912 |
| 913 // If there's enough space, but the secure state decoration had animated | 913 // If there's enough space, but the secure state decoration had animated |
| 914 // out, animate it back in. Otherwise, if the security state has changed, | 914 // out, animate it back in. Otherwise, if the security state has changed, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 925 security_state_bubble_decoration_->ShowWithoutAnimation(); | 925 security_state_bubble_decoration_->ShowWithoutAnimation(); |
| 926 else if (is_new_security_level) | 926 else if (is_new_security_level) |
| 927 security_state_bubble_decoration_->AnimateIn(); | 927 security_state_bubble_decoration_->AnimateIn(); |
| 928 } else { | 928 } else { |
| 929 // Animate the decoration out if there's not enough space. | 929 // Animate the decoration out if there's not enough space. |
| 930 security_state_bubble_decoration_->AnimateOut(); | 930 security_state_bubble_decoration_->AnimateOut(); |
| 931 } | 931 } |
| 932 } | 932 } |
| 933 | 933 |
| 934 bool LocationBarViewMac::IsSecureConnection( | 934 bool LocationBarViewMac::IsSecureConnection( |
| 935 security_state::SecurityStateModel::SecurityLevel level) const { | 935 security_state::SecurityLevel level) const { |
| 936 return level == security_state::SecurityStateModel::SECURE || | 936 return level == security_state::SECURE || |
| 937 level == security_state::SecurityStateModel::EV_SECURE; | 937 level == security_state::EV_SECURE; |
| 938 } | 938 } |
| 939 | 939 |
| 940 void LocationBarViewMac::UpdateAccessibilityViewPosition( | 940 void LocationBarViewMac::UpdateAccessibilityViewPosition( |
| 941 LocationBarDecoration* decoration) { | 941 LocationBarDecoration* decoration) { |
| 942 if (!decoration->IsVisible()) | 942 if (!decoration->IsVisible()) |
| 943 return; | 943 return; |
| 944 NSRect r = | 944 NSRect r = |
| 945 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; | 945 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; |
| 946 [decoration->GetAccessibilityView() setFrame:r]; | 946 [decoration->GetAccessibilityView() setFrame:r]; |
| 947 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; | 947 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 967 OnDecorationsChanged(); | 967 OnDecorationsChanged(); |
| 968 } | 968 } |
| 969 | 969 |
| 970 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 970 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 971 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 971 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 972 std::vector<NSView*> views; | 972 std::vector<NSView*> views; |
| 973 for (auto* decoration : decorations) | 973 for (auto* decoration : decorations) |
| 974 views.push_back(decoration->GetAccessibilityView()); | 974 views.push_back(decoration->GetAccessibilityView()); |
| 975 return views; | 975 return views; |
| 976 } | 976 } |
| OLD | NEW |