| 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> | 491 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> |
| 492 GetKeywordShortName(keyword, &is_extension_keyword); | 492 GetKeywordShortName(keyword, &is_extension_keyword); |
| 493 } | 493 } |
| 494 | 494 |
| 495 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); | 495 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); |
| 496 | 496 |
| 497 // This is true for EV certificate since the certificate should be | 497 // This is true for EV certificate since the certificate should be |
| 498 // displayed, even if the width is narrow. | 498 // displayed, even if the width is narrow. |
| 499 CGFloat available_width = | 499 CGFloat available_width = |
| 500 [cell availableWidthInFrame:[[cell controlView] frame]]; | 500 [cell availableWidthInFrame:[[cell controlView] frame]]; |
| 501 is_width_available_for_security_verbose_ = | 501 is_width_available_for_security_verbose_ = available_width >= kMinURLWidth || |
| 502 available_width >= kMinURLWidth || ShouldShowEVBubble(); | 502 ShouldShowEVBubble() || |
| 503 ShouldShowExtensionBubble(); |
| 503 | 504 |
| 504 if (!keyword.empty() && !is_keyword_hint) { | 505 if (!keyword.empty() && !is_keyword_hint) { |
| 505 // Switch from location icon to keyword mode. | 506 // Switch from location icon to keyword mode. |
| 506 location_icon_decoration_->SetVisible(false); | 507 location_icon_decoration_->SetVisible(false); |
| 507 selected_keyword_decoration_->SetVisible(true); | 508 selected_keyword_decoration_->SetVisible(true); |
| 508 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); | 509 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 509 // Note: the first time through this code path the | 510 // Note: the first time through this code path the |
| 510 // |selected_keyword_decoration_| has no image set because under Material | 511 // |selected_keyword_decoration_| has no image set because under Material |
| 511 // Design we need to set its color, which we cannot do until we know the | 512 // Design we need to set its color, which we cannot do until we know the |
| 512 // theme (by being installed in a browser window). | 513 // theme (by being installed in a browser window). |
| 513 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 514 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
| 514 } else if (!keyword.empty() && is_keyword_hint) { | 515 } else if (!keyword.empty() && is_keyword_hint) { |
| 515 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); | 516 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 516 keyword_hint_decoration_->SetVisible(true); | 517 keyword_hint_decoration_->SetVisible(true); |
| 517 } else if (ShouldShowEVBubble()) { | 518 } else if (ShouldShowEVBubble()) { |
| 518 // Switch from location icon to show the EV bubble instead. | 519 // Switch from location icon to show the EV bubble instead. |
| 519 location_icon_decoration_->SetVisible(false); | 520 location_icon_decoration_->SetVisible(false); |
| 520 security_state_bubble_decoration_->SetVisible(true); | 521 security_state_bubble_decoration_->SetVisible(true); |
| 521 | 522 |
| 522 base::string16 label(GetToolbarModel()->GetEVCertName()); | 523 base::string16 label(GetToolbarModel()->GetEVCertName()); |
| 523 security_state_bubble_decoration_->SetFullLabel( | 524 security_state_bubble_decoration_->SetFullLabel( |
| 524 base::SysUTF16ToNSString(label)); | 525 base::SysUTF16ToNSString(label)); |
| 526 } else if (ShouldShowExtensionBubble()) { |
| 527 // Switch from location icon to show the extension bubble instead. |
| 528 location_icon_decoration_->SetVisible(false); |
| 529 security_state_bubble_decoration_->SetVisible(true); |
| 530 |
| 531 base::string16 label( |
| 532 GetExtensionName(GetToolbarModel()->GetURL(), GetWebContents())); |
| 533 security_state_bubble_decoration_->SetFullLabel( |
| 534 base::SysUTF16ToNSString(label)); |
| 525 } else if (ShouldShowSecurityState() || | 535 } else if (ShouldShowSecurityState() || |
| 526 security_state_bubble_decoration_->AnimatingOut()) { | 536 security_state_bubble_decoration_->AnimatingOut()) { |
| 527 bool is_security_state_visible = | 537 bool is_security_state_visible = |
| 528 is_width_available_for_security_verbose_ || | 538 is_width_available_for_security_verbose_ || |
| 529 security_state_bubble_decoration_->AnimatingOut(); | 539 security_state_bubble_decoration_->AnimatingOut(); |
| 530 location_icon_decoration_->SetVisible(!is_security_state_visible); | 540 location_icon_decoration_->SetVisible(!is_security_state_visible); |
| 531 security_state_bubble_decoration_->SetVisible(is_security_state_visible); | 541 security_state_bubble_decoration_->SetVisible(is_security_state_visible); |
| 532 | 542 |
| 533 // Don't change the label if the bubble is in the process of animating | 543 // Don't change the label if the bubble is in the process of animating |
| 534 // out the old one. | 544 // out the old one. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 695 |
| 686 WebContents* LocationBarViewMac::GetWebContents() { | 696 WebContents* LocationBarViewMac::GetWebContents() { |
| 687 return browser_->tab_strip_model()->GetActiveWebContents(); | 697 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 688 } | 698 } |
| 689 | 699 |
| 690 bool LocationBarViewMac::ShouldShowEVBubble() const { | 700 bool LocationBarViewMac::ShouldShowEVBubble() const { |
| 691 return GetToolbarModel()->GetSecurityLevel(false) == | 701 return GetToolbarModel()->GetSecurityLevel(false) == |
| 692 security_state::EV_SECURE; | 702 security_state::EV_SECURE; |
| 693 } | 703 } |
| 694 | 704 |
| 705 bool LocationBarViewMac::ShouldShowExtensionBubble() const { |
| 706 return GetToolbarModel()->GetURL().SchemeIs(extensions::kExtensionScheme); |
| 707 } |
| 708 |
| 695 bool LocationBarViewMac::ShouldShowSecurityState() const { | 709 bool LocationBarViewMac::ShouldShowSecurityState() const { |
| 696 if (omnibox_view_->IsEditingOrEmpty() || | 710 if (omnibox_view_->IsEditingOrEmpty() || |
| 697 omnibox_view_->model()->is_keyword_hint()) { | 711 omnibox_view_->model()->is_keyword_hint()) { |
| 698 return false; | 712 return false; |
| 699 } | 713 } |
| 700 | 714 |
| 701 security_state::SecurityLevel security = | 715 security_state::SecurityLevel security = |
| 702 GetToolbarModel()->GetSecurityLevel(false); | 716 GetToolbarModel()->GetSecurityLevel(false); |
| 703 | 717 |
| 704 if (security == security_state::EV_SECURE) | 718 if (security == security_state::EV_SECURE) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 } | 911 } |
| 898 | 912 |
| 899 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { | 913 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { |
| 900 using SecurityLevel = security_state::SecurityLevel; | 914 using SecurityLevel = security_state::SecurityLevel; |
| 901 SecurityLevel new_security_level = GetToolbarModel()->GetSecurityLevel(false); | 915 SecurityLevel new_security_level = GetToolbarModel()->GetSecurityLevel(false); |
| 902 | 916 |
| 903 // If there's enough space, but the secure state decoration had animated | 917 // If there's enough space, but the secure state decoration had animated |
| 904 // out, animate it back in. Otherwise, if the security state has changed, | 918 // out, animate it back in. Otherwise, if the security state has changed, |
| 905 // animate the decoration if animation is enabled and the state changed is | 919 // animate the decoration if animation is enabled and the state changed is |
| 906 // not from a tab switch. | 920 // not from a tab switch. |
| 907 if (ShouldShowSecurityState() && is_width_available_for_security_verbose_) { | 921 if ((ShouldShowSecurityState() || ShouldShowExtensionBubble()) && |
| 922 is_width_available_for_security_verbose_) { |
| 908 bool is_secure_to_secure = IsSecureConnection(new_security_level) && | 923 bool is_secure_to_secure = IsSecureConnection(new_security_level) && |
| 909 IsSecureConnection(security_level_); | 924 IsSecureConnection(security_level_); |
| 910 bool is_new_security_level = | 925 bool is_new_security_level = |
| 911 security_level_ != new_security_level && !is_secure_to_secure; | 926 security_level_ != new_security_level && !is_secure_to_secure; |
| 912 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) | 927 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) |
| 913 security_state_bubble_decoration_->AnimateIn(false); | 928 security_state_bubble_decoration_->AnimateIn(false); |
| 914 else if (tab_changed || !CanAnimateSecurityLevel(new_security_level)) | 929 else if (tab_changed || !CanAnimateSecurityLevel(new_security_level)) |
| 915 security_state_bubble_decoration_->ShowWithoutAnimation(); | 930 security_state_bubble_decoration_->ShowWithoutAnimation(); |
| 916 else if (is_new_security_level) | 931 else if (is_new_security_level) |
| 917 security_state_bubble_decoration_->AnimateIn(); | 932 security_state_bubble_decoration_->AnimateIn(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 OnDecorationsChanged(); | 987 OnDecorationsChanged(); |
| 973 } | 988 } |
| 974 | 989 |
| 975 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 990 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 976 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 991 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 977 std::vector<NSView*> views; | 992 std::vector<NSView*> views; |
| 978 for (auto* decoration : decorations) | 993 for (auto* decoration : decorations) |
| 979 views.push_back(decoration->GetAccessibilityView()); | 994 views.push_back(decoration->GetAccessibilityView()); |
| 980 return views; | 995 return views; |
| 981 } | 996 } |
| OLD | NEW |