Chromium Code Reviews| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 is_width_available_for_security_verbose_ = true; | |
|
Robert Sesek
2016/09/15 16:18:13
I don't follow why this unconditionally true.
spqchan
2016/09/15 22:43:32
only non-EV verbose should be hidden if the width
| |
| 508 | |
|
Robert Sesek
2016/09/15 16:18:12
nit: extra blank line
spqchan
2016/09/15 22:43:31
Done.
| |
| 486 } else if (ShouldShowSecurityState()) { | 509 } 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 = | 510 CGFloat available_width = |
| 491 [cell availableWidthInFrame:[[cell controlView] frame]]; | 511 [cell availableWidthInFrame:[[cell controlView] frame]]; |
| 492 | 512 is_width_available_for_security_verbose_ = available_width >= kMinURLWidth; |
| 493 if (available_width < kMinURLWidth) { | 513 bool is_security_state_visible = |
| 494 // If there's not enough space, animate out the security state bubble. | 514 is_width_available_for_security_verbose_ || |
| 495 // Show it until it has finished animating out. | 515 security_state_bubble_decoration_->AnimatingOut(); |
| 496 is_security_state_visible = | 516 location_icon_decoration_->SetVisible(!is_security_state_visible); |
| 497 security_state_bubble_decoration_->AnimatingOut(); | 517 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 | 518 |
| 506 // Don't change the label if the bubble is in the process of animating | 519 // Don't change the label if the bubble is in the process of animating |
| 507 // out the old one. | 520 // out the old one. |
| 508 base::string16 label(GetToolbarModel()->GetSecureVerboseText()); | 521 base::string16 label(GetToolbarModel()->GetSecureVerboseText()); |
| 509 if (!security_state_bubble_decoration_->AnimatingOut()) { | 522 if (!security_state_bubble_decoration_->AnimatingOut()) { |
| 510 security_state_bubble_decoration_->SetFullLabel( | 523 security_state_bubble_decoration_->SetFullLabel( |
| 511 base::SysUTF16ToNSString(label)); | 524 base::SysUTF16ToNSString(label)); |
| 512 } | 525 } |
| 513 | |
| 514 location_icon_decoration_->SetVisible(!is_security_state_visible); | |
| 515 security_state_bubble_decoration_->SetVisible(is_security_state_visible); | |
| 516 } | 526 } |
| 517 | 527 |
| 518 // These need to change anytime the layout changes. | 528 // These need to change anytime the layout changes. |
| 519 // TODO(shess): Anytime the field editor might have changed, the | 529 // TODO(shess): Anytime the field editor might have changed, the |
| 520 // cursor rects almost certainly should have changed. The tooltips | 530 // cursor rects almost certainly should have changed. The tooltips |
| 521 // might change even when the rects don't change. | 531 // might change even when the rects don't change. |
| 522 OnDecorationsChanged(); | 532 OnDecorationsChanged(); |
| 523 } | 533 } |
| 524 | 534 |
| 525 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { | 535 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 void LocationBarViewMac::ResetTabState(WebContents* contents) { | 590 void LocationBarViewMac::ResetTabState(WebContents* contents) { |
| 581 omnibox_view_->ResetTabState(contents); | 591 omnibox_view_->ResetTabState(contents); |
| 582 } | 592 } |
| 583 | 593 |
| 584 void LocationBarViewMac::Update(const WebContents* contents) { | 594 void LocationBarViewMac::Update(const WebContents* contents) { |
| 585 UpdateManagePasswordsIconAndBubble(); | 595 UpdateManagePasswordsIconAndBubble(); |
| 586 UpdateBookmarkStarVisibility(); | 596 UpdateBookmarkStarVisibility(); |
| 587 UpdateSaveCreditCardIcon(); | 597 UpdateSaveCreditCardIcon(); |
| 588 UpdateTranslateDecoration(); | 598 UpdateTranslateDecoration(); |
| 589 UpdateZoomDecoration(/*default_zoom_changed=*/false); | 599 UpdateZoomDecoration(/*default_zoom_changed=*/false); |
| 600 UpdateSecurityState(contents); | |
| 590 RefreshPageActionDecorations(); | 601 RefreshPageActionDecorations(); |
| 591 RefreshContentSettingsDecorations(); | 602 RefreshContentSettingsDecorations(); |
| 592 if (contents) | 603 if (contents) |
| 593 omnibox_view_->OnTabChanged(contents); | 604 omnibox_view_->OnTabChanged(contents); |
| 594 else | 605 else |
| 595 omnibox_view_->Update(); | 606 omnibox_view_->Update(); |
| 596 | 607 |
| 597 OnChanged(); | 608 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 } | 609 } |
| 604 | 610 |
| 605 void LocationBarViewMac::UpdateWithoutTabRestore() { | 611 void LocationBarViewMac::UpdateWithoutTabRestore() { |
| 606 Update(nullptr); | 612 Update(nullptr); |
| 607 } | 613 } |
| 608 | 614 |
| 609 void LocationBarViewMac::UpdateLocationIcon() { | 615 void LocationBarViewMac::UpdateLocationIcon() { |
| 610 SkColor vector_icon_color = GetLocationBarIconColor(); | 616 SkColor vector_icon_color = GetLocationBarIconColor(); |
| 611 gfx::VectorIconId vector_icon_id = | 617 gfx::VectorIconId vector_icon_id = |
| 612 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID | 618 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 | 659 |
| 654 void LocationBarViewMac::OnChanged() { | 660 void LocationBarViewMac::OnChanged() { |
| 655 if (!ui::MaterialDesignController::IsModeMaterial()) { | 661 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 656 const int resource_id = omnibox_view_->GetIcon(); | 662 const int resource_id = omnibox_view_->GetIcon(); |
| 657 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); | 663 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); |
| 658 location_icon_decoration_->SetImage(image); | 664 location_icon_decoration_->SetImage(image); |
| 659 security_state_bubble_decoration_->SetImage(image); | 665 security_state_bubble_decoration_->SetImage(image); |
| 660 Layout(); | 666 Layout(); |
| 661 return; | 667 return; |
| 662 } | 668 } |
| 669 UpdateSecurityState(false); | |
| 663 UpdateLocationIcon(); | 670 UpdateLocationIcon(); |
| 664 } | 671 } |
| 665 | 672 |
| 666 ToolbarModel* LocationBarViewMac::GetToolbarModel() { | 673 ToolbarModel* LocationBarViewMac::GetToolbarModel() { |
| 667 return browser_->toolbar_model(); | 674 return browser_->toolbar_model(); |
| 668 } | 675 } |
| 669 | 676 |
| 670 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { | 677 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { |
| 671 return browser_->toolbar_model(); | 678 return browser_->toolbar_model(); |
| 672 } | 679 } |
| 673 | 680 |
| 674 WebContents* LocationBarViewMac::GetWebContents() { | 681 WebContents* LocationBarViewMac::GetWebContents() { |
| 675 return browser_->tab_strip_model()->GetActiveWebContents(); | 682 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 676 } | 683 } |
| 677 | 684 |
| 678 bool LocationBarViewMac::ShouldShowEVBubble() const { | 685 bool LocationBarViewMac::ShouldShowEVBubble() const { |
| 679 return (GetToolbarModel()->GetSecurityLevel(false) == | 686 return (GetToolbarModel()->GetSecurityLevel(false) == |
| 680 security_state::SecurityStateModel::EV_SECURE); | 687 security_state::SecurityStateModel::EV_SECURE); |
| 681 } | 688 } |
| 682 | 689 |
| 683 bool LocationBarViewMac::ShouldShowSecurityState() const { | 690 bool LocationBarViewMac::ShouldShowSecurityState() const { |
| 684 security_state::SecurityStateModel::SecurityLevel security = | 691 security_state::SecurityStateModel::SecurityLevel security = |
| 685 GetToolbarModel()->GetSecurityLevel(false); | 692 GetToolbarModel()->GetSecurityLevel(false); |
| 693 | |
| 686 bool has_verbose_for_security = | 694 bool has_verbose_for_security = |
| 687 IsSecureConnection(security) || | 695 security == security_state::SecurityStateModel::EV_SECURE || |
| 688 security == security_state::SecurityStateModel::SECURITY_ERROR; | 696 security == security_state::SecurityStateModel::SECURITY_ERROR || |
| 697 (security == security_state::SecurityStateModel::SECURE && | |
| 698 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 Loading... | |
| 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 Loading... | |
| 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 } |
| OLD | NEW |