Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where editing a frequent site wouldn't apply the change. #14293

Merged
merged 1 commit into from
Jul 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions browser/ui/webui/new_tab_page/top_sites_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,25 @@ void TopSitesMessageHandler::HandleEditTopSite(const base::Value::List& args) {

GURL gurl(url);
GURL new_gurl(new_url);
std::u16string title16 = base::UTF8ToUTF16(title);

if (most_visited_sites_->IsCustomLinksEnabled()) {
// similar to `MostVisitedHandler::UpdateMostVisitedTile`
most_visited_sites_->UpdateCustomLink(
gurl, new_gurl != gurl ? new_gurl : GURL(), base::UTF8ToUTF16(title));
gurl, new_gurl != gurl ? new_gurl : GURL(), title16);
} else {
// when user modifies current top sites, change to favorite mode.
profile_->GetPrefs()->SetBoolean(ntp_prefs::kNtpUseMostVisitedTiles, false);
most_visited_sites_->EnableCustomLinks(IsCustomLinksEnabled());

// When user tries to edit from frecency mode, we just try to add modified
// item to favorites. If modified url is already existed in favorites,
// nothing happened.
most_visited_sites_->AddCustomLink(
new_url.empty() ? GURL(url) : GURL(new_url), base::UTF8ToUTF16(title));
// When user tries to edit from frecency mode, try to edit an existing
// site, if one exists. If none exists, add a new custom link for the site.
bool updated = most_visited_sites_->UpdateCustomLink(
gurl, new_gurl, base::UTF8ToUTF16(title));
if (!updated) {
most_visited_sites_->AddCustomLink(new_url.empty() ? gurl : new_gurl,
title16);
}
}
}

Expand Down