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

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

Issue 2378623007: [Material] Update Material Security Verbose Decoration Flag (Closed)
Patch Set: fixed an animation error on cocoa Created 4 years, 2 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/command_line.h" 10 #include "base/command_line.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 manage_passwords_icon_view_(nullptr), 134 manage_passwords_icon_view_(nullptr),
135 save_credit_card_icon_view_(nullptr), 135 save_credit_card_icon_view_(nullptr),
136 translate_icon_view_(nullptr), 136 translate_icon_view_(nullptr),
137 star_view_(nullptr), 137 star_view_(nullptr),
138 size_animation_(this), 138 size_animation_(this),
139 is_popup_mode_(is_popup_mode), 139 is_popup_mode_(is_popup_mode),
140 show_focus_rect_(false), 140 show_focus_rect_(false),
141 template_url_service_(NULL), 141 template_url_service_(NULL),
142 web_contents_null_at_last_refresh_(true), 142 web_contents_null_at_last_refresh_(true),
143 should_show_secure_state_(true), 143 should_show_secure_state_(true),
144 should_animate_secure_state_(true) { 144 should_animate_secure_state_(false),
145 should_animate_nonsecure_state_(false) {
145 edit_bookmarks_enabled_.Init( 146 edit_bookmarks_enabled_.Init(
146 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 147 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
147 base::Bind(&LocationBarView::UpdateWithoutTabRestore, 148 base::Bind(&LocationBarView::UpdateWithoutTabRestore,
148 base::Unretained(this))); 149 base::Unretained(this)));
149 150
150 zoom::ZoomEventManager::GetForBrowserContext(profile) 151 zoom::ZoomEventManager::GetForBrowserContext(profile)
151 ->AddZoomEventManagerObserver(this); 152 ->AddZoomEventManagerObserver(this);
152 153
153 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 154 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
154 if (command_line->HasSwitch(switches::kMaterialSecurityVerbose)) { 155 if (command_line->HasSwitch(switches::kSecurityVerboseDecoration)) {
155 std::string security_verbose_flag = 156 std::string security_verbose_flag =
156 command_line->GetSwitchValueASCII(switches::kMaterialSecurityVerbose); 157 command_line->GetSwitchValueASCII(switches::kSecurityVerboseDecoration);
157 158
158 should_show_secure_state_ = 159 should_show_secure_state_ =
159 security_verbose_flag == 160 security_verbose_flag ==
160 switches::kMaterialSecurityVerboseShowAllAnimated || 161 switches::kSecurityVerboseDecorationShowAllAnimated ||
161 security_verbose_flag == 162 security_verbose_flag ==
162 switches::kMaterialSecurityVerboseShowAllNonAnimated; 163 switches::kSecurityVerboseDecorationShowAllNonAnimated ||
164 security_verbose_flag ==
165 switches::
166 kSecurityVerboseDecorationShowAllWithOnlyNonSecureAnimated;
163 167
164 should_animate_secure_state_ = 168 should_animate_secure_state_ =
165 security_verbose_flag == 169 security_verbose_flag ==
166 switches::kMaterialSecurityVerboseShowAllAnimated || 170 switches::kSecurityVerboseDecorationShowAllAnimated;
171
172 should_animate_nonsecure_state_ =
167 security_verbose_flag == 173 security_verbose_flag ==
168 switches::kMaterialSecurityVerboseShowNonSecureAnimated; 174 switches::kSecurityVerboseDecorationShowAllAnimated ||
175 security_verbose_flag ==
176 switches::kSecurityVerboseDecorationShowNonSecureAnimated ||
177 security_verbose_flag ==
178 switches::
179 kSecurityVerboseDecorationShowAllWithOnlyNonSecureAnimated;
169 } 180 }
170 } 181 }
171 182
172 LocationBarView::~LocationBarView() { 183 LocationBarView::~LocationBarView() {
173 if (template_url_service_) 184 if (template_url_service_)
174 template_url_service_->RemoveObserver(this); 185 template_url_service_->RemoveObserver(this);
175 186
176 zoom::ZoomEventManager::GetForBrowserContext(profile()) 187 zoom::ZoomEventManager::GetForBrowserContext(profile())
177 ->RemoveZoomEventManagerObserver(this); 188 ->RemoveZoomEventManagerObserver(this);
178 } 189 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 510
500 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 511 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
501 512
502 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 513 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
503 514
504 // Compute width of omnibox-leading content. 515 // Compute width of omnibox-leading content.
505 const int edge_thickness = GetHorizontalEdgeThickness(); 516 const int edge_thickness = GetHorizontalEdgeThickness();
506 int leading_width = edge_thickness; 517 int leading_width = edge_thickness;
507 if (ShouldShowKeywordBubble()) { 518 if (ShouldShowKeywordBubble()) {
508 // The selected keyword view can collapse completely. 519 // The selected keyword view can collapse completely.
509 } else if (ShouldShowSecurityChip()) { 520 } else if (ShouldShowSecurityChip(nullptr)) {
510 base::string16 security_text = GetSecurityText(); 521 base::string16 security_text = GetSecurityText();
511 leading_width += 522 leading_width +=
512 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + 523 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
513 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); 524 location_icon_view_->GetMinimumSizeForLabelText(security_text).width();
514 } else { 525 } else {
515 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 526 leading_width += padding + location_icon_view_->GetMinimumSize().width();
516 } 527 }
517 528
518 // Compute width of omnibox-trailing content. 529 // Compute width of omnibox-trailing content.
519 int trailing_width = edge_thickness; 530 int trailing_width = edge_thickness;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 GetTemplateURLForKeyword(keyword); 587 GetTemplateURLForKeyword(keyword);
577 if (template_url && 588 if (template_url &&
578 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { 589 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) {
579 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 590 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
580 GetOmniboxIcon(template_url->GetExtensionId()); 591 GetOmniboxIcon(template_url->GetExtensionId());
581 selected_keyword_view_->SetImage(image.AsImageSkia()); 592 selected_keyword_view_->SetImage(image.AsImageSkia());
582 } else { 593 } else {
583 selected_keyword_view_->ResetImage(); 594 selected_keyword_view_->ResetImage();
584 } 595 }
585 } 596 }
586 } else if (ShouldShowSecurityChip()) { 597 } else if (ShouldShowSecurityChip(nullptr)) {
587 location_icon_view_->SetLabel(GetSecurityText()); 598 location_icon_view_->SetLabel(GetSecurityText());
588 // The largest fraction of the omnibox that can be taken by the EV bubble. 599 // The largest fraction of the omnibox that can be taken by the EV bubble.
589 const double kMaxBubbleFraction = 0.5; 600 const double kMaxBubbleFraction = 0.5;
590 leading_decorations.AddDecoration( 601 leading_decorations.AddDecoration(
591 vertical_padding, location_height, false, kMaxBubbleFraction, 602 vertical_padding, location_height, false, kMaxBubbleFraction,
592 bubble_horizontal_padding, item_padding, location_icon_view_); 603 bubble_horizontal_padding, item_padding, location_icon_view_);
593 } else { 604 } else {
594 leading_decorations.AddDecoration(vertical_padding, location_height, 605 leading_decorations.AddDecoration(vertical_padding, location_height,
595 location_icon_view_); 606 location_icon_view_);
596 } 607 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 774 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
764 775
765 if (star_view_) 776 if (star_view_)
766 UpdateBookmarkStarVisibility(); 777 UpdateBookmarkStarVisibility();
767 778
768 if (contents) 779 if (contents)
769 omnibox_view_->OnTabChanged(contents); 780 omnibox_view_->OnTabChanged(contents);
770 else 781 else
771 omnibox_view_->Update(); 782 omnibox_view_->Update();
772 783
773 bool should_show = ShouldShowSecurityChip(); 784 bool should_animate;
774 location_icon_view_->SetSecurityState( 785 bool should_show = ShouldShowSecurityChip(&should_animate);
775 should_show, should_show && !contents && should_animate_secure_state_); 786 location_icon_view_->SetSecurityState(should_show,
787 !contents && should_animate);
776 788
777 OnChanged(); // NOTE: Calls Layout(). 789 OnChanged(); // NOTE: Calls Layout().
778 } 790 }
779 791
780 void LocationBarView::ResetTabState(WebContents* contents) { 792 void LocationBarView::ResetTabState(WebContents* contents) {
781 omnibox_view_->ResetTabState(contents); 793 omnibox_view_->ResetTabState(contents);
782 } 794 }
783 795
784 //////////////////////////////////////////////////////////////////////////////// 796 ////////////////////////////////////////////////////////////////////////////////
785 // LocationBarView, public OmniboxEditController implementation: 797 // LocationBarView, public OmniboxEditController implementation:
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 return !omnibox_view_->model()->keyword().empty() && 1015 return !omnibox_view_->model()->keyword().empty() &&
1004 !omnibox_view_->model()->is_keyword_hint(); 1016 !omnibox_view_->model()->is_keyword_hint();
1005 } 1017 }
1006 1018
1007 bool LocationBarView::ShouldShowEVBubble() const { 1019 bool LocationBarView::ShouldShowEVBubble() const {
1008 return (GetToolbarModel()->GetSecurityLevel(false) == 1020 return (GetToolbarModel()->GetSecurityLevel(false) ==
1009 security_state::SecurityStateModel::EV_SECURE) && 1021 security_state::SecurityStateModel::EV_SECURE) &&
1010 should_show_secure_state_; 1022 should_show_secure_state_;
1011 } 1023 }
1012 1024
1013 bool LocationBarView::ShouldShowSecurityChip() const { 1025 bool LocationBarView::ShouldShowSecurityChip(bool* should_animate) const {
1014 using SecurityLevel = security_state::SecurityStateModel::SecurityLevel; 1026 using SecurityLevel = security_state::SecurityStateModel::SecurityLevel;
1015 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); 1027 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false);
1016 return ((level == SecurityLevel::SECURE || 1028
1017 level == SecurityLevel::EV_SECURE) && 1029 bool should_show =
1018 should_show_secure_state_) || 1030 ((level == SecurityLevel::SECURE || level == SecurityLevel::EV_SECURE) &&
1019 level == SecurityLevel::DANGEROUS; 1031 should_show_secure_state_) ||
1032 level == SecurityLevel::DANGEROUS;
1033
1034 if (should_animate) {
1035 bool is_secure_level =
1036 level == SecurityLevel::EV_SECURE || level == SecurityLevel::SECURE;
1037 *should_animate =
1038 should_show && ((level == SecurityLevel::DANGEROUS &&
1039 should_animate_nonsecure_state_) ||
1040 (is_secure_level && should_animate_secure_state_));
1041 }
1042
1043 return should_show;
1020 } 1044 }
1021 1045
1022 //////////////////////////////////////////////////////////////////////////////// 1046 ////////////////////////////////////////////////////////////////////////////////
1023 // LocationBarView, private LocationBar implementation: 1047 // LocationBarView, private LocationBar implementation:
1024 1048
1025 void LocationBarView::ShowFirstRunBubble() { 1049 void LocationBarView::ShowFirstRunBubble() {
1026 // Wait until search engines have loaded to show the first run bubble. 1050 // Wait until search engines have loaded to show the first run bubble.
1027 TemplateURLService* url_service = 1051 TemplateURLService* url_service =
1028 TemplateURLServiceFactory::GetForProfile(profile()); 1052 TemplateURLServiceFactory::GetForProfile(profile());
1029 if (!url_service->loaded()) { 1053 if (!url_service->loaded()) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 // LocationBarView, private TemplateURLServiceObserver implementation: 1351 // LocationBarView, private TemplateURLServiceObserver implementation:
1328 1352
1329 void LocationBarView::OnTemplateURLServiceChanged() { 1353 void LocationBarView::OnTemplateURLServiceChanged() {
1330 template_url_service_->RemoveObserver(this); 1354 template_url_service_->RemoveObserver(this);
1331 template_url_service_ = nullptr; 1355 template_url_service_ = nullptr;
1332 // If the browser is no longer active, let's not show the info bubble, as this 1356 // If the browser is no longer active, let's not show the info bubble, as this
1333 // would make the browser the active window again. 1357 // would make the browser the active window again.
1334 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1358 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1335 ShowFirstRunBubble(); 1359 ShowFirstRunBubble();
1336 } 1360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698