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

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: Don't animate if level is same Created 4 years, 4 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 zoom_view_(nullptr), 131 zoom_view_(nullptr),
132 open_pdf_in_reader_view_(nullptr), 132 open_pdf_in_reader_view_(nullptr),
133 manage_passwords_icon_view_(nullptr), 133 manage_passwords_icon_view_(nullptr),
134 save_credit_card_icon_view_(nullptr), 134 save_credit_card_icon_view_(nullptr),
135 translate_icon_view_(nullptr), 135 translate_icon_view_(nullptr),
136 star_view_(nullptr), 136 star_view_(nullptr),
137 size_animation_(this), 137 size_animation_(this),
138 is_popup_mode_(is_popup_mode), 138 is_popup_mode_(is_popup_mode),
139 show_focus_rect_(false), 139 show_focus_rect_(false),
140 template_url_service_(NULL), 140 template_url_service_(NULL),
141 web_contents_null_at_last_refresh_(true) { 141 web_contents_null_at_last_refresh_(true),
142 previous_security_level_(
143 security_state::SecurityStateModel::SecurityLevel::NONE) {
142 edit_bookmarks_enabled_.Init( 144 edit_bookmarks_enabled_.Init(
143 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 145 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
144 base::Bind(&LocationBarView::UpdateWithoutTabRestore, 146 base::Bind(&LocationBarView::UpdateWithoutTabRestore,
145 base::Unretained(this))); 147 base::Unretained(this)));
146 148
147 zoom::ZoomEventManager::GetForBrowserContext(profile) 149 zoom::ZoomEventManager::GetForBrowserContext(profile)
148 ->AddZoomEventManagerObserver(this); 150 ->AddZoomEventManagerObserver(this);
149 } 151 }
150 152
151 LocationBarView::~LocationBarView() { 153 LocationBarView::~LocationBarView() {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return native_theme->GetSystemColor( 321 return native_theme->GetSystemColor(
320 ui::NativeTheme::kColorId_TextfieldDefaultColor); 322 ui::NativeTheme::kColorId_TextfieldDefaultColor);
321 323
322 case SELECTED_TEXT: 324 case SELECTED_TEXT:
323 return native_theme->GetSystemColor( 325 return native_theme->GetSystemColor(
324 ui::NativeTheme::kColorId_TextfieldSelectionColor); 326 ui::NativeTheme::kColorId_TextfieldSelectionColor);
325 327
326 case DEEMPHASIZED_TEXT: 328 case DEEMPHASIZED_TEXT:
327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); 329 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128);
328 330
329 case EV_BUBBLE_TEXT_AND_BORDER: 331 case SECURITY_CHIP_TEXT_AND_BORDER:
330 return ui::MaterialDesignController::IsModeMaterial() 332 return ui::MaterialDesignController::IsModeMaterial()
331 ? GetSecureTextColor( 333 ? GetSecureTextColor(
332 security_state::SecurityStateModel::EV_SECURE) 334 GetToolbarModel()->GetSecurityLevel(false))
333 : SkColorSetRGB(7, 149, 0); 335 : SkColorSetRGB(7, 149, 0);
334 } 336 }
335 NOTREACHED(); 337 NOTREACHED();
336 return gfx::kPlaceholderColor; 338 return gfx::kPlaceholderColor;
337 } 339 }
338 340
339 SkColor LocationBarView::GetSecureTextColor( 341 SkColor LocationBarView::GetSecureTextColor(
340 security_state::SecurityStateModel::SecurityLevel security_level) const { 342 security_state::SecurityStateModel::SecurityLevel security_level) const {
341 if (security_level == 343 if (security_level ==
342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { 344 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) {
343 return GetColor(DEEMPHASIZED_TEXT); 345 return GetColor(DEEMPHASIZED_TEXT);
344 } 346 }
345 347
346 SkColor text_color = GetColor(TEXT); 348 SkColor text_color = GetColor(TEXT);
347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || 349 if ((security_level == security_state::SecurityStateModel::EV_SECURE) ||
348 (security_level == security_state::SecurityStateModel::SECURE) || 350 (security_level == security_state::SecurityStateModel::SECURE) ||
349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { 351 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) {
350 if (ui::MaterialDesignController::IsModeMaterial()) { 352 if (ui::MaterialDesignController::IsModeMaterial()) {
351 if (color_utils::IsDark(GetColor(BACKGROUND))) 353 if (color_utils::IsDark(GetColor(BACKGROUND)))
352 return text_color; 354 return text_color;
353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) 355 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR)
354 text_color = gfx::kGoogleRed700; 356 text_color = gfx::kGoogleRed700;
355 else 357 else
356 text_color = gfx::kGoogleGreen700; 358 text_color = gfx::kGoogleGreen700;
357 } else if (security_level == 359 } else if (security_level ==
358 security_state::SecurityStateModel::SECURITY_ERROR) { 360 security_state::SecurityStateModel::SECURITY_ERROR) {
359 text_color = SkColorSetRGB(162, 0, 0); 361 text_color = SkColorSetRGB(162, 0, 0);
360 } else { 362 } else {
361 text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); 363 text_color = GetColor(SECURITY_CHIP_TEXT_AND_BORDER);
362 } 364 }
363 } 365 }
364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); 366 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND));
365 } 367 }
366 368
367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 369 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
368 DCHECK(zoom_view_); 370 DCHECK(zoom_view_);
369 if (RefreshZoomView()) { 371 if (RefreshZoomView()) {
370 Layout(); 372 Layout();
371 SchedulePaint(); 373 SchedulePaint();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 527
526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 528 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
527 529
528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 530 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
529 531
530 // Compute width of omnibox-leading content. 532 // Compute width of omnibox-leading content.
531 const int edge_thickness = GetHorizontalEdgeThickness(); 533 const int edge_thickness = GetHorizontalEdgeThickness();
532 int leading_width = edge_thickness; 534 int leading_width = edge_thickness;
533 if (ShouldShowKeywordBubble()) { 535 if (ShouldShowKeywordBubble()) {
534 // The selected keyword view can collapse completely. 536 // The selected keyword view can collapse completely.
535 } else if (ShouldShowEVBubble()) { 537 } else if (ShouldShowSecurityChip()) {
536 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + 538 base::string16 security_text = GetSecurityText();
537 location_icon_view_->GetMinimumSizeForLabelText( 539 leading_width +=
538 GetToolbarModel()->GetEVCertName()) 540 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
539 .width(); 541 location_icon_view_->GetMinimumSizeForLabelText(security_text).width();
540 } else { 542 } else {
541 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 543 leading_width += padding + location_icon_view_->GetMinimumSize().width();
542 } 544 }
543 545
544 // Compute width of omnibox-trailing content. 546 // Compute width of omnibox-trailing content.
545 int trailing_width = edge_thickness; 547 int trailing_width = edge_thickness;
546 trailing_width += IncrementalMinimumWidth(star_view_) + 548 trailing_width += IncrementalMinimumWidth(star_view_) +
547 IncrementalMinimumWidth(translate_icon_view_) + 549 IncrementalMinimumWidth(translate_icon_view_) +
548 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 550 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
549 IncrementalMinimumWidth(save_credit_card_icon_view_) + 551 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)) { 607 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 608 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
607 GetOmniboxIcon(template_url->GetExtensionId()); 609 GetOmniboxIcon(template_url->GetExtensionId());
608 selected_keyword_view_->SetImage(image.AsImageSkia()); 610 selected_keyword_view_->SetImage(image.AsImageSkia());
609 selected_keyword_view_->set_is_extension_icon(true); 611 selected_keyword_view_->set_is_extension_icon(true);
610 } else { 612 } else {
611 selected_keyword_view_->ResetImage(); 613 selected_keyword_view_->ResetImage();
612 selected_keyword_view_->set_is_extension_icon(false); 614 selected_keyword_view_->set_is_extension_icon(false);
613 } 615 }
614 } 616 }
615 } else if (ShouldShowEVBubble()) { 617 } else if (ShouldShowSecurityChip()) {
616 location_icon_view_->SetLabel(GetToolbarModel()->GetEVCertName()); 618 location_icon_view_->SetLabel(GetSecurityText());
617 location_icon_view_->SetBackground(true); 619 location_icon_view_->SetBackground(true);
618 // The largest fraction of the omnibox that can be taken by the EV bubble. 620 // The largest fraction of the omnibox that can be taken by the EV bubble.
619 const double kMaxBubbleFraction = 0.5; 621 const double kMaxBubbleFraction = 0.5;
620 leading_decorations.AddDecoration( 622 leading_decorations.AddDecoration(
621 vertical_padding, location_height, false, kMaxBubbleFraction, 623 vertical_padding, location_height, false, kMaxBubbleFraction,
622 bubble_horizontal_padding, item_padding, location_icon_view_); 624 bubble_horizontal_padding, item_padding, location_icon_view_);
623 } else { 625 } else {
624 leading_decorations.AddDecoration(vertical_padding, location_height, 626 leading_decorations.AddDecoration(vertical_padding, location_height,
625 location_icon_view_); 627 location_icon_view_);
626 } 628 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 785 }
784 } 786 }
785 787
786 void LocationBarView::Update(const WebContents* contents) { 788 void LocationBarView::Update(const WebContents* contents) {
787 RefreshContentSettingViews(); 789 RefreshContentSettingViews();
788 RefreshZoomView(); 790 RefreshZoomView();
789 RefreshPageActionViews(); 791 RefreshPageActionViews();
790 RefreshTranslateIcon(); 792 RefreshTranslateIcon();
791 RefreshSaveCreditCardIconView(); 793 RefreshSaveCreditCardIconView();
792 RefreshManagePasswordsIconView(); 794 RefreshManagePasswordsIconView();
793 content::WebContents* web_contents_for_sub_views = 795 WebContents* web_contents_for_sub_views =
794 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents(); 796 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents();
795 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 797 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
796 798
797 if (star_view_) 799 if (star_view_)
798 UpdateBookmarkStarVisibility(); 800 UpdateBookmarkStarVisibility();
799 801
800 if (contents) 802 if (contents)
801 omnibox_view_->OnTabChanged(contents); 803 omnibox_view_->OnTabChanged(contents);
802 else 804 else
803 omnibox_view_->Update(); 805 omnibox_view_->Update();
804 806
807 if (ShouldShowSecurityChip()) {
808 security_state::SecurityStateModel::SecurityLevel level =
809 GetToolbarModel()->GetSecurityLevel(false);
810 if (level == security_state::SecurityStateModel::SecurityLevel::EV_SECURE)
811 level = security_state::SecurityStateModel::SecurityLevel::SECURE;
812 if (previous_security_level_ != level) {
813 previous_security_level_ = level;
814 location_icon_view_->AnimateSecurityChip();
815 } else if (!location_icon_view_->IsAnimatingSecurityChip()) {
816 location_icon_view_->ShowSecurityChip();
817 }
Peter Kasting 2016/08/20 01:16:43 I don't understand why this whole complicated bloc
Kevin Bailey 2016/08/22 15:58:56 Correct. I assumed that you saw this in: coderevi
Peter Kasting 2016/08/22 22:58:09 I left a similar comment there. THanks for pointi
Kevin Bailey 2016/08/23 15:17:13 When the user presses back arrow or forwards, cont
Peter Kasting 2016/08/23 18:01:57 Yes, because that's an update to the state of the
Kevin Bailey 2016/08/23 20:01:39 I'm not sure who "we" is, but LocationBarView::Upd
Peter Kasting 2016/08/23 20:11:00 You always tell the icon to animate (or snap, if t
Kevin Bailey 2016/08/23 20:39:25 The UI designers want it such that, if you go from
Peter Kasting 2016/08/23 20:42:20 I'm confused. That's what you should get with my
groby-ooo-7-16 2016/08/23 22:11:15 I think the confusion here stems from a previous c
Peter Kasting 2016/08/23 22:17:18 No. We don't need to track the previous level. I
groby-ooo-7-16 2016/08/23 23:12:40 Thank you for clarifying that! That does cover the
Peter Kasting 2016/08/23 23:19:15 OK, that contradicts Kevin's earlier comment. I w
818 } else {
819 previous_security_level_ = GetToolbarModel()->GetSecurityLevel(false);
820 location_icon_view_->HideSecurityChip();
821 }
822
805 OnChanged(); // NOTE: Calls Layout(). 823 OnChanged(); // NOTE: Calls Layout().
806 } 824 }
807 825
808 void LocationBarView::ResetTabState(WebContents* contents) { 826 void LocationBarView::ResetTabState(WebContents* contents) {
809 omnibox_view_->ResetTabState(contents); 827 omnibox_view_->ResetTabState(contents);
810 } 828 }
811 829
812 //////////////////////////////////////////////////////////////////////////////// 830 ////////////////////////////////////////////////////////////////////////////////
813 // LocationBarView, public OmniboxEditController implementation: 831 // LocationBarView, public OmniboxEditController implementation:
814 832
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 if (browser) 1049 if (browser)
1032 FirstRunBubble::ShowBubble(browser, location_icon_view_); 1050 FirstRunBubble::ShowBubble(browser, location_icon_view_);
1033 #endif 1051 #endif
1034 } 1052 }
1035 1053
1036 bool LocationBarView::HasValidSuggestText() const { 1054 bool LocationBarView::HasValidSuggestText() const {
1037 return suggested_text_view_->visible() && 1055 return suggested_text_view_->visible() &&
1038 !suggested_text_view_->size().IsEmpty(); 1056 !suggested_text_view_->size().IsEmpty();
1039 } 1057 }
1040 1058
1059 base::string16 LocationBarView::GetSecurityText() const {
1060 return ShouldShowEVBubble() ? GetToolbarModel()->GetEVCertName()
1061 : GetToolbarModel()->GetSecureVerboseText();
1062 }
1063
1041 bool LocationBarView::ShouldShowKeywordBubble() const { 1064 bool LocationBarView::ShouldShowKeywordBubble() const {
1042 return !omnibox_view_->model()->keyword().empty() && 1065 return !omnibox_view_->model()->keyword().empty() &&
1043 !omnibox_view_->model()->is_keyword_hint(); 1066 !omnibox_view_->model()->is_keyword_hint();
1044 } 1067 }
1045 1068
1046 bool LocationBarView::ShouldShowEVBubble() const { 1069 bool LocationBarView::ShouldShowEVBubble() const {
1047 return (GetToolbarModel()->GetSecurityLevel(false) == 1070 return (GetToolbarModel()->GetSecurityLevel(false) ==
1048 security_state::SecurityStateModel::EV_SECURE); 1071 security_state::SecurityStateModel::EV_SECURE);
1049 } 1072 }
1050 1073
1074 bool LocationBarView::ShouldShowSecurityChip() const {
1075 if (ShouldShowKeywordBubble())
1076 return false;
1077 using security_state::SecurityStateModel;
1078 SecurityStateModel::SecurityLevel level =
1079 GetToolbarModel()->GetSecurityLevel(false);
1080 return level == SecurityStateModel::SecurityLevel::SECURE ||
1081 level == SecurityStateModel::SecurityLevel::EV_SECURE ||
1082 level == SecurityStateModel::SecurityLevel::SECURITY_ERROR;
1083 }
1084
1051 //////////////////////////////////////////////////////////////////////////////// 1085 ////////////////////////////////////////////////////////////////////////////////
1052 // LocationBarView, private LocationBar implementation: 1086 // LocationBarView, private LocationBar implementation:
1053 1087
1054 void LocationBarView::ShowFirstRunBubble() { 1088 void LocationBarView::ShowFirstRunBubble() {
1055 // Wait until search engines have loaded to show the first run bubble. 1089 // Wait until search engines have loaded to show the first run bubble.
1056 TemplateURLService* url_service = 1090 TemplateURLService* url_service =
1057 TemplateURLServiceFactory::GetForProfile(profile()); 1091 TemplateURLServiceFactory::GetForProfile(profile());
1058 if (!url_service->loaded()) { 1092 if (!url_service->loaded()) {
1059 template_url_service_ = url_service; 1093 template_url_service_ = url_service;
1060 template_url_service_->AddObserver(this); 1094 template_url_service_->AddObserver(this);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // LocationBarView, private TemplateURLServiceObserver implementation: 1419 // LocationBarView, private TemplateURLServiceObserver implementation:
1386 1420
1387 void LocationBarView::OnTemplateURLServiceChanged() { 1421 void LocationBarView::OnTemplateURLServiceChanged() {
1388 template_url_service_->RemoveObserver(this); 1422 template_url_service_->RemoveObserver(this);
1389 template_url_service_ = nullptr; 1423 template_url_service_ = nullptr;
1390 // If the browser is no longer active, let's not show the info bubble, as this 1424 // 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. 1425 // would make the browser the active window again.
1392 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1426 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1393 ShowFirstRunBubble(); 1427 ShowFirstRunBubble();
1394 } 1428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698