1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/page_info/page_info_security_content_view.h"
#include <string>
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/page_info/page_info_view_factory.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "net/base/features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h"
PageInfoSecurityContentView::PageInfoSecurityContentView(
PageInfo* presenter,
bool is_standalone_page)
: presenter_(presenter) {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
security_view_ = AddChildView(std::make_unique<SecurityInformationView>(
ChromeLayoutProvider::Get()
->GetInsetsMetric(views::INSETS_DIALOG)
.left()));
if (is_standalone_page) {
const int bottom_margin = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_CONTENT_LIST_VERTICAL_MULTI);
// The last view in the subpage is a RichHoverButton, which overrides the
// bottom dialog inset in favor of its own.
SetProperty(views::kMarginsKey, gfx::Insets::TLBR(0, 0, bottom_margin, 0));
presenter_->InitializeUiState(this, base::DoNothing());
}
}
PageInfoSecurityContentView::~PageInfoSecurityContentView() = default;
void PageInfoSecurityContentView::SetIdentityInfo(
const IdentityInfo& identity_info) {
std::unique_ptr<PageInfoUI::SecurityDescription> security_description =
GetSecurityDescription(identity_info);
security_description_type_ = security_description->type;
const int icon_size = GetLayoutConstant(PAGE_INFO_ICON_SIZE);
if (security_description->summary_style == SecuritySummaryColor::RED) {
if (identity_info.safe_browsing_status ==
PageInfo::SAFE_BROWSING_STATUS_MALWARE ||
identity_info.safe_browsing_status ==
PageInfo::SAFE_BROWSING_STATUS_SOCIAL_ENGINEERING ||
identity_info.safe_browsing_status ==
PageInfo::SAFE_BROWSING_STATUS_UNWANTED_SOFTWARE) {
security_view_->SetIcon(ui::ImageModel::FromVectorIcon(
vector_icons::kDangerousIcon, ui::kColorAlertHighSeverity,
icon_size));
} else {
security_view_->SetIcon(ui::ImageModel::FromVectorIcon(
vector_icons::kNotSecureWarningIcon, ui::kColorAlertHighSeverity,
icon_size));
}
security_view_->SetSummary(security_description->summary, STYLE_RED);
} else if (security_description->summary_style ==
SecuritySummaryColor::ENTERPRISE &&
(identity_info.safe_browsing_status ==
PageInfo::SAFE_BROWSING_STATUS_MANAGED_POLICY_WARN ||
identity_info.safe_browsing_status ==
PageInfo::SAFE_BROWSING_STATUS_MANAGED_POLICY_BLOCK)) {
security_view_->SetIcon(
PageInfoViewFactory::GetImageModel(vector_icons::kBusinessIcon));
security_view_->SetSummary(security_description->summary,
views::style::STYLE_BODY_3_MEDIUM);
} else {
security_view_->SetIcon(PageInfoViewFactory::GetConnectionSecureIcon());
security_view_->SetSummary(security_description->summary,
views::style::STYLE_BODY_3_MEDIUM);
}
security_view_->SetDetailsWithLearnMore(
security_description->details,
base::BindRepeating(&PageInfoSecurityContentView::SecurityDetailsClicked,
base::Unretained(this)));
// The "re-enable warnings" button is shown if the user has bypassed SSL
// error interstitials or HTTP warning interstitials (with HTTPS-First Mode
// enabled) on this site.
if (identity_info.show_ssl_decision_revoke_button) {
security_view_->AddResetDecisionsLabel(
base::BindRepeating(&PageInfoSecurityContentView::ResetDecisionsClicked,
base::Unretained(this)));
}
if (identity_info.certificate) {
certificate_ = identity_info.certificate;
// Show information about the page's certificate.
// The text of link to the Certificate Viewer varies depending on the
// validity of the Certificate.
const bool valid_identity =
(identity_info.identity_status != PageInfo::SITE_IDENTITY_STATUS_ERROR);
std::u16string tooltip;
if (valid_identity) {
tooltip = l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_CERTIFICATE_VALID_LINK_TOOLTIP,
base::UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
} else {
tooltip = l10n_util::GetStringUTF16(
IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK_TOOLTIP);
}
// Add the Certificate Section.
const ui::ImageModel icon =
base::FeatureList::IsEnabled(net::features::kVerifyQWACs)
? PageInfoViewFactory::GetImageModel(vector_icons::kStickyNote2Icon)
: (valid_identity ? PageInfoViewFactory::GetImageModel(
vector_icons::kCertificateIcon)
: PageInfoViewFactory::GetImageModel(
vector_icons::kCertificateOffIcon));
const int title_id = (valid_identity && !base::FeatureList::IsEnabled(
net::features::kVerifyQWACs))
? IDS_PAGE_INFO_CERTIFICATE_IS_VALID
: IDS_PAGE_INFO_CERTIFICATE_DETAILS;
std::u16string subtitle_text;
// Only show the EV certificate details if there are no errors or mixed
// content.
if (identity_info.identity_status ==
PageInfo::SITE_IDENTITY_STATUS_EV_CERT &&
identity_info.connection_status ==
PageInfo::SITE_CONNECTION_STATUS_ENCRYPTED) {
// An EV cert is required to have an organization name and a country.
if (!certificate_->subject().organization_names.empty() &&
!certificate_->subject().country_name.empty()) {
subtitle_text = l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_VERIFIED,
base::UTF8ToUTF16(certificate_->subject().organization_names[0]),
base::UTF8ToUTF16(certificate_->subject().country_name));
}
}
if (base::FeatureList::IsEnabled(net::features::kVerifyQWACs)) {
std::u16string qwac_title =
l10n_util::GetStringUTF16(IDS_PAGE_INFO_QWAC_STATUS_TITLE);
const ui::ImageModel qwac_icon =
PageInfoViewFactory::GetImageModel(vector_icons::kQwacStatusIcon);
// If QWAC info line has been added previously, remove the old one before
// recreating it. Re-adding it bumps it to the bottom of the
// container, but its unlikely that the user will notice, since other
// things are changing too.
if (one_qwac_view_) {
RemoveChildViewT(one_qwac_view_.get());
}
if (identity_info.identity_status ==
PageInfo::SITE_IDENTITY_STATUS_1QWAC_CERT &&
identity_info.connection_status ==
PageInfo::SITE_CONNECTION_STATUS_ENCRYPTED) {
one_qwac_view_ = AddChildView(std::make_unique<SecurityInformationView>(
ChromeLayoutProvider::Get()
->GetInsetsMetric(views::INSETS_DIALOG)
.left()));
one_qwac_view_->SetSummary(qwac_title,
views::style::STYLE_BODY_3_MEDIUM);
one_qwac_view_->SetIcon(qwac_icon);
if (certificate_ &&
!certificate_->subject().organization_names.empty() &&
!certificate_->subject().country_name.empty()) {
one_qwac_view_->SetDetails(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_VERIFIED,
base::UTF8ToUTF16(certificate_->subject().organization_names[0]),
base::UTF8ToUTF16(certificate_->subject().country_name)));
}
}
// If QWAC info line has been added previously, remove the old one before
// recreating it. Re-adding it bumps it to the bottom of the container,
// but its unlikely that the user will notice, since other things are
// changing too.
if (two_qwac_button_) {
RemoveChildViewT(two_qwac_button_.get());
}
if (identity_info.two_qwac) {
two_qwac_ = identity_info.two_qwac;
std::u16string qwac_subtitle;
if (!two_qwac_->subject().organization_names.empty() &&
!two_qwac_->subject().country_name.empty()) {
qwac_subtitle = l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_VERIFIED,
base::UTF8ToUTF16(two_qwac_->subject().organization_names[0]),
base::UTF8ToUTF16(two_qwac_->subject().country_name));
}
two_qwac_button_ = AddChildView(std::make_unique<RichHoverButton>(
base::BindRepeating(
[](PageInfoSecurityContentView* view) {
view->presenter_->OpenCertificateDialog(
view->two_qwac_.get());
},
this),
qwac_icon, qwac_title, qwac_subtitle,
PageInfoViewFactory::GetLaunchIcon()));
two_qwac_button_->SetTitleTextStyleAndColor(
views::style::STYLE_BODY_3_MEDIUM, kColorPageInfoForeground);
two_qwac_button_->SetSubtitleTextStyleAndColor(
views::style::STYLE_BODY_4, kColorPageInfoSubtitleForeground);
}
}
// If the certificate button has been added previously, remove the old one
// before recreating it. Re-adding it bumps it to the bottom of the
// container, but its unlikely that the user will notice, since other
// things are changing too.
if (certificate_button_) {
RemoveChildViewT(certificate_button_.get());
}
certificate_button_ =
AddChildViewRaw(std::make_unique<RichHoverButton>(
base::BindRepeating(
[](PageInfoSecurityContentView* view) {
view->presenter_->OpenCertificateDialog(
view->certificate_.get());
},
this),
icon, l10n_util::GetStringUTF16(title_id),
subtitle_text, PageInfoViewFactory::GetLaunchIcon())
.release());
certificate_button_->SetID(
PageInfoViewFactory::
VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_CERTIFICATE_VIEWER);
certificate_button_->SetTooltipText(tooltip);
certificate_button_->SetTitleTextStyleAndColor(
views::style::STYLE_BODY_3_MEDIUM, kColorPageInfoForeground);
certificate_button_->SetSubtitleTextStyleAndColor(
views::style::STYLE_BODY_4, kColorPageInfoSubtitleForeground);
}
if (identity_info.show_change_password_buttons) {
security_view_->AddPasswordReuseButtons(
identity_info.safe_browsing_status,
base::BindRepeating(
[](PageInfoSecurityContentView* view) {
view->presenter_->OnChangePasswordButtonPressed();
},
this),
base::BindRepeating(
[](PageInfoSecurityContentView* view) {
view->GetWidget()->Close();
view->presenter_->OnAllowlistPasswordReuseButtonPressed();
},
this));
}
PreferredSizeChanged();
}
void PageInfoSecurityContentView::ResetDecisionsClicked() {
presenter_->OnRevokeSSLErrorBypassButtonPressed();
GetWidget()->Close();
}
void PageInfoSecurityContentView::SecurityDetailsClicked(
const ui::Event& event) {
if (security_description_type_ == SecurityDescriptionType::SAFETY_TIP) {
presenter_->OpenSafetyTipHelpCenterPage();
} else if (security_description_type_ ==
SecurityDescriptionType::SAFE_BROWSING) {
presenter_->OpenSafeBrowsingHelpCenterPage(event);
} else {
presenter_->OpenConnectionHelpCenterPage(event);
}
}
BEGIN_METADATA(PageInfoSecurityContentView)
END_METADATA
|