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

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

Issue 2555063003: Render extension URLs with chips (Closed)
Patch Set: pkasting comments and rebase 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 (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 (ShouldShowSecurityText()) {
460 base::string16 security_text = GetSecurityText(); 460 const base::string16 security_text = GetSecurityText(
461 GetToolbarModel()->GetURL(), delegate_->GetWebContents());
461 leading_width += 462 leading_width +=
462 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); 463 location_icon_view_->GetMinimumSizeForLabelText(security_text).width();
463 } else { 464 } else {
464 leading_width += 465 leading_width +=
465 kHorizontalPadding + location_icon_view_->GetMinimumSize().width(); 466 kHorizontalPadding + location_icon_view_->GetMinimumSize().width();
466 } 467 }
467 468
468 // Compute width of omnibox-trailing content. 469 // Compute width of omnibox-trailing content.
469 int trailing_width = edge_thickness; 470 int trailing_width = edge_thickness;
470 trailing_width += IncrementalMinimumWidth(star_view_) + 471 trailing_width += IncrementalMinimumWidth(star_view_) +
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 GetTemplateURLForKeyword(keyword); 524 GetTemplateURLForKeyword(keyword);
524 if (template_url && 525 if (template_url &&
525 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { 526 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) {
526 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 527 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
527 GetOmniboxIcon(template_url->GetExtensionId()); 528 GetOmniboxIcon(template_url->GetExtensionId());
528 selected_keyword_view_->SetImage(image.AsImageSkia()); 529 selected_keyword_view_->SetImage(image.AsImageSkia());
529 } else { 530 } else {
530 selected_keyword_view_->ResetImage(); 531 selected_keyword_view_->ResetImage();
531 } 532 }
532 } 533 }
533 } else if (ShouldShowSecurityChip()) { 534 } else if (ShouldShowSecurityText()) {
534 location_icon_view_->SetLabel(GetSecurityText()); 535 const base::string16 security_text = GetSecurityText(
536 GetToolbarModel()->GetURL(), delegate_->GetWebContents());
537 location_icon_view_->SetLabel(security_text);
535 // The largest fraction of the omnibox that can be taken by the EV bubble. 538 // The largest fraction of the omnibox that can be taken by the EV bubble.
536 const double kMaxBubbleFraction = 0.5; 539 const double kMaxBubbleFraction = 0.5;
537 leading_decorations.AddDecoration(vertical_padding, location_height, false, 540 leading_decorations.AddDecoration(vertical_padding, location_height, false,
538 kMaxBubbleFraction, 0, item_padding, 541 kMaxBubbleFraction, 0, item_padding,
539 location_icon_view_); 542 location_icon_view_);
540 } else { 543 } else {
541 leading_decorations.AddDecoration(vertical_padding, location_height, 544 leading_decorations.AddDecoration(vertical_padding, location_height,
542 location_icon_view_); 545 location_icon_view_);
543 } 546 }
544 547
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 656 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
654 657
655 if (star_view_) 658 if (star_view_)
656 UpdateBookmarkStarVisibility(); 659 UpdateBookmarkStarVisibility();
657 660
658 if (contents) 661 if (contents)
659 omnibox_view_->OnTabChanged(contents); 662 omnibox_view_->OnTabChanged(contents);
660 else 663 else
661 omnibox_view_->Update(); 664 omnibox_view_->Update();
662 665
663 location_icon_view_->SetSecurityState( 666 location_icon_view_->SetTextVisibility(
664 ShouldShowSecurityChip(), !contents && ShouldAnimateSecurityChip()); 667 ShouldShowSecurityText(), !contents && ShouldAnimateSecurityText());
665
666 OnChanged(); // NOTE: Calls Layout(). 668 OnChanged(); // NOTE: Calls Layout().
667 } 669 }
668 670
669 void LocationBarView::ResetTabState(WebContents* contents) { 671 void LocationBarView::ResetTabState(WebContents* contents) {
670 omnibox_view_->ResetTabState(contents); 672 omnibox_view_->ResetTabState(contents);
671 } 673 }
672 674
673 //////////////////////////////////////////////////////////////////////////////// 675 ////////////////////////////////////////////////////////////////////////////////
674 // LocationBarView, public OmniboxEditController implementation: 676 // LocationBarView, public OmniboxEditController implementation:
675 677
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 #if !defined(OS_CHROMEOS) 874 #if !defined(OS_CHROMEOS)
873 WebContents* web_contents = delegate_->GetWebContents(); 875 WebContents* web_contents = delegate_->GetWebContents();
874 if (!web_contents) 876 if (!web_contents)
875 return; 877 return;
876 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 878 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
877 if (browser) 879 if (browser)
878 FirstRunBubble::ShowBubble(browser, location_icon_view_); 880 FirstRunBubble::ShowBubble(browser, location_icon_view_);
879 #endif 881 #endif
880 } 882 }
881 883
882 base::string16 LocationBarView::GetSecurityText() const { 884 base::string16 LocationBarView::GetSecurityText(const GURL& url,
885 WebContents* contents) const {
886 base::string16 extension_name = GetExtensionName(url, contents);
887 if (!extension_name.empty())
888 return extension_name;
889
883 bool has_ev_cert = 890 bool has_ev_cert =
884 (GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE); 891 (GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE);
885 return has_ev_cert ? GetToolbarModel()->GetEVCertName() 892 return has_ev_cert ? GetToolbarModel()->GetEVCertName()
886 : GetToolbarModel()->GetSecureVerboseText(); 893 : GetToolbarModel()->GetSecureVerboseText();
887 } 894 }
888 895
889 bool LocationBarView::ShouldShowKeywordBubble() const { 896 bool LocationBarView::ShouldShowKeywordBubble() const {
890 return !omnibox_view_->model()->keyword().empty() && 897 return !omnibox_view_->model()->keyword().empty() &&
891 !omnibox_view_->model()->is_keyword_hint(); 898 !omnibox_view_->model()->is_keyword_hint();
892 } 899 }
893 900
894 bool LocationBarView::ShouldShowSecurityChip() const { 901 bool LocationBarView::ShouldShowSecurityText() const {
902 if (GetToolbarModel()->GetURL().SchemeIs(extensions::kExtensionScheme))
903 return true;
904
895 using SecurityLevel = security_state::SecurityLevel; 905 using SecurityLevel = security_state::SecurityLevel;
896 const SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); 906 const SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false);
897 return level == SecurityLevel::EV_SECURE || level == SecurityLevel::SECURE || 907 return level == SecurityLevel::EV_SECURE || level == SecurityLevel::SECURE ||
898 level == SecurityLevel::DANGEROUS || 908 level == SecurityLevel::DANGEROUS ||
899 level == SecurityLevel::HTTP_SHOW_WARNING; 909 level == SecurityLevel::HTTP_SHOW_WARNING;
900 } 910 }
901 911
902 bool LocationBarView::ShouldAnimateSecurityChip() const { 912 bool LocationBarView::ShouldAnimateSecurityText() const {
903 using SecurityLevel = security_state::SecurityLevel; 913 using SecurityLevel = security_state::SecurityLevel;
904 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); 914 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false);
905 return level == SecurityLevel::DANGEROUS || 915 return level == SecurityLevel::DANGEROUS ||
906 level == SecurityLevel::HTTP_SHOW_WARNING; 916 level == SecurityLevel::HTTP_SHOW_WARNING;
907 } 917 }
908 918
909 //////////////////////////////////////////////////////////////////////////////// 919 ////////////////////////////////////////////////////////////////////////////////
910 // LocationBarView, private LocationBar implementation: 920 // LocationBarView, private LocationBar implementation:
911 921
912 void LocationBarView::ShowFirstRunBubble() { 922 void LocationBarView::ShowFirstRunBubble() {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 // LocationBarView, private TemplateURLServiceObserver implementation: 1224 // LocationBarView, private TemplateURLServiceObserver implementation:
1215 1225
1216 void LocationBarView::OnTemplateURLServiceChanged() { 1226 void LocationBarView::OnTemplateURLServiceChanged() {
1217 template_url_service_->RemoveObserver(this); 1227 template_url_service_->RemoveObserver(this);
1218 template_url_service_ = nullptr; 1228 template_url_service_ = nullptr;
1219 // If the browser is no longer active, let's not show the info bubble, as this 1229 // 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. 1230 // would make the browser the active window again.
1221 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1231 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1222 ShowFirstRunBubble(); 1232 ShowFirstRunBubble();
1223 } 1233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698