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

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

Issue 2555063003: Render extension URLs with chips (Closed)
Patch Set: Chip -> text Created 4 years 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 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> 451 short_name = TemplateURLServiceFactory::GetForProfile(profile())->
452 GetKeywordShortName(keyword, &is_extension_keyword); 452 GetKeywordShortName(keyword, &is_extension_keyword);
453 } 453 }
454 454
455 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); 455 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint();
456 456
457 // This is true for EV certificate since the certificate should be 457 // This is true for EV certificate since the certificate should be
458 // displayed, even if the width is narrow. 458 // displayed, even if the width is narrow.
459 CGFloat available_width = 459 CGFloat available_width =
460 [cell availableWidthInFrame:[[cell controlView] frame]]; 460 [cell availableWidthInFrame:[[cell controlView] frame]];
461 is_width_available_for_security_verbose_ = 461 is_width_available_for_security_verbose_ = available_width >= kMinURLWidth ||
462 available_width >= kMinURLWidth || ShouldShowEVBubble(); 462 ShouldShowEVBubble() ||
463 ShouldShowExtensionBubble();
463 464
464 if (!keyword.empty() && !is_keyword_hint) { 465 if (!keyword.empty() && !is_keyword_hint) {
465 // Switch from location icon to keyword mode. 466 // Switch from location icon to keyword mode.
466 location_icon_decoration_->SetVisible(false); 467 location_icon_decoration_->SetVisible(false);
467 selected_keyword_decoration_->SetVisible(true); 468 selected_keyword_decoration_->SetVisible(true);
468 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); 469 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
469 // Note: the first time through this code path the 470 // Note: the first time through this code path the
470 // |selected_keyword_decoration_| has no image set because under Material 471 // |selected_keyword_decoration_| has no image set because under Material
471 // Design we need to set its color, which we cannot do until we know the 472 // Design we need to set its color, which we cannot do until we know the
472 // theme (by being installed in a browser window). 473 // theme (by being installed in a browser window).
473 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); 474 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword));
474 } else if (!keyword.empty() && is_keyword_hint) { 475 } else if (!keyword.empty() && is_keyword_hint) {
475 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); 476 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword);
476 keyword_hint_decoration_->SetVisible(true); 477 keyword_hint_decoration_->SetVisible(true);
477 } else if (ShouldShowEVBubble()) { 478 } else if (ShouldShowEVBubble()) {
478 // Switch from location icon to show the EV bubble instead. 479 // Switch from location icon to show the EV bubble instead.
479 location_icon_decoration_->SetVisible(false); 480 location_icon_decoration_->SetVisible(false);
480 security_state_bubble_decoration_->SetVisible(true); 481 security_state_bubble_decoration_->SetVisible(true);
481 482
482 base::string16 label(GetToolbarModel()->GetEVCertName()); 483 base::string16 label(GetToolbarModel()->GetEVCertName());
483 security_state_bubble_decoration_->SetFullLabel( 484 security_state_bubble_decoration_->SetFullLabel(
484 base::SysUTF16ToNSString(label)); 485 base::SysUTF16ToNSString(label));
486 } else if (ShouldShowExtensionBubble()) {
487 // Switch from location icon to show the extension bubble instead.
488 location_icon_decoration_->SetVisible(false);
489 security_state_bubble_decoration_->SetVisible(true);
490
491 base::string16 label(
492 GetExtensionName(GetToolbarModel()->GetURL(), GetWebContents()));
493 security_state_bubble_decoration_->SetFullLabel(
494 base::SysUTF16ToNSString(label));
485 } else if (ShouldShowSecurityState() || 495 } else if (ShouldShowSecurityState() ||
486 security_state_bubble_decoration_->AnimatingOut()) { 496 security_state_bubble_decoration_->AnimatingOut()) {
487 bool is_security_state_visible = 497 bool is_security_state_visible =
488 is_width_available_for_security_verbose_ || 498 is_width_available_for_security_verbose_ ||
489 security_state_bubble_decoration_->AnimatingOut(); 499 security_state_bubble_decoration_->AnimatingOut();
490 location_icon_decoration_->SetVisible(!is_security_state_visible); 500 location_icon_decoration_->SetVisible(!is_security_state_visible);
491 security_state_bubble_decoration_->SetVisible(is_security_state_visible); 501 security_state_bubble_decoration_->SetVisible(is_security_state_visible);
492 502
493 // Don't change the label if the bubble is in the process of animating 503 // Don't change the label if the bubble is in the process of animating
494 // out the old one. 504 // out the old one.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 655
646 WebContents* LocationBarViewMac::GetWebContents() { 656 WebContents* LocationBarViewMac::GetWebContents() {
647 return browser_->tab_strip_model()->GetActiveWebContents(); 657 return browser_->tab_strip_model()->GetActiveWebContents();
648 } 658 }
649 659
650 bool LocationBarViewMac::ShouldShowEVBubble() const { 660 bool LocationBarViewMac::ShouldShowEVBubble() const {
651 return GetToolbarModel()->GetSecurityLevel(false) == 661 return GetToolbarModel()->GetSecurityLevel(false) ==
652 security_state::EV_SECURE; 662 security_state::EV_SECURE;
653 } 663 }
654 664
665 bool LocationBarViewMac::ShouldShowExtensionBubble() const {
666 return !GetOmniboxView()->IsEditingOrEmpty() &&
667 GetToolbarModel()->GetURL().SchemeIs(extensions::kExtensionScheme);
668 }
669
655 bool LocationBarViewMac::ShouldShowSecurityState() const { 670 bool LocationBarViewMac::ShouldShowSecurityState() const {
656 if (omnibox_view_->IsEditingOrEmpty() || 671 if (omnibox_view_->IsEditingOrEmpty() ||
657 omnibox_view_->model()->is_keyword_hint()) { 672 omnibox_view_->model()->is_keyword_hint()) {
658 return false; 673 return false;
659 } 674 }
660 675
661 security_state::SecurityLevel security = 676 security_state::SecurityLevel security =
662 GetToolbarModel()->GetSecurityLevel(false); 677 GetToolbarModel()->GetSecurityLevel(false);
663 678
664 return security == security_state::EV_SECURE || 679 return security == security_state::EV_SECURE ||
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 } 868 }
854 869
855 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) { 870 void LocationBarViewMac::UpdateSecurityState(bool tab_changed) {
856 using SecurityLevel = security_state::SecurityLevel; 871 using SecurityLevel = security_state::SecurityLevel;
857 SecurityLevel new_security_level = GetToolbarModel()->GetSecurityLevel(false); 872 SecurityLevel new_security_level = GetToolbarModel()->GetSecurityLevel(false);
858 873
859 // If there's enough space, but the secure state decoration had animated 874 // If there's enough space, but the secure state decoration had animated
860 // out, animate it back in. Otherwise, if the security state has changed, 875 // out, animate it back in. Otherwise, if the security state has changed,
861 // animate the decoration if animation is enabled and the state changed is 876 // animate the decoration if animation is enabled and the state changed is
862 // not from a tab switch. 877 // not from a tab switch.
863 if (ShouldShowSecurityState() && is_width_available_for_security_verbose_) { 878 if ((ShouldShowSecurityState() || ShouldShowExtensionBubble()) &&
879 is_width_available_for_security_verbose_) {
864 bool is_secure_to_secure = IsSecureConnection(new_security_level) && 880 bool is_secure_to_secure = IsSecureConnection(new_security_level) &&
865 IsSecureConnection(security_level_); 881 IsSecureConnection(security_level_);
866 bool is_new_security_level = 882 bool is_new_security_level =
867 security_level_ != new_security_level && !is_secure_to_secure; 883 security_level_ != new_security_level && !is_secure_to_secure;
868 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut()) 884 if (!tab_changed && security_state_bubble_decoration_->HasAnimatedOut())
869 security_state_bubble_decoration_->AnimateIn(false); 885 security_state_bubble_decoration_->AnimateIn(false);
870 else if (tab_changed || !CanAnimateSecurityLevel(new_security_level)) 886 else if (tab_changed || !CanAnimateSecurityLevel(new_security_level))
871 security_state_bubble_decoration_->ShowWithoutAnimation(); 887 security_state_bubble_decoration_->ShowWithoutAnimation();
872 else if (is_new_security_level) 888 else if (is_new_security_level)
873 security_state_bubble_decoration_->AnimateIn(); 889 security_state_bubble_decoration_->AnimateIn();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 OnDecorationsChanged(); 937 OnDecorationsChanged();
922 } 938 }
923 939
924 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { 940 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() {
925 std::vector<LocationBarDecoration*> decorations = GetDecorations(); 941 std::vector<LocationBarDecoration*> decorations = GetDecorations();
926 std::vector<NSView*> views; 942 std::vector<NSView*> views;
927 for (auto* decoration : decorations) 943 for (auto* decoration : decorations)
928 views.push_back(decoration->GetAccessibilityView()); 944 views.push_back(decoration->GetAccessibilityView());
929 return views; 945 return views;
930 } 946 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h ('k') | chrome/browser/ui/location_bar/location_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698