| 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 for (auto* decoration : decorations) | 451 for (auto* decoration : decorations) |
| 452 UpdateAccessibilityViewPosition(decoration); | 452 UpdateAccessibilityViewPosition(decoration); |
| 453 [field_ updateMouseTracking]; | 453 [field_ updateMouseTracking]; |
| 454 [field_ resetFieldEditorFrameIfNeeded]; | 454 [field_ resetFieldEditorFrameIfNeeded]; |
| 455 [field_ setNeedsDisplay:YES]; | 455 [field_ setNeedsDisplay:YES]; |
| 456 } | 456 } |
| 457 | 457 |
| 458 // TODO(shess): This function should over time grow to closely match | 458 // TODO(shess): This function should over time grow to closely match |
| 459 // the views Layout() function. | 459 // the views Layout() function. |
| 460 void LocationBarViewMac::Layout() { | 460 void LocationBarViewMac::Layout() { |
| 461 LOG(ERROR) << "LBVMac::Layout, security bubble is visible? " << security_state
_bubble_decoration_->IsVisible(); |
| 461 AutocompleteTextFieldCell* cell = [field_ cell]; | 462 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 462 | 463 |
| 463 // Reset the left-hand decorations. | 464 // Reset the left-hand decorations. |
| 464 // TODO(shess): Shortly, this code will live somewhere else, like in | 465 // TODO(shess): Shortly, this code will live somewhere else, like in |
| 465 // the constructor. I am still wrestling with how best to deal with | 466 // the constructor. I am still wrestling with how best to deal with |
| 466 // right-hand decorations, which are not a static set. | 467 // right-hand decorations, which are not a static set. |
| 467 [cell clearDecorations]; | 468 [cell clearDecorations]; |
| 468 [cell addLeftDecoration:location_icon_decoration_.get()]; | 469 [cell addLeftDecoration:location_icon_decoration_.get()]; |
| 469 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 470 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
| 470 [cell addLeftDecoration:security_state_bubble_decoration_.get()]; | 471 [cell addLeftDecoration:security_state_bubble_decoration_.get()]; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 security_state_bubble_decoration_->SetVisible(true); | 523 security_state_bubble_decoration_->SetVisible(true); |
| 523 | 524 |
| 524 base::string16 label(GetToolbarModel()->GetEVCertName()); | 525 base::string16 label(GetToolbarModel()->GetEVCertName()); |
| 525 security_state_bubble_decoration_->SetFullLabel( | 526 security_state_bubble_decoration_->SetFullLabel( |
| 526 base::SysUTF16ToNSString(label)); | 527 base::SysUTF16ToNSString(label)); |
| 527 | 528 |
| 528 // This is true for EV certificate since the certificate should be | 529 // This is true for EV certificate since the certificate should be |
| 529 // displayed, even if the width is narrow. | 530 // displayed, even if the width is narrow. |
| 530 is_width_available_for_security_verbose_ = true; | 531 is_width_available_for_security_verbose_ = true; |
| 531 } else if (ShouldShowSecurityState()) { | 532 } else if (ShouldShowSecurityState()) { |
| 533 LOG(ERROR) << "LBVMac::Layout, ShouldShowSecurityState true"; |
| 532 CGFloat available_width = | 534 CGFloat available_width = |
| 533 [cell availableWidthInFrame:[[cell controlView] frame]]; | 535 [cell availableWidthInFrame:[[cell controlView] frame]]; |
| 534 is_width_available_for_security_verbose_ = available_width >= kMinURLWidth; | 536 is_width_available_for_security_verbose_ = available_width >= kMinURLWidth; |
| 535 bool is_security_state_visible = | 537 bool is_security_state_visible = |
| 536 is_width_available_for_security_verbose_ || | 538 is_width_available_for_security_verbose_ || |
| 537 security_state_bubble_decoration_->AnimatingOut(); | 539 security_state_bubble_decoration_->AnimatingOut(); |
| 540 LOG(ERROR) << "LBVMac::Layout, setting security bubble visibility to " << is
_security_state_visible; |
| 538 location_icon_decoration_->SetVisible(!is_security_state_visible); | 541 location_icon_decoration_->SetVisible(!is_security_state_visible); |
| 539 security_state_bubble_decoration_->SetVisible(is_security_state_visible); | 542 security_state_bubble_decoration_->SetVisible(is_security_state_visible); |
| 540 | 543 |
| 541 // Don't change the label if the bubble is in the process of animating | 544 // Don't change the label if the bubble is in the process of animating |
| 542 // out the old one. | 545 // out the old one. |
| 543 base::string16 label(GetToolbarModel()->GetSecureVerboseText()); | 546 base::string16 label(GetToolbarModel()->GetSecureVerboseText()); |
| 544 if (!security_state_bubble_decoration_->AnimatingOut()) { | 547 if (!security_state_bubble_decoration_->AnimatingOut()) { |
| 545 security_state_bubble_decoration_->SetFullLabel( | 548 security_state_bubble_decoration_->SetFullLabel( |
| 546 base::SysUTF16ToNSString(label)); | 549 base::SysUTF16ToNSString(label)); |
| 547 } | 550 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 613 |
| 611 NSPoint bubble_point = decoration->GetBubblePointInFrame(frame); | 614 NSPoint bubble_point = decoration->GetBubblePointInFrame(frame); |
| 612 return [field_ convertPoint:bubble_point toView:nil]; | 615 return [field_ convertPoint:bubble_point toView:nil]; |
| 613 } | 616 } |
| 614 | 617 |
| 615 void LocationBarViewMac::ResetTabState(WebContents* contents) { | 618 void LocationBarViewMac::ResetTabState(WebContents* contents) { |
| 616 omnibox_view_->ResetTabState(contents); | 619 omnibox_view_->ResetTabState(contents); |
| 617 } | 620 } |
| 618 | 621 |
| 619 void LocationBarViewMac::Update(const WebContents* contents) { | 622 void LocationBarViewMac::Update(const WebContents* contents) { |
| 623 LOG(ERROR) << "LBVMac::Update " << contents; |
| 620 UpdateManagePasswordsIconAndBubble(); | 624 UpdateManagePasswordsIconAndBubble(); |
| 621 UpdateBookmarkStarVisibility(); | 625 UpdateBookmarkStarVisibility(); |
| 622 UpdateSaveCreditCardIcon(); | 626 UpdateSaveCreditCardIcon(); |
| 623 UpdateTranslateDecoration(); | 627 UpdateTranslateDecoration(); |
| 624 UpdateZoomDecoration(/*default_zoom_changed=*/false); | 628 UpdateZoomDecoration(/*default_zoom_changed=*/false); |
| 625 UpdateSecurityState(contents); | 629 UpdateSecurityState(contents); |
| 626 RefreshPageActionDecorations(); | 630 RefreshPageActionDecorations(); |
| 627 RefreshContentSettingsDecorations(); | 631 RefreshContentSettingsDecorations(); |
| 628 if (contents) | 632 if (contents) |
| 629 omnibox_view_->OnTabChanged(contents); | 633 omnibox_view_->OnTabChanged(contents); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 645 | 649 |
| 646 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); | 650 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); |
| 647 NSImage* image = NSImageFromImageSkiaWithColorSpace( | 651 NSImage* image = NSImageFromImageSkiaWithColorSpace( |
| 648 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize, | 652 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize, |
| 649 vector_icon_color), | 653 vector_icon_color), |
| 650 base::mac::GetSRGBColorSpace()); | 654 base::mac::GetSRGBColorSpace()); |
| 651 location_icon_decoration_->SetImage(image); | 655 location_icon_decoration_->SetImage(image); |
| 652 security_state_bubble_decoration_->SetImage(image); | 656 security_state_bubble_decoration_->SetImage(image); |
| 653 security_state_bubble_decoration_->SetLabelColor(vector_icon_color); | 657 security_state_bubble_decoration_->SetLabelColor(vector_icon_color); |
| 654 | 658 |
| 659 LOG(ERROR) << "LBVMac::UpdateLocationIcon, security bubble is visible? " << se
curity_state_bubble_decoration_->IsVisible(); |
| 660 |
| 655 Layout(); | 661 Layout(); |
| 656 } | 662 } |
| 657 | 663 |
| 658 void LocationBarViewMac::UpdateColorsToMatchTheme() { | 664 void LocationBarViewMac::UpdateColorsToMatchTheme() { |
| 659 // Update the location-bar icon. | 665 // Update the location-bar icon. |
| 660 UpdateLocationIcon(); | 666 UpdateLocationIcon(); |
| 661 | 667 |
| 662 // Make sure we're displaying the correct star color for Incognito mode. If | 668 // Make sure we're displaying the correct star color for Incognito mode. If |
| 663 // the window is in Incognito mode, switching between a theme and no theme | 669 // the window is in Incognito mode, switching between a theme and no theme |
| 664 // can move the window in and out of dark mode. | 670 // can move the window in and out of dark mode. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 693 WebContents* LocationBarViewMac::GetWebContents() { | 699 WebContents* LocationBarViewMac::GetWebContents() { |
| 694 return browser_->tab_strip_model()->GetActiveWebContents(); | 700 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 695 } | 701 } |
| 696 | 702 |
| 697 bool LocationBarViewMac::ShouldShowEVBubble() const { | 703 bool LocationBarViewMac::ShouldShowEVBubble() const { |
| 698 return GetToolbarModel()->GetSecurityLevel(false) == | 704 return GetToolbarModel()->GetSecurityLevel(false) == |
| 699 security_state::SecurityStateModel::EV_SECURE; | 705 security_state::SecurityStateModel::EV_SECURE; |
| 700 } | 706 } |
| 701 | 707 |
| 702 bool LocationBarViewMac::ShouldShowSecurityState() const { | 708 bool LocationBarViewMac::ShouldShowSecurityState() const { |
| 709 LOG(ERROR) << "LBVMac::ShouldShowSecurityState"; |
| 703 if (omnibox_view_->IsEditingOrEmpty() || | 710 if (omnibox_view_->IsEditingOrEmpty() || |
| 704 omnibox_view_->model()->is_keyword_hint()) { | 711 omnibox_view_->model()->is_keyword_hint()) { |
| 705 return false; | 712 return false; |
| 706 } | 713 } |
| 707 | 714 |
| 708 security_state::SecurityStateModel::SecurityLevel security = | 715 security_state::SecurityStateModel::SecurityLevel security = |
| 709 GetToolbarModel()->GetSecurityLevel(false); | 716 GetToolbarModel()->GetSecurityLevel(false); |
| 717 LOG(ERROR) << "LBVMac::ShouldShowSecurityState security level " << security <<
", " << should_show_nonsecure_verbose_ << ", " << should_show_secure_verbose_; |
| 710 | 718 |
| 711 if (security == security_state::SecurityStateModel::EV_SECURE) | 719 if (security == security_state::SecurityStateModel::EV_SECURE) |
| 712 return true; | 720 return true; |
| 713 else if (security == security_state::SecurityStateModel::SECURE) | 721 else if (security == security_state::SecurityStateModel::SECURE) |
| 714 return should_show_secure_verbose_; | 722 return should_show_secure_verbose_; |
| 715 | 723 |
| 716 return should_show_nonsecure_verbose_ && | 724 return should_show_nonsecure_verbose_ && |
| 717 (security == security_state::SecurityStateModel::DANGEROUS || | 725 (security == security_state::SecurityStateModel::DANGEROUS || |
| 718 security == security_state::SecurityStateModel::HTTP_SHOW_WARNING); | 726 security == security_state::SecurityStateModel::HTTP_SHOW_WARNING); |
| 719 } | 727 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 WebContents* web_contents = GetWebContents(); | 898 WebContents* web_contents = GetWebContents(); |
| 891 if (!web_contents) | 899 if (!web_contents) |
| 892 return false; | 900 return false; |
| 893 | 901 |
| 894 return zoom_decoration_->UpdateIfNecessary( | 902 return zoom_decoration_->UpdateIfNecessary( |
| 895 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, | 903 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, |
| 896 IsLocationBarDark()); | 904 IsLocationBarDark()); |
| 897 } | 905 } |
| 898 | 906 |
| 899 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { | 907 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { |
| 908 LOG(ERROR) << "LBVMac::UpdateSecurityState " << tab_changed; |
| 900 if (!ShouldShowSecurityState()) | 909 if (!ShouldShowSecurityState()) |
| 901 return; | 910 return; |
| 911 LOG(ERROR) << "LBVMac::UpdateSecurityState should show. Old security level " <
< security_level_; |
| 902 | 912 |
| 903 security_state::SecurityStateModel::SecurityLevel new_security_level = | 913 security_state::SecurityStateModel::SecurityLevel new_security_level = |
| 904 GetToolbarModel()->GetSecurityLevel(false); | 914 GetToolbarModel()->GetSecurityLevel(false); |
| 905 bool is_new_level_secure = IsSecureConnection(new_security_level); | 915 bool is_new_level_secure = IsSecureConnection(new_security_level); |
| 906 bool is_secure_to_secure = | 916 bool is_secure_to_secure = |
| 907 is_new_level_secure && IsSecureConnection(security_level_); | 917 is_new_level_secure && IsSecureConnection(security_level_); |
| 908 bool is_new_security_level = | 918 bool is_new_security_level = |
| 909 security_level_ != new_security_level && !is_secure_to_secure; | 919 security_level_ != new_security_level && !is_secure_to_secure; |
| 910 security_level_ = new_security_level; | 920 security_level_ = new_security_level; |
| 911 | 921 |
| 922 LOG(ERROR) << "LBVMac::UpdateSecurityState new security level " << new_securit
y_level << ", " << is_secure_to_secure << ", " << is_new_security_level; |
| 923 |
| 912 // If there's enough space, but the secure state decoration had animated | 924 // If there's enough space, but the secure state decoration had animated |
| 913 // out, animate it back in. Otherwise, if the security state has changed, | 925 // out, animate it back in. Otherwise, if the security state has changed, |
| 914 // animate the decoration if animation is enabled and the state changed is | 926 // animate the decoration if animation is enabled and the state changed is |
| 915 // not from a tab switch. | 927 // not from a tab switch. |
| 916 if (is_width_available_for_security_verbose_) { | 928 if (is_width_available_for_security_verbose_) { |
| 929 LOG(ERROR) << "LBVMac::UpdateSecurityState is width available yes"; |
| 917 bool is_animated = | 930 bool is_animated = |
| 918 (is_new_level_secure && should_animate_secure_verbose_) || | 931 (is_new_level_secure && should_animate_secure_verbose_) || |
| 919 (!is_new_level_secure && should_animate_nonsecure_verbose_); | 932 (!is_new_level_secure && should_animate_nonsecure_verbose_); |
| 920 | 933 |
| 934 LOG(ERROR) << "LBVMac::UpdateSecurityState tab changed " << tab_changed; |
| 935 LOG(ERROR) << "LBVMac::UpdateSecurityState has animated out " << security_st
ate_bubble_decoration_->HasAnimatedOut(); |
| 936 |
| 921 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) | 937 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) |
| 922 security_state_bubble_decoration_->AnimateIn(false); | 938 security_state_bubble_decoration_->AnimateIn(false); |
| 923 else if (tab_changed || !is_animated) | 939 else if (tab_changed || !is_animated) |
| 924 security_state_bubble_decoration_->ShowWithoutAnimation(); | 940 security_state_bubble_decoration_->ShowWithoutAnimation(); |
| 925 else if (is_new_security_level) | 941 else if (is_new_security_level) |
| 926 security_state_bubble_decoration_->AnimateIn(); | 942 security_state_bubble_decoration_->AnimateIn(); |
| 927 } else { | 943 } else { |
| 928 // Animate the decoration out if there's not enough space. | 944 // Animate the decoration out if there's not enough space. |
| 929 security_state_bubble_decoration_->AnimateOut(); | 945 security_state_bubble_decoration_->AnimateOut(); |
| 930 } | 946 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 OnDecorationsChanged(); | 982 OnDecorationsChanged(); |
| 967 } | 983 } |
| 968 | 984 |
| 969 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 985 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 970 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 986 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 971 std::vector<NSView*> views; | 987 std::vector<NSView*> views; |
| 972 for (auto* decoration : decorations) | 988 for (auto* decoration : decorations) |
| 973 views.push_back(decoration->GetAccessibilityView()); | 989 views.push_back(decoration->GetAccessibilityView()); |
| 974 return views; | 990 return views; |
| 975 } | 991 } |
| OLD | NEW |