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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" |
46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 53 #include "chrome/common/chrome_features.h" |
53 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
54 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
55 #include "chrome/grit/theme_resources.h" | 56 #include "chrome/grit/theme_resources.h" |
56 #include "components/bookmarks/common/bookmark_pref_names.h" | 57 #include "components/bookmarks/common/bookmark_pref_names.h" |
57 #include "components/grit/components_scaled_resources.h" | 58 #include "components/grit/components_scaled_resources.h" |
58 #import "components/omnibox/browser/omnibox_popup_model.h" | 59 #import "components/omnibox/browser/omnibox_popup_model.h" |
59 #include "components/prefs/pref_service.h" | 60 #include "components/prefs/pref_service.h" |
60 #include "components/search_engines/template_url.h" | 61 #include "components/search_engines/template_url.h" |
61 #include "components/search_engines/template_url_service.h" | 62 #include "components/search_engines/template_url_service.h" |
62 #include "components/translate/core/browser/language_state.h" | 63 #include "components/translate/core/browser/language_state.h" |
| 64 #include "components/variations/variations_associated_data.h" |
63 #include "components/zoom/zoom_controller.h" | 65 #include "components/zoom/zoom_controller.h" |
64 #include "components/zoom/zoom_event_manager.h" | 66 #include "components/zoom/zoom_event_manager.h" |
65 #include "content/public/browser/web_contents.h" | 67 #include "content/public/browser/web_contents.h" |
66 #include "extensions/browser/extension_system.h" | 68 #include "extensions/browser/extension_system.h" |
67 #include "extensions/common/extension.h" | 69 #include "extensions/common/extension.h" |
68 #include "skia/ext/skia_utils_mac.h" | 70 #include "skia/ext/skia_utils_mac.h" |
69 #import "ui/base/cocoa/cocoa_base_utils.h" | 71 #import "ui/base/cocoa/cocoa_base_utils.h" |
70 #include "ui/base/l10n/l10n_util_mac.h" | 72 #include "ui/base/l10n/l10n_util_mac.h" |
71 #include "ui/base/material_design/material_design_controller.h" | 73 #include "ui/base/material_design/material_design_controller.h" |
72 #include "ui/gfx/color_palette.h" | 74 #include "ui/gfx/color_palette.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 star_decoration_(new StarDecoration(command_updater)), | 118 star_decoration_(new StarDecoration(command_updater)), |
117 translate_decoration_(new TranslateDecoration(command_updater)), | 119 translate_decoration_(new TranslateDecoration(command_updater)), |
118 zoom_decoration_(new ZoomDecoration(this)), | 120 zoom_decoration_(new ZoomDecoration(this)), |
119 keyword_hint_decoration_(new KeywordHintDecoration()), | 121 keyword_hint_decoration_(new KeywordHintDecoration()), |
120 manage_passwords_decoration_( | 122 manage_passwords_decoration_( |
121 new ManagePasswordsDecoration(command_updater, this)), | 123 new ManagePasswordsDecoration(command_updater, this)), |
122 browser_(browser), | 124 browser_(browser), |
123 location_bar_visible_(true), | 125 location_bar_visible_(true), |
124 should_show_secure_verbose_(false), | 126 should_show_secure_verbose_(false), |
125 should_show_nonsecure_verbose_(false), | 127 should_show_nonsecure_verbose_(false), |
126 should_animate_security_verbose_(false), | 128 should_animate_secure_verbose_(false), |
| 129 should_animate_nonsecure_verbose_(false), |
127 is_width_available_for_security_verbose_(false), | 130 is_width_available_for_security_verbose_(false), |
128 weak_ptr_factory_(this) { | 131 weak_ptr_factory_(this) { |
129 ScopedVector<ContentSettingImageModel> models = | 132 ScopedVector<ContentSettingImageModel> models = |
130 ContentSettingImageModel::GenerateContentSettingImageModels(); | 133 ContentSettingImageModel::GenerateContentSettingImageModels(); |
131 for (ContentSettingImageModel* model : models.get()) { | 134 for (ContentSettingImageModel* model : models.get()) { |
132 // ContentSettingDecoration takes ownership of its model. | 135 // ContentSettingDecoration takes ownership of its model. |
133 content_setting_decorations_.push_back( | 136 content_setting_decorations_.push_back( |
134 new ContentSettingDecoration(model, this, profile)); | 137 new ContentSettingDecoration(model, this, profile)); |
135 } | 138 } |
136 models.weak_clear(); | 139 models.weak_clear(); |
137 | 140 |
138 edit_bookmarks_enabled_.Init( | 141 edit_bookmarks_enabled_.Init( |
139 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 142 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
140 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, | 143 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, |
141 base::Unretained(this))); | 144 base::Unretained(this))); |
142 | 145 |
143 zoom::ZoomEventManager::GetForBrowserContext(profile) | 146 zoom::ZoomEventManager::GetForBrowserContext(profile) |
144 ->AddZoomEventManagerObserver(this); | 147 ->AddZoomEventManagerObserver(this); |
145 | 148 |
146 [[field_ cell] setIsPopupMode: | 149 [[field_ cell] setIsPopupMode: |
147 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; | 150 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; |
148 | 151 |
149 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 152 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 153 |
150 if (command_line->HasSwitch(switches::kMaterialSecurityVerbose)) { | 154 if (command_line->HasSwitch(switches::kMaterialSecurityVerbose)) { |
151 std::string security_verbose_flag = | 155 std::string security_verbose_flag = |
152 command_line->GetSwitchValueASCII(switches::kMaterialSecurityVerbose); | 156 command_line->GetSwitchValueASCII(switches::kMaterialSecurityVerbose); |
153 should_show_secure_verbose_ = | 157 should_show_secure_verbose_ = |
154 security_verbose_flag == | 158 security_verbose_flag == |
155 switches::kMaterialSecurityVerboseShowAllAnimated || | 159 switches::kMaterialSecurityVerboseShowAllAnimated || |
156 security_verbose_flag == | 160 security_verbose_flag == |
157 switches::kMaterialSecurityVerboseShowAllNonAnimated; | 161 switches::kMaterialSecurityVerboseShowAllNonAnimated; |
158 | 162 |
159 should_show_nonsecure_verbose_ = true; | 163 should_show_nonsecure_verbose_ = true; |
160 | 164 |
161 should_animate_security_verbose_ = | 165 should_show_nonsecure_verbose_ = |
162 security_verbose_flag == | 166 security_verbose_flag == |
163 switches::kMaterialSecurityVerboseShowAllAnimated || | 167 switches::kMaterialSecurityVerboseShowAllAnimated || |
164 security_verbose_flag == | 168 security_verbose_flag == |
165 switches::kMaterialSecurityVerboseShowNonSecureAnimated; | 169 switches::kMaterialSecurityVerboseShowNonSecureAnimated; |
| 170 should_animate_secure_verbose_ = should_show_nonsecure_verbose_; |
| 171 } else if (base::FeatureList::IsEnabled(features::kSecurityChip)) { |
| 172 // Visibility value. |
| 173 std::string security_chip = variations::GetVariationParamValueByFeature( |
| 174 features::kSecurityChip, kSecurityChipFeatureVisibilityParam); |
| 175 if (security_chip == switches::kSecurityChipShowNonSecureOnly) { |
| 176 should_show_nonsecure_verbose_ = true; |
| 177 } else if (security_chip == switches::kSecurityChipShowAll) { |
| 178 should_show_secure_verbose_ = true; |
| 179 should_show_nonsecure_verbose_ = true; |
| 180 } |
| 181 |
| 182 // Animation value. |
| 183 std::string security_chip_animation = |
| 184 command_line->GetSwitchValueASCII(switches::kSecurityChipAnimation); |
| 185 if (security_chip_animation == |
| 186 switches::kSecurityChipAnimationNonSecureOnly) { |
| 187 should_animate_nonsecure_verbose_ = true; |
| 188 } else if (security_chip_animation == switches::kSecurityChipAnimationAll) { |
| 189 should_animate_secure_verbose_ = true; |
| 190 should_animate_nonsecure_verbose_ = true; |
| 191 } |
166 } | 192 } |
167 | 193 |
168 // Sets images for the decorations, and performs a layout. This call ensures | 194 // Sets images for the decorations, and performs a layout. This call ensures |
169 // that this class is in a consistent state after initialization. | 195 // that this class is in a consistent state after initialization. |
170 OnChanged(); | 196 OnChanged(); |
171 } | 197 } |
172 | 198 |
173 LocationBarViewMac::~LocationBarViewMac() { | 199 LocationBarViewMac::~LocationBarViewMac() { |
174 // Disconnect from cell in case it outlives us. | 200 // Disconnect from cell in case it outlives us. |
175 [[field_ cell] clearDecorations]; | 201 [[field_ cell] clearDecorations]; |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, | 899 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, |
874 IsLocationBarDark()); | 900 IsLocationBarDark()); |
875 } | 901 } |
876 | 902 |
877 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { | 903 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { |
878 if (!ShouldShowSecurityState()) | 904 if (!ShouldShowSecurityState()) |
879 return; | 905 return; |
880 | 906 |
881 security_state::SecurityStateModel::SecurityLevel new_security_level = | 907 security_state::SecurityStateModel::SecurityLevel new_security_level = |
882 GetToolbarModel()->GetSecurityLevel(false); | 908 GetToolbarModel()->GetSecurityLevel(false); |
883 bool is_secure_to_secure = IsSecureConnection(new_security_level) && | 909 bool is_new_level_secure = IsSecureConnection(new_security_level); |
884 IsSecureConnection(security_level_); | 910 bool is_secure_to_secure = |
| 911 is_new_level_secure && IsSecureConnection(security_level_); |
885 bool is_new_security_level = | 912 bool is_new_security_level = |
886 security_level_ != new_security_level && !is_secure_to_secure; | 913 security_level_ != new_security_level && !is_secure_to_secure; |
887 security_level_ = new_security_level; | 914 security_level_ = new_security_level; |
888 | 915 |
889 // If there's enough space, but the secure state decoration had animated | 916 // If there's enough space, but the secure state decoration had animated |
890 // out, animate it back in. Otherwise, if the security state has changed, | 917 // out, animate it back in. Otherwise, if the security state has changed, |
891 // animate the decoration if animation is enabled and the state changed is | 918 // animate the decoration if animation is enabled and the state changed is |
892 // not from a tab switch. | 919 // not from a tab switch. |
893 if (is_width_available_for_security_verbose_) { | 920 if (is_width_available_for_security_verbose_) { |
| 921 bool is_animated = |
| 922 (is_new_level_secure && should_animate_secure_verbose_) || |
| 923 (!is_new_level_secure && should_animate_nonsecure_verbose_); |
| 924 |
894 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) | 925 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) |
895 security_state_bubble_decoration_->AnimateIn(false); | 926 security_state_bubble_decoration_->AnimateIn(false); |
896 else if (!should_animate_security_verbose_ || tab_changed) | 927 else if (!is_animated || tab_changed) |
897 security_state_bubble_decoration_->ShowWithoutAnimation(); | 928 security_state_bubble_decoration_->ShowWithoutAnimation(); |
898 else if (is_new_security_level) | 929 else if (is_new_security_level) |
899 security_state_bubble_decoration_->AnimateIn(); | 930 security_state_bubble_decoration_->AnimateIn(); |
900 } else { | 931 } else { |
901 // Animate the decoration out if there's not enough space. | 932 // Animate the decoration out if there's not enough space. |
902 security_state_bubble_decoration_->AnimateOut(); | 933 security_state_bubble_decoration_->AnimateOut(); |
903 } | 934 } |
904 } | 935 } |
905 | 936 |
906 bool LocationBarViewMac::IsSecureConnection( | 937 bool LocationBarViewMac::IsSecureConnection( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 OnDecorationsChanged(); | 970 OnDecorationsChanged(); |
940 } | 971 } |
941 | 972 |
942 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 973 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
943 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 974 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
944 std::vector<NSView*> views; | 975 std::vector<NSView*> views; |
945 for (auto* decoration : decorations) | 976 for (auto* decoration : decorations) |
946 views.push_back(decoration->GetAccessibilityView()); | 977 views.push_back(decoration->GetAccessibilityView()); |
947 return views; | 978 return views; |
948 } | 979 } |
OLD | NEW |