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( ...@@ -1060,9 +1060,9 @@ base::string16 ChromePasswordProtectionService::GetWarningDetailText(
IDS_PAGE_INFO_CHANGE_PASSWORD_DETAILS_ENTERPRISE); IDS_PAGE_INFO_CHANGE_PASSWORD_DETAILS_ENTERPRISE);
} }
base::string16 std::vector<base::string16>
ChromePasswordProtectionService::GetWarningDetailTextForSavedPasswords( ChromePasswordProtectionService::GetPlaceholdersForSavedPasswordWarningText()
std::vector<size_t>* placeholder_offsets) const { const {
const std::vector<std::string>& matching_domains = const std::vector<std::string>& matching_domains =
saved_passwords_matching_domains(); saved_passwords_matching_domains();
const std::list<std::string>& spoofed_domains = common_spoofed_domains(); const std::list<std::string>& spoofed_domains = common_spoofed_domains();
...@@ -1092,7 +1092,14 @@ ChromePasswordProtectionService::GetWarningDetailTextForSavedPasswords( ...@@ -1092,7 +1092,14 @@ ChromePasswordProtectionService::GetWarningDetailTextForSavedPasswords(
placeholders.push_back(base::UTF8ToUTF16(matching_domains[idx])); placeholders.push_back(base::UTF8ToUTF16(matching_domains[idx]));
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 // 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. // are no saved domains, default to original saved passwords reuse warning.
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
......
...@@ -174,6 +174,11 @@ class ChromePasswordProtectionService : public PasswordProtectionService { ...@@ -174,6 +174,11 @@ class ChromePasswordProtectionService : public PasswordProtectionService {
ReusedPasswordAccountType password_type, ReusedPasswordAccountType password_type,
std::vector<size_t>* placeholder_offsets) const; 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 // If password protection trigger is configured via enterprise policy, gets
// the name of the organization that owns the enterprise policy. Otherwise, // the name of the organization that owns the enterprise policy. Otherwise,
// returns an empty string. // returns an empty string.
......
...@@ -148,12 +148,15 @@ PasswordReuseModalWarningDialog::PasswordReuseModalWarningDialog( ...@@ -148,12 +148,15 @@ PasswordReuseModalWarningDialog::PasswordReuseModalWarningDialog(
service_->AddObserver(this); service_->AddObserver(this);
std::vector<size_t> placeholder_offsets; std::vector<size_t> placeholder_offsets;
if (password_type.account_type() == if (password_type.account_type() ==
ReusedPasswordAccountType::SAVED_PASSWORD) { ReusedPasswordAccountType::SAVED_PASSWORD) {
const base::string16 message_body = const base::string16 message_body =
service_->GetWarningDetailText(password_type, &placeholder_offsets); service_->GetWarningDetailText(password_type, &placeholder_offsets);
CreateSavedPasswordReuseModalWarningDialog(message_body,
placeholder_offsets); CreateSavedPasswordReuseModalWarningDialog(
message_body, service_->GetPlaceholdersForSavedPasswordWarningText(),
placeholder_offsets);
} else { } else {
views::Label* message_body_label = CreateMessageBodyLabel( views::Label* message_body_label = CreateMessageBodyLabel(
service_ service_
...@@ -172,6 +175,7 @@ PasswordReuseModalWarningDialog::~PasswordReuseModalWarningDialog() { ...@@ -172,6 +175,7 @@ PasswordReuseModalWarningDialog::~PasswordReuseModalWarningDialog() {
void PasswordReuseModalWarningDialog:: void PasswordReuseModalWarningDialog::
CreateSavedPasswordReuseModalWarningDialog( CreateSavedPasswordReuseModalWarningDialog(
const base::string16 message_body, const base::string16 message_body,
std::vector<base::string16> placeholders,
std::vector<size_t> placeholder_offsets) { std::vector<size_t> placeholder_offsets) {
SetLayoutManager(std::make_unique<BoxLayout>( SetLayoutManager(std::make_unique<BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(), views::BoxLayout::Orientation::kVertical, gfx::Insets(),
...@@ -186,17 +190,10 @@ void PasswordReuseModalWarningDialog:: ...@@ -186,17 +190,10 @@ void PasswordReuseModalWarningDialog::
new views::StyledLabel(message_body, nullptr); new views::StyledLabel(message_body, nullptr);
views::StyledLabel::RangeStyleInfo bold_style; views::StyledLabel::RangeStyleInfo bold_style;
bold_style.text_style = STYLE_EMPHASIZED; 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++) { for (size_t idx = 0; idx < placeholder_offsets.size(); idx++) {
styled_message_body_label->AddStyleRange( styled_message_body_label->AddStyleRange(
gfx::Range( gfx::Range(placeholder_offsets[idx],
placeholder_offsets[idx], placeholder_offsets[idx] + placeholders.at(idx).length()),
placeholder_offsets[idx] + converted_domains.at(idx).length()),
bold_style); bold_style);
} }
styled_message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); styled_message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
......
...@@ -35,6 +35,7 @@ class PasswordReuseModalWarningDialog ...@@ -35,6 +35,7 @@ class PasswordReuseModalWarningDialog
void CreateSavedPasswordReuseModalWarningDialog( void CreateSavedPasswordReuseModalWarningDialog(
const base::string16 message_body, const base::string16 message_body,
std::vector<base::string16> placeholders,
std::vector<size_t> placeholder_offsets); std::vector<size_t> placeholder_offsets);
void CreateGaiaPasswordReuseModalWarningDialog( void CreateGaiaPasswordReuseModalWarningDialog(
views::Label* message_body_label); 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