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

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

Issue 2144903004: New location security strings and animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor responses Created 4 years, 3 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return native_theme->GetSystemColor( 319 return native_theme->GetSystemColor(
320 ui::NativeTheme::kColorId_TextfieldDefaultColor); 320 ui::NativeTheme::kColorId_TextfieldDefaultColor);
321 321
322 case SELECTED_TEXT: 322 case SELECTED_TEXT:
323 return native_theme->GetSystemColor( 323 return native_theme->GetSystemColor(
324 ui::NativeTheme::kColorId_TextfieldSelectionColor); 324 ui::NativeTheme::kColorId_TextfieldSelectionColor);
325 325
326 case DEEMPHASIZED_TEXT: 326 case DEEMPHASIZED_TEXT:
327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); 327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128);
328 328
329 case EV_BUBBLE_TEXT_AND_BORDER: 329 case SECURITY_CHIP_TEXT:
330 return ui::MaterialDesignController::IsModeMaterial() 330 return ui::MaterialDesignController::IsModeMaterial()
331 ? GetSecureTextColor( 331 ? GetSecureTextColor(
332 security_state::SecurityStateModel::EV_SECURE) 332 GetToolbarModel()->GetSecurityLevel(false))
333 : SkColorSetRGB(7, 149, 0); 333 : SkColorSetRGB(7, 149, 0);
334 } 334 }
335 NOTREACHED(); 335 NOTREACHED();
336 return gfx::kPlaceholderColor; 336 return gfx::kPlaceholderColor;
337 } 337 }
338 338
339 SkColor LocationBarView::GetSecureTextColor( 339 SkColor LocationBarView::GetSecureTextColor(
340 security_state::SecurityStateModel::SecurityLevel security_level) const { 340 security_state::SecurityStateModel::SecurityLevel security_level) const {
341 if (security_level == 341 if (security_level ==
342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { 342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) {
343 return GetColor(DEEMPHASIZED_TEXT); 343 return GetColor(DEEMPHASIZED_TEXT);
344 } 344 }
345 345
346 SkColor text_color = GetColor(TEXT); 346 SkColor text_color = GetColor(TEXT);
347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || 347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) ||
348 (security_level == security_state::SecurityStateModel::SECURE) || 348 (security_level == security_state::SecurityStateModel::SECURE) ||
349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { 349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) {
350 if (ui::MaterialDesignController::IsModeMaterial()) { 350 if (ui::MaterialDesignController::IsModeMaterial()) {
351 if (color_utils::IsDark(GetColor(BACKGROUND))) 351 if (color_utils::IsDark(GetColor(BACKGROUND)))
352 return text_color; 352 return text_color;
353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) 353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR)
354 text_color = gfx::kGoogleRed700; 354 text_color = gfx::kGoogleRed700;
355 else 355 else
356 text_color = gfx::kGoogleGreen700; 356 text_color = gfx::kGoogleGreen700;
357 } else if (security_level == 357 } else if (security_level ==
358 security_state::SecurityStateModel::SECURITY_ERROR) { 358 security_state::SecurityStateModel::SECURITY_ERROR) {
359 text_color = SkColorSetRGB(162, 0, 0); 359 text_color = SkColorSetRGB(162, 0, 0);
360 } else { 360 } else {
361 text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); 361 text_color = GetColor(SECURITY_CHIP_TEXT);
362 } 362 }
363 } 363 }
364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); 364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND));
365 } 365 }
366 366
367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
368 DCHECK(zoom_view_); 368 DCHECK(zoom_view_);
369 if (RefreshZoomView()) { 369 if (RefreshZoomView()) {
370 Layout(); 370 Layout();
371 SchedulePaint(); 371 SchedulePaint();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 525
526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
527 527
528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
529 529
530 // Compute width of omnibox-leading content. 530 // Compute width of omnibox-leading content.
531 const int edge_thickness = GetHorizontalEdgeThickness(); 531 const int edge_thickness = GetHorizontalEdgeThickness();
532 int leading_width = edge_thickness; 532 int leading_width = edge_thickness;
533 if (ShouldShowKeywordBubble()) { 533 if (ShouldShowKeywordBubble()) {
534 // The selected keyword view can collapse completely. 534 // The selected keyword view can collapse completely.
535 } else if (ShouldShowEVBubble()) { 535 } else if (ShouldShowSecurityChip()) {
536 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + 536 base::string16 security_text = GetSecurityText();
537 location_icon_view_->GetMinimumSizeForLabelText( 537 leading_width +=
538 GetToolbarModel()->GetEVCertName()) 538 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
539 .width(); 539 location_icon_view_->GetMinimumSizeForLabelText(security_text).width();
540 } else { 540 } else {
541 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 541 leading_width += padding + location_icon_view_->GetMinimumSize().width();
542 } 542 }
543 543
544 // Compute width of omnibox-trailing content. 544 // Compute width of omnibox-trailing content.
545 int trailing_width = edge_thickness; 545 int trailing_width = edge_thickness;
546 trailing_width += IncrementalMinimumWidth(star_view_) + 546 trailing_width += IncrementalMinimumWidth(star_view_) +
547 IncrementalMinimumWidth(translate_icon_view_) + 547 IncrementalMinimumWidth(translate_icon_view_) +
548 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 548 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
549 IncrementalMinimumWidth(save_credit_card_icon_view_) + 549 IncrementalMinimumWidth(save_credit_card_icon_view_) +
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 606 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
607 GetOmniboxIcon(template_url->GetExtensionId()); 607 GetOmniboxIcon(template_url->GetExtensionId());
608 selected_keyword_view_->SetImage(image.AsImageSkia()); 608 selected_keyword_view_->SetImage(image.AsImageSkia());
609 selected_keyword_view_->set_is_extension_icon(true); 609 selected_keyword_view_->set_is_extension_icon(true);
610 } else { 610 } else {
611 selected_keyword_view_->ResetImage(); 611 selected_keyword_view_->ResetImage();
612 selected_keyword_view_->set_is_extension_icon(false); 612 selected_keyword_view_->set_is_extension_icon(false);
613 } 613 }
614 } 614 }
615 } else if (ShouldShowEVBubble()) { 615 } else if (ShouldShowSecurityChip()) {
616 location_icon_view_->SetLabel(GetToolbarModel()->GetEVCertName()); 616 location_icon_view_->SetLabel(GetSecurityText());
617 location_icon_view_->SetBackground(true); 617 location_icon_view_->SetBackground(true);
618 // The largest fraction of the omnibox that can be taken by the EV bubble. 618 // The largest fraction of the omnibox that can be taken by the EV bubble.
619 const double kMaxBubbleFraction = 0.5; 619 const double kMaxBubbleFraction = 0.5;
620 leading_decorations.AddDecoration( 620 leading_decorations.AddDecoration(
621 vertical_padding, location_height, false, kMaxBubbleFraction, 621 vertical_padding, location_height, false, kMaxBubbleFraction,
622 bubble_horizontal_padding, item_padding, location_icon_view_); 622 bubble_horizontal_padding, item_padding, location_icon_view_);
623 } else { 623 } else {
624 leading_decorations.AddDecoration(vertical_padding, location_height, 624 leading_decorations.AddDecoration(vertical_padding, location_height,
625 location_icon_view_); 625 location_icon_view_);
626 } 626 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 783 }
784 } 784 }
785 785
786 void LocationBarView::Update(const WebContents* contents) { 786 void LocationBarView::Update(const WebContents* contents) {
787 RefreshContentSettingViews(); 787 RefreshContentSettingViews();
788 RefreshZoomView(); 788 RefreshZoomView();
789 RefreshPageActionViews(); 789 RefreshPageActionViews();
790 RefreshTranslateIcon(); 790 RefreshTranslateIcon();
791 RefreshSaveCreditCardIconView(); 791 RefreshSaveCreditCardIconView();
792 RefreshManagePasswordsIconView(); 792 RefreshManagePasswordsIconView();
793 content::WebContents* web_contents_for_sub_views = 793 WebContents* web_contents_for_sub_views =
794 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents(); 794 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents();
795 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 795 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
796 796
797 if (star_view_) 797 if (star_view_)
798 UpdateBookmarkStarVisibility(); 798 UpdateBookmarkStarVisibility();
799 799
800 if (contents) 800 if (contents)
801 omnibox_view_->OnTabChanged(contents); 801 omnibox_view_->OnTabChanged(contents);
802 else 802 else
803 omnibox_view_->Update(); 803 omnibox_view_->Update();
804 804
805 bool should_show = ShouldShowSecurityChip();
806 location_icon_view_->SetSecurityState(should_show, should_show && !contents);
807
805 OnChanged(); // NOTE: Calls Layout(). 808 OnChanged(); // NOTE: Calls Layout().
806 } 809 }
807 810
808 void LocationBarView::ResetTabState(WebContents* contents) { 811 void LocationBarView::ResetTabState(WebContents* contents) {
809 omnibox_view_->ResetTabState(contents); 812 omnibox_view_->ResetTabState(contents);
810 } 813 }
811 814
812 //////////////////////////////////////////////////////////////////////////////// 815 ////////////////////////////////////////////////////////////////////////////////
813 // LocationBarView, public OmniboxEditController implementation: 816 // LocationBarView, public OmniboxEditController implementation:
814 817
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 if (browser) 1034 if (browser)
1032 FirstRunBubble::ShowBubble(browser, location_icon_view_); 1035 FirstRunBubble::ShowBubble(browser, location_icon_view_);
1033 #endif 1036 #endif
1034 } 1037 }
1035 1038
1036 bool LocationBarView::HasValidSuggestText() const { 1039 bool LocationBarView::HasValidSuggestText() const {
1037 return suggested_text_view_->visible() && 1040 return suggested_text_view_->visible() &&
1038 !suggested_text_view_->size().IsEmpty(); 1041 !suggested_text_view_->size().IsEmpty();
1039 } 1042 }
1040 1043
1044 base::string16 LocationBarView::GetSecurityText() const {
1045 return ShouldShowEVBubble() ? GetToolbarModel()->GetEVCertName()
1046 : GetToolbarModel()->GetSecureVerboseText();
1047 }
1048
1041 bool LocationBarView::ShouldShowKeywordBubble() const { 1049 bool LocationBarView::ShouldShowKeywordBubble() const {
1042 return !omnibox_view_->model()->keyword().empty() && 1050 return !omnibox_view_->model()->keyword().empty() &&
1043 !omnibox_view_->model()->is_keyword_hint(); 1051 !omnibox_view_->model()->is_keyword_hint();
1044 } 1052 }
1045 1053
1046 bool LocationBarView::ShouldShowEVBubble() const { 1054 bool LocationBarView::ShouldShowEVBubble() const {
1047 return (GetToolbarModel()->GetSecurityLevel(false) == 1055 return (GetToolbarModel()->GetSecurityLevel(false) ==
1048 security_state::SecurityStateModel::EV_SECURE); 1056 security_state::SecurityStateModel::EV_SECURE);
1049 } 1057 }
1050 1058
1059 bool LocationBarView::ShouldShowSecurityChip() const {
1060 using SecurityLevel = security_state::SecurityStateModel::SecurityLevel;
1061 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false);
1062 return level == SecurityLevel::SECURE || level == SecurityLevel::EV_SECURE ||
1063 level == SecurityLevel::SECURITY_ERROR;
1064 }
1065
1051 //////////////////////////////////////////////////////////////////////////////// 1066 ////////////////////////////////////////////////////////////////////////////////
1052 // LocationBarView, private LocationBar implementation: 1067 // LocationBarView, private LocationBar implementation:
1053 1068
1054 void LocationBarView::ShowFirstRunBubble() { 1069 void LocationBarView::ShowFirstRunBubble() {
1055 // Wait until search engines have loaded to show the first run bubble. 1070 // Wait until search engines have loaded to show the first run bubble.
1056 TemplateURLService* url_service = 1071 TemplateURLService* url_service =
1057 TemplateURLServiceFactory::GetForProfile(profile()); 1072 TemplateURLServiceFactory::GetForProfile(profile());
1058 if (!url_service->loaded()) { 1073 if (!url_service->loaded()) {
1059 template_url_service_ = url_service; 1074 template_url_service_ = url_service;
1060 template_url_service_->AddObserver(this); 1075 template_url_service_->AddObserver(this);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // LocationBarView, private TemplateURLServiceObserver implementation: 1400 // LocationBarView, private TemplateURLServiceObserver implementation:
1386 1401
1387 void LocationBarView::OnTemplateURLServiceChanged() { 1402 void LocationBarView::OnTemplateURLServiceChanged() {
1388 template_url_service_->RemoveObserver(this); 1403 template_url_service_->RemoveObserver(this);
1389 template_url_service_ = nullptr; 1404 template_url_service_ = nullptr;
1390 // If the browser is no longer active, let's not show the info bubble, as this 1405 // If the browser is no longer active, let's not show the info bubble, as this
1391 // would make the browser the active window again. 1406 // would make the browser the active window again.
1392 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1407 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1393 ShowFirstRunBubble(); 1408 ShowFirstRunBubble();
1394 } 1409 }
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