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

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

Issue 2336423002: [Material][Mac] Flag and clean for the Security State Decoration (Closed)
Patch Set: Fix for rsesek, hide EV cert along with secure Created 4 years, 3 months 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 save_credit_card_decoration_( 114 save_credit_card_decoration_(
115 new SaveCreditCardDecoration(command_updater)), 115 new SaveCreditCardDecoration(command_updater)),
116 star_decoration_(new StarDecoration(command_updater)), 116 star_decoration_(new StarDecoration(command_updater)),
117 translate_decoration_(new TranslateDecoration(command_updater)), 117 translate_decoration_(new TranslateDecoration(command_updater)),
118 zoom_decoration_(new ZoomDecoration(this)), 118 zoom_decoration_(new ZoomDecoration(this)),
119 keyword_hint_decoration_(new KeywordHintDecoration()), 119 keyword_hint_decoration_(new KeywordHintDecoration()),
120 manage_passwords_decoration_( 120 manage_passwords_decoration_(
121 new ManagePasswordsDecoration(command_updater, this)), 121 new ManagePasswordsDecoration(command_updater, this)),
122 browser_(browser), 122 browser_(browser),
123 location_bar_visible_(true), 123 location_bar_visible_(true),
124 should_show_secure_verbose_(false),
125 should_animate_security_verbose_(false),
126 is_width_available_for_security_verbose_(false),
124 weak_ptr_factory_(this) { 127 weak_ptr_factory_(this) {
125 ScopedVector<ContentSettingImageModel> models = 128 ScopedVector<ContentSettingImageModel> models =
126 ContentSettingImageModel::GenerateContentSettingImageModels(); 129 ContentSettingImageModel::GenerateContentSettingImageModels();
127 for (ContentSettingImageModel* model : models.get()) { 130 for (ContentSettingImageModel* model : models.get()) {
128 // ContentSettingDecoration takes ownership of its model. 131 // ContentSettingDecoration takes ownership of its model.
129 content_setting_decorations_.push_back( 132 content_setting_decorations_.push_back(
130 new ContentSettingDecoration(model, this, profile)); 133 new ContentSettingDecoration(model, this, profile));
131 } 134 }
132 models.weak_clear(); 135 models.weak_clear();
133 136
134 edit_bookmarks_enabled_.Init( 137 edit_bookmarks_enabled_.Init(
135 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 138 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
136 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, 139 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged,
137 base::Unretained(this))); 140 base::Unretained(this)));
138 141
139 zoom::ZoomEventManager::GetForBrowserContext(profile) 142 zoom::ZoomEventManager::GetForBrowserContext(profile)
140 ->AddZoomEventManagerObserver(this); 143 ->AddZoomEventManagerObserver(this);
141 144
142 [[field_ cell] setIsPopupMode: 145 [[field_ cell] setIsPopupMode:
143 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; 146 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)];
144 147
148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
149 if (command_line->HasSwitch(switches::kMaterialSecurityVerbose)) {
150 std::string security_verbose_flag =
151 command_line->GetSwitchValueASCII(switches::kMaterialSecurityVerbose);
152
153 should_show_secure_verbose_ =
154 security_verbose_flag ==
155 switches::kMaterialSecurityVerboseShowAllAnimated ||
156 security_verbose_flag ==
157 switches::kMaterialSecurityVerboseShowAllNonAnimated;
158
159 should_animate_security_verbose_ =
160 security_verbose_flag ==
161 switches::kMaterialSecurityVerboseShowAllAnimated ||
162 security_verbose_flag ==
163 switches::kMaterialSecurityVerboseShowNonSecureAnimated;
164 }
165
145 // Sets images for the decorations, and performs a layout. This call ensures 166 // Sets images for the decorations, and performs a layout. This call ensures
146 // that this class is in a consistent state after initialization. 167 // that this class is in a consistent state after initialization.
147 OnChanged(); 168 OnChanged();
148 } 169 }
149 170
150 LocationBarViewMac::~LocationBarViewMac() { 171 LocationBarViewMac::~LocationBarViewMac() {
151 // Disconnect from cell in case it outlives us. 172 // Disconnect from cell in case it outlives us.
152 [[field_ cell] clearDecorations]; 173 [[field_ cell] clearDecorations];
153 174
154 zoom::ZoomEventManager::GetForBrowserContext(profile()) 175 zoom::ZoomEventManager::GetForBrowserContext(profile())
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); 497 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword);
477 keyword_hint_decoration_->SetVisible(true); 498 keyword_hint_decoration_->SetVisible(true);
478 } else if (ShouldShowEVBubble()) { 499 } else if (ShouldShowEVBubble()) {
479 // Switch from location icon to show the EV bubble instead. 500 // Switch from location icon to show the EV bubble instead.
480 location_icon_decoration_->SetVisible(false); 501 location_icon_decoration_->SetVisible(false);
481 security_state_bubble_decoration_->SetVisible(true); 502 security_state_bubble_decoration_->SetVisible(true);
482 503
483 base::string16 label(GetToolbarModel()->GetEVCertName()); 504 base::string16 label(GetToolbarModel()->GetEVCertName());
484 security_state_bubble_decoration_->SetFullLabel( 505 security_state_bubble_decoration_->SetFullLabel(
485 base::SysUTF16ToNSString(label)); 506 base::SysUTF16ToNSString(label));
507
508 // This is true for EV certificate since the certificate should be
509 // displayed, even if the width is narrow.
510 is_width_available_for_security_verbose_ = true;
486 } else if (ShouldShowSecurityState()) { 511 } else if (ShouldShowSecurityState()) {
487 // TODO(spqchan): Clean up location_bar_view_mac so that animation
488 // code isn't in Layout(). See crbug.com/642977.
489 bool is_security_state_visible = true;
490 CGFloat available_width = 512 CGFloat available_width =
491 [cell availableWidthInFrame:[[cell controlView] frame]]; 513 [cell availableWidthInFrame:[[cell controlView] frame]];
492 514 is_width_available_for_security_verbose_ = available_width >= kMinURLWidth;
493 if (available_width < kMinURLWidth) { 515 bool is_security_state_visible =
494 // If there's not enough space, animate out the security state bubble. 516 is_width_available_for_security_verbose_ ||
495 // Show it until it has finished animating out. 517 security_state_bubble_decoration_->AnimatingOut();
496 is_security_state_visible = 518 location_icon_decoration_->SetVisible(!is_security_state_visible);
497 security_state_bubble_decoration_->AnimatingOut(); 519 security_state_bubble_decoration_->SetVisible(is_security_state_visible);
498 if (security_state_bubble_decoration_->HasAnimatedIn())
499 security_state_bubble_decoration_->AnimateOut();
500 } else if (security_state_bubble_decoration_->HasAnimatedOut()) {
501 // If there's enough space, but the secure state bubble had animated
502 // out, animate it back in.
503 security_state_bubble_decoration_->AnimateIn(false);
504 }
505 520
506 // Don't change the label if the bubble is in the process of animating 521 // Don't change the label if the bubble is in the process of animating
507 // out the old one. 522 // out the old one.
508 base::string16 label(GetToolbarModel()->GetSecureVerboseText()); 523 base::string16 label(GetToolbarModel()->GetSecureVerboseText());
509 if (!security_state_bubble_decoration_->AnimatingOut()) { 524 if (!security_state_bubble_decoration_->AnimatingOut()) {
510 security_state_bubble_decoration_->SetFullLabel( 525 security_state_bubble_decoration_->SetFullLabel(
511 base::SysUTF16ToNSString(label)); 526 base::SysUTF16ToNSString(label));
512 } 527 }
513
514 location_icon_decoration_->SetVisible(!is_security_state_visible);
515 security_state_bubble_decoration_->SetVisible(is_security_state_visible);
516 } 528 }
517 529
518 // These need to change anytime the layout changes. 530 // These need to change anytime the layout changes.
519 // TODO(shess): Anytime the field editor might have changed, the 531 // TODO(shess): Anytime the field editor might have changed, the
520 // cursor rects almost certainly should have changed. The tooltips 532 // cursor rects almost certainly should have changed. The tooltips
521 // might change even when the rects don't change. 533 // might change even when the rects don't change.
522 OnDecorationsChanged(); 534 OnDecorationsChanged();
523 } 535 }
524 536
525 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { 537 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 void LocationBarViewMac::ResetTabState(WebContents* contents) { 592 void LocationBarViewMac::ResetTabState(WebContents* contents) {
581 omnibox_view_->ResetTabState(contents); 593 omnibox_view_->ResetTabState(contents);
582 } 594 }
583 595
584 void LocationBarViewMac::Update(const WebContents* contents) { 596 void LocationBarViewMac::Update(const WebContents* contents) {
585 UpdateManagePasswordsIconAndBubble(); 597 UpdateManagePasswordsIconAndBubble();
586 UpdateBookmarkStarVisibility(); 598 UpdateBookmarkStarVisibility();
587 UpdateSaveCreditCardIcon(); 599 UpdateSaveCreditCardIcon();
588 UpdateTranslateDecoration(); 600 UpdateTranslateDecoration();
589 UpdateZoomDecoration(/*default_zoom_changed=*/false); 601 UpdateZoomDecoration(/*default_zoom_changed=*/false);
602 UpdateSecurityState(contents);
590 RefreshPageActionDecorations(); 603 RefreshPageActionDecorations();
591 RefreshContentSettingsDecorations(); 604 RefreshContentSettingsDecorations();
592 if (contents) 605 if (contents)
593 omnibox_view_->OnTabChanged(contents); 606 omnibox_view_->OnTabChanged(contents);
594 else 607 else
595 omnibox_view_->Update(); 608 omnibox_view_->Update();
596 609
597 OnChanged(); 610 OnChanged();
598
599 // To avoid animating the security state bubble decoration if it
600 // should be hidden for a narrow omnibox, call UpdateSecurityState() after
601 // OnChanged().
602 UpdateSecurityState(contents);
603 } 611 }
604 612
605 void LocationBarViewMac::UpdateWithoutTabRestore() { 613 void LocationBarViewMac::UpdateWithoutTabRestore() {
606 Update(nullptr); 614 Update(nullptr);
607 } 615 }
608 616
609 void LocationBarViewMac::UpdateLocationIcon() { 617 void LocationBarViewMac::UpdateLocationIcon() {
610 SkColor vector_icon_color = GetLocationBarIconColor(); 618 SkColor vector_icon_color = GetLocationBarIconColor();
611 gfx::VectorIconId vector_icon_id = 619 gfx::VectorIconId vector_icon_id =
612 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID 620 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 661
654 void LocationBarViewMac::OnChanged() { 662 void LocationBarViewMac::OnChanged() {
655 if (!ui::MaterialDesignController::IsModeMaterial()) { 663 if (!ui::MaterialDesignController::IsModeMaterial()) {
656 const int resource_id = omnibox_view_->GetIcon(); 664 const int resource_id = omnibox_view_->GetIcon();
657 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); 665 NSImage* image = OmniboxViewMac::ImageForResource(resource_id);
658 location_icon_decoration_->SetImage(image); 666 location_icon_decoration_->SetImage(image);
659 security_state_bubble_decoration_->SetImage(image); 667 security_state_bubble_decoration_->SetImage(image);
660 Layout(); 668 Layout();
661 return; 669 return;
662 } 670 }
671 UpdateSecurityState(false);
663 UpdateLocationIcon(); 672 UpdateLocationIcon();
664 } 673 }
665 674
666 ToolbarModel* LocationBarViewMac::GetToolbarModel() { 675 ToolbarModel* LocationBarViewMac::GetToolbarModel() {
667 return browser_->toolbar_model(); 676 return browser_->toolbar_model();
668 } 677 }
669 678
670 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { 679 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const {
671 return browser_->toolbar_model(); 680 return browser_->toolbar_model();
672 } 681 }
673 682
674 WebContents* LocationBarViewMac::GetWebContents() { 683 WebContents* LocationBarViewMac::GetWebContents() {
675 return browser_->tab_strip_model()->GetActiveWebContents(); 684 return browser_->tab_strip_model()->GetActiveWebContents();
676 } 685 }
677 686
678 bool LocationBarViewMac::ShouldShowEVBubble() const { 687 bool LocationBarViewMac::ShouldShowEVBubble() const {
679 return (GetToolbarModel()->GetSecurityLevel(false) == 688 return (GetToolbarModel()->GetSecurityLevel(false) ==
680 security_state::SecurityStateModel::EV_SECURE); 689 security_state::SecurityStateModel::EV_SECURE) &&
690 should_show_secure_verbose_;
681 } 691 }
682 692
683 bool LocationBarViewMac::ShouldShowSecurityState() const { 693 bool LocationBarViewMac::ShouldShowSecurityState() const {
684 security_state::SecurityStateModel::SecurityLevel security = 694 security_state::SecurityStateModel::SecurityLevel security =
685 GetToolbarModel()->GetSecurityLevel(false); 695 GetToolbarModel()->GetSecurityLevel(false);
686 bool has_verbose_for_security = 696 bool has_verbose_for_security =
687 IsSecureConnection(security) || 697 security == security_state::SecurityStateModel::SECURITY_ERROR ||
688 security == security_state::SecurityStateModel::SECURITY_ERROR; 698 (IsSecureConnection(security) && should_show_secure_verbose_);
689 699
690 return ui::MaterialDesignController::IsModeMaterial() && 700 return ui::MaterialDesignController::IsModeMaterial() &&
691 has_verbose_for_security && !omnibox_view_->IsEditingOrEmpty() && 701 has_verbose_for_security && !omnibox_view_->IsEditingOrEmpty() &&
692 !omnibox_view_->model()->is_keyword_hint(); 702 !omnibox_view_->model()->is_keyword_hint();
693 } 703 }
694 704
695 bool LocationBarViewMac::IsLocationBarDark() const { 705 bool LocationBarViewMac::IsLocationBarDark() const {
696 return [[field_ window] inIncognitoModeWithSystemTheme]; 706 return [[field_ window] inIncognitoModeWithSystemTheme];
697 } 707 }
698 708
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 WebContents* web_contents = GetWebContents(); 876 WebContents* web_contents = GetWebContents();
867 if (!web_contents) 877 if (!web_contents)
868 return false; 878 return false;
869 879
870 return zoom_decoration_->UpdateIfNecessary( 880 return zoom_decoration_->UpdateIfNecessary(
871 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, 881 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed,
872 IsLocationBarDark()); 882 IsLocationBarDark());
873 } 883 }
874 884
875 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { 885 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) {
876 // If the security level has changed, check if the verbose state decoration 886 if (!ShouldShowSecurityState())
877 // needs to be animated. If we need to show it, animate it in. Otherwise, 887 return;
878 // animate it out if it's already fully displayed. 888
879 security_state::SecurityStateModel::SecurityLevel new_security_level = 889 security_state::SecurityStateModel::SecurityLevel new_security_level =
880 GetToolbarModel()->GetSecurityLevel(false); 890 GetToolbarModel()->GetSecurityLevel(false);
881 bool is_secure_to_secure = IsSecureConnection(new_security_level) && 891 bool is_secure_to_secure = IsSecureConnection(new_security_level) &&
882 IsSecureConnection(security_level_); 892 IsSecureConnection(security_level_);
883 if (ShouldShowSecurityState() && 893 bool is_new_security_level =
884 security_state_bubble_decoration_->IsVisible()) { 894 security_level_ != new_security_level && !is_secure_to_secure;
885 // Animate the verbose if we entered a new connection state on the current 895 security_level_ = new_security_level;
886 // tab. If it had animated out (from a narrow width). 896
887 if (!tab_changed && 897 // If there's enough space, but the secure state decoration had animated
888 (security_level_ != new_security_level && !is_secure_to_secure)) { 898 // out, animate it back in. Otherwise, if the security state has changed,
899 // animate the decoration if animation is enabled and the state changed is
900 // not from a tab switch.
901 if (is_width_available_for_security_verbose_) {
902 if (security_state_bubble_decoration_->HasAnimatedOut())
903 security_state_bubble_decoration_->AnimateIn(false);
904 else if (!should_animate_security_verbose_ || tab_changed)
905 security_state_bubble_decoration_->ShowWithoutAnimation();
906 else if (is_new_security_level)
889 security_state_bubble_decoration_->AnimateIn(); 907 security_state_bubble_decoration_->AnimateIn();
890 } 908 } else {
909 // Animate the decoration out if there's not enough space.
910 security_state_bubble_decoration_->AnimateOut();
891 } 911 }
892
893 security_level_ = new_security_level;
894 } 912 }
895 913
896 bool LocationBarViewMac::IsSecureConnection( 914 bool LocationBarViewMac::IsSecureConnection(
897 security_state::SecurityStateModel::SecurityLevel level) const { 915 security_state::SecurityStateModel::SecurityLevel level) const {
898 return level == security_state::SecurityStateModel::SECURE || 916 return level == security_state::SecurityStateModel::SECURE ||
899 level == security_state::SecurityStateModel::EV_SECURE; 917 level == security_state::SecurityStateModel::EV_SECURE;
900 } 918 }
901 919
902 void LocationBarViewMac::UpdateAccessibilityViewPosition( 920 void LocationBarViewMac::UpdateAccessibilityViewPosition(
903 LocationBarDecoration* decoration) { 921 LocationBarDecoration* decoration) {
(...skipping 25 matching lines...) Expand all
929 OnDecorationsChanged(); 947 OnDecorationsChanged();
930 } 948 }
931 949
932 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { 950 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() {
933 std::vector<LocationBarDecoration*> decorations = GetDecorations(); 951 std::vector<LocationBarDecoration*> decorations = GetDecorations();
934 std::vector<NSView*> views; 952 std::vector<NSView*> views;
935 for (auto* decoration : decorations) 953 for (auto* decoration : decorations)
936 views.push_back(decoration->GetAccessibilityView()); 954 views.push_back(decoration->GetAccessibilityView());
937 return views; 955 return views;
938 } 956 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698