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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 2555063003: Render extension URLs with chips (Closed)
Patch Set: Chip -> text Created 3 years, 12 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (!IsInitialized()) 449 if (!IsInitialized())
450 return min_size; 450 return min_size;
451 451
452 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 452 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
453 453
454 // Compute width of omnibox-leading content. 454 // Compute width of omnibox-leading content.
455 const int edge_thickness = GetHorizontalEdgeThickness(); 455 const int edge_thickness = GetHorizontalEdgeThickness();
456 int leading_width = edge_thickness; 456 int leading_width = edge_thickness;
457 if (ShouldShowKeywordBubble()) { 457 if (ShouldShowKeywordBubble()) {
458 // The selected keyword view can collapse completely. 458 // The selected keyword view can collapse completely.
459 } else if (ShouldShowSecurityChip()) { 459 } else if (ShouldShowLocationIconText()) {
460 base::string16 security_text = GetSecurityText();
461 leading_width += 460 leading_width +=
462 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); 461 location_icon_view_->GetMinimumSizeForLabelText(GetLocationIconText())
462 .width();
463 } else { 463 } else {
464 leading_width += 464 leading_width +=
465 kHorizontalPadding + location_icon_view_->GetMinimumSize().width(); 465 kHorizontalPadding + location_icon_view_->GetMinimumSize().width();
466 } 466 }
467 467
468 // Compute width of omnibox-trailing content. 468 // Compute width of omnibox-trailing content.
469 int trailing_width = edge_thickness; 469 int trailing_width = edge_thickness;
470 trailing_width += IncrementalMinimumWidth(star_view_) + 470 trailing_width += IncrementalMinimumWidth(star_view_) +
471 IncrementalMinimumWidth(translate_icon_view_) + 471 IncrementalMinimumWidth(translate_icon_view_) +
472 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 472 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 GetTemplateURLForKeyword(keyword); 523 GetTemplateURLForKeyword(keyword);
524 if (template_url && 524 if (template_url &&
525 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { 525 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) {
526 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 526 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
527 GetOmniboxIcon(template_url->GetExtensionId()); 527 GetOmniboxIcon(template_url->GetExtensionId());
528 selected_keyword_view_->SetImage(image.AsImageSkia()); 528 selected_keyword_view_->SetImage(image.AsImageSkia());
529 } else { 529 } else {
530 selected_keyword_view_->ResetImage(); 530 selected_keyword_view_->ResetImage();
531 } 531 }
532 } 532 }
533 } else if (ShouldShowSecurityChip()) { 533 } else if (ShouldShowLocationIconText()) {
534 location_icon_view_->SetLabel(GetSecurityText()); 534 location_icon_view_->SetLabel(GetLocationIconText());
535 // The largest fraction of the omnibox that can be taken by the EV bubble. 535 // The largest fraction of the omnibox that can be taken by the EV bubble.
536 const double kMaxBubbleFraction = 0.5; 536 const double kMaxBubbleFraction = 0.5;
537 leading_decorations.AddDecoration(vertical_padding, location_height, false, 537 leading_decorations.AddDecoration(vertical_padding, location_height, false,
538 kMaxBubbleFraction, 0, item_padding, 538 kMaxBubbleFraction, 0, item_padding,
539 location_icon_view_); 539 location_icon_view_);
540 } else { 540 } else {
541 leading_decorations.AddDecoration(vertical_padding, location_height, 541 leading_decorations.AddDecoration(vertical_padding, location_height,
542 location_icon_view_); 542 location_icon_view_);
543 } 543 }
544 544
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 653 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
654 654
655 if (star_view_) 655 if (star_view_)
656 UpdateBookmarkStarVisibility(); 656 UpdateBookmarkStarVisibility();
657 657
658 if (contents) 658 if (contents)
659 omnibox_view_->OnTabChanged(contents); 659 omnibox_view_->OnTabChanged(contents);
660 else 660 else
661 omnibox_view_->Update(); 661 omnibox_view_->Update();
662 662
663 location_icon_view_->SetSecurityState( 663 location_icon_view_->SetTextVisibility(
664 ShouldShowSecurityChip(), !contents && ShouldAnimateSecurityChip()); 664 ShouldShowLocationIconText(),
665 665 !contents && ShouldAnimateLocationIconTextVisibilityChange());
666 OnChanged(); // NOTE: Calls Layout(). 666 OnChanged(); // NOTE: Calls Layout().
667 } 667 }
668 668
669 void LocationBarView::ResetTabState(WebContents* contents) { 669 void LocationBarView::ResetTabState(WebContents* contents) {
670 omnibox_view_->ResetTabState(contents); 670 omnibox_view_->ResetTabState(contents);
671 } 671 }
672 672
673 //////////////////////////////////////////////////////////////////////////////// 673 ////////////////////////////////////////////////////////////////////////////////
674 // LocationBarView, public OmniboxEditController implementation: 674 // LocationBarView, public OmniboxEditController implementation:
675 675
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 #if !defined(OS_CHROMEOS) 872 #if !defined(OS_CHROMEOS)
873 WebContents* web_contents = delegate_->GetWebContents(); 873 WebContents* web_contents = delegate_->GetWebContents();
874 if (!web_contents) 874 if (!web_contents)
875 return; 875 return;
876 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 876 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
877 if (browser) 877 if (browser)
878 FirstRunBubble::ShowBubble(browser, location_icon_view_); 878 FirstRunBubble::ShowBubble(browser, location_icon_view_);
879 #endif 879 #endif
880 } 880 }
881 881
882 base::string16 LocationBarView::GetSecurityText() const { 882 base::string16 LocationBarView::GetLocationIconText() const {
883 const base::string16 extension_name = GetExtensionName(
884 GetToolbarModel()->GetURL(), delegate_->GetWebContents());
885 if (!extension_name.empty())
886 return extension_name;
887
883 bool has_ev_cert = 888 bool has_ev_cert =
884 (GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE); 889 (GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE);
885 return has_ev_cert ? GetToolbarModel()->GetEVCertName() 890 return has_ev_cert ? GetToolbarModel()->GetEVCertName()
886 : GetToolbarModel()->GetSecureVerboseText(); 891 : GetToolbarModel()->GetSecureVerboseText();
887 } 892 }
888 893
889 bool LocationBarView::ShouldShowKeywordBubble() const { 894 bool LocationBarView::ShouldShowKeywordBubble() const {
890 return !omnibox_view_->model()->keyword().empty() && 895 return !omnibox_view_->model()->keyword().empty() &&
891 !omnibox_view_->model()->is_keyword_hint(); 896 !omnibox_view_->model()->is_keyword_hint();
892 } 897 }
893 898
894 bool LocationBarView::ShouldShowSecurityChip() const { 899 bool LocationBarView::ShouldShowLocationIconText() const {
900 if (!GetOmniboxView()->IsEditingOrEmpty() &&
901 GetToolbarModel()->GetURL().SchemeIs(extensions::kExtensionScheme))
902 return true;
903
895 using SecurityLevel = security_state::SecurityLevel; 904 using SecurityLevel = security_state::SecurityLevel;
896 const SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); 905 const SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false);
897 return level == SecurityLevel::EV_SECURE || level == SecurityLevel::SECURE || 906 return level == SecurityLevel::EV_SECURE || level == SecurityLevel::SECURE ||
898 level == SecurityLevel::DANGEROUS || 907 level == SecurityLevel::DANGEROUS ||
899 level == SecurityLevel::HTTP_SHOW_WARNING; 908 level == SecurityLevel::HTTP_SHOW_WARNING;
900 } 909 }
901 910
902 bool LocationBarView::ShouldAnimateSecurityChip() const { 911 bool LocationBarView::ShouldAnimateLocationIconTextVisibilityChange() const {
912 // Text for extension URLs should not be animated (their security level is
913 // SecurityLevel::NONE).
903 using SecurityLevel = security_state::SecurityLevel; 914 using SecurityLevel = security_state::SecurityLevel;
904 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); 915 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false);
905 return level == SecurityLevel::DANGEROUS || 916 return level == SecurityLevel::DANGEROUS ||
906 level == SecurityLevel::HTTP_SHOW_WARNING; 917 level == SecurityLevel::HTTP_SHOW_WARNING;
907 } 918 }
908 919
909 //////////////////////////////////////////////////////////////////////////////// 920 ////////////////////////////////////////////////////////////////////////////////
910 // LocationBarView, private LocationBar implementation: 921 // LocationBarView, private LocationBar implementation:
911 922
912 void LocationBarView::ShowFirstRunBubble() { 923 void LocationBarView::ShowFirstRunBubble() {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 // LocationBarView, private TemplateURLServiceObserver implementation: 1225 // LocationBarView, private TemplateURLServiceObserver implementation:
1215 1226
1216 void LocationBarView::OnTemplateURLServiceChanged() { 1227 void LocationBarView::OnTemplateURLServiceChanged() {
1217 template_url_service_->RemoveObserver(this); 1228 template_url_service_->RemoveObserver(this);
1218 template_url_service_ = nullptr; 1229 template_url_service_ = nullptr;
1219 // If the browser is no longer active, let's not show the info bubble, as this 1230 // If the browser is no longer active, let's not show the info bubble, as this
1220 // would make the browser the active window again. 1231 // would make the browser the active window again.
1221 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1232 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1222 ShowFirstRunBubble(); 1233 ShowFirstRunBubble();
1223 } 1234 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/location_bar/location_icon_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698