Commit 0710ebc3 authored by Bettina's avatar Bettina Committed by Commit Bot

Bold the correct range for placeholders.

For saved password reuse warning text, the
domains are reordered based off of which are
most commonly spoofed. Thus, the correct domain
ranges should be used when bolding.

Bug: 1038132
Change-Id: If7f372b3bd7b8f2aaf379f556dee5348f1441dce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983352Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Bettina Dea <bdea@chromium.org>
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728005}
parent 0c48d4d6
......@@ -1060,9 +1060,9 @@ base::string16 ChromePasswordProtectionService::GetWarningDetailText(
IDS_PAGE_INFO_CHANGE_PASSWORD_DETAILS_ENTERPRISE);
}
base::string16
ChromePasswordProtectionService::GetWarningDetailTextForSavedPasswords(
std::vector<size_t>* placeholder_offsets) const {
std::vector<base::string16>
ChromePasswordProtectionService::GetPlaceholdersForSavedPasswordWarningText()
const {
const std::vector<std::string>& matching_domains =
saved_passwords_matching_domains();
const std::list<std::string>& spoofed_domains = common_spoofed_domains();
......@@ -1092,7 +1092,14 @@ ChromePasswordProtectionService::GetWarningDetailTextForSavedPasswords(
placeholders.push_back(base::UTF8ToUTF16(matching_domains[idx]));
domains_idx++;
}
return placeholders;
}
base::string16
ChromePasswordProtectionService::GetWarningDetailTextForSavedPasswords(
std::vector<size_t>* placeholder_offsets) const {
std::vector<base::string16> placeholders =
GetPlaceholdersForSavedPasswordWarningText();
// If showing the saved passwords domain experiment is not on or if there is
// are no saved domains, default to original saved passwords reuse warning.
if (!base::FeatureList::IsEnabled(
......
......@@ -174,6 +174,11 @@ class ChromePasswordProtectionService : public PasswordProtectionService {
ReusedPasswordAccountType password_type,
std::vector<size_t>* placeholder_offsets) const;
// Get placeholders for the warning detail text for saved password reuse
// warnings.
std::vector<base::string16> GetPlaceholdersForSavedPasswordWarningText()
const;
// If password protection trigger is configured via enterprise policy, gets
// the name of the organization that owns the enterprise policy. Otherwise,
// returns an empty string.
......
......@@ -148,11 +148,14 @@ PasswordReuseModalWarningDialog::PasswordReuseModalWarningDialog(
service_->AddObserver(this);
std::vector<size_t> placeholder_offsets;
if (password_type.account_type() ==
ReusedPasswordAccountType::SAVED_PASSWORD) {
const base::string16 message_body =
service_->GetWarningDetailText(password_type, &placeholder_offsets);
CreateSavedPasswordReuseModalWarningDialog(message_body,
CreateSavedPasswordReuseModalWarningDialog(
message_body, service_->GetPlaceholdersForSavedPasswordWarningText(),
placeholder_offsets);
} else {
views::Label* message_body_label = CreateMessageBodyLabel(
......@@ -172,6 +175,7 @@ PasswordReuseModalWarningDialog::~PasswordReuseModalWarningDialog() {
void PasswordReuseModalWarningDialog::
CreateSavedPasswordReuseModalWarningDialog(
const base::string16 message_body,
std::vector<base::string16> placeholders,
std::vector<size_t> placeholder_offsets) {
SetLayoutManager(std::make_unique<BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
......@@ -186,17 +190,10 @@ void PasswordReuseModalWarningDialog::
new views::StyledLabel(message_body, nullptr);
views::StyledLabel::RangeStyleInfo bold_style;
bold_style.text_style = STYLE_EMPHASIZED;
const std::vector<std::string>& domains =
service_->saved_passwords_matching_domains();
std::vector<base::string16> converted_domains;
for (size_t idx = 0; idx < placeholder_offsets.size() && idx < 3; idx++) {
converted_domains.push_back(base::UTF8ToUTF16(domains[idx]));
}
for (size_t idx = 0; idx < placeholder_offsets.size(); idx++) {
styled_message_body_label->AddStyleRange(
gfx::Range(
placeholder_offsets[idx],
placeholder_offsets[idx] + converted_domains.at(idx).length()),
gfx::Range(placeholder_offsets[idx],
placeholder_offsets[idx] + placeholders.at(idx).length()),
bold_style);
}
styled_message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
......
......@@ -35,6 +35,7 @@ class PasswordReuseModalWarningDialog
void CreateSavedPasswordReuseModalWarningDialog(
const base::string16 message_body,
std::vector<base::string16> placeholders,
std::vector<size_t> placeholder_offsets);
void CreateGaiaPasswordReuseModalWarningDialog(
views::Label* message_body_label);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment