| 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" | |
| 9 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
| 10 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 16 #import "chrome/browser/app_controller_mac.h" | 15 #import "chrome/browser/app_controller_mac.h" |
| 17 #include "chrome/browser/command_updater.h" | 16 #include "chrome/browser/command_updater.h" |
| 18 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" |
| 46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 46 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 47 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 50 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 51 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 53 #include "chrome/common/chrome_features.h" | |
| 54 #include "chrome/common/chrome_switches.h" | |
| 55 #include "chrome/common/pref_names.h" | 52 #include "chrome/common/pref_names.h" |
| 56 #include "chrome/grit/theme_resources.h" | 53 #include "chrome/grit/theme_resources.h" |
| 57 #include "components/bookmarks/common/bookmark_pref_names.h" | 54 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 58 #include "components/grit/components_scaled_resources.h" | 55 #include "components/grit/components_scaled_resources.h" |
| 59 #import "components/omnibox/browser/omnibox_popup_model.h" | 56 #import "components/omnibox/browser/omnibox_popup_model.h" |
| 60 #include "components/prefs/pref_service.h" | 57 #include "components/prefs/pref_service.h" |
| 61 #include "components/search_engines/template_url.h" | 58 #include "components/search_engines/template_url.h" |
| 62 #include "components/search_engines/template_url_service.h" | 59 #include "components/search_engines/template_url_service.h" |
| 63 #include "components/translate/core/browser/language_state.h" | 60 #include "components/translate/core/browser/language_state.h" |
| 64 #include "components/variations/variations_associated_data.h" | 61 #include "components/variations/variations_associated_data.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 save_credit_card_decoration_( | 113 save_credit_card_decoration_( |
| 117 new SaveCreditCardDecoration(command_updater)), | 114 new SaveCreditCardDecoration(command_updater)), |
| 118 star_decoration_(new StarDecoration(command_updater)), | 115 star_decoration_(new StarDecoration(command_updater)), |
| 119 translate_decoration_(new TranslateDecoration(command_updater)), | 116 translate_decoration_(new TranslateDecoration(command_updater)), |
| 120 zoom_decoration_(new ZoomDecoration(this)), | 117 zoom_decoration_(new ZoomDecoration(this)), |
| 121 keyword_hint_decoration_(new KeywordHintDecoration()), | 118 keyword_hint_decoration_(new KeywordHintDecoration()), |
| 122 manage_passwords_decoration_( | 119 manage_passwords_decoration_( |
| 123 new ManagePasswordsDecoration(command_updater, this)), | 120 new ManagePasswordsDecoration(command_updater, this)), |
| 124 browser_(browser), | 121 browser_(browser), |
| 125 location_bar_visible_(true), | 122 location_bar_visible_(true), |
| 126 should_show_secure_verbose_(false), | |
| 127 should_show_nonsecure_verbose_(false), | |
| 128 should_animate_secure_verbose_(false), | |
| 129 should_animate_nonsecure_verbose_(false), | |
| 130 is_width_available_for_security_verbose_(false), | 123 is_width_available_for_security_verbose_(false), |
| 131 security_level_(security_state::NONE), | 124 security_level_(security_state::NONE), |
| 132 weak_ptr_factory_(this) { | 125 weak_ptr_factory_(this) { |
| 133 ScopedVector<ContentSettingImageModel> models = | 126 ScopedVector<ContentSettingImageModel> models = |
| 134 ContentSettingImageModel::GenerateContentSettingImageModels(); | 127 ContentSettingImageModel::GenerateContentSettingImageModels(); |
| 135 for (ContentSettingImageModel* model : models.get()) { | 128 for (ContentSettingImageModel* model : models.get()) { |
| 136 // ContentSettingDecoration takes ownership of its model. | 129 // ContentSettingDecoration takes ownership of its model. |
| 137 content_setting_decorations_.push_back( | 130 content_setting_decorations_.push_back( |
| 138 new ContentSettingDecoration(model, this, profile)); | 131 new ContentSettingDecoration(model, this, profile)); |
| 139 } | 132 } |
| 140 models.weak_clear(); | 133 models.weak_clear(); |
| 141 | 134 |
| 142 edit_bookmarks_enabled_.Init( | 135 edit_bookmarks_enabled_.Init( |
| 143 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 136 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
| 144 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, | 137 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, |
| 145 base::Unretained(this))); | 138 base::Unretained(this))); |
| 146 | 139 |
| 147 zoom::ZoomEventManager::GetForBrowserContext(profile) | 140 zoom::ZoomEventManager::GetForBrowserContext(profile) |
| 148 ->AddZoomEventManagerObserver(this); | 141 ->AddZoomEventManagerObserver(this); |
| 149 | 142 |
| 150 [[field_ cell] setIsPopupMode: | 143 [[field_ cell] setIsPopupMode: |
| 151 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; | 144 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; |
| 152 | 145 |
| 153 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 154 std::string security_chip; | |
| 155 if (command_line->HasSwitch(switches::kSecurityChip)) { | |
| 156 security_chip = command_line->GetSwitchValueASCII(switches::kSecurityChip); | |
| 157 } else if (base::FeatureList::IsEnabled(features::kSecurityChip)) { | |
| 158 security_chip = variations::GetVariationParamValueByFeature( | |
| 159 features::kSecurityChip, kSecurityChipFeatureVisibilityParam); | |
| 160 } | |
| 161 | |
| 162 if (security_chip == switches::kSecurityChipShowNonSecureOnly) { | |
| 163 should_show_nonsecure_verbose_ = true; | |
| 164 } else if (security_chip == switches::kSecurityChipShowAll) { | |
| 165 should_show_secure_verbose_ = true; | |
| 166 should_show_nonsecure_verbose_ = true; | |
| 167 } | |
| 168 | |
| 169 std::string security_chip_animation; | |
| 170 if (command_line->HasSwitch(switches::kSecurityChipAnimation)) { | |
| 171 security_chip_animation = | |
| 172 command_line->GetSwitchValueASCII(switches::kSecurityChipAnimation); | |
| 173 } else if (base::FeatureList::IsEnabled(features::kSecurityChip)) { | |
| 174 security_chip_animation = variations::GetVariationParamValueByFeature( | |
| 175 features::kSecurityChip, kSecurityChipFeatureAnimationParam); | |
| 176 } | |
| 177 | |
| 178 if (security_chip_animation == | |
| 179 switches::kSecurityChipAnimationNonSecureOnly) { | |
| 180 should_animate_nonsecure_verbose_ = true; | |
| 181 } else if (security_chip_animation == switches::kSecurityChipAnimationAll) { | |
| 182 should_animate_secure_verbose_ = true; | |
| 183 should_animate_nonsecure_verbose_ = true; | |
| 184 } | |
| 185 | |
| 186 // Sets images for the decorations, and performs a layout. This call ensures | 146 // Sets images for the decorations, and performs a layout. This call ensures |
| 187 // that this class is in a consistent state after initialization. | 147 // that this class is in a consistent state after initialization. |
| 188 OnChanged(); | 148 OnChanged(); |
| 189 } | 149 } |
| 190 | 150 |
| 191 LocationBarViewMac::~LocationBarViewMac() { | 151 LocationBarViewMac::~LocationBarViewMac() { |
| 192 // Disconnect from cell in case it outlives us. | 152 // Disconnect from cell in case it outlives us. |
| 193 [[field_ cell] clearDecorations]; | 153 [[field_ cell] clearDecorations]; |
| 194 | 154 |
| 195 zoom::ZoomEventManager::GetForBrowserContext(profile()) | 155 zoom::ZoomEventManager::GetForBrowserContext(profile()) |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 654 |
| 695 bool LocationBarViewMac::ShouldShowSecurityState() const { | 655 bool LocationBarViewMac::ShouldShowSecurityState() const { |
| 696 if (omnibox_view_->IsEditingOrEmpty() || | 656 if (omnibox_view_->IsEditingOrEmpty() || |
| 697 omnibox_view_->model()->is_keyword_hint()) { | 657 omnibox_view_->model()->is_keyword_hint()) { |
| 698 return false; | 658 return false; |
| 699 } | 659 } |
| 700 | 660 |
| 701 security_state::SecurityLevel security = | 661 security_state::SecurityLevel security = |
| 702 GetToolbarModel()->GetSecurityLevel(false); | 662 GetToolbarModel()->GetSecurityLevel(false); |
| 703 | 663 |
| 704 if (security == security_state::EV_SECURE) | 664 return security == security_state::EV_SECURE || |
| 705 return true; | 665 security == security_state::SECURE || |
| 706 else if (security == security_state::SECURE) | 666 security == security_state::DANGEROUS || |
| 707 return should_show_secure_verbose_; | 667 security == security_state::HTTP_SHOW_WARNING; |
| 708 | |
| 709 return should_show_nonsecure_verbose_ && | |
| 710 (security == security_state::DANGEROUS || | |
| 711 security == security_state::HTTP_SHOW_WARNING); | |
| 712 } | 668 } |
| 713 | 669 |
| 714 bool LocationBarViewMac::IsLocationBarDark() const { | 670 bool LocationBarViewMac::IsLocationBarDark() const { |
| 715 return [[field_ window] inIncognitoModeWithSystemTheme]; | 671 return [[field_ window] inIncognitoModeWithSystemTheme]; |
| 716 } | 672 } |
| 717 | 673 |
| 718 LocationBarDecoration* LocationBarViewMac::GetPageInfoDecoration() const { | 674 LocationBarDecoration* LocationBarViewMac::GetPageInfoDecoration() const { |
| 719 if (security_state_bubble_decoration_->IsVisible()) | 675 if (security_state_bubble_decoration_->IsVisible()) |
| 720 return security_state_bubble_decoration_.get(); | 676 return security_state_bubble_decoration_.get(); |
| 721 | 677 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 } else if (!is_width_available_for_security_verbose_ || | 874 } else if (!is_width_available_for_security_verbose_ || |
| 919 CanAnimateSecurityLevel(security_level_)) { | 875 CanAnimateSecurityLevel(security_level_)) { |
| 920 security_state_bubble_decoration_->AnimateOut(); | 876 security_state_bubble_decoration_->AnimateOut(); |
| 921 } | 877 } |
| 922 | 878 |
| 923 security_level_ = new_security_level; | 879 security_level_ = new_security_level; |
| 924 } | 880 } |
| 925 | 881 |
| 926 bool LocationBarViewMac::CanAnimateSecurityLevel( | 882 bool LocationBarViewMac::CanAnimateSecurityLevel( |
| 927 security_state::SecurityLevel level) const { | 883 security_state::SecurityLevel level) const { |
| 928 using SecurityLevel = security_state::SecurityLevel; | 884 return security_level_ == security_state::SecurityLevel::DANGEROUS || |
| 929 if (IsSecureConnection(level)) { | 885 security_level_ == security_state::SecurityLevel::HTTP_SHOW_WARNING; |
| 930 return should_animate_secure_verbose_; | |
| 931 } else if (security_level_ == SecurityLevel::DANGEROUS || | |
| 932 security_level_ == SecurityLevel::HTTP_SHOW_WARNING) { | |
| 933 return should_animate_nonsecure_verbose_; | |
| 934 } else { | |
| 935 return false; | |
| 936 } | |
| 937 } | 886 } |
| 938 | 887 |
| 939 bool LocationBarViewMac::IsSecureConnection( | 888 bool LocationBarViewMac::IsSecureConnection( |
| 940 security_state::SecurityLevel level) const { | 889 security_state::SecurityLevel level) const { |
| 941 return level == security_state::SECURE || | 890 return level == security_state::SECURE || |
| 942 level == security_state::EV_SECURE; | 891 level == security_state::EV_SECURE; |
| 943 } | 892 } |
| 944 | 893 |
| 945 void LocationBarViewMac::UpdateAccessibilityViewPosition( | 894 void LocationBarViewMac::UpdateAccessibilityViewPosition( |
| 946 LocationBarDecoration* decoration) { | 895 LocationBarDecoration* decoration) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 972 OnDecorationsChanged(); | 921 OnDecorationsChanged(); |
| 973 } | 922 } |
| 974 | 923 |
| 975 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 924 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 976 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 925 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 977 std::vector<NSView*> views; | 926 std::vector<NSView*> views; |
| 978 for (auto* decoration : decorations) | 927 for (auto* decoration : decorations) |
| 979 views.push_back(decoration->GetAccessibilityView()); | 928 views.push_back(decoration->GetAccessibilityView()); |
| 980 return views; | 929 return views; |
| 981 } | 930 } |
| OLD | NEW |